glyf: support setting vmtx advance/tsb from phantom points

This commit is contained in:
Cosimo Lupo 2019-04-20 13:05:42 +01:00
parent 2b50b94ed7
commit 91089b7a1b
No known key found for this signature in database
GPG Key ID: 179A8F0895A02F4F

View File

@ -362,9 +362,9 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
"coord" is an array of GlyphCoordinates which must include the four "coord" is an array of GlyphCoordinates which must include the four
"phantom points". "phantom points".
Only the horizontal advance and sidebearings in "hmtx" table are updated Both the horizontal/vertical advances and left/top sidebearings in "hmtx"
from the first two phantom points. The last two phantom points for and "vmtx" tables (if any) are updated from four phantom points and
vertical typesetting are currently ignored. the glyph's bounding boxes.
""" """
# TODO: Create new glyph if not already present # TODO: Create new glyph if not already present
assert glyphName in self.glyphs assert glyphName in self.glyphs
@ -400,9 +400,15 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
# https://github.com/fonttools/fonttools/pull/1198 # https://github.com/fonttools/fonttools/pull/1198
horizontalAdvanceWidth = 0 horizontalAdvanceWidth = 0
leftSideBearing = otRound(glyph.xMin - leftSideX) leftSideBearing = otRound(glyph.xMin - leftSideX)
# TODO Handle vertical metrics?
ttFont["hmtx"].metrics[glyphName] = horizontalAdvanceWidth, leftSideBearing ttFont["hmtx"].metrics[glyphName] = horizontalAdvanceWidth, leftSideBearing
if "vmtx" in ttFont:
verticalAdvanceWidth = otRound(topSideY - bottomSideY)
if verticalAdvanceWidth < 0: # unlikely but do the same as horizontal
verticalAdvanceWidth = 0
topSideBearing = otRound(topSideY - glyph.yMax)
ttFont["vmtx"].metrics[glyphName] = verticalAdvanceWidth, topSideBearing
_GlyphControls = namedtuple( _GlyphControls = namedtuple(
"_GlyphControls", "numberOfContours endPts flags components" "_GlyphControls", "numberOfContours endPts flags components"