Compare commits

..
Author SHA1 Message Date
Dylan M. Taylor 11fec161cc Fonts: ignore variation tags the font has no axis for 2026-11-03 20:32:00 +00:00
2 changed files with 14 additions and 26 deletions
+7 -3
View File
@@ -1215,9 +1215,8 @@ impl FontDb {
fn instance(&self, family: &str, style: &str) -> Option<Arc<FontFace>> {
let open = style.find('{')?;
let base = self.find(family, style[..open].trim())?;
if base.skrifa().is_none_or(|f| f.axes().is_empty()) {
return Some(base);
}
let Some(font) = base.skrifa().filter(|f| !f.axes().is_empty()) else { return Some(base) };
let axis_tags: Vec<[u8; 4]> = font.axes().iter().map(|a| a.tag().to_be_bytes()).collect();
let mut coords = base.coords.clone();
for kv in style[open + 1..].trim_end_matches('}').split(',') {
let (k, v) = kv.split_once(':')?;
@@ -1227,6 +1226,11 @@ impl FontDb {
return None;
}
let tag = [k[0], k[1], k[2], k[3]];
// A tag the font has no axis for changes nothing; keeping it would grow the list with
// every distinct tag in the style text.
if !axis_tags.contains(&tag) {
continue;
}
match coords.iter_mut().find(|(t, _)| *t == tag) {
Some(c) => c.1 = v,
None => coords.push((tag, v)),
+7 -23
View File
@@ -61,23 +61,16 @@ pub fn missing(files: &[String], assets_md: &str) -> Vec<String> {
files.iter().filter(|f| is_asset(f) && !patterns.iter().any(|p| glob(p, f))).cloned().collect()
}
/// `*` matches any run of characters except `/`; everything else literally. Matched with a
/// table over the pattern, so a pattern with many `*` costs pattern length times name length
/// rather than exploring every way to split the name.
/// `*` matches any run of characters except `/`; everything else literally.
fn glob(pat: &str, s: &str) -> bool {
let t: Vec<char> = s.chars().collect();
// `row[k]`: the pattern so far matches the first k characters of the name.
let mut row = vec![false; t.len() + 1];
row[0] = true;
for pc in pat.chars() {
let mut next = vec![false; t.len() + 1];
next[0] = pc == '*' && row[0];
for k in 1..=t.len() {
next[k] = if pc == '*' { row[k] || (next[k - 1] && t[k - 1] != '/') } else { row[k - 1] && t[k - 1] == pc };
match pat.split_once('*') {
None => pat == s,
Some((head, tail)) => {
let Some(rest) = s.strip_prefix(head) else { return false };
let ends = rest.char_indices().map(|(i, _)| i).chain(std::iter::once(rest.len()));
ends.take_while(|&i| !rest[..i].contains('/')).any(|i| glob(tail, &rest[i..]))
}
row = next;
}
row[t.len()]
}
/// Splits `git ls-files -z` output into real file names (no display quoting of Unicode or special characters).
@@ -127,15 +120,6 @@ mod tests {
assert_eq!(missing(&["assets/é.png".into()], "`assets/*.svg`"), vec!["assets/é.png".to_string()]);
}
#[test]
fn many_wildcards_on_a_failing_name_finish_at_once() {
let pat = format!("{}b", "a*".repeat(40));
assert!(!glob(&pat, &"a".repeat(60)));
assert!(glob(&pat, &format!("{}b", "a".repeat(60))));
assert!(!glob("a*b", "a/b"));
assert!(glob("a*b", "ab"));
}
#[test]
fn ls_files_output_is_nul_separated_and_unquoted() {
let names = parse_ls_files("assets/zażółć.png\0docs/images/a b\nc.png\0".as_bytes());