コード例 #1
0
ファイル: glifLib_test.py プロジェクト: typoman/fonttools
    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)
コード例 #2
0
ファイル: GLIF1_test.py プロジェクト: MrBrezina/fonttools
	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))
コード例 #3
0
ファイル: glyph.py プロジェクト: huertatipografica/Andada-Pro
 def _dumpToGLIF(self, glyphFormatVersion):
     glyph = self.naked()
     return writeGlyphToString(
         glyphName=glyph.name,
         glyphObject=glyph,
         drawPointsFunc=glyph.drawPoints,
         formatVersion=glyphFormatVersion
     )
コード例 #4
0
ファイル: glyph.py プロジェクト: moyogo/fontparts
 def _dumpToGLIF(self, glyphFormatVersion):
     glyph = self.naked()
     return writeGlyphToString(
         glyphName=glyph.name,
         glyphObject=glyph,
         drawPointsFunc=glyph.drawPoints,
         formatVersion=glyphFormatVersion
     )
コード例 #5
0
 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)
コード例 #6
0
ファイル: svg2glif.py プロジェクト: behdad/fonttools
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)
コード例 #7
0
ファイル: glifLib_test.py プロジェクト: typoman/fonttools
 def testXmlDeclaration(self):
     s = writeGlyphToString("a", _Glyph())
     self.assertTrue(s.startswith(XML_DECLARATION % "UTF-8"))