Changing an element's font leaves Arabic, Hebrew and Indic text on the old
typeface, so the control looks broken for anyone writing in those scripts.
OOXML splits a run's font into three slots and picks by script: a:latin, a:ea
for CJK, and a:cs for complex scripts. Every emit site wrote latin and ea and
left cs alone:
before <a:latin typeface="Calibri"/><a:cs typeface="Traditional Arabic"/>
pick Amiri
after <a:latin typeface="Amiri"/><a:cs typeface="Traditional Arabic"/>
The Latin half of a mixed run changes and the Arabic half does not. A run that
declares no fonts at all, which is the shape the deck fixtures actually use, got
latin and ea injected and still no cs.
Write the three slots together wherever the font is set, and clear csFont with
its latin and ea siblings so a rebuilt run re-derives it from the choice the user
made instead of re-emitting the old typeface.
patchRunFont now works on the direct children of the run's own a:rPr, through the
depth-aware scanner already in this file, rather than searching the whole run
slice. a:ln carries its own extension payloads and a:extLst holds arbitrary ones,
so a typeface nested in either belongs to whatever wrote it and is left alone.
The group is rebuilt whole rather than patched in place, so a run carrying only
a:cs comes back as latin, ea, cs rather than gaining a second a:cs or landing out
of schema order. Elements that were already present keep their other attributes,
pitchFamily, charset and panose among them.
The structured path is taken only when every direct child of the run properties
is a recognised CT_TextCharacterProperties element and the run holds no comment,
CDATA or processing instruction. Any of those can put element-looking text where
a child is not, and a markup-compatibility wrapper supplies its children only
once a consumer picks a branch, whatever prefix it was bound to. Everything else
keeps the previous function unchanged, a:cs untouched included, so a run this
file cannot read structurally is handled exactly as it was before.
Two details the scan needed. XML names may begin with an underscore or a
non-ASCII character, so the child scan was anchored too narrowly and could not
see a wrapper bound to such a prefix. And a slot's typeface is now read from its
start tag alone, by whole attribute name, so a payload nested inside a paired
slot keeps what it declared and an attribute merely ending in "typeface" is left
as it is.
Two details the scan needed. The child scan reads a name as [a-zA-Z][\w:]*,
while XML also allows a leading underscore, a non-ASCII character and an interior
middle dot, so a name outside that is read short and one element is mistaken for
another. Rather than widen a scanner five other callers share, a run carrying any
such name is handled by the previous function. And a slot's typeface is read from
its start tag alone, by whole attribute name, so a payload nested in a paired slot
keeps what it declared and an attribute merely ending in "typeface" is left alone.
The run's properties are taken as a direct child rather than as the first a:rPr
in the text, since an extension payload may carry one of its own, and both its
opening and closing tags are located rather than assumed: a closing tag may carry
whitespace before its bracket, and measuring it by a fixed length splices through
it.
A run that repeats a font slot also goes to the previous function. The schema
allows one of each, and rebuilding the group from one of them would drop the
others along with their attributes.
Setting a slot to the typeface it already carries leaves the element untouched,
which is not the same as the element having no typeface, so the attribute is
added or replaced in one place rather than inferred from an unchanged string. And
a run whose properties cannot be located structurally is handed to the previous
function rather than returned untouched, since a payload carrying its own closing
tag can truncate the slice this is given. A slot's start tag is
sliced at its known boundaries rather than grouped by pattern, since an attribute
pattern permissive enough for unquoted values also swallows the slash of a
self-closing tag.