Skip to content

Commit

Permalink
Merge pull request #193 from ftCLI/dev
Browse files Browse the repository at this point in the history
Add file naming for variable fonts and get_axes method
  • Loading branch information
ftCLI authored Sep 24, 2024
2 parents 91e5d04 + 519e3f0 commit 6e6549f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.1.17
current_version = 1.1.18
commit = True
tag = True

Expand Down
16 changes: 16 additions & 0 deletions foundryToolsCLI/Lib/Font.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from fontTools.misc.psCharStrings import T2CharString
from fontTools.misc.timeTools import timestampToString
from fontTools.pens.statisticsPen import StatisticsPen
from fontTools.ttLib.tables._f_v_a_r import Axis
from fontTools.ttLib.ttFont import TTFont

from foundryToolsCLI.Lib.tables.OS_2 import TableOS2
Expand Down Expand Up @@ -623,6 +624,13 @@ def get_file_name(self, source) -> str:
name.
:return: A string representing the file name of the font.
"""
if self.is_variable:
family_name = self.guess_family_name().replace(" ", "").strip()
if self.is_italic:
family_name += "-Italic"
axes = self.get_axes()
file_name = f"{family_name}[{','.join([axis.axisTag for axis in axes])}]"
return file_name

if self.is_ttf:
if source in (4, 5):
Expand All @@ -644,6 +652,14 @@ def get_file_name(self, source) -> str:
else:
return Path(self.reader.file.name).stem

def get_axes(self) -> list[Axis]:
"""
This function returns a list of axes in a variable font.
"""
if not self.is_variable:
return []
return [axis for axis in self["fvar"].axes if axis.flags == 0]

def fix_cff_top_dict_version(self) -> None:
if not self.is_otf:
return
Expand Down
5 changes: 1 addition & 4 deletions foundryToolsCLI/Lib/VFont.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from fontTools.ttLib.tables._f_v_a_r import NamedInstance, Axis
from fontTools.ttLib.tables._f_v_a_r import NamedInstance

from foundryToolsCLI.Lib.Font import Font

Expand All @@ -10,9 +10,6 @@ def __init__(self, file=None, recalcTimestamp=False):
super().__init__(file=file, recalcTimestamp=recalcTimestamp)
assert "fvar" in self

def get_axes(self) -> list[Axis]:
return [axis for axis in self["fvar"].axes if axis.flags == 0]

def get_instances(self) -> list[NamedInstance]:
return [instance for instance in self["fvar"].instances]

Expand Down
2 changes: 1 addition & 1 deletion foundryToolsCLI/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = __version__ = "1.1.17"
VERSION = __version__ = "1.1.18"

__all__ = ["VERSION"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _get_requirements():

setuptools.setup(
name="foundrytools-cli",
version="1.1.17",
version="1.1.18",
description="A set of command line tools to inspect, manipulate and convert font files",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 6e6549f

Please sign in to comment.