Skip to content

Commit

Permalink
Version 0.2.5
Browse files Browse the repository at this point in the history
Added 'remove-hinting' under 'ftcli utils'
  • Loading branch information
ftCLI committed May 28, 2021
1 parent a906142 commit 0dde227
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 10 deletions.
39 changes: 34 additions & 5 deletions ftcli/commands/ftcli_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,33 @@ def recalc_names(
A set of tools to correctly compile the name table and set proper values for usWeightClass, usWidthClass, bold, italic
and oblique bits.
The process creates a JSON configuration file and a CSV file that will be used to fix the fonts. Both files can be
automatically created and eventually edited manually or using the integrated command line editor. Once everything is
correctly set in the CSV file, the values inside it can be written to the fonts.
With the aide of a JSON configuration file, that can be edited according to user's needs, this tool will help create a
CSV file containing, for each file in a set of fonts, the following values:
\b
- is_bold
- is_italic
- is_oblique
- usWidthClass
- usWeightClass
- width (short and long literals, e.g.: 'Cn', 'Condensed')
- weight (short and long literals, e.g.: 'Lt', 'Light')
- slope (short and long literals, e.g.: 'It', 'Italic')
- family name
The values can be recalculated with the help of the automation provided by the tool (using the 'init-csv' and
'recalc-csv' commands) or manually edited using a suitable editor.
When the CSV file is correctly compiled, values contained in it can be written into the fonts using the 'recalc-names'
command. This command will not only correctly compile the name table, but will also change usWidthClass and
usWeightClass values, as well as the italic and oblique bits. The bold bits are another matter: they will be set only in
the bold styles of a family with linked styles and only if the user opts for using linked styles. In all other cases,
the bold bits will be cleared.
1) The JSON configuration file.
The 'config.json' file contains the desired style names to pair with each usWidthClass and usWeightClass values of the
family, as well as the desired italic and oblique literals:
The configurationn file, normally named 'config.json' and stored in the work folder, contains the desired style names to
pair with each usWidthClass and usWeightClass values of the family, as well as the desired italic and oblique literals:
\b
{
Expand Down Expand Up @@ -416,6 +435,16 @@ def recalc_names(
Once created the configuration file, you may be in need to edit it according to your needs.
ftcli assistant edit-cfg CONFIG_FILE
This command will open a command line editor that allows to add, delete and edit weights, widths, italic and oblique
style names and values.
Both steps can be skipped directly running the following command:
ftcli assistant edit-csv INPUT_PATH
This command will create inside the INPUT_PATH folder, a file named 'config.json', a file named 'data.csv' and will open
a command line editor that allows to edit both them.
Values contained in the configuration file will be used to fill the data.csv file in the next steps.
Expand Down
43 changes: 39 additions & 4 deletions ftcli/commands/ftcli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@
from ftcli.Lib.utils import getFontsList, makeOutputFileName, getSourceString


@click.group()
def rmHinting():
pass


@rmHinting.command()
@click.argument('input_path', type=click.Path(exists=True, resolve_path=True))
@click.option('-o', '--output-dir', type=click.Path(file_okay=False, resolve_path=True), default=None,
help='Specify the output directory where the output files are to be saved. If output_directory doesn\'t'
'exist, will be created. If not specified, files are saved to the same folder.')
@click.option('--recalc-timestamp/--no-recalc-timestamp', default=False, show_default=True,
help='Keep the original font \'modified\' timestamp (head.modified) or set it to current time. By'
'default, original timestamp is kept.')
@click.option('--overwrite/--no-overwrite', default=True, show_default=True,
help='Overwrite existing output files or save them to a new file (numbers are appended at the end of file'
'name). By default, files are overwritten.')
def remove_hinting(input_path, output_dir=None, recalc_timestamp=False, overwrite=True):
"""Drops hinting from all glyphs.
Currently this only works with TrueType fonts with 'glyf' table.
"""

files = getFontsList(input_path)
for f in files:
try:
font = TTFont(f, recalcTimestamp=recalc_timestamp)
if not font.sfntVersion == 'OTTO':
font['glyf'].removeHinting()
output_file = makeOutputFileName(f, outputDir=output_dir, overWrite=overwrite)
font.save(output_file)
click.secho('%s saved' % output_file, fg='green')
else:
click.secho('%s is not a TrueType file' % f, fg='red')
except Exception as e:
click.secho('ERROR: {}'.format(e), fg='red')


@click.group()
def rmOverlaps():
pass
Expand All @@ -26,13 +63,11 @@ def rmOverlaps():
help='Overwrite existing output files or save them to a new file (numbers are appended at the end of file'
'name). By default, files are overwritten.')
def remove_overlaps(input_path, output_dir=None, recalc_timestamp=False, overwrite=True):
"""
Simplify glyphs in TTFont by merging overlapping contours.
"""Simplify glyphs in TTFont by merging overlapping contours.
Overlapping components are first decomposed to simple contours, then merged.
Currently this only works with TrueType fonts with 'glyf' table.
Raises NotImplementedError if 'glyf' table is absent.
Note that removing overlaps invalidates the hinting. Hinting is dropped from
all glyphs whether or not overlaps are removed from a given one, as it would
Expand Down Expand Up @@ -203,4 +238,4 @@ def font_renamer(input_path, source_string):
click.secho("%s --> skipped" % n, fg='yellow')


cli = click.CommandCollection(sources=[rmOverlaps, extractTTC, addDSIG, fontRenamer], help="Miscellaneous utilities.")
cli = click.CommandCollection(sources=[rmOverlaps, rmHinting, extractTTC, addDSIG, fontRenamer], help="Miscellaneous utilities.")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name='ftcli',
version='0.2.4',
version='0.2.5',
description='ftCLI',
packages=setuptools.find_packages(),
include_package_data=True,
Expand Down

0 comments on commit 0dde227

Please sign in to comment.