Skip to content

Commit

Permalink
Merge pull request #62 from googlefonts/fix-data-format
Browse files Browse the repository at this point in the history
Fix glyphDataFormat for CFF2 (VARC) output
  • Loading branch information
justvanrossum authored Oct 25, 2024
2 parents 581b501 + 82604c7 commit f1533a4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/fontra_compile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ async def main_async() -> None:
help="Comma- or space-delimited list of glyph names to include. "
"When not given, include all glyphs.",
)
parser.add_argument(
"--no-cff-subroutinize",
action="store_true",
help="Don't perform CFF subroutinizing.",
)

args = parser.parse_args()
sourceFontPath = pathlib.Path(args.source_font).resolve()
Expand All @@ -27,6 +32,7 @@ async def main_async() -> None:
reader=reader,
requestedGlyphNames=glyphNames,
buildCFF2=outputFontPath.suffix.lower() == ".otf",
subroutinize=not args.no_cff_subroutinize,
)
await builder.setup()
ttFont = await builder.build()
Expand Down
7 changes: 5 additions & 2 deletions src/fontra_compile/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class Builder:
reader: ReadableFontBackend # a Fontra Backend, such as DesignspaceBackend
requestedGlyphNames: list = field(default_factory=list)
buildCFF2: bool = False
subroutinize: bool = True

async def setup(self) -> None:
self.glyphMap = await self.reader.getGlyphMap()
Expand Down Expand Up @@ -442,7 +443,9 @@ async def setupComponentBaseInfo(self, baseGlyphName: str) -> dict[str, Any]:
async def buildFont(self) -> TTFont:
builder = FontBuilder(
await self.reader.getUnitsPerEm(),
glyphDataFormat=1,
glyphDataFormat=(
0 if self.buildCFF2 else 1
), # FIXME: set only for cubic-in-glyf
isTTF=not self.buildCFF2,
)

Expand Down Expand Up @@ -495,7 +498,7 @@ async def buildFont(self) -> TTFont:
builder.setupOS2()
builder.setupPost()

if self.buildCFF2:
if self.buildCFF2 and self.subroutinize:
cffsubr.subroutinize(builder.font)

return builder.font
Expand Down
5 changes: 4 additions & 1 deletion src/fontra_compile/compile_varc_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class FontraCompileAction:
destination: str
input: ReadableFontBackend | None = field(init=False, default=None)
subroutinize: bool = True

@asynccontextmanager
async def connect(
Expand All @@ -33,7 +34,9 @@ async def process(
outputFontPath = outputDir / self.destination
assert self.input is not None
builder = Builder(
reader=self.input, buildCFF2=outputFontPath.suffix.lower() == ".otf"
reader=self.input,
buildCFF2=outputFontPath.suffix.lower() == ".otf",
subroutinize=self.subroutinize,
)
await builder.setup()
ttFont = await builder.build()
Expand Down
2 changes: 1 addition & 1 deletion tests/data/MutatorSans.otf.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<lowestRecPPEM value="3"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="1"/>
<glyphDataFormat value="0"/>
</head>

<hhea>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/figArnaud.otf.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<lowestRecPPEM value="3"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="1"/>
<glyphDataFormat value="0"/>
</head>

<hhea>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/notosanscjksc.otf.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<lowestRecPPEM value="3"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="1"/>
<glyphDataFormat value="0"/>
</head>

<hhea>
Expand Down

0 comments on commit f1533a4

Please sign in to comment.