Created
November 21, 2017 14:10
-
-
Save typemytype/98b8faa1680144cd70535b6f2475a35c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fontTools.pens.basePen import BasePen | |
| program = """void draw(SkCanvas* canvas) { | |
| SkPaint paint; | |
| SkPath path, dummy, result; | |
| SkOpBuilder builder; | |
| paint.setAntiAlias(true); | |
| path.setFillType(SkPath::kWinding_FillType); | |
| %s | |
| Op(path, dummy, SkPathOp::kUnion_SkPathOp, &result); | |
| canvas->drawPath(result, paint); | |
| result.dump(); | |
| } | |
| """ | |
| class SkiaPen(BasePen): | |
| def __init__(self, glyphSet): | |
| BasePen.__init__(self, glyphSet) | |
| self._skia = [] | |
| def _moveTo(self, xy): | |
| x, y = xy | |
| self._skia.append("path.moveTo(%s, %s);" % (x, y)) | |
| def _lineTo(self, xy): | |
| x, y = xy | |
| self._skia.append("path.lineTo(%s, %s);" % (x, y)) | |
| def _curveToOne(self, xy1, xy2, xy3): | |
| x1, y1 = xy1 | |
| x2, y2 = xy2 | |
| x3, y3 = xy3 | |
| self._skia.append("path.cubicTo(%s, %s, %s, %s, %s, %s);" % (x1, y1, x2, y2, x3, y3)) | |
| def closePath(self): | |
| self._skia.append("path.close();") | |
| def get(self): | |
| return program % "\n ".join(self._skia) | |
| g = CurrentGlyph() | |
| pen = SkiaPen(g.font) | |
| g.draw(pen) | |
| print pen.get() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment