• Stars
    star
    184
  • Rank 209,187 (Top 5 %)
  • Language
    Python
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OpenType vertical metrics reporting and font line spacing adjustment tool

PyPI Python CI Python Lints codecov.io Codacy Badge

About

font-line is a libre, open source command line tool for OpenType vertical metrics reporting and command line based font line spacing modifications. It supports .ttf and .otf font builds.

Contents

Quickstart

  • Install: $ pip3 install font-line
  • Metrics Report: $ font-line report [font path]
  • Modify line spacing: $ font-line percent [integer %] [font path]
  • Help: $ font-line --help

Install

font-line is built with Python and supports Python 3.7+ interpreters. Check your installed Python version on the command line with the command:

$ python3 --version

Use either of the following methods to install font-line on your system.

pip Install

The latest font-line release is available through the Python Package Index and can be installed with pip:

$ pip3 install font-line

To upgrade to a new version of font-line after a pip install, use the command pip3 install --upgrade font-line.

Download Project Repository and Install

The current repository version (which may be ahead of the PyPI release) can be installed by downloading the repository or cloning it with git:

git clone https://github.com/source-foundry/font-line.git

Navigate to the top level repository directory and enter the following command:

$ pip3 install .

Follow the same instructions to upgrade to a new version of the application if you install with this approach.

Usage

font-line works via sub-commands to the font-line command line executable. The following sub-commands are available:

  • percent - modify the line spacing of a font to a percent of the Ascender to Descender distance
  • report - report OpenType metrics values for a font

Usage of these sub-commands is described in detail below.

Vertical Metrics Reporting

The following OpenType vertical metrics values and calculated values derived from these data are displayed with the report sub-command:

  • [OS/2] TypoAscender
  • [OS/2] TypoDescender
  • [OS/2] WinAscent
  • [OS/2] WinDescent
  • [OS/2] TypoLineGap
  • [OS/2] xHeight
  • [OS/2] CapHeight
  • [hhea] Ascent
  • [hhea] Descent
  • [hhea] lineGap
  • [head] unitsPerEm
  • [head] yMax
  • [head] yMin

report Sub-Command Usage

Enter one or more font path arguments to the command:

$ font-line report [fontpath 1] <fontpath ...>

Here is an example of the report generated with the Hack typeface file Hack-Regular.ttf using the command:

$ font-line report Hack-Regular.ttf

Example Font Vertical Metrics Report

=== Hack-Regular.ttf ===
Version 3.003;[3114f1256]-release
SHA1: b1cd50ba36380d6d6ada37facfc954a8f20c15ba

::::::::::::::::::::::::::::::::::::::::::::::::::
  Metrics
::::::::::::::::::::::::::::::::::::::::::::::::::
[head] Units per Em:   2048
[head] yMax:           2027
[head] yMin:          -605
[OS/2] CapHeight:      1493
[OS/2] xHeight:        1120
[OS/2] TypoAscender:   1556
[OS/2] TypoDescender: -492
[OS/2] WinAscent:      1901
[OS/2] WinDescent:     483
[hhea] Ascent:         1901
[hhea] Descent:       -483

[hhea] LineGap:        0
[OS/2] TypoLineGap:    410

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ascent to Descent Calculations
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to Descent:              2384
[OS/2] TypoAscender to TypoDescender:  2048
[OS/2] WinAscent to WinDescent:        2384

::::::::::::::::::::::::::::::::::::::::::::::::::
  Delta Values
::::::::::::::::::::::::::::::::::::::::::::::::::
[hhea] Ascent to [OS/2] TypoAscender:       345
[hhea] Descent to [OS/2] TypoDescender:     -9
[OS/2] WinAscent to [OS/2] TypoAscender:    345
[OS/2] WinDescent to [OS/2] TypoDescender:  -9

::::::::::::::::::::::::::::::::::::::::::::::::::
  Baseline to Baseline Distances
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics: 2384
typo metrics: 2458
win metrics:  2384

[OS/2] fsSelection USE_TYPO_METRICS bit set: False

::::::::::::::::::::::::::::::::::::::::::::::::::
  Ratios
::::::::::::::::::::::::::::::::::::::::::::::::::
hhea metrics / UPM:  1.16
typo metrics / UPM:  1.2
win metrics  / UPM:  1.16

The report includes the font version string, a SHA-1 hash digest of the font file, and OpenType table metrics that are associated with line spacing in the font.

Unix/Linux/OS X users can write this report to a file with the > command line idiom:

$ font-line report TheFont.ttf > font-report.txt

Modify the font-report.txt file path above to the file path string of your choice.

Baseline to Baseline Distance Calculations

Baseline to baseline distance (BTBD) calculations are performed according to the Microsoft Recommendations for OpenType Fonts and OpenType OS/2 table specification.

hhea Metrics
BTBD = hhea.Ascent + abs(hhea.Descent) + hhea.LineGap
typo Metrics
BTBD = OS/2.typoAscent + abs(OS/2.typoDescent) + OS/2.typoLineGap
win Metrics
BTBD = OS/2.winAscent + OS/2.winDescent + [External Leading]

where external leading is defined as:

MAX(0, hhea.LineGap - ((OS/2.WinAscent + OS/2.winDescent) - (hhea.Ascent - hhea.Descent)))

Vertical Metrics Modifications

font-line supports automated line spacing modifications to a user-defined percentage of the units per em metric. This value will be abbreviated as UPM below.

percent Sub-Command Usage

Enter the desired percentage of the UPM as the first argument to the command. This should be entered as an integer value. Then enter one or more font paths to which you would like to apply your font metrics changes.

$ font-line percent [percent change] [fontpath 1] <fontpath ...>

A common default value used by typeface designers is 20% UPM. To modify a font on the path TheFont.ttf to 20% of the UPM metric, you would enter the following command:

$ font-line percent 20 TheFont.ttf

Increase or decrease the integer value to increase or decrease your line spacing accordingly.

The original font file is preserved in an unmodified version and the modified file write takes place on a new path defined as [original filename]-linegap[percent].[ttf|otf]. The path to the file is reported to you in the standard output after the modification is completed. font-line does not modify the glyph set or hints applied to the font. See the Details section below for a description of the OpenType table modifications that occur when the application is used on a font file.

You can inspect the vertical metrics in the new font file with the report sub-command (see Usage above).

Details of Font Metrics Changes with percent Sub-Command

The interpretation and display of these multiple vertical metrics values is platform and application dependent. There is no broadly accepted "best" approach. As such, font-line attempts to preserve the original metrics design in the font when modifications are made with the percent sub-command.

font-line currently supports three commonly used vertical metrics approaches.

Vertical Metrics Approach 1:

Where metrics are defined as:

  • [OS/2] TypoLinegap = 0
  • [hhea] linegap = 0
  • [OS/2] TypoAscender = [OS/2] winAscent = [hhea] Ascent
  • [OS/2] TypoDescender = [OS/2] winDescent = [hhea] Descent

font-line calculates a delta value for the total expected height based upon the % UPM value defined on the command line. The difference between this value and the observed number of units that span the [OS/2] winAscent to winDescent values is divided by half and then added to (for increased line spacing) or subtracted from (for decreased line spacing) each of the three sets of Ascender/Descender values in the font. The [OS/2] TypoLinegap and [hhea] linegap values are not modified.

Vertical Metrics Approach 2

Where metrics are defined as:

  • [OS/2] TypoLinegap = 0
  • [hhea] linegap = 0
  • [OS/2] TypoAscender + TypoDescender = UPM
  • [OS/2] winAscent = [hhea] Ascent
  • [OS/2] winDescent = [hhea] Descent

font-line calculates a delta value for the total expected height based upon the % UPM value defined on the command line. The difference between this value and the observed number of units that span the [OS/2] winAscent to winDescent values is divided by half and then added to (for increased line spacing) or subtracted from (for decreased line spacing) the [OS/2] winAsc/winDesc and [hhea] Asc/Desc values. The [OS/2] TypoAsc/TypoDesc values are not modified and maintain a definition of size = UPM value. The [OS/2] TypoLinegap and [hhea] linegap values are not modified.

Vertical Metrics Approach 3

Where metrics are defined as:

  • [OS/2] TypoAscender + TypoDescender = UPM
  • [OS/2] TypoLinegap is set to leading value
  • [hhea] linegap = 0
  • [OS/2] winAscent = [hhea] Ascent
  • [OS/2] winDescent = [hhea] Descent

Changes to the metrics values in the font are defined as:

  • [OS/2] TypoLineGap = x% * UPM value
  • [hhea] Ascent = [OS/2] TypoAscender + 0.5(modified TypoLineGap)
  • [hhea] Descent = [OS/2] TypoDescender + 0.5(modified TypoLineGap)
  • [OS/2] WinAscent = [OS/2] TypoAscender + 0.5(modified TypoLineGap)
  • [OS/2] WinDescent = [OS/2] TypoDescender + 0.5(modified TypoLineGap)

Note that the internal leading modifications are split evenly across [hhea] Ascent & Descent values, and across [OS/2] WinAscent & WinDescent values. We add half of the new [OS/2] TypoLineGap value to the original [OS/2] TypoAscender or TypoDescender in order to define these new metrics properties. The [hhea] linegap value is always defined as zero.

Important

The newly defined vertical metrics values can lead to clipping of glyph components if not properly defined. There are no tests in font-line to provide assurance that this does not occur. We assume that the user is versed in these issues before use of the application and leave this testing to the designer / user before the modified fonts are used in a production setting.

Issue Reporting

Please submit a new issue report on the project repository.

Acknowledgments

font-line is built with the fantastic fontTools Python library.

License

MIT License. See LICENSE.md for details.

More Repositories

1

Hack

A typeface designed for source code
Shell
16,474
star
2

Hack-windows-installer

A Windows installer for the Hack typeface
Inno Setup
751
star
3

Slice

An open-source, cross-platform GUI app to generate custom font design spaces from variable fonts
Python
158
star
4

alt-hack

A stylistic alternate glyph library for the Hack typeface
Shell
104
star
5

fdiff

An OpenType table diff tool for fonts. Based on the fontTools TTX format.
Python
41
star
6

code-corpora

Source code corpora for text analysis
Go
29
star
7

ttfautohint-build

Build ttfautohint from source on Linux and macOS platforms
Shell
27
star
8

Woffle

Drag and drop woff and woff2 web font generator for macOS
Python
27
star
9

ufodiff

UFO source file diff application
Python
27
star
10

ufolint

UFO source format linter
Python
24
star
11

hack-linux-installer

Install and upgrade the Hack typeface on the Linux platform
Shell
22
star
12

font-v

Font version string reporting and modification library + executable tool
Python
19
star
13

dehinter

A tool for the removal of TrueType instruction sets (hints) in fonts
Python
16
star
14

fontmake-mp

Concurrent font compilation from UFO source files with fontmake
Python
15
star
15

FSCW

Toolkit to create Windows desktop setups for fonts.
Inno Setup
12
star
16

uni

Unicode code point search
Go
11
star
17

manual-ttfa

Manual ttfautohint Instruction Set Adjustments with Delta Exceptions and Control Instructions Files
8
star
18

ufofmt

A fast, flexible UFO source file formatter based on the Rust Norad library
Rust
7
star
19

text-specimens

Text specimens for the display of typefaces that are used in source code development
C
7
star
20

font-unicode

Command line Unicode character code point and character name search
Python
7
star
21

glyph-filter-lists

Glyph name filter list repository
Python
7
star
22

font-ttfa

A command line TTFA table reporting tool for fonts hinted with ttfautohint
Python
6
star
23

compare-typefaces

Simple browser tool to compare a string between several typefaces, intended to judge the legibility of easily confusable glyphs
JavaScript
5
star
24

set-unicoderange

Python script to automatically set OpenType OS/2 table Unicode range bit flags in fonts
Python
5
star
25

FilterListManager

Glyphs font editor filter list manager plugin
Python
5
star
26

panosifier

Panose data editor for fonts
Python
5
star
27

java-glyph-tester

A tool for testing the JDK font rendering behaviour
Java
4
star
28

font-size

Font file size and individual OpenType table size command line reporting tool
Python
4
star
29

library

A library of type development + design resources
3
star
30

caniusefonts

Always current cross-browser font support based on the caniuse.com API and Embed service.
3
star
31

unilist

Unicode code point list generator with support for inclusion/exclusion criteria
Go
2
star
32

Hack-Test-Win-Installer

A Windows installer for test/development builds of the Hack typeface.
Inno Setup
2
star
33

path-inspector

Quadratic font curve path inspector
Python
2
star
34

freetype2

Customized freetype2 library
C
1
star
35

freetype2-demos

A fork of the freetype2-demos applications with customizations
C
1
star
36

Slice-docs

Documentation for the Slice project
Makefile
1
star
37

opentype-notes

Interactive OpenType resource
Jupyter Notebook
1
star
38

pre-post

pre/post web font specimen sheets rendered with Flask + Jinja2
HTML
1
star