def componentsOverlap(glyph: _g_l_y_f.Glyph, glyphSet: _TTGlyphMapping) -> bool: if not glyph.isComposite(): raise ValueError("This method only works with TrueType composite glyphs") if len(glyph.components) < 2: return False # single component, no overlaps component_paths = {} def _get_nth_component_path(index: int) -> pathops.Path: if index not in component_paths: component_paths[index] = skPathFromGlyphComponent( glyph.components[index], glyphSet ) return component_paths[index] return any( pathops.op( _get_nth_component_path(i), _get_nth_component_path(j), pathops.PathOp.INTERSECTION, fix_winding=False, keep_starting_points=False, ) for i, j in itertools.combinations(range(len(glyph.components)), 2) )
def _do_pathop(op, svg_shapes): if not svg_shapes: return SVGPath() sk_path = skia_path(svg_shapes[0]) for svg_shape in svg_shapes[1:]: sk_path2 = skia_path(svg_shape) sk_path = pathops.op(sk_path, sk_path2, op) return svg_path(sk_path)
def _do_pathop(op: str, svg_cmd_seqs: Sequence[SVGCommandSeq], fill_rules: Sequence[str]) -> SVGCommandGen: if not svg_cmd_seqs: return # pytype: disable=bad-return-type assert len(svg_cmd_seqs) == len(fill_rules) sk_path = skia_path(svg_cmd_seqs[0], fill_rules[0]) for svg_cmds, fill_rule in zip(svg_cmd_seqs[1:], fill_rules[1:]): sk_path2 = skia_path(svg_cmds, fill_rule) sk_path = pathops.op(sk_path, sk_path2, op, fix_winding=True) else: sk_path.simplify(fix_winding=True) assert sk_path.fillType == pathops.FillType.WINDING return svg_commands(sk_path)
def _doPathOp(self, other, operator): from pathops import Path, op path1 = Path() path2 = Path() self.drawToPen(path1.getPen()) other.drawToPen(path2.getPen()) result = op( path1, path2, operator, fix_winding=True, keep_starting_points=True, ) resultPath = BezierPath() result.draw(resultPath) return resultPath