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: wrap keeps words whole in every space-delimited script

hugohe388fb8221c29f
diff --git a/skills/ppt-master/scripts/tests/test_dogfood_leaves_fixes.py b/skills/ppt-master/scripts/tests/test_dogfood_leaves_fixes.py
index daded3e1..06764afd 100644
--- a/skills/ppt-master/scripts/tests/test_dogfood_leaves_fixes.py
+++ b/skills/ppt-master/scripts/tests/test_dogfood_leaves_fixes.py
@@ -427,6 +427,15 @@ class KoreanIntakeTests(unittest.TestCase):
for line in lines:
self.assertTrue(set(line.split()) <= words, lines)
+ def test_wrap_keeps_arabic_and_cyrillic_words_whole(self) -> None:
+ for text in (
+ "القهوة العربية رمز للكرم والضيافة في شبه الجزيرة العربية",
+ "Кофе по-арабски является символом гостеприимства на Аравийском полуострове",
+ ):
+ lines, _widths, _oversized = text_measure.wrap_text(
+ text, size=24, max_width=260, family="Arial", include_headroom=False)
+ self.assertEqual(" ".join(lines).split(), text.split(), lines)
+
def test_pdf_join_keeps_korean_word_space(self) -> None:
self.assertEqual(pdf_to_md.join_wrapped_text("감소하였으며", "이중"), "감소하였으며 이중")
self.assertEqual(pdf_to_md.join_wrapped_text("新幹", "線"), "新幹線")
diff --git a/skills/ppt-master/scripts/text_measure.py b/skills/ppt-master/scripts/text_measure.py
index a68c32cc..6cd000b3 100644
--- a/skills/ppt-master/scripts/text_measure.py
+++ b/skills/ppt-master/scripts/text_measure.py
@@ -36,7 +36,7 @@ from svg_to_pptx.drawingml.elements import estimate_single_line_text_frame_width
from svg_to_pptx.drawingml.utils import split_project_text_clusters # noqa: E402
-_CLOSING_PUNCTUATION = frozenset(',.;:!?)]}、,。;:!?)》」』】”’')
+_CLOSING_PUNCTUATION = frozenset(',.;:!?)]}、,。;:!?)》」』】”’،؛؟')
_OPENING_PUNCTUATION = frozenset('([{(《「『【“‘')
# Japanese line-start prohibitions beyond punctuation: small kana, the long
# vowel mark, iteration marks, and the middle dot never open a line.
@@ -116,15 +116,26 @@ def measure_text(
)
-def _is_latin_or_number_cluster(cluster: str) -> bool:
- """Return whether a rendered cluster belongs to a Latin/number token."""
+# Scripts written without spaces between words; everything else that is a
+# letter or digit (Latin, Cyrillic, Greek, Arabic, Hebrew, Devanagari, ...)
+# forms words that only break at spaces.
+_UNSPACED_SCRIPT_PREFIXES = ('THAI ', 'LAO ', 'KHMER ', 'MYANMAR ', 'TIBETAN ')
+
+
+def _is_word_cluster(cluster: str) -> bool:
+ """Return whether a rendered cluster belongs to a space-delimited word."""
bases = [
ch
for ch in cluster
if unicodedata.category(ch) not in {'Mn', 'Mc', 'Me'}
]
return bool(bases) and all(
- ch.isdigit() or 'LATIN' in unicodedata.name(ch, '')
+ ch.isdigit()
+ or (
+ ch.isalpha()
+ and unicodedata.east_asian_width(ch) not in {'W', 'F'}
+ and not unicodedata.name(ch, '').startswith(_UNSPACED_SCRIPT_PREFIXES)
+ )
for ch in bases
)
@@ -138,7 +149,7 @@ def _is_hangul_cluster(cluster: str) -> bool:
def _lexical_units(text: str) -> list[str]:
- """Split a paragraph while keeping Latin words, numbers, and Korean words atomic."""
+ """Split a paragraph while keeping space-delimited words, numbers, and Korean words atomic."""
clusters = split_project_text_clusters(' '.join(text.split()))
units: list[str] = []
pending_space = False
@@ -158,10 +169,10 @@ def _lexical_units(text: str) -> list[str]:
# Korean breaks between space-separated words (eojeol), never
# inside one; an eojeol wider than the line is reported oversized.
end = word_end
- elif _is_latin_or_number_cluster(cluster):
+ elif _is_word_cluster(cluster):
while end < len(clusters):
next_cluster = clusters[end]
- if _is_latin_or_number_cluster(next_cluster):
+ if _is_word_cluster(next_cluster):
end += 1
continue
connector = (
@@ -174,7 +185,7 @@ def _lexical_units(text: str) -> list[str]:
if (
connector
and end + 1 < len(clusters)
- and _is_latin_or_number_cluster(clusters[end + 1])
+ and _is_word_cluster(clusters[end + 1])
):
end += 2
continue