def get_cached_glyph(self, name): if name in self.glyphcache: return self.glyphcache[name] paths = BezierPath.fromFonttoolsGlyph(self.font, name) pathbounds = [] paths = list(filter(lambda p: p.length > 0, paths)) for p in paths: p.hasAnchor = False p.glyphname = name if name in self.anchors: for a in self.anchors[name]: if p.pointIsInside(Point(*a)): p.hasAnchor = True bounds = p.bounds() pathbounds.append(bounds) glyphbounds = BoundingBox() if pathbounds: for p in pathbounds: glyphbounds.extend(p) else: glyphbounds.tr = Point(0, 0) glyphbounds.bl = Point(0, 0) self.glyphcache[name] = { "name": name, "paths": paths, "pathbounds": pathbounds, "glyphbounds": glyphbounds, "category": categorize_glyph(self.font, name)[0], "pathconvexhull": None # XXX } assert (len(self.glyphcache[name]["pathbounds"]) == len( self.glyphcache[name]["paths"])) return self.glyphcache[name]
def calcStart(f, n, verbose): g = f['glyf'][n] #bs = BezierPath.fromFonttoolsGlyph(g, gset, f['glyf']) bs = BezierPath.fromFonttoolsGlyph(f, n) # for b in bs: # b.removeOverlap() bs = removeEncompassed(bs, verbose) segs = sum((b.asSegments() for b in bs), []) area = sum(s.area for s in segs) start = Octabox(segs) return start
def xheight_intersections(ttFont, glyph): glyphset = ttFont.getGlyphSet() if glyph not in glyphset: return [] paths = BezierPath.fromFonttoolsGlyph(ttFont, glyph) if len(paths) != 1: return [] path = paths[0] xheight = ttFont["OS/2"].sxHeight bounds = path.bounds() bounds.addMargin(10) ray = Line(Point(bounds.left, xheight), Point(bounds.right, xheight)) intersections = [] for seg in path.asSegments(): intersections.extend(seg.intersections(ray)) return sorted(intersections, key=lambda i: i.point.x)
def outlines_dict(ttFont): return {g: BezierPath.fromFonttoolsGlyph(ttFont, g) for g in ttFont.getGlyphOrder()}