SVG export: a Japanese face's numbered weight (W0–W9) is its font-weight, W6 600 (#2873)

style_weight reads W0–W9 style names (Hiragino, Morisawa…) as their weight classes before the English words, so SVG and CSS export write font-weight 600 for W6, and nearest-style matching weighs them too.
This commit is contained in:
bflatastic
2026-10-18 19:02:52 +07:00
parent b934451b6d
commit eec304dde1
3 changed files with 17 additions and 2 deletions
+7
View File
@@ -55,6 +55,13 @@ fn every_style_is_written_with_its_numeric_weight() {
("Extrabold", Some("800")),
("Black", Some("900")),
("Heavy", Some("900")),
// Japanese faces' numbered weights (#2873); W4 is the regular weight.
("W0", Some("100")),
("W3", Some("300")),
("W4", None),
("W6", Some("600")),
("W9", Some("900")),
("Wide", None),
] {
let want = want.map(str::to_string);
assert_eq!(weights(style), (want.clone(), want), "{style}");
+9 -1
View File
@@ -1568,8 +1568,16 @@ fn norm(s: &str) -> String {
norm_chars(s).collect()
}
/// Weight implied by a style name (400 = regular).
/// Weight implied by a style name (400 = regular). Japanese faces number their weights W0–W9
/// (Hiragino, Morisawa…), W6 weighing 600 as its weight class does (#2873).
pub fn style_weight(style: &str) -> f32 {
let numbered = style.split(|c: char| !c.is_ascii_alphanumeric()).find_map(|part| match part.as_bytes() {
[b'W' | b'w', d @ b'0'..=b'9'] => Some(f32::from(d - b'0') * 100.0),
_ => None,
});
if let Some(w) = numbered {
return w.max(100.0);
}
let s = norm(style);
const TABLE: &[(&str, f32)] = &[
("extralight", 200.0),
+1 -1
View File
@@ -467,7 +467,7 @@ lists every option with its default. `encoding` is `utf8`, `utf16` (big-endian a
(presentation attributes only; filters, masks, blend modes and embedded fonts left out, symbols as art, each with
a warning). `embedFonts: true` embeds the fonts type uses as `@font-face` rules subset to the characters used; a
font whose licence (OS/2 `fsType`) forbids subsetting is embedded whole, one that forbids embedding is left out
with a warning. Type names its faces by numeric `font-weight` (600 for Semibold, 300 for Light, `bold` for 700),
with a warning. Type names its faces by numeric `font-weight` (600 for Semibold and for a Japanese face's W6, 300 for Light, `bold` for 700),
embedded or not. `svgz` takes the same options and writes the SVG gzipped (`.svgz` files also open,
place and paste). `run_command document.save {path: "x.svg", svg: {…}}` saves as SVG (or `.svgz`).