Skip to content

Commit

Permalink
test5: remove fontconfig in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Aug 9, 2023
1 parent 94eb60f commit 0911357
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
30 changes: 10 additions & 20 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -297,8 +296,8 @@ jobs:
fail-fast: false
matrix:
node:
# - '14'
# - '16'
- '14'
- '16'
- '18'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -334,8 +333,8 @@ jobs:
fail-fast: false
matrix:
node:
# - '14'
# - '16'
- '14'
- '16'
- '18'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -373,8 +372,8 @@ jobs:
fail-fast: false
matrix:
node:
# - '14'
# - '16'
- '14'
- '16'
- '18'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -458,8 +451,8 @@ jobs:
fail-fast: false
matrix:
node:
# - '14'
# - '16'
- '14'
- '16'
- '18'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200" viewBox="0 0 300 200">
<text fill="blue" font-family="" font-size="100">
Expand Down Expand Up @@ -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',
Expand Down
19 changes: 7 additions & 12 deletions src/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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())
Expand Down Expand Up @@ -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
);
}
Expand Down

0 comments on commit 0911357

Please sign in to comment.