def test_remove_extra_move_points(self): pen = TTGlyphPen(None) pen.moveTo((0, 0)) pen.lineTo((100, 0)) pen.qCurveTo((100, 50), (50, 100), (0, 0)) pen.closePath() self.assertEqual(len(pen.points), 4) self.assertEqual(pen.points[0], (0, 0))
def test_remove_extra_move_points(self): pen = TTGlyphPen(None) pen.moveTo((0, 0)) pen.lineTo((100, 0)) pen.qCurveTo((100, 50), (50, 100), (0, 0)) pen.closePath() assert len(pen.points) == 4 assert pen.points[0] == (0, 0)
def test_keep_duplicate_end_point(self): pen = TTGlyphPen(None) pen.moveTo((0, 0)) pen.lineTo((100, 0)) pen.qCurveTo((100, 50), (50, 100), (0, 0)) pen.lineTo((0, 0)) # the duplicate point is not removed pen.closePath() assert len(pen.points) == 5 assert pen.points[0] == (0, 0)
def test_keep_move_point(self): pen = TTGlyphPen(None) pen.moveTo((0, 0)) pen.lineTo((100, 0)) pen.qCurveTo((100, 50), (50, 100), (30, 30)) # when last and move pts are different, closePath() implies a lineTo pen.closePath() assert len(pen.points) == 5 assert pen.points[0] == (0, 0)
def test_keep_duplicate_end_point(self): pen = TTGlyphPen(None) pen.moveTo((0, 0)) pen.lineTo((100, 0)) pen.qCurveTo((100, 50), (50, 100), (0, 0)) pen.lineTo((0, 0)) # the duplicate point is not removed pen.closePath() self.assertEqual(len(pen.points), 5) self.assertEqual(pen.points[0], (0, 0))
def test_keep_move_point(self): pen = TTGlyphPen(None) pen.moveTo((0, 0)) pen.lineTo((100, 0)) pen.qCurveTo((100, 50), (50, 100), (30, 30)) # when last and move pts are different, closePath() implies a lineTo pen.closePath() self.assertEqual(len(pen.points), 5) self.assertEqual(pen.points[0], (0, 0))
def makeGlyfBBox1(calcBBoxes=True, composite=False): font = getTTFont(sfntTTFSourcePath, recalcBBoxes=calcBBoxes) glyf = font["glyf"] hmtx = font["hmtx"] for name in ("bbox1", "bbox2"): pen = TTGlyphPen(None) if name == "bbox1": pen.moveTo((0, 0)) pen.lineTo((0, 1000)) pen.lineTo((1000, 1000)) pen.lineTo((1000, 0)) pen.closePath() else: pen.moveTo((0, 0)) pen.qCurveTo((500, 750), (600, 500), (500, 250), (0, 0)) pen.closePath() glyph = pen.glyph() if not calcBBoxes: glyph.recalcBounds(glyf) glyph.xMax -= 100 glyf.glyphs[name] = glyph hmtx.metrics[name] = (0, 0) glyf.glyphOrder.append(name) if composite: name = "bbox3" pen = TTGlyphPen(glyf.glyphOrder) pen.addComponent("bbox1", [1, 0, 0, 1, 0, 0]) pen.addComponent("bbox2", [1, 0, 0, 1, 1000, 0]) glyph = pen.glyph() glyph.recalcBounds(glyf) glyf.glyphs[name] = glyph hmtx.metrics[name] = (0, 0) glyf.glyphOrder.append(name) tableData = getSFNTData(font)[0] font.close() del font header, directory, tableData = defaultSFNTTestData(tableData=tableData, flavor="TTF") data = packSFNT(header, directory, tableData, flavor="TTF") return data
def replaceGlyphRecord(font, fontFile): glyfTable = font["glyf"] for key in glyfTable.keys(): glyf = glyfTable[key] if fontFile == "TakaoGothic.ttf" and key == "aj247": ttPen = TTGlyphPen(glyfTable) ttPen.moveTo((512, 1579)) ttPen.qCurveTo((910, 1579), (910, 821)) ttPen.qCurveTo((910, 63), (512, 63)) ttPen.qCurveTo((115, 63), (115, 821)) ttPen.qCurveTo((115, 1579), None) ttPen.closePath() ttPen.moveTo((510, 1438)) ttPen.qCurveTo((283, 1438), (283, 204), (512, 204)) ttPen.qCurveTo((742, 204), (742, 823)) ttPen.qCurveTo((742, 1438), None) ttPen.closePath() glyf = ttPen.glyph() glyfTable[key] = glyf coordinates = glyf.getCoordinates(glyfTable) coordinates[0].translate((0, -137)) glyf.removeHinting() glyfTable.compile(font)