Skip to content

Commit

Permalink
Disable JSON structure when using fontc
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Nov 20, 2024
1 parent f0b9df0 commit 1eba766
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Lib/gftools/builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def edge_with_operation(node, operation):
class GFBuilder:
config: dict
recipe: Recipe
fontc_args: FontcArgs

def __init__(
self,
Expand All @@ -60,6 +61,7 @@ def __init__(
else:
self._orig_config = yaml.dump(config)
self.config = config
self.fontc_args = fontc_args
fontc_args.modify_config(self.config)

self.known_operations = OperationRegistry(use_fontc=fontc_args.use_fontc)
Expand Down Expand Up @@ -150,14 +152,17 @@ def glyphs_to_ufo(self, source):
glyph_data = self.config.get("glyphData")
if glyph_data is not None:
glyph_data = glyph_data
ufo_structure = "json"
if self.fontc_args.use_fontc:
ufo_structure = "package"
FontProject().run_from_glyphs(
str(source.resolve()),
**{
"output": ["ufo"],
"output_dir": directory,
"master_dir": directory,
"designspace_path": output,
"ufo_structure": "json",
"ufo_structure": ufo_structure,
"glyph_data": glyph_data,
},
)
Expand Down
5 changes: 5 additions & 0 deletions Lib/gftools/builder/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ def get(self, operation_name: str):

return FontcBuildOTF

if operation_name == "addSubset":
from .fontc.fontcAddSubset import FontcAddSubset

return FontcAddSubset

return self.known_operations.get(operation_name)


Expand Down
43 changes: 43 additions & 0 deletions Lib/gftools/builder/operations/fontc/fontcAddSubset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
from tempfile import NamedTemporaryFile, TemporaryDirectory

import yaml

from gftools.builder.file import File
from gftools.builder.operations import OperationBase


class FontcAddSubset(OperationBase):
description = "Add a subset from another font"
rule = "gftools-add-ds-subsets $args -y $yaml -o $out $in"

def validate(self):
# Ensure there is a new name
if not self.first_source.is_font_source:
raise ValueError("%s is not a font source file" % self.first_source)
if "subsets" not in self.original:
raise ValueError("No subsets defined")

def convert_dependencies(self, graph):
self._target = TemporaryDirectory() # Stow object
self._orig = NamedTemporaryFile(delete=False, mode="w")
yaml.dump(self.original["subsets"], self._orig)
self._orig.close()

@property
def targets(self):
if "directory" in self.original:
target = self.original["directory"]
else:
target = self._target.name
dspath = os.path.join(
target, self.first_source.basename.rsplit(".", 1)[0] + ".designspace"
)
return [File(dspath)]

@property
def variables(self):
return {
"yaml": self._orig.name,
"args": self.original.get("args"),
}

0 comments on commit 1eba766

Please sign in to comment.