Skip to content

Commit

Permalink
Merge pull request #66 from ftCLI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ftCLI authored Aug 10, 2023
2 parents d77aa2f + ea5576b commit ce030f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
16 changes: 8 additions & 8 deletions foundryToolsCLI/Lib/VFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class VariableFont(Font):
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]
Expand All @@ -18,14 +19,13 @@ def get_instances(self) -> list[NamedInstance]:
def get_var_name_ids_to_delete(self) -> list:
name_ids_to_delete = [25]

if "fvar" in self.keys():
for axis in self.get_axes():
name_ids_to_delete.append(axis.axisNameID)
for instance in self.get_instances():
if hasattr(instance, "subfamilyNameID"):
name_ids_to_delete.append(instance.subfamilyNameID)
if hasattr(instance, "postscriptNameID"):
name_ids_to_delete.append(instance.postscriptNameID)
for axis in self.get_axes():
name_ids_to_delete.append(axis.axisNameID)
for instance in self.get_instances():
if hasattr(instance, "subfamilyNameID"):
name_ids_to_delete.append(instance.subfamilyNameID)
if hasattr(instance, "postscriptNameID"):
name_ids_to_delete.append(instance.postscriptNameID)

if "STAT" in self.keys():
if hasattr(self["STAT"].table, "DesignAxisRecord"):
Expand Down
7 changes: 4 additions & 3 deletions foundryToolsCLI/Lib/converters/ttf_to_otf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def run(self, source_fonts: list[Font]) -> None:

if len(failed) > 0:
generic_info_message(f"Retrying to get {len(failed)} charstrings...")
fallback_charstrings = get_fallback_charstrings(font=source_font)
fallback_charstrings = get_fallback_charstrings(font=source_font, tolerance=tolerance)

for c in failed:
try:
Expand All @@ -82,6 +82,7 @@ def run(self, source_fonts: list[Font]) -> None:
cff_font: Font = ttf2otf_converter.run(charstrings=charstrings)

# We need to save the file here, otherwise the script won't correctly compile cff.topDictIndex values
# TODO: this is a workaround. Try to find a solution
cff_font.save(output_file)
cff_font = Font(output_file, recalcTimestamp=False)
cff_font.otf_fix_contours(min_area=25, verbose=False)
Expand Down Expand Up @@ -217,11 +218,11 @@ def get_t2_charstrings(font: Font) -> dict:
return t2_charstrings


def get_fallback_charstrings(font: Font) -> dict:
def get_fallback_charstrings(font: Font, tolerance: float = 1.0) -> dict:
ttf2otf_converter = TrueTypeToCFF(font=font)
t2_charstrings = get_t2_charstrings(font=font)
otf_font: Font = ttf2otf_converter.run(charstrings=t2_charstrings)
otf_2_ttf_converter = CFFToTrueType(font=otf_font)
otf_font = otf_2_ttf_converter.run()
_, fallback_charstrings = get_qu2cu_charstrings(otf_font)
_, fallback_charstrings = get_qu2cu_charstrings(otf_font, tolerance=tolerance)
return fallback_charstrings
45 changes: 19 additions & 26 deletions foundryToolsCLI/Lib/utils/cli_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def get_variable_fonts_in_path(input_path: pathlib.Path, recalc_timestamp: bool


def get_fonts_in_path(
input_path: pathlib.Path,
recalc_timestamp: bool = False,
allow_extensions: list = None,
allow_ttf=True,
allow_cff=True,
allow_static=True,
allow_variable=True,
input_path: pathlib.Path,
recalc_timestamp: bool = False,
allow_extensions: list = None,
allow_ttf=True,
allow_cff=True,
allow_static=True,
allow_variable=True,
) -> list[Font]:
files = []
if input_path.is_file():
Expand All @@ -44,26 +44,19 @@ def get_fonts_in_path(
for file in files:
try:
font = Font(file, recalcTimestamp=recalc_timestamp)
fonts.append(font)

if allow_extensions:
if font.get_real_extension() not in allow_extensions:
fonts.remove(font)
continue
if not allow_ttf:
if font.is_ttf:
fonts.remove(font)
continue
if not allow_cff:
if font.is_otf:
fonts.remove(font)
continue
if not allow_static:
if font.is_static:
fonts.remove(font)
if not allow_variable:
if font.is_variable:
fonts.remove(font)
if allow_extensions and font.get_real_extension() not in allow_extensions:
continue
if not allow_ttf and font.is_ttf:
continue
if not allow_cff and font.is_otf:
continue
if not allow_static and font.is_static:
continue
if not allow_variable and font.is_variable:
continue

fonts.append(font)

except (TTLibError, Exception):
pass
Expand Down

0 comments on commit ce030f6

Please sign in to comment.