コード例 #1
0
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)
    )
コード例 #2
0
def number_of_contours(glyphname: str, glyph: Glyph, tt: TTFont) -> int:
    """
    Returns the number of contours in a glyph outline.  Composite
    glyphs are decomposed before assessment.
    """
    if glyph.isComposite():
        # decompose composite glyphs
        glyph = skia_path_to_ttfont_glyph(
            ttfont_glyph_to_skia_path(glyphname, tt))
    return glyph.numberOfContours
コード例 #3
0
ファイル: outlineCompiler.py プロジェクト: lamby/ufo2ft
    def setupTable_glyf(self):
        """Make the glyf table."""

        self.otf["loca"] = newTable("loca")
        self.otf["glyf"] = glyf = newTable("glyf")
        glyf.glyphs = {}
        glyf.glyphOrder = self.glyphOrder

        allGlyphs = self.allGlyphs
        for name in self.glyphOrder:
            glyph = allGlyphs[name]
            pen = TTGlyphPen(allGlyphs)
            try:
                glyph.draw(pen)
            except NotImplementedError:
                logger.error("%r has invalid curve format; skipped", name)
                ttGlyph = Glyph()
            else:
                ttGlyph = pen.glyph()
                if ttGlyph.isComposite() and self.autoUseMyMetrics:
                    self.autoUseMyMetrics(ttGlyph, glyph.width, allGlyphs)
            glyf[name] = ttGlyph
コード例 #4
0
def _get_components_with_transforms(glyph: Glyph) -> Sequence[Tuple]:
    """
    Returns list with component glyph names and x,y transforms
    for composite glyphs with transforms. In all other cases,
    returns an empty list
    """
    components_with_transforms = []
    if glyph.isComposite():
        for component in glyph.components:
            if hasattr(component, "transform"):
                # transform attribute will include one of the
                # following data sets:
                # (1) simple X and Y scale only @ [0][0]
                # (2) x-scale @ [0][0] and y-scale @ [1][1]
                # (3) x-scale @ [0][0], scale01 @ [0][1],
                #     y-scale @ [1][1], scale10 @ [1][0]
                a1 = round(component.transform[0][0], 3)
                a2 = round(component.transform[0][1], 3)
                b1 = round(component.transform[1][0], 3)
                b2 = round(component.transform[1][1], 3)
                components_with_transforms.append(
                    (component.glyphName, [[a1, a2], [b1, b2]]))
    return components_with_transforms