Skip to content

Commit eaab73f

Browse files
authored
Merge pull request #27 from jenskutilek/ttf-pointpen
Use PointPen to preserve TrueType point indices
2 parents 22941bf + ec3e92f commit eaab73f

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

Lib/extractor/formats/opentype.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -314,34 +314,11 @@ def binaryToIntList(value, start=0):
314314

315315
def extractOpenTypeGlyphs(source, destination):
316316
# grab the cmap
317-
cmap = source["cmap"]
318317
vmtx = source.get("vmtx")
319318
vorg = source.get("VORG")
320-
preferred = [
321-
(3, 10, 12),
322-
(3, 10, 4),
323-
(3, 1, 12),
324-
(3, 1, 4),
325-
(0, 3, 12),
326-
(0, 3, 4),
327-
(3, 0, 12),
328-
(3, 0, 4),
329-
(1, 0, 12),
330-
(1, 0, 4)
331-
]
332-
found = {}
333-
for table in cmap.tables:
334-
found[table.platformID, table.platEncID, table.format] = table
335-
table = None
336-
for key in preferred:
337-
if key not in found:
338-
continue
339-
table = found[key]
340-
break
341-
reversedMapping = {}
342-
if table is not None:
343-
for uniValue, glyphName in table.cmap.items():
344-
reversedMapping[glyphName] = uniValue
319+
cmap = source.getBestCmap()
320+
is_ttf = "glyf" in source
321+
reversedMapping = source.get("cmap").buildReversed()
345322
# grab the glyphs
346323
glyphSet = source.getGlyphSet()
347324
for glyphName in glyphSet.keys():
@@ -350,8 +327,12 @@ def extractOpenTypeGlyphs(source, destination):
350327
destination.newGlyph(glyphName)
351328
destinationGlyph = destination[glyphName]
352329
# outlines
353-
pen = destinationGlyph.getPen()
354-
sourceGlyph.draw(pen)
330+
if is_ttf:
331+
pen = destinationGlyph.getPointPen()
332+
sourceGlyph.drawPoints(pen)
333+
else:
334+
pen = destinationGlyph.getPen()
335+
sourceGlyph.draw(pen)
355336
# width
356337
destinationGlyph.width = sourceGlyph.width
357338
# height and vertical origin
@@ -370,8 +351,8 @@ def extractOpenTypeGlyphs(source, destination):
370351
continue
371352
xMin, yMin, xMax, yMax = bounds_pen.bounds
372353
destinationGlyph.verticalOrigin = tsb + yMax
373-
# unicode
374-
destinationGlyph.unicode = reversedMapping.get(glyphName)
354+
# unicodes
355+
destinationGlyph.unicodes = reversedMapping.get(glyphName, [])
375356

376357
# -------
377358
# Kerning

0 commit comments

Comments
 (0)