Merge pull request #3682 from ftCLI/reorder-glyphs
[ttLib.reorderGlyphs] Update CFF table charstrings and charset
This commit is contained in:
commit
18d4b17070
@ -19,9 +19,7 @@ from typing import (
|
|||||||
Deque,
|
Deque,
|
||||||
Iterable,
|
Iterable,
|
||||||
List,
|
List,
|
||||||
NamedTuple,
|
|
||||||
Tuple,
|
Tuple,
|
||||||
Union,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -276,3 +274,11 @@ def reorderGlyphs(font: ttLib.TTFont, new_glyph_order: List[str]):
|
|||||||
reorder_key = (type(value), getattr(value, "Format", None))
|
reorder_key = (type(value), getattr(value, "Format", None))
|
||||||
for reorder in _REORDER_RULES.get(reorder_key, []):
|
for reorder in _REORDER_RULES.get(reorder_key, []):
|
||||||
reorder.apply(font, value)
|
reorder.apply(font, value)
|
||||||
|
|
||||||
|
if "CFF " in font:
|
||||||
|
cff_table = font["CFF "]
|
||||||
|
charstrings = cff_table.cff.topDictIndex[0].CharStrings.charStrings
|
||||||
|
cff_table.cff.topDictIndex[0].charset = new_glyph_order
|
||||||
|
cff_table.cff.topDictIndex[0].CharStrings.charStrings = {
|
||||||
|
k: charstrings.get(k) for k in new_glyph_order
|
||||||
|
}
|
||||||
|
@ -59,6 +59,17 @@ def test_ttfont_reorder_glyphs():
|
|||||||
assert list(reversed(old_coverage2)) == new_coverage2
|
assert list(reversed(old_coverage2)) == new_coverage2
|
||||||
|
|
||||||
|
|
||||||
|
def test_reorder_glyphs_cff():
|
||||||
|
font_path = DATA_DIR / "TestVGID-Regular.otf"
|
||||||
|
font = TTFont(str(font_path))
|
||||||
|
ga = font.getGlyphOrder()
|
||||||
|
ga = list(reversed(ga))
|
||||||
|
reorderGlyphs(font, ga)
|
||||||
|
|
||||||
|
assert list(font["CFF "].cff.topDictIndex[0].CharStrings.charStrings.keys()) == ga
|
||||||
|
assert font["CFF "].cff.topDictIndex[0].charset == ga
|
||||||
|
|
||||||
|
|
||||||
def test_reorder_glyphs_bad_length(caplog):
|
def test_reorder_glyphs_bad_length(caplog):
|
||||||
font_path = DATA_DIR / "Test-Regular.ttf"
|
font_path = DATA_DIR / "Test-Regular.ttf"
|
||||||
font = TTFont(str(font_path))
|
font = TTFont(str(font_path))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user