Skip to content

Commit ed428e4

Browse files
fschuttclaude
andcommitted
fix: repair red master CI introduced by 4.3.0
tests: 4.3.0 deliberately expanded the macOS/iOS serif + sans-serif lists (Times New Roman; .AppleSystemUIFont/.SFUIText/.SFUI-Regular/Helvetica), mirrored in config.rs's iOS common_font_families, but left test_operating_system_font_expansion asserting the old lists. Update the assertions to match. ffi + examples: the shared-cache refactor renamed FontSource -> OwnedFontSource and FcFontRegistry::into_fc_font_cache -> shared_cache, and list()/get_metadata_by_id() now return owned FcPattern. Update src/ffi.rs and the examples (incl. &pattern borrow in debug_azul_fonts). FFI ABI is unchanged. wasm: FontBytes::Mmapped wrapped mmapio::Mmap but was gated only on std; mmapio is target-gated off wasm, so the variant referenced a missing crate on wasm32. Gate the variant + its match arms on not(target_family="wasm"). warnings: pattern_from_filename was gated std while its sole caller build_from_filenames is std+not(parsing), so --all-features flagged it dead and tripped rust.yml's zero-warning gate. Match the gate. Verified locally: full feature matrix, cross targets (wasm32-{unknown,wasip1}, aarch64-apple-ios{,-sim}, aarch64-linux-android), --features ffi build, and the --all-features no-warnings gate. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6d204c7 commit ed428e4

7 files changed

Lines changed: 26 additions & 18 deletions

File tree

examples/debug_azul_fonts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
oblique: PatternMatch::False,
3232
..Default::default()
3333
},
34-
pattern,
34+
&pattern,
3535
);
3636
println!(
3737
" id={} name={:?} family={:?} italic={:?} bold={:?} weight={:?} stretch={:?} style_score={} subfamily={:?}",
@@ -74,7 +74,7 @@ fn main() {
7474
oblique: PatternMatch::False,
7575
..Default::default()
7676
},
77-
pattern,
77+
&pattern,
7878
);
7979
println!(
8080
" [{}] id={} name={:?} family={:?} italic={:?} bold={:?} weight={:?} style_score={} subfamily={:?}",

examples/integration_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ fn main() {
103103
.unwrap_or("?");
104104
if let Some(source) = cache.get_font_by_id(font_id) {
105105
match source {
106-
rust_fontconfig::FontSource::Disk(path) => {
106+
rust_fontconfig::OwnedFontSource::Disk(path) => {
107107
println!(" {} -> {}", name, path.path);
108108
}
109-
rust_fontconfig::FontSource::Memory(font) => {
109+
rust_fontconfig::OwnedFontSource::Memory(font) => {
110110
println!(" {} -> memory (id: {})", name, font.id);
111111
}
112112
}

examples/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ fn main() {
3131
}
3232
if let Some(source) = cache.get_font_by_id(&result.id) {
3333
match source {
34-
rust_fontconfig::FontSource::Disk(path) => println!(" Path: {}", path.path),
35-
rust_fontconfig::FontSource::Memory(font) => {
34+
rust_fontconfig::OwnedFontSource::Disk(path) => println!(" Path: {}", path.path),
35+
rust_fontconfig::OwnedFontSource::Memory(font) => {
3636
println!(" Memory font: {}", font.id)
3737
}
3838
}

examples/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ fn main() {
137137

138138
// Step 7: Snapshot to FcFontCache for text resolution
139139
let t6 = Instant::now();
140-
let new_cache = registry.into_fc_font_cache();
141-
println!(" 7. into_fc_font_cache() {:>10?}", t6.elapsed());
140+
let new_cache = registry.shared_cache();
141+
println!(" 7. shared_cache() {:>10?}", t6.elapsed());
142142

143143
let new_resolved = new_chain.resolve_text(&new_cache, test_text);
144144
print!(" Text '{}': ", test_text);

src/ffi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ pub extern "C" fn fc_cache_get_font_path(
918918
let id_rust = FontId::from_fontid_c(&*id);
919919

920920
match cache.get_font_by_id(&id_rust) {
921-
Some(FontSource::Disk(path)) => {
921+
Some(OwnedFontSource::Disk(path)) => {
922922
let path_c = FcFontPathC {
923923
path: CString::new(path.path.clone())
924924
.unwrap_or_default()
@@ -928,7 +928,7 @@ pub extern "C" fn fc_cache_get_font_path(
928928

929929
Box::into_raw(Box::new(path_c))
930930
}
931-
Some(FontSource::Memory(font)) => {
931+
Some(OwnedFontSource::Memory(font)) => {
932932
// For memory fonts, return a special path
933933
let path_c = FcFontPathC {
934934
path: CString::new(format!("memory:{}", font.id))
@@ -1626,7 +1626,7 @@ pub extern "C" fn fc_registry_query(
16261626

16271627
match registry.query(&pattern_rust) {
16281628
Some(match_obj) => {
1629-
let cache = registry.into_fc_font_cache();
1629+
let cache = registry.shared_cache();
16301630
let match_c = font_match_to_c(&cache, &match_obj);
16311631
Box::into_raw(Box::new(match_c))
16321632
}
@@ -1760,7 +1760,7 @@ pub extern "C" fn fc_registry_snapshot(
17601760
}
17611761
unsafe {
17621762
let registry = &*registry;
1763-
let cache = registry.into_fc_font_cache();
1763+
let cache = registry.shared_cache();
17641764
Box::into_raw(Box::new(cache))
17651765
}
17661766
}

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,9 @@ pub enum FontBytes {
13441344
/// fallback when mmap is unavailable.
13451345
Owned(std::sync::Arc<[u8]>),
13461346
/// File-backed mmap. Read-only; pages are demand-loaded by the
1347-
/// kernel.
1347+
/// kernel. Absent on wasm targets, where `mmapio` is unavailable
1348+
/// (the optional dep is gated to `cfg(not(target_family="wasm"))`).
1349+
#[cfg(not(target_family = "wasm"))]
13481350
Mmapped(mmapio::Mmap),
13491351
}
13501352

@@ -1355,6 +1357,7 @@ impl FontBytes {
13551357
pub fn as_slice(&self) -> &[u8] {
13561358
match self {
13571359
FontBytes::Owned(arc) => arc,
1360+
#[cfg(not(target_family = "wasm"))]
13581361
FontBytes::Mmapped(m) => &m[..],
13591362
}
13601363
}
@@ -1382,6 +1385,7 @@ impl core::fmt::Debug for FontBytes {
13821385
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
13831386
let kind = match self {
13841387
FontBytes::Owned(_) => "Owned",
1388+
#[cfg(not(target_family = "wasm"))]
13851389
FontBytes::Mmapped(_) => "Mmapped",
13861390
};
13871391
write!(f, "FontBytes::{}({} bytes)", kind, self.as_slice().len())
@@ -4818,7 +4822,11 @@ fn detect_monospace(
48184822
///
48194823
/// Uses [`config::tokenize_font_stem`] and [`config::FONT_STYLE_TOKENS`]
48204824
/// to extract the family name and detect style hints from the filename.
4821-
#[cfg(feature = "std")]
4825+
///
4826+
/// Only compiled for the filename-only (`not(parsing)`) scan path — its
4827+
/// sole caller is [`FcFontCache::build_from_filenames`]. With `parsing`
4828+
/// on, allsorts reads real metadata and this fallback is unused.
4829+
#[cfg(all(feature = "std", not(feature = "parsing")))]
48224830
fn pattern_from_filename(path: &std::path::Path) -> Option<FcPattern> {
48234831
let ext = path.extension()?.to_str()?.to_lowercase();
48244832
match ext.as_str() {

tests/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn test_operating_system_font_expansion() {
2222
let macos_os = OperatingSystem::MacOS;
2323
assert_eq!(
2424
macos_os.get_serif_fonts(no_ranges),
25-
vec!["Times", "New York", "Palatino"].iter().map(|s| s.to_string()).collect::<Vec<_>>()
25+
vec!["Times New Roman", "Times", "New York", "Palatino"].iter().map(|s| s.to_string()).collect::<Vec<_>>()
2626
);
2727
assert_eq!(
2828
macos_os.get_sans_serif_fonts(no_ranges),
29-
vec!["San Francisco", "Helvetica Neue", "Lucida Grande"]
29+
vec!["San Francisco", ".AppleSystemUIFont", ".SFUIText", ".SFUI-Regular", "Helvetica Neue", "Helvetica", "Lucida Grande"]
3030
.iter().map(|s| s.to_string()).collect::<Vec<_>>()
3131
);
3232
assert_eq!(
@@ -53,8 +53,8 @@ fn test_operating_system_font_expansion() {
5353
let expanded = expand_font_families(&families, OperatingSystem::MacOS, no_ranges);
5454
assert_eq!(expanded[0], "Arial");
5555
assert_eq!(expanded[1], "San Francisco");
56-
assert_eq!(expanded[2], "Helvetica Neue");
57-
assert_eq!(expanded[3], "Lucida Grande");
56+
assert_eq!(expanded[2], ".AppleSystemUIFont");
57+
assert_eq!(expanded[3], ".SFUIText");
5858

5959
// Test non-generic family (should pass through unchanged)
6060
let specific = vec!["MyCustomFont".to_string()];

0 commit comments

Comments
 (0)