From 60cc184ab7ebb3b0a23e83c3ea6f2b0d816cddf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindr=CC=8Cich=20S=CC=8Cars=CC=8Con?= Date: Wed, 21 Oct 2026 16:28:16 +0200 Subject: [PATCH] M6: Sketch import: PingFang families keep their own names Co-Authored-By: Claude Opus 5.5 --- crates/format/src/sketch/text.rs | 6 ++++-- crates/format/src/sketch/text_tests.rs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/format/src/sketch/text.rs b/crates/format/src/sketch/text.rs index edafe30e..74e7a731 100644 --- a/crates/format/src/sketch/text.rs +++ b/crates/format/src/sketch/text.rs @@ -132,8 +132,8 @@ fn type_style(cx: &mut Cx, a: &Value) -> Value { /// Family and style of a font from its PostScript name: "HelveticaNeue-Bold" → ("Helvetica Neue", /// "Bold"). Words of the family are split at case changes, which can't always match the real name -/// ("PingFangSC" → "Ping Fang SC"); the engine matches families against the installed fonts ignoring -/// spaces. Apple's system fonts take the SF Pro names. +/// (a CJK family would split as "Ping Fang SC"); the engine matches families against the installed +/// fonts ignoring spaces. Apple's system fonts take the SF Pro names, PingFang its own. pub(crate) fn font_name(ps: &str) -> (String, String) { let (family, style) = ps.split_once('-').unwrap_or((ps, "")); let style = if style.is_empty() { "Regular".to_string() } else { crate::fig::style_name(style) }; @@ -141,6 +141,8 @@ pub(crate) fn font_name(ps: &str) -> (String, String) { "" => "Helvetica".to_string(), ".SFNSText" | ".SFUIText" | "SanFranciscoText" | ".SFProText" => "SF Pro Text".into(), ".SFNSDisplay" | ".SFUIDisplay" | "SanFranciscoDisplay" | ".SFProDisplay" => "SF Pro Display".into(), + // Apple's CJK families whose names don't split at case changes. + "PingFangSC" | "PingFangTC" | "PingFangHK" => format!("PingFang {}", family.get(8..).unwrap_or("")), f => words(f.trim_start_matches('.')), }; (family, style) diff --git a/crates/format/src/sketch/text_tests.rs b/crates/format/src/sketch/text_tests.rs index bde9dcef..a7ee96b0 100644 --- a/crates/format/src/sketch/text_tests.rs +++ b/crates/format/src/sketch/text_tests.rs @@ -146,7 +146,8 @@ fn font_names() { ("HelveticaNeue-Bold", "Helvetica Neue", "Bold"), ("HelveticaNeue", "Helvetica Neue", "Regular"), ("HelveticaNeue-Medium", "Helvetica Neue", "Medium"), - ("PingFangSC-Semibold", "Ping Fang SC", "Semi Bold"), + ("PingFangSC-Semibold", "PingFang SC", "Semi Bold"), + ("PingFangTC-Regular", "PingFang TC", "Regular"), (".SFNSText", "SF Pro Text", "Regular"), (".SFNSDisplay-Bold", "SF Pro Display", "Bold"), ("SanFranciscoText-Semibold", "SF Pro Text", "Semi Bold"),