def testRoundTrip(self): glyph = _Glyph() glyph.name = "a" glyph.unicodes = [0x0061] s1 = writeGlyphToString(glyph.name, glyph) glyph2 = _Glyph() readGlyphFromString(s1, glyph2) self.assertEqual(glyph.__dict__, glyph2.__dict__) s2 = writeGlyphToString(glyph2.name, glyph2) self.assertEqual(s1, s2)
def pyToGLIF(self, py): py = stripText(py) glyph = Glyph() exec(py, {"glyph" : glyph, "pointPen" : glyph}) glif = writeGlyphToString(glyph.name, glyphObject=glyph, drawPointsFunc=glyph.drawPoints, formatVersion=1, validate=True) # discard the first line containing the xml declaration return "\n".join(islice(glif.splitlines(), 1, None))
def _dumpToGLIF(self, glyphFormatVersion): glyph = self.naked() return writeGlyphToString( glyphName=glyph.name, glyphObject=glyph, drawPointsFunc=glyph.drawPoints, formatVersion=glyphFormatVersion )
def _dumpToGLIF(self, glyphFormatVersion): glyph = self.naked() return writeGlyphToString( glyphName=glyph.name, glyphObject=glyph, drawPointsFunc=glyph.drawPoints, formatVersion=glyphFormatVersion )
def menu_copyResult(self, sender): # copy the result to the clipboard if self.result is None: print("nothing to copy") return out = RGlyph() out.fromMathGlyph(self.result) text = writeGlyphToString("threenterpolation", out, out.drawPoints) pb = AppKit.NSPasteboard.generalPasteboard() pb.clearContents() pb.declareTypes_owner_([ NSPasteboardTypeString, ], None) pb.setString_forType_(text, AppKit.NSPasteboardTypeString)
def svg2glif(svg, name, width=0, height=0, unicodes=None, transform=None, version=2): """ Convert an SVG outline to a UFO glyph with given 'name', advance 'width' and 'height' (int), and 'unicodes' (list of int). Return the resulting string in GLIF format (default: version 2). If 'transform' is provided, apply a transformation matrix before the conversion (must be tuple of 6 floats, or a FontTools Transform object). """ glyph = SimpleNamespace(width=width, height=height, unicodes=unicodes) outline = SVGPath.fromstring(svg, transform=transform) # writeGlyphToString takes a callable (usually a glyph's drawPoints # method) that accepts a PointPen, however SVGPath currently only has # a draw method that accepts a segment pen. We need to wrap the call # with a converter pen. def drawPoints(pointPen): pen = SegmentToPointPen(pointPen) outline.draw(pen) return writeGlyphToString(name, glyphObject=glyph, drawPointsFunc=drawPoints, formatVersion=version)
def testXmlDeclaration(self): s = writeGlyphToString("a", _Glyph()) self.assertTrue(s.startswith(XML_DECLARATION % "UTF-8"))