-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: the defaultFontFamily
not working
#208
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@RazrFalcon Sorry for pinging you here, can you help to see why the default font family can't be loaded after splitting into usvg-text-layout? Our resvg upgrade code changes are here: #194 |
What are you using it for? Maybe this would help linebender/resvg#566 |
@RazrFalcon I found that it is indeed related to linebender/resvg#566. The main change I think is caused here: if families.is_empty() { // Removing this judgment will restore the effect to 0.27.0.
families.push(state.opt.font_family.clone())
} ExpectedConsider the following SVG: Case 1<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
<text fill="blue" font-family="serif" font-size="120">
<tspan x="40" y="143">水</tspan>
</text>
</svg> When the font-family does not exist or is const resvg = new Resvg(svg, {
background: 'pink',
font: {
fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts.
loadSystemFonts: false, // It will be faster to disable loading system fonts.
defaultFontFamily: 'Source Han Serif CN Light',
},
logLevel: 'debug',
}) I've done some debugging, can you help me see what the problem is? npm install
npm run build:debug
node example/text.js Generated PNG: Case 1 debug[2023-02-13T05:33:34Z DEBUG resvg_js::fonts] Loaded 1 font faces in 0.741ms.
[2023-02-13T05:33:34Z DEBUG resvg_js::fonts] Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.016ms.
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:509] &span.font.families = [
"serif",
]
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:686] &name_list = [
Serif,
Serif,
]
[2023-02-13T05:33:34Z WARN usvg_text_layout] No match for 'serif' font-family.
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:509] resolve_font(&span.font, fontdb) = None
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:686] &name_list = [
Serif,
Serif,
]
[2023-02-13T05:33:34Z WARN usvg_text_layout] No match for 'serif' font-family. Case 2Explicitly set font-family to the family name of the actual font <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
<text fill="blue" font-family="Source Han Serif CN Light" font-size="120">
<tspan x="40" y="143">水</tspan>
</text>
</svg> Case 2 debug[2023-02-13T05:44:43Z DEBUG resvg_js::fonts] Loaded 1 font faces in 0.131ms.
[2023-02-13T05:44:43Z DEBUG resvg_js::fonts] Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.009ms.
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"Source Han Serif CN Light",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"Source Han Serif CN Light",
]
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"Source Han Serif CN Light",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"Source Han Serif CN Light",
]
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"Source Han Serif CN Light",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"Source Han Serif CN Light",
]
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:509] &span.font.families = [
"Source Han Serif CN Light",
]
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:686] &name_list = [
Name(
"Source Han Serif CN Light",
),
Serif,
]
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:509] resolve_font(&span.font, fontdb) = Some(
ResolvedFont {
id: ID(
2,
),
units_per_em: 2048,
ascent: 2357,
descent: -586,
x_height: 1053,
underline_position: -307,
underline_thickness: 102,
line_through_position: 631,
subscript_offset: 154,
superscript_offset: 717,
},
)
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:686] &name_list = [
Name(
"Source Han Serif CN Light",
),
Serif,
] TryDoes it need to be changed to this? if families.is_empty() || !state.opt.font_family.is_empty() {
families.push(state.opt.font_family.clone())
} debug output[2023-02-13T05:33:34Z DEBUG resvg_js::fonts] Loaded 1 font faces in 0.741ms.
[2023-02-13T05:33:34Z DEBUG resvg_js::fonts] Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.016ms.
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:677] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg/src/text.rs:678] &state.opt.font_family = "Source Han Serif CN Light"
[/Users/yisibl/resvg/usvg/src/text.rs:679] &families = [
"serif",
]
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:509] &span.font.families = [
"serif",
]
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:686] &name_list = [
Serif,
Serif,
]
[2023-02-13T05:33:34Z WARN usvg_text_layout] No match for 'serif' font-family.
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:509] resolve_font(&span.font, fontdb) = None
[/Users/yisibl/resvg/usvg-text-layout/src/lib.rs:686] &name_list = [
Serif,
Serif,
]
[2023-02-13T05:33:34Z WARN usvg_text_layout] No match for 'serif' font-family. |
fc96adf
to
7064b13
Compare
7064b13
to
1cc5234
Compare
You must not use/rely on In short, as the linked issue noted, the rules are simple: In case of your file, you do define family as The previous behavior wasn't technically correct. |
8cad124
to
ed4c850
Compare
@RazrFalcon Yes, I'm using |
Fixed: #207
Test