Skip to content

Commit

Permalink
feat: load fonts from user dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Aug 25, 2021
1 parent 177e4f6 commit fd6fb78
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { platform, homedir } = require('os')
const { join } = require('path')

const { loadBinding } = require('@node-rs/helper')

/**
Expand Down Expand Up @@ -207,6 +210,20 @@ class Canvas {

if (!process.env.DISABLE_SYSTEM_FONTS_LOAD) {
GlobalFontsSingleton.loadSystemFonts()
const platformName = platform()
const homedirPath = homedir()
switch (platformName) {
case 'win32':
GlobalFontsSingleton.loadFontsFromDir(join(homedirPath, 'AppData', 'Local', 'Microsoft', 'Windows', 'Fonts'))
break
case 'darwin':
GlobalFontsSingleton.loadFontsFromDir(join(homedirPath, 'Library', 'Fonts'))
break
case 'linux':
GlobalFontsSingleton.loadFontsFromDir(join('usr', 'local', 'share', 'fonts'))
GlobalFontsSingleton.loadFontsFromDir(join(homedirPath, '.fonts'))

This comment has been minimized.

Copy link
@yisibl

yisibl Sep 1, 2021

Collaborator

不用加载 .local/share/fonts 目录吗?

break
}
FamilyNamesSet = JSON.parse(GlobalFontsSingleton._families)
}

Expand Down

1 comment on commit fd6fb78

@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: fd6fb78 Previous: 92c60c1 Ratio
Draw house#skia-canvas 20 ops/sec (±0.65%) 20 ops/sec (±1.26%) 1
Draw house#node-canvas 24 ops/sec (±0.93%) 23 ops/sec (±1.88%) 0.96
Draw house#@napi-rs/skia 25 ops/sec (±1.54%) 24 ops/sec (±1.72%) 0.96
Draw gradient#skia-canvas 19.5 ops/sec (±0.77%) 20 ops/sec (±1.42%) 1.03
Draw gradient#node-canvas 23 ops/sec (±1.18%) 22 ops/sec (±2.68%) 0.96
Draw gradient#@napi-rs/skia 23.2 ops/sec (±2.06%) 25 ops/sec (±2.02%) 1.08

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

Please sign in to comment.