-
Notifications
You must be signed in to change notification settings - Fork 73
Disable JSON structure when using fontc #1067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,13 +69,10 @@ def modify_config(self, config: dict): | |
| extra_args = config.get("extraFontmakeArgs") or "" | ||
| extra_args += " --no-production-names --drop-implied-oncurves" | ||
| config["extraFontmakeArgs"] = extra_args | ||
| # override config to turn not build instances if we're variable | ||
| if self.will_build_variable_font(config): | ||
| config["buildStatic"] = False | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you accomplishing this another way, or are you building statics? The current Maybe we could keep this, but have it be gated on the |
||
| # 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 is this even a thing?) | ||
| elif config.get("buildTTF", True): | ||
| if config.get("buildTTF", True): | ||
| config["buildOTF"] = False | ||
| if self.simple_output_path: | ||
| output_dir = str(self.simple_output_path) | ||
|
|
||
| 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"), | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from pathlib import Path | ||
| from typing import List | ||
| from gftools.builder.file import File | ||
| from gftools.builder.operations import FontmakeOperationBase | ||
| import glyphsLib | ||
| import os | ||
| import gftools.builder | ||
| from functools import cached_property | ||
| from glyphsLib.builder import UFOBuilder | ||
| from ninja.ninja_syntax import Writer, escape_path | ||
| from fontTools.designspaceLib import InstanceDescriptor | ||
|
|
||
|
|
||
| class FontcInstantiateUFO(FontmakeOperationBase): | ||
| description = "Create instance UFOs from a Glyphs or designspace file" | ||
| rule = 'fontmake -i "$instance_name" -o ufo $fontmake_type $in $args' | ||
|
|
||
| def validate(self): | ||
| # Ensure there is an instance name | ||
| if "instance_name" not in self.original: | ||
| raise ValueError("No instance name specified") | ||
| # Ensure the instance is defined in the font | ||
| desired = self.original["instance_name"] | ||
| if "target" not in self.original and not self.relevant_instance: | ||
| raise ValueError( | ||
| f"Instance {desired} not found in {self.first_source.path}" | ||
| ) | ||
|
|
||
| @cached_property | ||
| def relevant_instance(self): | ||
| desired = self.original["instance_name"] | ||
| relevant_instance = [ | ||
| i | ||
| for i in self.first_source.instances | ||
| if i.name == desired or i.familyName + " " + i.styleName == desired | ||
| ] | ||
| if len(relevant_instance) == 0: | ||
| return None | ||
| return relevant_instance[0] | ||
|
|
||
| @property | ||
| def instance_dir(self): | ||
| return Path(self.first_source.path).parent / "instance_ufos" | ||
|
|
||
| @property | ||
| def targets(self): | ||
| if "target" in self.original: | ||
| return [File(self.original["target"])] | ||
| instance = self.relevant_instance | ||
| assert instance is not None | ||
| assert instance.filename is not None | ||
| # if self.first_source.is_glyphs: | ||
| return [File(str(self.instance_dir / (os.path.basename(instance.filename))))] | ||
| # return [ File(instance.filename) ] | ||
|
|
||
| @property | ||
| def variables(self): | ||
| vars = super().variables | ||
| if self.first_source.is_glyphs: | ||
| vars["args"] += f"--instance-dir {escape_path(str(self.instance_dir))}" | ||
| else: | ||
| vars["args"] += f"--output-dir {escape_path(str(self.instance_dir))}" | ||
| vars["instance_name"] = self.original["instance_name"] | ||
| if self.original.get("glyphData") is not None: | ||
| for glyphData in self.original["glyphData"]: | ||
| vars["args"] += f" --glyph-data {escape_path(glyphData)}" | ||
| return vars | ||
|
|
||
| def set_target(self, target: File): | ||
| raise ValueError("Cannot set target on InstantiateUFO") |
Uh oh!
There was an error while loading. Please reload this page.