diff --git a/src/fontra_compile/builder.py b/src/fontra_compile/builder.py index 02658bc..e5a484b 100644 --- a/src/fontra_compile/builder.py +++ b/src/fontra_compile/builder.py @@ -3,7 +3,7 @@ import cffsubr from fontra.core.classes import VariableGlyph -from fontra.core.path import PackedPath +from fontra.core.path import PackedPath, Path from fontra.core.protocols import ReadableFontBackend from fontTools.designspaceLib import AxisDescriptor from fontTools.fontBuilder import FontBuilder @@ -277,9 +277,7 @@ async def prepareOneGlyph(self, glyphName: str) -> GlyphInfo: componentInfo = await self.collectComponentInfo(glyph, defaultSourceIndex) - boundsPen = (BoundsPen if self.buildCFF2 else ControlBoundsPen)(None) - defaultLayerGlyph.path.drawPoints(PointToSegmentPen(boundsPen)) - leftSideBearing = boundsPen.bounds[0] if boundsPen.bounds is not None else 0 + leftSideBearing = computeLeftSideBearing(defaultLayerGlyph.path, self.buildCFF2) return GlyphInfo( ttGlyph=ttGlyph, @@ -783,6 +781,12 @@ def buildCharString(glyph, glyphSources, defaultLayerGlyph, model): return charString, charStringSupports +def computeLeftSideBearing(path: Path | PackedPath, useTightBounds: bool) -> int: + boundsPen = (BoundsPen if useTightBounds else ControlBoundsPen)(None) + path.drawPoints(PointToSegmentPen(boundsPen)) + return otRound(boundsPen.bounds[0]) if boundsPen.bounds is not None else 0 + + def prepareCFFVarData(charStrings, charStringSupports): vsindexMap = {} for supports in charStringSupports.values():