From f08bf1e5663cb4a4d3c017e7484f35fff8a4396c Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Sat, 13 Jul 2024 14:47:27 +0200 Subject: [PATCH] Generalize helper func, because who knows --- src/fontra_compile/builder.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/fontra_compile/builder.py b/src/fontra_compile/builder.py index b4e2a81..9225364 100644 --- a/src/fontra_compile/builder.py +++ b/src/fontra_compile/builder.py @@ -484,9 +484,9 @@ async def buildFont(self) -> TTFont: builder.setupHorizontalHeader() builder.setupHorizontalMetrics( - addLSB( - getGlyphInfoAttributes(self.glyphInfos, "leftSideBearing"), + dictZip( getGlyphInfoAttributes(self.glyphInfos, "xAdvance"), + getGlyphInfoAttributes(self.glyphInfos, "leftSideBearing"), ) ) hvarTable = self.buildHVAR(axisTags) @@ -815,13 +815,11 @@ def prepareCFFVarData(charStrings, charStringSupports): return varDataList, regionList -def addLSB( - leftSideBearings: dict[str, int], metrics: dict[str, int] -) -> dict[str, tuple[int, int]]: - return { - glyphName: (xAdvance, leftSideBearings.get(glyphName, 0)) - for glyphName, xAdvance in metrics.items() - } +def dictZip(*dicts: dict) -> dict: + keys = dicts[0].keys() + if not all(keys == d.keys() for d in dicts[1:]): + raise ValueError("all input dicts must have the same set of keys") + return {key: tuple(d[key] for d in dicts) for key in keys} def applyAxisMapToAxisValues(axis) -> tuple[float, float, float]: