def glyph(self, componentFlags=0x4): assert self._isClosed(), "Didn't close last contour." components = [] for glyphName, transformation in self.components: if self.points: # can't have both, so decompose the glyph tpen = TransformPen(self, transformation) self.glyphSet[glyphName].draw(tpen) continue component = GlyphComponent() component.glyphName = glyphName if transformation[:4] != (1, 0, 0, 1): component.transform = (transformation[:2], transformation[2:4]) component.x, component.y = transformation[4:] component.flags = componentFlags components.append(component) glyph = Glyph() glyph.coordinates = GlyphCoordinates(self.points) glyph.endPtsOfContours = self.endPts glyph.flags = array("B", self.types) self.init() if components: glyph.components = components glyph.numberOfContours = -1 else: glyph.numberOfContours = len(glyph.endPtsOfContours) glyph.program = ttProgram.Program() glyph.program.fromBytecode(b"") return glyph
def glyph(self, componentFlags: int = 0x4) -> Glyph: """ Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph. """ if not self._isClosed(): raise PenError("Didn't close last contour.") components = self._buildComponents(componentFlags) glyph = Glyph() glyph.coordinates = GlyphCoordinates(self.points) glyph.coordinates.toInt() glyph.endPtsOfContours = self.endPts glyph.flags = array("B", self.types) self.init() if components: # If both components and contours were present, they have by now # been decomposed by _buildComponents. glyph.components = components glyph.numberOfContours = -1 else: glyph.numberOfContours = len(glyph.endPtsOfContours) glyph.program = ttProgram.Program() glyph.program.fromBytecode(b"") return glyph
def glyph(self, componentFlags=0x4): assert self._isClosed(), "Didn't close last contour." if self.handleOverflowingTransforms: # we can't encode transform values > 2 or < -2 in F2Dot14, # so we must decompose the glyph if any transform exceeds these overflowing = any(s > 2 or s < -2 for (glyphName, transformation) in self.components for s in transformation[:4]) components = [] for glyphName, transformation in self.components: if (self.points or (self.handleOverflowingTransforms and overflowing)): # can't have both coordinates and components, so decompose try: baseGlyph = self.glyphSet[glyphName] except KeyError: self.log.debug( "can't decompose non-existing component '%s'; skipped", glyphName) continue else: tpen = TransformPen(self, transformation) baseGlyph.draw(tpen) continue component = GlyphComponent() component.glyphName = glyphName component.x, component.y = transformation[4:] transformation = transformation[:4] if transformation != (1, 0, 0, 1): if (self.handleOverflowingTransforms and any(MAX_F2DOT14 < s <= 2 for s in transformation)): # clamp values ~= +2.0 so we can keep the component transformation = tuple( MAX_F2DOT14 if MAX_F2DOT14 < s <= 2 else s for s in transformation) component.transform = (transformation[:2], transformation[2:]) component.flags = componentFlags components.append(component) glyph = Glyph() glyph.coordinates = GlyphCoordinates(self.points) glyph.endPtsOfContours = self.endPts glyph.flags = array("B", self.types) self.init() if components: glyph.components = components glyph.numberOfContours = -1 else: glyph.numberOfContours = len(glyph.endPtsOfContours) glyph.program = ttProgram.Program() glyph.program.fromBytecode(b"") return glyph
def _newGlyph(self, name, **kwargs): layer = self.naked() layer["hmtx"][name] = (0, 0) layer.glyphOrder.append(name) # newId = layer["maxp"].numGlyphs # layer["maxp"].numGlyphs = newId + 1 layer["glyf"][name] = Glyph() # XXX Only TTF layer["glyf"][name].numberOfContours = -1 # Only components right now return self[name]
def test_compile_empty_table(self): font = TTFont(sfntVersion="\x00\x01\x00\x00") font.importXML(GLYF_TTX) glyfTable = font['glyf'] # set all glyphs to zero contours glyfTable.glyphs = {glyphName: Glyph() for glyphName in font.getGlyphOrder()} glyfData = glyfTable.compile(font) self.assertEqual(glyfData, b"\x00") self.assertEqual(list(font["loca"]), [0] * (font["maxp"].numGlyphs+1))
def _make_fontfile_with_OS2(*, version, **kwargs): upem = 1000 glyphOrder = [".notdef", "a"] cmap = {0x61: "a"} glyphs = {gn: Glyph() for gn in glyphOrder} hmtx = {gn: (500, 0) for gn in glyphOrder} names = {"familyName": "TestOS2", "styleName": "Regular"} fb = FontBuilder(unitsPerEm=upem) fb.setupGlyphOrder(glyphOrder) fb.setupCharacterMap(cmap) fb.setupGlyf(glyphs) fb.setupHorizontalMetrics(hmtx) fb.setupHorizontalHeader() fb.setupNameTable(names) fb.setupOS2(version=version, **kwargs) return _compile(fb.font)
def glyph(self): glyph = Glyph() glyph.coordinates = GlyphCoordinates(self.points) glyph.endPtsOfContours = self.endPts glyph.flags = array("B", self.types) glyph.components = self.components if glyph.components: assert not glyph.endPtsOfContours, ( "TrueType glyph can't have both contours and components.") glyph.numberOfContours = -1 else: glyph.numberOfContours = len(glyph.endPtsOfContours) glyph.program = ttProgram.Program() glyph.program.fromBytecode("") return glyph
def glyph(self, componentFlags=0x4): assert self._isClosed(), "Didn't close last contour." components = self._buildComponents(componentFlags) glyph = Glyph() glyph.coordinates = GlyphCoordinates(self.points) glyph.endPtsOfContours = self.endPts glyph.flags = array("B", self.types) self.init() if components: glyph.components = components glyph.numberOfContours = -1 else: glyph.numberOfContours = len(glyph.endPtsOfContours) glyph.program = ttProgram.Program() glyph.program.fromBytecode(b"") return glyph
def glyph(self, componentFlags=0x4): """Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.""" assert self._isClosed(), "Didn't close last contour." components = self._buildComponents(componentFlags) glyph = Glyph() glyph.coordinates = GlyphCoordinates(self.points) glyph.coordinates.toInt() glyph.endPtsOfContours = self.endPts glyph.flags = array("B", self.types) self.init() if components: glyph.components = components glyph.numberOfContours = -1 else: glyph.numberOfContours = len(glyph.endPtsOfContours) glyph.program = ttProgram.Program() glyph.program.fromBytecode(b"") return glyph
def setupTable_glyf(self): """Make the glyf table.""" self.otf["loca"] = newTable("loca") self.otf["glyf"] = glyf = newTable("glyf") glyf.glyphs = {} glyf.glyphOrder = self.glyphOrder allGlyphs = self.allGlyphs for name in self.glyphOrder: glyph = allGlyphs[name] pen = TTGlyphPen(allGlyphs) try: glyph.draw(pen) except NotImplementedError: logger.error("%r has invalid curve format; skipped", name) ttGlyph = Glyph() else: ttGlyph = pen.glyph() if ttGlyph.isComposite() and self.autoUseMyMetrics: self.autoUseMyMetrics(ttGlyph, glyph.width, allGlyphs) glyf[name] = ttGlyph
def _newGlyph(self, name, **kwargs): import array layer = self.naked() self._trashPost(layer) layer["hmtx"][name] = (0, 0) layer.glyphOrder.append(name) # newId = layer["maxp"].numGlyphs # layer["maxp"].numGlyphs = newId + 1 if "hdmx" in layer: del (layer["hdmx"]) # Obviously this is wrong. XXX layer["glyf"][name] = Glyph() # XXX Only TTF layer["glyf"][name].numberOfContours = -1 # Only components right now layer["glyf"][name].flags = array.array("B", []) layer["glyf"][name].coordinates = GlyphCoordinates([]) layer["glyf"][name].endPtsOfContours = [] layer["glyf"][name].program = ttProgram.Program() layer["glyf"][name].program.fromBytecode([]) layer["glyf"][name].xMin = 0 layer["glyf"][name].yMin = 0 layer["glyf"][name].xMax = 0 layer["glyf"][name].yMax = 0 return self[name]
for key, value in data.items(): dflt, mn, mx = value["default"], value["min"], value["max"] try: f = 1.0 * (dflt - mn) / (mx - mn) except ZeroDivisionError: f = 0 # TEST THIS loc = (xtramax - xtramin) * f + xtramin location = {"XOPQ": xopq, "YOPQ": yopq, "XTRA": loc} tempFont = instantiateVariableFont(ttFont, location) tempglyph = tempFont.getGlyphSet()[key] glyf[key] = Glyph() pen = TTGlyphPen(None) tempglyph.draw(pen) glyf[key] = pen.glyph() """ #print "Removing GX tables" for tag in ('fvar','avar','gvar'): if tag in gradeFont: del gradeFont[tag] """ import os TARGET_DIR = "" fileName = "RobotoDelta-GRADmax.ttf"