Skip to content

Commit

Permalink
Add subset adder (needs merge of googlefonts#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Sep 27, 2023
1 parent 82a331e commit 882379e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Lib/gftools/builder/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def is_ufo(self):
@property
def is_designspace(self):
return self.extension == "designspace"


@property
def is_font_source(self):
return (self.is_glyphs or self.is_ufo or self.is_designspace)

@cached_property
def gsfont(self):
if self.is_glyphs:
Expand Down
38 changes: 38 additions & 0 deletions Lib/gftools/builder/operations/addSubset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import sys
from tempfile import NamedTemporaryFile, TemporaryDirectory

import yaml

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


class AddSubset(OperationBase):
description = "Add a subset from another font"
rule = "gftools-add-ds-subsets -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, builder):
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):
dspath = os.path.join(self._target.name, self.first_source.basename.rsplit(".", 1)[0] + ".designspace")
return [ File(dspath) ]

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

0 comments on commit 882379e

Please sign in to comment.