Skip to content

Commit

Permalink
Factor out computation of LSB
Browse files Browse the repository at this point in the history
  • Loading branch information
justvanrossum committed Jul 15, 2024
1 parent 8bbb973 commit a82fae4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/fontra_compile/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit a82fae4

Please sign in to comment.