Skip to content

Commit

Permalink
fix: fonts with uppercase extensions are not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Aug 4, 2023
1 parent 7fc5243 commit 949e88b
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions __test__/draw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ test('fillText-AA', async (t) => {
await snapshotImage(t, { canvas, ctx }, 'png', 3.2)
})

test('fillText-COLRv1', async (t) => {
test.only('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)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion __test__/global-fonts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ test('should be able to register font with name alias', (t) => {
})
})

test('should be able to register fonts from dir', (t) => {
test.only('should be able to register fonts from dir', (t) => {
t.is(GlobalFonts.loadFontsFromDir(join(__dirname, 'fonts-dir')), 3)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"prepublishOnly": "pinst --disable && napi prepublish -t npm",
"postpublish": "pinst --enable",
"test:ci": "ava -c 1",
"test": "ava",
"test": "ava __test__/global-fonts.spec.ts __test__/draw.spec.ts",
"version": "napi version && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/global_fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ fn load_fonts_from_dir<P: AsRef<path::Path>>(dir: P) -> napi::Result<u32> {
load_fonts_from_dir(f.path())?;
} else {
let p = f.path();
let ext = p.extension().and_then(|s| s.to_str());
// let ext = p.extension().and_then(|s| s.to_str());
let ext = p.extension().and_then(|s| s.to_str()).map(|s| s.to_lowercase());

match ext {
Some("ttf") | Some("ttc") | Some("otf") | Some("pfb") | Some("woff2")
Expand Down

0 comments on commit 949e88b

Please sign in to comment.