Skip to content

Commit

Permalink
Merge pull request #1029 from daltonmaag/build-loaded
Browse files Browse the repository at this point in the history
Allow GSFont object to be passed to `build_masters` directly (in place of a path)
  • Loading branch information
anthrotype authored Sep 4, 2024
2 parents 101f481 + a998d52 commit 6b9c4ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions Lib/glyphsLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

from io import open
import collections
Expand Down Expand Up @@ -78,7 +79,7 @@ def load_to_ufos(


def build_masters(
filename,
filename: str | bytes | os.PathLike[str] | os.PathLike[bytes] | GSFont,
master_dir,
designspace_instance_dir=None,
designspace_path=None,
Expand All @@ -99,6 +100,7 @@ def build_masters(
.glyphs file.
Args:
filename: Path to Glyphs sources, or GSFont object (may be mutated)
master_dir: Directory where masters are written.
designspace_instance_dir: If provided, a designspace document will be
written alongside the master UFOs though no instances will be built.
Expand All @@ -110,7 +112,12 @@ def build_masters(
file (`designspace_path`).
"""

font = GSFont(filename)
# Either use 'filename' as a loaded font, or interpret it as a path.
# (variable name is 'filename' in both cases for backwards compatibility)
if isinstance(filename, GSFont):
font = filename
else:
font = GSFont(filename)

if not os.path.isdir(master_dir):
os.mkdir(master_dir)
Expand Down
5 changes: 4 additions & 1 deletion Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import copy
import logging
Expand Down Expand Up @@ -4458,7 +4459,9 @@ def _parse_settings_dict(self, parser, settings):
def _parse___formatVersion_dict(self, parser, val):
self.format_version = parser.format_version = val

def __init__(self, path=None):
def __init__(
self, path: str | bytes | os.PathLike[str] | os.PathLike[bytes] | None = None
):
self.DisplayStrings = ""
self._glyphs = []
self._instances = []
Expand Down

0 comments on commit 6b9c4ee

Please sign in to comment.