Esempio n. 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
Esempio n. 2
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
    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
Esempio n. 4
0
    def _loadDesignspace(self, designspace):
        # Note: Only used for building variable fonts
        log.info("loading designspace sources")
        if isinstance(designspace, str):
            designspace = DesignSpaceDocument.fromfile(designspace)
        else:
            # copy that we can mess with
            designspace = DesignSpaceDocument.fromfile(designspace.path)

        masters = designspace.loadSourceFonts(opener=Font)
        # masters = [s.font for s in designspace.sources]  # list of UFO font objects

        # Update the default source's full name to not include style name
        defaultFont = designspace.default.font
        defaultFont.info.openTypeNameCompatibleFullName = defaultFont.info.familyName

        log.info("Preprocessing glyphs")
        # find glyphs subject to decomposition and/or overlap removal
        # TODO: Find out why this loop is SO DAMN SLOW. It might just be so that defcon is
        #       really slow when reading glyphs. Perhaps we can sidestep defcon and just
        #       read & parse the .glif files ourselves.
        glyphNamesToDecompose = set()  # glyph names
        glyphsToRemoveOverlaps = set()  # glyph objects
        for ufo in masters:
            # Note: ufo is of type defcon.objects.font.Font
            # update font version
            updateFontVersion(ufo, dummy=False, isVF=True)
            componentReferences = set(ufo.componentReferences)
            for g in ufo:
                directives = findGlyphDirectives(g.note)
                if self._shouldDecomposeGlyph(g, directives,
                                              componentReferences):
                    glyphNamesToDecompose.add(g.name)
                if 'removeoverlap' in directives:
                    if g.components and len(g.components) > 0:
                        glyphNamesToDecompose.add(g.name)
                    glyphsToRemoveOverlaps.add(g)

        self._decompose(masters, glyphNamesToDecompose)

        # remove overlaps
        if glyphsToRemoveOverlaps:
            rmoverlapFilter = RemoveOverlapsFilter(backend='pathops')
            rmoverlapFilter.start()
            if log.isEnabledFor(logging.DEBUG):
                log.debug(
                    'Removing overlaps in glyphs:\n  %s',
                    "\n  ".join(set([g.name for g in glyphsToRemoveOverlaps])),
                )
            elif log.isEnabledFor(logging.INFO):
                log.info('Removing overlaps in %d glyphs',
                         len(glyphsToRemoveOverlaps))
            for g in glyphsToRemoveOverlaps:
                rmoverlapFilter.filter(g)

        # handle control back to fontmake
        return designspace
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 = []
for glyphname in glyphnames:
Esempio n. 6
0
 def initDefaultFilters(self, removeOverlaps=False):
     filters = [DecomposeComponentsFilter()]
     if removeOverlaps:
         from ufo2ft.filters.removeOverlaps import RemoveOverlapsFilter
         filters.append(RemoveOverlapsFilter())
     return filters