Skip to content

Commit

Permalink
Merge pull request #24 from source-foundry/dev
Browse files Browse the repository at this point in the history
Add baseline to baseline distance calculations across typo, hhea, win metrics, add OS/2.fsSelection USE_TYPO_METRICS bit setting
  • Loading branch information
chrissimpkins authored Dec 14, 2019
2 parents 7cc5f91 + 077a498 commit 885f6b1
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 162 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ matrix:
env: TOX_ENV=lint
install: pip install flake8
script: flake8 --ignore=E501,W503 lib/fontline/*.py
- python: 3.5
env: TOX_ENV=py35
install: pip install tox
script: tox -e $TOX_ENV
- python: 3.6
env: TOX_ENV=py36
install: pip install tox
Expand All @@ -22,6 +18,17 @@ matrix:
install: pip install tox
dist: xenial
script: tox -e $TOX_ENV
- python: 3.7
dist: xenial
env: TOX_ENV=coverage
install:
- pip install --upgrade coverage
- pip install .
script:
- coverage run --source fontline -m py.test
- coverage report -m
after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email: false
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Changelog

### v3.0.0

- added baseline to baseline distance calculations for hhea, typo, and win metrics to reports
- added fsSelection bit 7 `USE_TYPO_METRICS` bit flag setting to report
- standard output report formatting improvements for `report` subcommand
- removed Py3.5 interpreter testing, we will support for Py3.6+ only as of this release
- add support for automated source code coverage push to Codecov from Travis

### v2.0.0

- changed copyright notice from "Christopher Simpkins" to "Source Foundry Authors"
Expand Down
116 changes: 81 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ font-line is a libre, open source command line tool for OpenType vertical metric

## Install

font-line is built with Python and is tested with Python 3.5+ interpreters. You can verify your installed Python version on the command line with the command:
font-line is built with Python and is tested with Python 3.6+ interpreters. You can verify your installed Python version on the command line with the command:

```
$ python3 --version
Expand Down Expand Up @@ -106,40 +106,57 @@ $ font-line report Hack-Regular.ttf
#### Example Font Vertical Metrics Report
```
=== Hack-Regular.ttf ===
Version 3.001; 379b3ad6d-dev
SHA1: 20d02edca75f2d23787e80161a64418598c850de
--- 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
--- Height Calculations by Table Values ---
[OS/2] TypoAscender to TypoDescender: 2048
[OS/2] WinAscent to WinDescent: 2384
[hhea] Ascent to Descent: 2384
--- Delta Values ---
WinAscent to TypoAscender: 345
Ascent to TypoAscender: 345
WinDescent to TypoDescender: -9
Descent to TypoDescender: -9
--- Ratios ---
(Typo Asc + Desc + Linegap) / UPM: 1.2
(winAsc + winDesc) / UPM: 1.16
(hhea Asc + Desc) / UPM: 1.16
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.
Expand All @@ -152,6 +169,35 @@ $ font-line report TheFont.ttf > font-report.txt

You can 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](https://docs.microsoft.com/en-us/typography/opentype/spec/recom#baseline-to-baseline-distances) and [OpenType OS/2 table specification](https://docs.microsoft.com/en-us/typography/opentype/spec/os2).

##### 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.
Expand Down
41 changes: 17 additions & 24 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
environment:
matrix:
- JOB: "3.5 64-bit"
PYTHON_HOME: "C:\\Python35-x64"
TOX_PY: py35

- JOB: "3.6 64-bit"
PYTHON_HOME: "C:\\Python36-x64"
- JOB: "3.6 32-bit"
PYTHON_HOME: "C:\\Python36"
TOX_PY: py36

- JOB: "3.7 64-bit"
PYTHON_HOME: "C:\\Python37-x64"
TOX_PY: py37

- JOB: "3.7 32-bit"
PYTHON_HOME: "C:\\Python37"
TOX_PY: py37

install:
# If there is a newer build queued for the same PR, cancel this one.
# The AppVeyor 'rollout builds' option is supposed to serve the same
# purpose but it is problematic because it tends to cancel builds pushed
# directly to master instead of just PR builds (or the converse).
# credits: JuliaLang developers.
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }

# Prepend Python to the PATH of this build
- "SET PATH=%PYTHON_HOME%;%PYTHON_HOME%\\Scripts;%PATH%"

Expand All @@ -35,12 +17,23 @@ install:
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""

# upgrade pip and setuptools to avoid out-of-date warnings
- "python -m pip install --disable-pip-version-check --user --upgrade pip setuptools"
- "python -m pip install --disable-pip-version-check --user --upgrade pip setuptools virtualenv"

# install the test dependencies
- "python -m pip install tox"
# install the dependencies to run the tests
- "python -m pip install --upgrade tox pytest"

build: false

test_script:
# The following prevents Travis from running CI on pull requests that come from a
# branch in the same repository. Without this, it will run the same CI for the
# pull request branch _and_ the pull request itself, which makes no sense.
branches:
only:
- master
# We want to build wip/* branches since these are not usually used for PRs
- /^wip\/.*$/
# We want to build version tags as well.
- /^v\d+\.\d+.*$/

test_script:
- "tox -e %TOX_PY%"
11 changes: 11 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
codecov:
max_report_age: off

coverage:
status:
project:
default:
# basic
target: auto
threshold: 2%
base: auto

comment: off
2 changes: 0 additions & 2 deletions lib/fontline/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
The app.py module defines a main() function that includes the logic for the `font-line` command line executable.
Expand All @@ -23,7 +22,6 @@

# TODO: support integer addition and subtraction to the metrics values through new sub-commands
# TODO: JSON formatted metrics output
# TODO: add report line items for 'exceeds ymax/ymin values' across each of the three metrics


def main():
Expand Down
Loading

0 comments on commit 885f6b1

Please sign in to comment.