def addRCJKGlyphToVarCoUFO( ufo, rcjkGlyphSet, srcGlyphName, dstGlyphName, unicodes, renameTable, componentSourceGlyphSet, globalAxisNames, ): if renameTable is None: renameTable = {} rcjkGlyph = rcjkGlyphSet.getGlyph(srcGlyphName) if rcjkGlyph.components and not rcjkGlyph.outline.isEmpty(): logger.warning( f"glyph {srcGlyphName} has both outlines and components") glyph = UGlyph(dstGlyphName) glyph.unicodes = unicodes glyph.width = max(0, rcjkGlyph.width) # width can't be negative rcjkGlyphToVarCoGlyph(rcjkGlyph, glyph, renameTable, componentSourceGlyphSet) if globalAxisNames is None: axisNameMapping = _makeAxisNameMapping(rcjkGlyph.axes) axisNames = set(axisNameMapping.values()) else: axisNames = globalAxisNames for varIndex, rcjkVarGlyph in enumerate(rcjkGlyph.variations): location = rcjkVarGlyph.location location = normalizeLocation(location, rcjkGlyph.axes) if globalAxisNames is None: location = {axisNameMapping[k]: v for k, v in location.items()} sparseLocation = {k: v for k, v in location.items() if v != 0} layerName = layerNameFromLocation(sparseLocation, axisNames) assert layerName, (srcGlyphName, varIndex, location, rcjkGlyph.axes) layer = getUFOLayer(ufo, layerName) varGlyph = UGlyph(dstGlyphName) varGlyph.width = max(0, rcjkVarGlyph.width) # width can't be negative rcjkGlyphToVarCoGlyph(rcjkVarGlyph, varGlyph, renameTable, componentSourceGlyphSet) layer[dstGlyphName] = varGlyph ufo[dstGlyphName] = glyph
def addFlattenedGlyphsToUFO(self, ufo, location, numDecimalsRounding=0, characterSet=None, glyphSet=None): if characterSet is not None and glyphSet is not None: raise TypeError("can't pass both characterSet and glyphSet") if numDecimalsRounding == 1: roundFunc = roundFuncOneDecimal elif numDecimalsRounding != 0: assert 0, numDecimalsRounding else: roundFunc = otRound revCmap = self.getGlyphNamesAndUnicodes() glyphNames = filterGlyphNames(sorted(revCmap)) for glyphName in glyphNames: if glyphSet is not None: if glyphName not in glyphSet: continue elif characterSet is not None: codePoints = set(revCmap[glyphName]) if not codePoints & characterSet: continue glyph = UGlyph(glyphName) glyph.unicodes = revCmap[glyphName] copyMarkColor(self.characterGlyphGlyphSet.getGlyph(glyphName), glyph) pen = RoundingPointPen(glyph.getPointPen(), roundFunc) try: width = self.drawPointsCharacterGlyph(glyphName, location, pen) except InterpolationError as e: logger.warning( f"glyph {glyphName} can't be interpolated ({e})") except Exception as e: logger.warning(f"glyph {glyphName} caused an error: {e!r}") raise else: glyph.width = max(0, width) # can't be negative ufo[glyphName] = glyph