diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 16665538..ab0852cf 100755 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -81,7 +81,6 @@ jobs: setup: | sudo apt-get update sudo apt-get install gcc-arm-linux-gnueabihf -y -# sudo apt-get install libfontconfig1 -y build: | yarn build --target armv7-unknown-linux-gnueabihf arm-linux-gnueabihf-strip *.node @@ -260,8 +259,8 @@ jobs: - host: windows-latest target: x86_64-pc-windows-msvc node: - # - '14' - # - '16' + - '14' + - '16' - '18' runs-on: ${{ matrix.settings.host }} steps: @@ -297,8 +296,8 @@ jobs: fail-fast: false matrix: node: - # - '14' - # - '16' + - '14' + - '16' - '18' runs-on: ubuntu-latest steps: @@ -334,8 +333,8 @@ jobs: fail-fast: false matrix: node: - # - '14' - # - '16' + - '14' + - '16' - '18' runs-on: ubuntu-latest steps: @@ -373,8 +372,8 @@ jobs: fail-fast: false matrix: node: - # - '14' - # - '16' + - '14' + - '16' - '18' runs-on: ubuntu-latest steps: @@ -406,9 +405,6 @@ jobs: run: | set -e find /usr/share/fonts -name *.ttf - apt-get install fontconfig -y - fc-cache --force - fc-list :lang=en ls -la yarn test test-linux-aarch64-musl-binding: @@ -445,9 +441,6 @@ jobs: run: | set -e find /usr/share/fonts -name *.ttf - apk add fontconfig - fc-cache --force - fc-list :lang=en apk add nodejs npm yarn yarn test test-linux-arm-gnueabihf-binding: @@ -458,8 +451,8 @@ jobs: fail-fast: false matrix: node: - # - '14' - # - '16' + - '14' + - '16' - '18' runs-on: ubuntu-latest steps: @@ -490,9 +483,6 @@ jobs: run: | set -e find /usr/share/fonts -name *.ttf - apt-get install fontconfig -y - fc-cache --force - fc-list :lang=en ls -la yarn test diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index 1716d206..aa225ca0 100755 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -270,7 +270,7 @@ test('should be load custom fontDirs(no defaultFontFamily option)', (t) => { t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1726) }) -test.only('The defaultFontFamily is not found in the OS and needs to be fallback', async (t) => { +test('The defaultFontFamily is not found in the OS and needs to be fallback', async (t) => { const svg = ` @@ -317,7 +317,7 @@ test.only('The defaultFontFamily is not found in the OS and needs to be fallback const resvg = new Resvg(svg, { font: { loadSystemFonts: true, - // fontDirs: ['/usr/share/fonts/'], // 防止在 CI 的 Docker 环境找不到字体 + fontDirs: ['/usr/share/fonts/'], // 防止在 CI 的 Docker 环境找不到字体 defaultFontFamily: 'this-is-a-non-existent-font-family', }, logLevel: 'debug', diff --git a/src/fonts.rs b/src/fonts.rs index af038f4d..b2701745 100644 --- a/src/fonts.rs +++ b/src/fonts.rs @@ -73,7 +73,7 @@ pub fn load_wasm_fonts( #[cfg(not(target_arch = "wasm32"))] fn set_font_families(font_options: &JsFontOptions, fontdb: &mut Database) { - let mut default_font_family = font_options.default_font_family.clone(); + let mut default_font_family = font_options.default_font_family.clone().trim().to_string(); // debug font list for face in fontdb.faces() { let family = face @@ -85,34 +85,29 @@ fn set_font_families(font_options: &JsFontOptions, fontdb: &mut Database) { debug!("font_id = {}, family_name = {}", face.id, family.0); } - let trimmed_default_font_family = default_font_family.trim(); let fontdb_found_default_font_family = fontdb .faces() .iter() .find_map(|it| { it.families .iter() - .find(|f| f.0 == trimmed_default_font_family) + .find(|f| f.0 == default_font_family) .map(|f| f.0.clone()) }) .unwrap_or_default(); debug!( - "fontdb 找到的默认字体名称 = {}", + "fontdb 找到的默认字体名称 = '{}'", fontdb_found_default_font_family ); // 当 default_font_family 为空或系统无该字体时,尝试把 fontdb // 中字体列表的第一个字体设置为默认的字体。 - if trimmed_default_font_family.is_empty() || fontdb_found_default_font_family.is_empty() { + if default_font_family.is_empty() || fontdb_found_default_font_family.is_empty() { // font_files 或 font_dirs 选项不为空时, 从已加载的字体列表中获取第一个字体的 font family。 if !font_options.font_files.is_empty() || !font_options.font_dirs.is_empty() { default_font_family = get_first_font_family_or_fallback(fontdb); } - // else { - // debug!("其他情况 = {}", default_font_family); - // default_font_family = fallback_font_family; - // } } fontdb.set_serif_family(&default_font_family); @@ -121,7 +116,7 @@ fn set_font_families(font_options: &JsFontOptions, fontdb: &mut Database) { fontdb.set_fantasy_family(&default_font_family); fontdb.set_monospace_family(&default_font_family); - debug!("📝 defaultFontFamily = {}", default_font_family); + debug!("📝 defaultFontFamily = '{}'", default_font_family); #[cfg(not(target_arch = "wasm32"))] find_and_debug_font_path(fontdb, default_font_family.as_str()) @@ -225,13 +220,13 @@ fn get_first_font_family_or_fallback(fontdb: &mut Database) -> String { default_font_family = base_family.0.clone(); debug!( - "📝 get_first_font_family 找到字体了 = {}", + "📝 get_first_font_family 找到字体了 = '{}'", default_font_family ); } None => { debug!( - "📝 get_first_font_family 没找到字体 = {}", + "📝 get_first_font_family 没找到字体 = '{}'", default_font_family ); }