Skip to content

Commit

Permalink
Merge pull request #971 from googlefonts/fontmake-no-variable
Browse files Browse the repository at this point in the history
[ttx_diff] Smarter selection of fontmake -o flag
  • Loading branch information
cmyr authored Sep 19, 2024
2 parents 09025bf + 3555574 commit a612b74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions resources/scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ fontmake[repacker]==3.8.1
fonttools
lxml
cdifflib
glyphsLib
15 changes: 14 additions & 1 deletion resources/scripts/ttx_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import sys
from cdifflib import CSequenceMatcher as SequenceMatcher
from typing import MutableSequence
from glyphsLib import GSFont
from fontTools.designspaceLib import DesignSpaceDocument


_COMPARE_DEFAULTS = "default"
Expand Down Expand Up @@ -199,7 +201,7 @@ def build_fontc(source: Path, fontc_cargo_path: Path, build_dir: Path, compare:

def build_fontmake(source: Path, build_dir: Path, compare: str):
buildtype = "variable"
if source.suffix == ".ufo":
if not source_is_variable(source):
buildtype = "ttf"
cmd = [
"fontmake",
Expand Down Expand Up @@ -230,6 +232,17 @@ def build_fontmake(source: Path, build_dir: Path, compare: str):
"fontmake",
)

def source_is_variable(path: Path) -> bool:
if path.suffix == ".ufo":
return False
if path.suffix == ".designspace":
dspace = DesignSpaceDocument.fromfile(path)
return len(dspace.sources) > 1
if path.suffix == ".glyphs" or path.suffix == ".glyphspackage":
font = GSFont(path)
return len(font.masters) > 1
# fallback to variable, the existing default, but we should never get here?
return True

def copy(old, new):
shutil.copyfile(old, new)
Expand Down

0 comments on commit a612b74

Please sign in to comment.