def _GetCoordinates(font, glyphName): """font, glyphName --> glyph coordinates as expected by "gvar" table The result includes four "phantom points" for the glyph metrics, as mandated by the "gvar" spec. """ glyf = font["glyf"] if glyphName not in glyf.glyphs: return None glyph = glyf[glyphName] if glyph.isComposite(): coord = GlyphCoordinates([(getattr(c, 'x', 0),getattr(c, 'y', 0)) for c in glyph.components]) control = (glyph.numberOfContours,[c.glyphName for c in glyph.components]) else: allData = glyph.getCoordinates(glyf) coord = allData[0] control = (glyph.numberOfContours,)+allData[1:] # Add phantom points for (left, right, top, bottom) positions. horizontalAdvanceWidth, leftSideBearing = font["hmtx"].metrics[glyphName] if not hasattr(glyph, 'xMin'): glyph.recalcBounds(glyf) leftSideX = glyph.xMin - leftSideBearing rightSideX = leftSideX + horizontalAdvanceWidth # XXX these are incorrect. Load vmtx and fix. topSideY = glyph.yMax bottomSideY = -glyph.yMin coord = coord.copy() coord.extend([(leftSideX, 0), (rightSideX, 0), (0, topSideY), (0, bottomSideY)]) return coord, control
def _GetCoordinates(font, glyphName): """font, glyphName --> glyph coordinates as expected by "gvar" table The result includes four "phantom points" for the glyph metrics, as mandated by the "gvar" spec. """ glyf = font["glyf"] if glyphName not in glyf.glyphs: return None glyph = glyf[glyphName] if glyph.isComposite(): coord = GlyphCoordinates([(getattr(c, 'x', 0),getattr(c, 'y', 0)) for c in glyph.components]) control = [c.glyphName for c in glyph.components] else: allData = glyph.getCoordinates(glyf) coord = allData[0] control = allData[1:] # Add phantom points for (left, right, top, bottom) positions. horizontalAdvanceWidth, leftSideBearing = font["hmtx"].metrics[glyphName] if not hasattr(glyph, 'xMin'): glyph.recalcBounds(glyf) leftSideX = glyph.xMin - leftSideBearing rightSideX = leftSideX + horizontalAdvanceWidth # XXX these are incorrect. Load vmtx and fix. topSideY = glyph.yMax bottomSideY = -glyph.yMin coord = coord.copy() coord.extend([(leftSideX, 0), (rightSideX, 0), (0, topSideY), (0, bottomSideY)]) return coord, control
def _GetCoordinates(font, glyphName, defaultVerticalOrigin=None): """font, glyphName --> glyph coordinates as expected by "gvar" table The result includes four "phantom points" for the glyph metrics, as mandated by the "gvar" spec. """ glyf = font["glyf"] if glyphName not in glyf.glyphs: return None glyph = glyf[glyphName] if glyph.isComposite(): coord = GlyphCoordinates([(getattr(c, 'x', 0), getattr(c, 'y', 0)) for c in glyph.components]) control = (glyph.numberOfContours, [c.glyphName for c in glyph.components]) else: allData = glyph.getCoordinates(glyf) coord = allData[0] control = (glyph.numberOfContours, ) + allData[1:] # Add phantom points for (left, right, top, bottom) positions. phantomPoints = _get_phantom_points(font, glyphName, defaultVerticalOrigin) coord = coord.copy() coord.extend(phantomPoints) return coord, control
def _GetCoordinates(font, glyphName, defaultVerticalOrigin=None): """font, glyphName --> glyph coordinates as expected by "gvar" table The result includes four "phantom points" for the glyph metrics, as mandated by the "gvar" spec. """ glyf = font["glyf"] if glyphName not in glyf.glyphs: return None glyph = glyf[glyphName] if glyph.isComposite(): coord = GlyphCoordinates([(getattr(c, 'x', 0),getattr(c, 'y', 0)) for c in glyph.components]) control = (glyph.numberOfContours,[c.glyphName for c in glyph.components]) else: allData = glyph.getCoordinates(glyf) coord = allData[0] control = (glyph.numberOfContours,)+allData[1:] # Add phantom points for (left, right, top, bottom) positions. phantomPoints = _get_phantom_points(font, glyphName, defaultVerticalOrigin) coord = coord.copy() coord.extend(phantomPoints) return coord, control