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 17, 2023
1 parent 7fc5243 commit e130387
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 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
5 changes: 3 additions & 2 deletions src/global_fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ 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());
// 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() {
Expand Down

1 comment on commit e130387

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e130387 Previous: 8c26434 Ratio
Draw house#skia-canvas 18.2 ops/sec (±1.36%) 18.2 ops/sec (±1.7%) 1
Draw house#node-canvas 22.4 ops/sec (±1.11%) 24.6 ops/sec (±1.37%) 1.10
Draw house#@napi-rs/skia 18 ops/sec (±1.84%) 18.1 ops/sec (±0.91%) 1.01
Draw gradient#skia-canvas 18 ops/sec (±0.7%) 18 ops/sec (±1.42%) 1
Draw gradient#node-canvas 22 ops/sec (±1.23%) 22 ops/sec (±2.32%) 1
Draw gradient#@napi-rs/skia 17 ops/sec (±0.89%) 17 ops/sec (±1.36%) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.