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(svg-to-pptx): stop treating "Unicode" and "Monotype" families as monospace

hugohe3c2668566a68b
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
index 9caa5e05..a138db30 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
@@ -2282,7 +2282,8 @@ def _run_primary_family(run: dict[str, Any]) -> str:
# Fixed-pitch faces outside the table almost always say so in their name
# (Cascadia Mono, Fira Code, Victor Mono, Noto Sans Mono CJK); 0.60 em is the
# common advance of the Courier-derived and modern coding families alike.
-_MONOSPACE_NAME_HINTS = ('mono', 'code', 'courier', 'consol', 'typewriter')
+# "Arial Unicode MS" and "Monotype Corsiva" are proportional despite the letters.
+_MONOSPACE_NAME_HINT_RE = re.compile(r'mono(?!type)|(?<!uni)code|courier|consol|typewriter')
_MONOSPACE_DEFAULT_ADVANCE_EM = 0.60
@@ -2294,7 +2295,7 @@ def _monospace_advance_em(run: dict[str, Any]) -> float | None:
advance = _MONOSPACE_ADVANCE_EM.get(family)
if advance is not None:
return advance
- if any(hint in family for hint in _MONOSPACE_NAME_HINTS):
+ if _MONOSPACE_NAME_HINT_RE.search(family):
return _MONOSPACE_DEFAULT_ADVANCE_EM
return None
diff --git a/skills/ppt-master/scripts/tests/test_text_measure.py b/skills/ppt-master/scripts/tests/test_text_measure.py
index 00b40b71..6ca76958 100644
--- a/skills/ppt-master/scripts/tests/test_text_measure.py
+++ b/skills/ppt-master/scripts/tests/test_text_measure.py
@@ -459,5 +459,18 @@ class TextMeasureTests(unittest.TestCase):
)
+
+class MonospaceFamilyHintTests(unittest.TestCase):
+ def test_proportional_families_with_mono_or_code_letters_stay_proportional(self) -> None:
+ from svg_to_pptx.drawingml.elements import _monospace_advance_em
+
+ for family in ('Arial Unicode MS', 'Lucida Sans Unicode', 'Monotype Corsiva'):
+ with self.subTest(family=family):
+ self.assertIsNone(_monospace_advance_em({'font_family': family}))
+ for family in ('Victor Mono', 'Source Code Pro'):
+ with self.subTest(family=family):
+ self.assertIsNotNone(_monospace_advance_em({'font_family': family}))
+
+
if __name__ == '__main__':
unittest.main()