Skip to content

Commit

Permalink
[fontc] Add --experimental-simple-output cli option
Browse files Browse the repository at this point in the history
This does two things:

- it takes a path, where all our final build products will be saved
- it reduces the set of build targets to match what we would build
  with fontc
  • Loading branch information
cmyr committed Oct 16, 2024
1 parent ec5552c commit a783e58
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
31 changes: 24 additions & 7 deletions Lib/gftools/builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from fontmake.font_project import FontProject
from ninja import _program
from ninja.ninja_syntax import Writer, escape_path
from typing import Union

from gftools.builder.file import File
from gftools.builder.operations import OperationBase, OperationRegistry
Expand All @@ -36,7 +37,12 @@ class GFBuilder:
config: dict
recipe: Recipe

def __init__(self, config: Union[dict, str], use_fontc=False, simple_outputs=False):
def __init__(
self,
config: Union[dict, str],
use_fontc=False,
simple_outputs=Union[Path, None],
):
if isinstance(config, str):
parentpath = Path(config).resolve().parent
with open(config, "r") as file:
Expand All @@ -62,11 +68,16 @@ def __init__(self, config: Union[dict, str], use_fontc=False, simple_outputs=Fal
# override config to turn not build instances if we're variable
if self.config.get("buildVariable", True):
self.config["buildStatic"] = False
# if the font doesn't explicitly request CFF, just built TT outlines
# if the font doesn't explicitly request CFF, just build TT outlines
# if the font _only_ wants CFF outlines, we will try to build them
# ( but fail on fontc for now )
# ( but fail on fontc for now) (but is this even a thing?)
elif self.config.get("buildTTF", True):
self.config["buildOTF"] = False
if simple_outputs:
# we dump everything into one dir in this case
self.config["outputDir"] = str(simple_outputs)
self.config["ttDir"] = str(simple_outputs)
self.config["otDir"] = str(simple_outputs)

self.known_operations = OperationRegistry(use_fontc=use_fontc)
self.writer = Writer(open("build.ninja", "w"))
Expand Down Expand Up @@ -173,7 +184,6 @@ def operation_step_to_object(self, step):
cls = self.known_operations.get(operation)
if cls is None:
raise ValueError(f"Unknown operation {operation}")

if operation not in self.used_operations:
self.used_operations.add(operation)
cls.write_rules(self.writer)
Expand Down Expand Up @@ -404,12 +414,15 @@ def main(args=None):

parser.add_argument(
"--experimental-simple-output",
help="For comparison with fontc: skip instancing, webfonts, and OTF (if building TTF)",
action="store_true",
help="generate a reduced set of targets, and copy them to the provided directory",
type=Path,
)

parser.add_argument("config", help="Path to config file or source file", nargs="+")
args = parser.parse_args(args)
if args.experimental_simple_output:
# get the abs path because we use cwd later and relative paths will break
args.experimental_simple_output = args.experimental_simple_output.absolute()
yaml_files = []
source_files = []
for config in args.config:
Expand All @@ -431,7 +444,11 @@ def main(args=None):
raise ValueError("Only one config file can be given for now")
config = args.config[0]

pd = GFBuilder(config, use_fontc=args.experimental_fontc, simple_outputs=args.experimental_simple_output)
pd = GFBuilder(
config,
use_fontc=args.experimental_fontc,
simple_outputs=args.experimental_simple_output,
)
if args.generate:
config = pd.config
config["recipe"] = pd.recipe
Expand Down
1 change: 1 addition & 0 deletions Lib/gftools/builder/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def get(self, operation_name: str):

if operation_name == "buildOTF":
from .fontc.fontcBuildOTF import FontcBuildOTF

return FontcBuildOTF

return self.known_operations.get(operation_name)
Expand Down
2 changes: 1 addition & 1 deletion Lib/gftools/builder/recipeproviders/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def build_a_static(self, source: File, instance: InstanceDescriptor, output):
{"source": source.path},
]
# if we're running fontc we skip conversion to UFO
if not source.is_ufo and not self.config.get('use_fontc', False):
if not source.is_ufo and not self.config.get("use_fontc", False):
instancename = instance.name
if instancename is None:
if not instance.familyName or not instance.styleName:
Expand Down

0 comments on commit a783e58

Please sign in to comment.