diff --git a/__test__/draw.spec.ts b/__test__/draw.spec.ts index a4f9adeb..0edd6219 100644 --- a/__test__/draw.spec.ts +++ b/__test__/draw.spec.ts @@ -488,7 +488,7 @@ test('fillText-AA', async (t) => { test('fillText-COLRv1', async (t) => { const { ctx, canvas } = t.context - GlobalFonts.registerFromPath(join(__dirname, 'fonts', 'COLRv1.ttf'), 'Colrv1') + GlobalFonts.registerFromPath(join(__dirname, 'fonts', 'COLR-v1.ttf'), 'Colrv1') ctx.font = '100px Colrv1' ctx.fillText('abc', 50, 100) await snapshotImage(t, { canvas, ctx }, 'png', 0.5) diff --git a/__test__/fonts-dir/iosevka-curly-heavy.woff2 b/__test__/fonts-dir/iosevka-curly_heavy.Woff2 similarity index 100% rename from __test__/fonts-dir/iosevka-curly-heavy.woff2 rename to __test__/fonts-dir/iosevka-curly_heavy.Woff2 diff --git a/__test__/fonts/COLRv1.ttf b/__test__/fonts/COLR-v1.ttf similarity index 100% rename from __test__/fonts/COLRv1.ttf rename to __test__/fonts/COLR-v1.ttf diff --git a/src/global_fonts.rs b/src/global_fonts.rs index 51262ada..ee519d5c 100644 --- a/src/global_fonts.rs +++ b/src/global_fonts.rs @@ -44,6 +44,9 @@ pub mod GlobalFonts { Ok(font.register(font_data.as_ref(), maybe_name_alias)) } + // TODO: Do file extensions in font_path need to be converted to lowercase? + // Windows and macOS are case-insensitive, Linux is not. + // See: https://github.com/Brooooooklyn/canvas/actions/runs/5893418006/job/15985737723 #[napi] pub fn register_from_path(font_path: String, name_alias: Option) -> Result { let maybe_name_alias = name_alias.and_then(|s| if s.is_empty() { None } else { Some(s) }); @@ -86,9 +89,13 @@ fn load_fonts_from_dir>(dir: P) -> napi::Result { load_fonts_from_dir(f.path())?; } else { let p = f.path(); - let ext = p.extension().and_then(|s| s.to_str()); + // The font file extensions are case-insensitive. + let ext = p + .extension() + .and_then(|s| s.to_str()) + .map(|s| s.to_ascii_lowercase()); - match ext { + match ext.as_deref() { Some("ttf") | Some("ttc") | Some("otf") | Some("pfb") | Some("woff2") | Some("woff") => { if let Some(p) = p.into_os_string().to_str() {