Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(fonts): preserve multilingual font semantics

hugohe360eccc372fd1
diff --git a/skills/ppt-master/scripts/beautify_identity.py b/skills/ppt-master/scripts/beautify_identity.py
index a5ac51c4..20dd54b4 100644
--- a/skills/ppt-master/scripts/beautify_identity.py
+++ b/skills/ppt-master/scripts/beautify_identity.py
@@ -46,9 +46,9 @@ from pptx_to_svg.ooxml_loader import OoxmlPackage # noqa: E402
configure_utf8_stdio()
-def _font_pair(theme_root, font_tag: str) -> dict[str, str]:
- """Read one <a:majorFont> / <a:minorFont> into {latin, ea} (skip empties)."""
- out: dict[str, str] = {}
+def _font_pair(theme_root, font_tag: str) -> dict[str, object]:
+ """Read one theme font family, including explicit CJK script mappings."""
+ out: dict[str, object] = {}
font = theme_root.find(f".//a:fontScheme/a:{font_tag}", NS)
if font is None:
return out
@@ -58,6 +58,14 @@ def _font_pair(theme_root, font_tag: str) -> dict[str, str]:
face = (elem.attrib.get("typeface") or "").strip()
if face:
out[key] = face
+ scripts: dict[str, str] = {}
+ for elem in font.findall("a:font", NS):
+ script = (elem.attrib.get("script") or "").strip()
+ face = (elem.attrib.get("typeface") or "").strip()
+ if script in {"Hans", "Hant", "Jpan", "Hang"} and face:
+ scripts[script] = face
+ if scripts:
+ out["scripts"] = scripts
return out
diff --git a/skills/ppt-master/scripts/pptx_animations.py b/skills/ppt-master/scripts/pptx_animations.py
index 8c5185bb..f24746c8 100644
--- a/skills/ppt-master/scripts/pptx_animations.py
+++ b/skills/ppt-master/scripts/pptx_animations.py
@@ -171,6 +171,27 @@ ANIMATION_TIMING_OPTION_FIELDS = (
)
ANIMATION_RESTARTS = ('always', 'when-not-active', 'never')
ANIMATION_AFTER_EFFECTS = ('none', 'dim', 'hide', 'hide-on-next-click')
+_NON_CONCRETE_FONT_NAMES = frozenset({
+ '-apple-system',
+ 'blinkmacsystemfont',
+ 'cursive',
+ 'emoji',
+ 'fantasy',
+ 'inherit',
+ 'initial',
+ 'math',
+ 'monospace',
+ 'revert',
+ 'revert-layer',
+ 'sans-serif',
+ 'serif',
+ 'system-ui',
+ 'ui-monospace',
+ 'ui-rounded',
+ 'ui-sans-serif',
+ 'ui-serif',
+ 'unset',
+})
# Legacy directional names retain their historical semantics by desugaring
# into one canonical effect plus the matching PowerPoint EffectParameters
@@ -503,6 +524,28 @@ def _normalize_animation_color(value: object, field: str) -> str:
)
+def _normalize_powerpoint_font_name(value: object, field: str) -> str:
+ """Return one concrete PowerPoint font name without checking installation."""
+ if not isinstance(value, str) or not value.strip():
+ raise ValueError(
+ f'{field} must be one concrete PowerPoint font name: {value!r}'
+ )
+ normalized = value.strip()
+ if len(normalized) > 255:
+ raise ValueError(f'{field} exceeds 255 characters')
+ if ',' in normalized:
+ raise ValueError(
+ f'{field} must be one concrete PowerPoint font name, '
+ f'not a CSS font stack: {value!r}'
+ )
+ if normalized.casefold() in _NON_CONCRETE_FONT_NAMES:
+ raise ValueError(
+ f'{field} must be one concrete PowerPoint font name, '
+ f'not a generic family or CSS-wide keyword: {value!r}'
+ )
+ return normalized
+
+
def normalize_animation_effect_options(
effect: str,
options: object = None,
@@ -573,11 +616,17 @@ def normalize_animation_effect_options(
)
normalized[name] = number
elif option_type == 'string':
- if not isinstance(value, str) or not value.strip():
- raise ValueError(f'{field} must be a non-empty string: {value!r}')
- if len(value) > 255:
- raise ValueError(f'{field} exceeds 255 characters')
- normalized[name] = value
+ if name == 'font_name':
+ normalized[name] = _normalize_powerpoint_font_name(value, field)
+ else:
+ if not isinstance(value, str) or not value.strip():
+ raise ValueError(
+ f'{field} must be a non-empty string: {value!r}'
+ )
+ normalized_value = value.strip()
+ if len(normalized_value) > 255:
+ raise ValueError(f'{field} exceeds 255 characters')
+ normalized[name] = normalized_value
elif option_type == 'boolean':
if not isinstance(value, bool):
raise ValueError(f'{field} must be a boolean: {value!r}')
@@ -2275,10 +2324,18 @@ def _read_effect_options(
value.get('val')
for value in node.iter(_qn(PML_NS, 'strVal'))
)
- if len(fonts) != 1 or not fonts[0]:
- errors.append('emphasis_change_font row has an invalid font name')
- else:
- values[name] = fonts[0]
+ if len(fonts) != 1:
+ errors.append(
+ 'emphasis_change_font row must contain one font name'
+ )
+ continue
+ try:
+ values[name] = _normalize_powerpoint_font_name(
+ fonts[0],
+ 'emphasis_change_font row font name',
+ )
+ except ValueError as exc:
+ errors.append(str(exc))
elif name == 'relative':
motions = list(row.iter(_qn(PML_NS, 'animMotion')))
if len(motions) != 1:
diff --git a/skills/ppt-master/scripts/pptx_to_svg/converter.py b/skills/ppt-master/scripts/pptx_to_svg/converter.py
index 8e92a8e4..fa867f4d 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/converter.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/converter.py
@@ -31,6 +31,9 @@ from .ooxml_loader import (
from .slide_to_svg import assemble_part_solo, assemble_slide
+_CJK_THEME_SCRIPTS = frozenset({"Hans", "Hant", "Jpan", "Hang"})
+
+
def _extract_theme_info(
theme: PartRef,
palette: ColorPalette,
@@ -77,6 +80,11 @@ def _extract_theme_info(
cs = fnt.find("a:cs", NS)
if cs is not None and cs.attrib.get("typeface"):
fonts[f"{role_prefix}ComplexScript"] = cs.attrib["typeface"]
+ for supplemental in fnt.findall("a:font", NS):
+ script = supplemental.attrib.get("script", "")
+ typeface = supplemental.attrib.get("typeface", "")
+ if script in _CJK_THEME_SCRIPTS and typeface:
+ fonts[f"{role_prefix}Script{script}"] = typeface
return colors, fonts
diff --git a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py
index fb3ffa41..b3240f1e 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py
@@ -25,6 +25,8 @@ from __future__ import annotations
from dataclasses import dataclass, field
from xml.etree import ElementTree as ET
+from svg_to_pptx.drawingml.utils import detect_text_lang, is_cjk_char
+
from .color_resolver import ColorPalette, find_color_elem, resolve_color
from .emu_units import (
NS, Xfrm, fmt_num, emu_to_px, format_ooxml_alpha,
@@ -576,11 +578,31 @@ def _build_run(
latin_face = _typeface_chain(style_chain, "latin")
ea_face = _typeface_chain(style_chain, "ea")
cs_face = _typeface_chain(style_chain, "cs")
+ lang = _attr_chain(style_chain, "lang")
+ alt_lang = _attr_chain(style_chain, "altLang")
# Resolve theme refs (e.g. typeface="+mn-lt" / "+mj-ea")
- latin_face = _resolve_theme_typeface(latin_face, theme_fonts)
- ea_face = _resolve_theme_typeface(ea_face, theme_fonts)
- cs_face = _resolve_theme_typeface(cs_face, theme_fonts)
+ latin_face = _resolve_theme_typeface(
+ latin_face,
+ theme_fonts,
+ text=text,
+ lang=lang,
+ alt_lang=alt_lang,
+ )
+ ea_face = _resolve_theme_typeface(
+ ea_face,
+ theme_fonts,
+ text=text,
+ lang=lang,
+ alt_lang=alt_lang,
+ )
+ cs_face = _resolve_theme_typeface(
+ cs_face,
+ theme_fonts,
+ text=text,
+ lang=lang,
+ alt_lang=alt_lang,
+ )
font_family = _build_font_stack(latin_face, ea_face, cs_face)
@@ -698,8 +720,63 @@ def _typeface_chain(
return None
-def _resolve_theme_typeface(face: str | None, theme_fonts: dict[str, str]) -> str | None:
- """Theme references look like '+mj-lt' (major latin) / '+mn-ea' (minor EA)."""
+def _theme_script_from_lang(lang: str | None) -> str | None:
+ """Map a DrawingML language tag to one theme supplemental-script key."""
+ if not lang:
+ return None
+ normalized = lang.strip().replace("_", "-").lower()
+ if not normalized:
+ return None
+ parts = normalized.split("-")
+ primary = parts[0]
+ if primary == "ja":
+ return "Jpan"
+ if primary == "ko":
+ return "Hang"
+ if primary != "zh":
+ return None
+ if any(part in {"hant", "cht", "tw", "hk", "mo"} for part in parts[1:]):
+ return "Hant"
+ return "Hans"
+
+
+def _theme_script_from_text(text: str) -> str | None:
+ """Infer a CJK theme script from glyph ranges, defaulting plain Han to Hans."""
+ if any(
+ 0x3100 <= ord(char) <= 0x312F
+ or 0x31A0 <= ord(char) <= 0x31BF
+ for char in text
+ ):
+ return "Hant"
+ return {
+ "ko-KR": "Hang",
+ "ja-JP": "Jpan",
+ "zh-CN": "Hans",
+ }.get(detect_text_lang(text))
+
+
+def _run_theme_script(
+ text: str,
+ lang: str | None,
+ alt_lang: str | None,
+) -> str | None:
+ """Resolve EA script from run language first, then alternate language/text."""
+ return (
+ _theme_script_from_lang(lang)
+ or _theme_script_from_lang(alt_lang)
+ or _theme_script_from_text(text)
+ )
+
+
+def _resolve_theme_typeface(
+ face: str | None,
+ theme_fonts: dict[str, str],
+ *,
+ text: str = "",
+ lang: str | None = None,
+ alt_lang: str | None = None,
+) -> str | None:
+ """Resolve DrawingML major/minor Latin, EA, and complex-script tokens."""
if not face or not face.startswith("+"):
return face
code = face[1:]
@@ -707,10 +784,31 @@ def _resolve_theme_typeface(face: str | None, theme_fonts: dict[str, str]) -> st
return theme_fonts.get("majorLatin") or face
if code == "mn-lt":
return theme_fonts.get("minorLatin") or face
- if code == "mj-ea":
- return theme_fonts.get("majorEastAsia") or theme_fonts.get("majorLatin") or face
- if code == "mn-ea":
- return theme_fonts.get("minorEastAsia") or theme_fonts.get("minorLatin") or face
+ if code in {"mj-ea", "mn-ea"}:
+ prefix = "major" if code.startswith("mj") else "minor"
+ script = _run_theme_script(text, lang, alt_lang)
+ script_face = (
+ theme_fonts.get(f"{prefix}Script{script}")
+ if script is not None else None
+ )
+ return (
+ theme_fonts.get(f"{prefix}EastAsia")
+ or script_face
+ or theme_fonts.get(f"{prefix}Latin")
+ or face
+ )
+ if code == "mj-cs":
+ return (
+ theme_fonts.get("majorComplexScript")
+ or theme_fonts.get("majorLatin")
+ or face
+ )
+ if code == "mn-cs":
+ return (
+ theme_fonts.get("minorComplexScript")
+ or theme_fonts.get("minorLatin")
+ or face
+ )
return face
@@ -848,11 +946,7 @@ def _collect_text_defs(paragraphs: list[TextParagraph]) -> list[str]:
def _is_cjk(ch: str) -> bool:
"""Check if a character is CJK (Chinese/Japanese/Korean) or full-width."""
- cp = ord(ch)
- return (0x4E00 <= cp <= 0x9FFF or 0x3400 <= cp <= 0x4DBF or
- 0x2E80 <= cp <= 0x2EFF or 0x3000 <= cp <= 0x303F or
- 0xFF00 <= cp <= 0xFFEF or 0xF900 <= cp <= 0xFAFF or
- 0x20000 <= cp <= 0x2A6DF)
+ return is_cjk_char(ch)
def _char_width(ch: str, font_size: float, bold: bool) -> float:
@@ -1197,11 +1291,12 @@ def _run_tspan_attrs(run: TextRun) -> str:
"""Per-run overrides on a <tspan>. Only emit attributes that differ from
the run that drove the parent <text> (we keep things simple: emit only
overrides that can plausibly change run-to-run, never re-emit common
- defaults). For v1 we just always emit fill / font-size / weight to be
- safe — tspan inherits when omitted, so callers can simplify later.
+ defaults). For v1 we always emit fill, font family, and font size so each
+ imported run keeps its resolved typeface even when adjacent runs differ.
"""
parts = [
f'fill="{run.fill}"',
+ f'font-family="{run.font_family}"',
f'font-size="{fmt_num(run.font_size_px)}"',
]
if run.fill_opacity < 1.0:
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
index fd353649..12f6dc75 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
@@ -147,13 +147,17 @@ _SERIF_LATIN = {
'Book Antiqua', 'Cambria', 'SimSun', 'Liberation Serif', 'DejaVu Serif',
}
-# Fonts that survive direct PPTX typeface assignment on a typical Windows /
-# macOS viewer without requiring a custom install. Keep this aligned with
-# strategist.md §g and FONT_FALLBACK_WIN above.
+# Common Office/OS faces accepted without a custom-font warning on their
+# corresponding target locale. Actual playback availability remains
+# target-specific; keep these examples aligned with strategist.md §g.
PPT_SAFE_FONTS = frozenset({
'microsoft yahei', 'simhei', 'simsun', 'kaiti', 'fangsong',
'dengxian', 'microsoft jhenghei',
'pingfang sc', 'heiti sc', 'songti sc', 'stsong',
+ 'yu gothic', 'yu gothic ui', 'yu mincho',
+ 'meiryo', 'meiryo ui',
+ 'ms gothic', 'ms mincho', 'ms pgothic', 'ms pmincho', 'ms ui gothic',
+ 'malgun gothic', 'gulim', 'dotum', 'batang',
'arial', 'arial black', 'calibri', 'segoe ui', 'verdana',
'helvetica', 'helvetica neue', 'tahoma', 'trebuchet ms',
'times new roman', 'times', 'georgia', 'cambria', 'palatino',
@@ -2936,18 +2940,85 @@ def unsafe_exported_font_faces(font_family_str: str) -> dict[str, str]:
}
+def _is_han_char(ch: str) -> bool:
+ """Return whether one character belongs to a Han ideograph block."""
+ cp = ord(ch)
+ return (
+ 0x3400 <= cp <= 0x4DBF
+ or 0x4E00 <= cp <= 0x9FFF
+ or 0xF900 <= cp <= 0xFAFF
+ or 0x20000 <= cp <= 0x2EE5F
+ or 0x30000 <= cp <= 0x323AF
+ )
+
+
+def _is_hiragana_char(ch: str) -> bool:
+ cp = ord(ch)
+ return (
+ 0x3040 <= cp <= 0x309F
+ or 0x1B001 <= cp <= 0x1B11F
+ )
+
+
+def _is_katakana_char(ch: str) -> bool:
+ cp = ord(ch)
+ return (
+ 0x30A0 <= cp <= 0x30FF
+ or 0x31F0 <= cp <= 0x31FF
+ or 0xFF65 <= cp <= 0xFF9F
+ or 0x1AFF0 <= cp <= 0x1AFFF
+ or cp == 0x1B000
+ or 0x1B120 <= cp <= 0x1B16F
+ )
+
+
+def _is_hangul_char(ch: str) -> bool:
+ cp = ord(ch)
+ return (
+ 0x1100 <= cp <= 0x11FF
+ or 0x3130 <= cp <= 0x318F
+ or 0xA960 <= cp <= 0xA97F
+ or 0xAC00 <= cp <= 0xD7AF
+ or 0xD7B0 <= cp <= 0xD7FF
+ or 0xFFA0 <= cp <= 0xFFDC
+ )
+
+
def is_cjk_char(ch: str) -> bool:
- """Check if a character is CJK (Chinese/Japanese/Korean)."""
+ """Return whether one character uses the project East Asian width model."""
cp = ord(ch)
- return (0x4E00 <= cp <= 0x9FFF or 0x3400 <= cp <= 0x4DBF or
- 0x2E80 <= cp <= 0x2EFF or 0x3000 <= cp <= 0x303F or
- 0xFF00 <= cp <= 0xFFEF or 0xF900 <= cp <= 0xFAFF or
- 0x20000 <= cp <= 0x2A6DF)
+ return (
+ _is_han_char(ch)
+ or _is_hiragana_char(ch)
+ or _is_katakana_char(ch)
+ or _is_hangul_char(ch)
+ or 0x2E80 <= cp <= 0x2FFF
+ or 0x3000 <= cp <= 0x303F
+ or 0x3100 <= cp <= 0x312F
+ or 0x31A0 <= cp <= 0x31BF
+ or 0x31C0 <= cp <= 0x31EF
+ or 0xFF00 <= cp <= 0xFFEF
+ )
def detect_text_lang(text: str) -> str:
"""Return a DrawingML language tag for a text run."""
- return 'zh-CN' if any(is_cjk_char(ch) for ch in text) else 'en-US'
+ has_hangul = False
+ has_kana = False
+ has_east_asian_text = False
+ for ch in text:
+ has_hangul = has_hangul or _is_hangul_char(ch)
+ has_kana = (
+ has_kana
+ or _is_hiragana_char(ch)
+ or _is_katakana_char(ch)
+ )
+ has_east_asian_text = has_east_asian_text or is_cjk_char(ch)
+ if has_hangul:
+ return 'ko-KR'
+ if has_kana:
+ return 'ja-JP'
+ return 'zh-CN' if has_east_asian_text else 'en-US'
def _is_grapheme_extend(ch: str) -> bool:
@@ -3070,7 +3141,7 @@ def split_project_text_clusters(text: str) -> list[str]:
def resolve_text_run_fonts(text: str, fonts: dict[str, str]) -> dict[str, str]:
"""Return DrawingML latin/ea/cs typefaces for one text run."""
latin = fonts['latin']
- if detect_text_lang(text) == 'zh-CN':
+ if detect_text_lang(text) != 'en-US':
ea = fonts['ea']
else:
ea = latin
diff --git a/skills/ppt-master/scripts/update_spec.py b/skills/ppt-master/scripts/update_spec.py
index 61386387..ed3ee434 100755
--- a/skills/ppt-master/scripts/update_spec.py
+++ b/skills/ppt-master/scripts/update_spec.py
@@ -4,21 +4,23 @@
Examples:
python3 update_spec.py <project_path> primary=#0066AA
python3 update_spec.py <project_path> colors.text=#111111
- python3 update_spec.py <project_path> typography.font_family='"PingFang SC", "Microsoft YaHei", sans-serif'
+ python3 update_spec.py <project_path> \\
+ typography.font_family='Arial, "Microsoft YaHei", sans-serif'
v2 scope:
- `colors.*` — HEX value replacement across svg_output/*.svg (case-insensitive match).
- `typography.font_family` — replaces the inner value of every `font-family="..."`
/ `font-family='...'` attribute in svg_output/*.svg. This is a global replace:
- every text element becomes the new family, regardless of role.
+ every text element becomes the new family, regardless of role, and every
+ existing `typography.*_family` lock row is updated to the same value.
Bare `key=value` (no dot) is treated as `colors.key=value` for backward compat.
-Other keys (typography sizes, per-role `typography.*_family` overrides, icons,
-images, canvas, forbidden) are intentionally NOT supported — they involve
-attribute-scoped or semantic replacements whose risk/benefit does not warrant
-bulk propagation. For per-role family changes, edit spec_lock.md and re-author
-the affected pages.
+Other keys as independent targets (typography sizes, per-role
+`typography.*_family` overrides, icons, images, canvas, forbidden) are
+intentionally NOT supported — they involve attribute-scoped or semantic
+replacements whose risk/benefit does not warrant bulk propagation. For
+per-role family changes, edit spec_lock.md and re-author the affected pages.
"""
from __future__ import annotations
@@ -36,23 +38,42 @@ HEX_RE = re.compile(r"^#(?:[0-9A-Fa-f]{3,4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$")
FONT_FAMILY_RE = re.compile(r"""(font-family\s*=\s*)(["'])(.*?)\2""")
-def rewrite_lock(lock_path: Path, section: str, key: str, new_value: str) -> None:
- """Rewrite the single `- key: old_value` line under `## section`."""
+def plan_lock_values(
+ lock_path: Path, section: str, updates: dict[str, str]
+) -> str:
+ """Return a lock rewrite only after every target row validates."""
lines = lock_path.read_text(encoding="utf-8").splitlines(keepends=True)
in_section = False
+ found: set[str] = set()
for i, raw in enumerate(lines):
- stripped = raw.rstrip("\n")
+ stripped = raw.rstrip("\r\n")
+ line_ending = raw[len(stripped) :]
if stripped.startswith("## "):
in_section = stripped[3:].strip() == section
continue
if not in_section:
continue
m = re.match(r"^(-\s+)([A-Za-z0-9_]+)(\s*:\s*)(.+?)(\s*)$", stripped)
- if m and m.group(2) == key:
- lines[i] = f"{m.group(1)}{m.group(2)}{m.group(3)}{new_value}{m.group(5)}\n"
- lock_path.write_text("".join(lines), encoding="utf-8")
- return
- raise KeyError(f"key {key!r} not found under section {section!r} in {lock_path}")
+ if not m or m.group(2) not in updates:
+ continue
+ key = m.group(2)
+ if key in found:
+ raise ValueError(
+ f"duplicate key {key!r} under section {section!r} in {lock_path}"
+ )
+ found.add(key)
+ lines[i] = (
+ f"{m.group(1)}{key}{m.group(3)}{updates[key]}{m.group(5)}"
+ f"{line_ending}"
+ )
+
+ missing = set(updates) - found
+ if missing:
+ missing_list = ", ".join(sorted(missing))
+ raise KeyError(
+ f"key(s) {missing_list} not found under section {section!r} in {lock_path}"
+ )
+ return "".join(lines)
def replace_color_in_svgs(
@@ -136,8 +157,11 @@ def main() -> int:
ap.add_argument("project_path", type=Path, help="project folder containing spec_lock.md and svg_output/")
ap.add_argument(
"assignment",
- help="section.key=value (e.g. colors.primary=#0066AA, typography.font_family='\"Inter\", Arial, sans-serif'). "
- "Bare key=value is treated as colors.key=value.",
+ help=(
+ "section.key=value (e.g. colors.primary=#0066AA, "
+ "typography.font_family='Arial, \"Microsoft YaHei\", sans-serif'). "
+ "Bare key=value is treated as colors.key=value."
+ ),
)
ap.add_argument(
"--dry-run",
@@ -183,6 +207,7 @@ def main() -> int:
return 2
old_value = section_map[key]
+ lock_changes: list[tuple[str, str, str]] = []
if section == "colors":
if not HEX_RE.match(new_value):
@@ -195,20 +220,41 @@ def main() -> int:
# avoids a state where lock claims new_value but SVGs still hold
# old_value — that state silences re-runs (parse_lock would then
# see new_value == old_value and exit early).
+ try:
+ planned_lock = plan_lock_values(lock, "colors", {key: new_value})
+ except (KeyError, ValueError) as exc:
+ print(f"error: {exc}", file=sys.stderr)
+ return 2
changed = replace_color_in_svgs(svg_dir, old_value, new_value, dry_run=args.dry_run)
+ lock_changes = [(key, old_value, new_value)]
if not args.dry_run:
- rewrite_lock(lock, "colors", key, new_value)
+ lock.write_text(planned_lock, encoding="utf-8")
elif section == "typography" and key == "font_family":
- if old_value == new_value:
- print(f"no change: typography.font_family already = {new_value}")
+ family_keys = [
+ name
+ for name in section_map
+ if name == "font_family" or name.endswith("_family")
+ ]
+ lock_changes = [
+ (name, section_map[name], new_value)
+ for name in family_keys
+ if section_map[name] != new_value
+ ]
+ if not lock_changes:
+ print(f"no change: all typography.*_family rows already = {new_value}")
return 0
try:
+ planned_lock = plan_lock_values(
+ lock,
+ "typography",
+ {name: new_value for name in family_keys},
+ )
changed = replace_font_family_in_svgs(svg_dir, new_value, dry_run=args.dry_run)
- except ValueError as e:
+ except (KeyError, ValueError) as e:
print(f"error: {e}", file=sys.stderr)
return 2
if not args.dry_run:
- rewrite_lock(lock, "typography", key, new_value)
+ lock.write_text(planned_lock, encoding="utf-8")
else:
print(
f"error: {section}.{key} is not supported by update_spec.py.\n"
@@ -219,10 +265,17 @@ def main() -> int:
return 2
if args.dry_run:
- print(f"[dry-run] spec_lock.md: {section}.{key} {old_value} → {new_value}")
+ for lock_key, previous, replacement in lock_changes:
+ print(
+ f"[dry-run] spec_lock.md: "
+ f"{section}.{lock_key} {previous} → {replacement}"
+ )
print(f"[dry-run] svg_output/: {len(changed)} file(s) would be updated")
else:
- print(f"spec_lock.md: {section}.{key} {old_value} → {new_value}")
+ for lock_key, previous, replacement in lock_changes:
+ print(
+ f"spec_lock.md: {section}.{lock_key} {previous} → {replacement}"
+ )
print(f"svg_output/: {len(changed)} file(s) updated")
for p, n in changed:
suffix = "replacement" if n == 1 else "replacements"