MCPcopy Create free account
hub / github.com/PageBot/PageBot / getGlyphPath

Method getGlyphPath

Lib/pagebot/contexts/flatcontext/flatcontext.py:476–515  ·  view source on GitHub ↗

Converts the cubic commands to a drawable path.

(self, glyph, p=None, path=None)

Source from the content-addressed store, hash-verified

474 # Glyphs.
475
476 def getGlyphPath(self, glyph, p=None, path=None):
477 """Converts the cubic commands to a drawable path."""
478 if path is None:
479 path = self.newPath()
480
481 if p is None:
482 px = py = 0
483 else:
484 px = p[0]
485 py = p[1]
486
487 for command, t in glyph.cubic:
488 # TODO: quadTo()
489
490 if command == 'moveTo':
491 x, y = t
492 px0, py0 = self.getTransformed(px+x, py+y)
493 path.moveTo((px0, py0))
494 elif command == 'lineTo':
495 x, y = t
496 px0, py0 = self.getTransformed(px+x, py+y)
497 path.lineTo((px0, py0))
498 elif command == 'curveTo':
499 p0, p1, p = t
500 x0, y0 = p0
501 x1, y1 = p1
502 x, y = p
503 x0, y0 = self.getTransformed(px + x0, py + y0)
504 x1, y1 = self.getTransformed(px + x1, py + y1)
505 x, y = self.getTransformed(px + x, py + y)
506 path.curveTo((x0, y0), (x1, y1), (x, y))
507 elif command == 'closePath':
508 path.closePath()
509 elif command == 'component':
510 (x, y), componentGlyph = t
511 # Flipping `y`-axis by default to conform to OS X / DrawBot origin at bottom.
512 y = -y
513 self.getGlyphPath(componentGlyph, (px+x, py+y), path)
514
515 return path
516
517 def getFlattenedPath(self, path=None):
518 # TODO

Callers 1

drawGlyphPathMethod · 0.95

Calls 6

newPathMethod · 0.95
getTransformedMethod · 0.95
moveToMethod · 0.45
lineToMethod · 0.45
curveToMethod · 0.45
closePathMethod · 0.45

Tested by

no test coverage detected