コード例 #1
0
    def initDefaultFilters(
        self,
        removeOverlaps=False,
        overlapsBackend=None,
        convertCubics=True,
        conversionError=None,
        reverseDirection=True,
        rememberCurveType=True,
    ):
        # len(g) is the number of contours, so we include the all glyphs
        # that have both components and at least one contour
        filters = [DecomposeComponentsFilter(include=lambda g: len(g))]

        if removeOverlaps:
            from ufo2ft.filters.removeOverlaps import RemoveOverlapsFilter

            if overlapsBackend is not None:
                filters.append(RemoveOverlapsFilter(backend=overlapsBackend))
            else:
                filters.append(RemoveOverlapsFilter())

        if convertCubics:
            from ufo2ft.filters.cubicToQuadratic import CubicToQuadraticFilter

            filters.append(
                CubicToQuadraticFilter(
                    conversionError=conversionError,
                    reverseDirection=reverseDirection,
                    rememberCurveType=rememberCurveType and self.inplace,
                ))
        return filters
コード例 #2
0
    def process(self):
        from cu2qu.ufo import fonts_to_quadratic

        # first apply all custom pre-filters
        for funcs, ufo, glyphSet in zip(self.preFilters, self.ufos,
                                        self.glyphSets):
            for func in funcs:
                func(ufo, glyphSet)

        fonts_to_quadratic(
            self.glyphSets,
            max_err=self._conversionErrors,
            reverse_direction=self._reverseDirection,
            dump_stats=True,
            remember_curve_type=self._rememberCurveType and self.inplace,
        )

        decompose = DecomposeComponentsFilter(include=lambda g: len(g))
        for ufo, glyphSet in zip(self.ufos, self.glyphSets):
            decompose(ufo, glyphSet)

        # finally apply all custom post-filters
        for funcs, ufo, glyphSet in zip(self.postFilters, self.ufos,
                                        self.glyphSets):
            for func in funcs:
                func(ufo, glyphSet)

        return self.glyphSets
コード例 #3
0
def test_missing_component_is_dropped(FontClass, caplog):
    ufo = FontClass()
    a = ufo.newGlyph("a")
    a.width = 100
    pen = a.getPen()
    pen.moveTo((0, 0))
    pen.lineTo((300, 0))
    pen.lineTo((300, 300))
    pen.lineTo((0, 300))
    pen.closePath()

    aacute = ufo.newGlyph("aacute")
    aacute.width = 100
    pen = aacute.getPen()
    pen.addComponent("a", (1, 0, 0, 1, 0, 0))
    pen.addComponent("acute", (1, 0, 0, 1, 350, 0))  # missing

    assert len(ufo["aacute"]) == 0
    assert len(ufo["aacute"].components) == 2

    with caplog.at_level(logging.WARNING, logger=logger.name):
        filter_ = DecomposeComponentsFilter()

    assert filter_(ufo)
    assert len(ufo["aacute"]) == 1
    assert len(ufo["aacute"].components) == 0

    assert len(caplog.records) == 1
    assert "dropping non-existent component" in caplog.text
コード例 #4
0
def test_nested_components(FontClass):
    ufo = FontClass()
    a = ufo.newGlyph("six.lf")
    a.width = 100
    pen = a.getPen()
    pen.moveTo((0, 0))
    pen.lineTo((300, 0))
    pen.lineTo((300, 300))
    pen.lineTo((0, 300))
    pen.closePath()

    b = ufo.newGlyph("nine.lf")
    b.width = 100
    pen = b.getPen()
    pen.addComponent("six.lf", (-1, 0, 0, -1, 0, 0))

    c = ufo.newGlyph("nine")
    c.width = 100
    pen = c.getPen()
    pen.addComponent("nine.lf", (1, 0, 0, 1, 0, 0))

    filter_ = DecomposeComponentsFilter()

    assert filter_(ufo)
    assert len(ufo["six.lf"]) == 1
    assert not ufo["six.lf"].components
    assert len(ufo["nine.lf"]) == 1
    assert not ufo["nine.lf"].components
    assert len(ufo["nine"]) == 1
    assert not ufo["nine"].components
コード例 #5
0
    def initDefaultFilters(self, removeOverlaps=False, overlapsBackend=None):
        filters = [DecomposeComponentsFilter()]
        if removeOverlaps:
            from ufo2ft.filters.removeOverlaps import RemoveOverlapsFilter

            if overlapsBackend is not None:
                filters.append(RemoveOverlapsFilter(backend=overlapsBackend))
            else:
                filters.append(RemoveOverlapsFilter())

        return filters
コード例 #6
0
    def process(self):
        from cu2qu.ufo import fonts_to_quadratic

        fonts_to_quadratic(self.glyphSets,
                           max_err=self._conversionErrors,
                           reverse_direction=self._reverseDirection,
                           dump_stats=True)

        decompose = DecomposeComponentsFilter(include=lambda g: len(g))
        for ufo, glyphSet in zip(self.ufos, self.glyphSets):
            decompose(ufo, glyphSet)

        return self.glyphSets
コード例 #7
0
    def initDefaultFilters(self, removeOverlaps=False, overlapsBackend=None):
        filters = []

        _init_explode_color_layer_glyphs_filter(self.ufo, filters)

        filters.append(DecomposeComponentsFilter())

        if removeOverlaps:
            from ufo2ft.filters.removeOverlaps import RemoveOverlapsFilter

            if overlapsBackend is not None:
                filters.append(RemoveOverlapsFilter(backend=overlapsBackend))
            else:
                filters.append(RemoveOverlapsFilter())

        return filters
コード例 #8
0
deleteNames.add('.null')

glyphnames = args.glyphs if len(args.glyphs) else ufo.keys()
glyphnameSet = set(glyphnames)

glyphnames = [gn for gn in glyphnames if gn not in deleteNames]
glyphnames.sort()

nameToIdMap, idToNameMap = genGlyphIDs(glyphnames)

print('generating kerning pair data')
kerning = genKerningInfo(ufo, glyphnames, nameToIdMap)

print('preprocessing glyphs')
filters = [
    DecomposeComponentsFilter(),
    RemoveOverlapsFilter(backend=RemoveOverlapsFilter.Backend.SKIA_PATHOPS),
]
glyphSet = {g.name: g for g in ufo}
for func in filters:
    func(ufo, glyphSet)

print('generating SVGs and metrics data')

# print('\n'.join(ufo.keys()))
# sys.exit(0)

glyphMetrics = {}

# jsonLines = []
svgLines = []
コード例 #9
0
 def initDefaultFilters(self, removeOverlaps=False):
     filters = [DecomposeComponentsFilter()]
     if removeOverlaps:
         from ufo2ft.filters.removeOverlaps import RemoveOverlapsFilter
         filters.append(RemoveOverlapsFilter())
     return filters