• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

docs/H08-Nov-2021-3624

lib/H08-Nov-2021-2,4191,664

MANIFEST.inH A D08-Nov-202145 32

PKG-INFOH A D08-Nov-202113.5 KiB401266

README.mdH A D08-Nov-202112.7 KiB376244

setup.cfgH A D08-Nov-2021138 149

setup.pyH A D08-Nov-20212.5 KiB7869

README.md

1![](https://github.com/source-foundry/font-v/raw/images/images/font-v-crunch.png)
2
3[![PyPI](https://img.shields.io/pypi/v/font-v.svg)](https://pypi.org/project/font-v)
4![Python CI](https://github.com/source-foundry/font-v/workflows/Python%20CI/badge.svg)
5[![Codacy Badge](https://api.codacy.com/project/badge/Grade/09e28ad7bc31400a806704ac1d2da70c)](https://app.codacy.com/app/SourceFoundry/font-v)
6
7## About
8
9font-v is an open source font version string library (`libfv`) and executable (`font-v`) for reading, reporting, modifying, and writing OpenType name table ID 5 records and head table fontRevision records in `*.otf` and `*.ttf` fonts.
10
11font-v is built with Python and can be used on Linux, macOS, and Windows platforms with current versions of the Python 2 and Python 3 interpreters.
12
13## Contents
14
15- [Installation](#installation)
16- [font-v Executable Usage](#font-v-executable-usage)
17- [libfv Library Usage](https://github.com/source-foundry/font-v/tree/dev#libfv-usage)
18- [libfv Library API Documentation](http://font-v.readthedocs.io)
19- [Contributing to font-v](#contributing-to-font-v)
20- [License](#license)
21
22## Installation
23
24The `libfv` library and the `font-v` executable are installed simultaneously with the following installation instructions.
25
26Installation with the [pip package manager](https://pip.pypa.io/en/stable/) is the recommended approach.
27
28### Install with pip
29
30Install with pip using the following command:
31
32```
33$ pip install font-v
34```
35
36### Upgrade with pip
37
38Upgrade to a new version of font-v with the following command:
39
40```
41$ pip install --upgrade font-v
42```
43
44## font-v Executable Usage
45
46font-v is executed with a set of subcommands and options that define your command line request.
47
48```
49$ font-v [subcommand] (options) [font path 1] ([font path ...])
50```
51
52### Available subcommands and options
53
54#### Subcommands
55
56#### `report`
57
58Report OpenType name table ID 5 and head table fontRevision records
59
60**_Option_**:
61
62- `--dev` - include all name table ID 5 x platformID records in report
63
64#### `write`
65
66Write version number to head table fontRevision records and version string to name table ID 5 records.
67
68**_Options_**:
69
70The following option is used with `write` to modify the version number in both the head fontRevision record and the name ID 5 record(s):
71
72- `--ver=[version #]` - modify current version number with a new version number using `1.000`, `1_000` or `1-000` syntax on the command line (the latter two formats are provided to support definitions in shells where the period is a special shell character)
73
74The following options can be used with `write` to modify the version string in name ID 5:
75
76- `--dev` - add development status metadata to the version string (mutually exclusive with `--rel`)
77- `--rel` - add release status metadata to the version string (mutually exclusive with `--dev`)
78- `--sha1` - add git commit sha1 short hash state metadata to the version string (requires source under git version control)
79
80### Examples
81
82### Version string reporting with `report`
83
84Enter the following to display the head fontRevision version number and name ID 5 font version string for the font Example-Regular.ttf:
85
86```
87$ font-v report Example-Regular.ttf
88```
89
90Include the `--dev` flag to include the version string (nameID 5) contained in all platformID records:
91
92```
93$ font-v report --dev Example-Regular.ttf
94```
95
96### Version number modification with `write`
97
98The name ID 5 record(s) and head fontRevision record are modified when `--ver=` is used in your command.
99
100Enter the desired version number in `MAJOR.MINOR` format after the `--ver=` flag. Support is provided for the intended period glyph to be replaced in the command with an underscore `_` or dash `-` for users on platforms where the period is a special shell character.
101
102All of the following result in modification of the version number to `2.020`:
103
104```
105$ font-v write --ver=2.020 Example-Regular.ttf
106```
107
108```
109$ font-v write --ver=2_020 Example-Regular.ttf
110```
111
112```
113$ font-v write --ver=2-020 Example-Regular.ttf
114```
115
116This request can be combined with other options to include state and status metadata simultaneously.
117
118### git SHA1 commit short hash state metadata with `write`
119
120If your typeface source is under git version control, you can stamp the name ID 5 version string with a short SHA1 hash digest (generally n=7-8 characters, a number that is determined in order to confirm that it represents a unique value for the repository commit) that represents the git commit at the HEAD of the active git branch. The git commit SHA1 hash digest is defined by the `git rev-list` command at the HEAD of your active repository branch and will match the initial n characters of the git commit SHA1 hash digest that is displayed when you review your `git log` (or review the commit hashes in the UI of git repository hosting platforms like Github). This is intended to maintain metadata in the font binary about source code state at build time.
121
122Use the `--sha1` option with the `write` subcommand like this:
123
124```
125$ font-v write --sha1 Example-Regular.ttf
126```
127
128The short SHA1 hash digest is added with the following version string formatting:
129
130```
131Version 1.000;[cf8dc25]
132```
133
134This can be combined with other options (e.g. to modify the version number +/- add development or release status metadata) in the same command. Other metadata are maintained and appended to the revised version string in a semicolon delimited format with this modification.
135
136This option does not modify the head fontRevision record.
137
138### Add development / release status metadata with `write`
139
140You can modify the name ID 5 version string to indicate that a build is intended as a development build or release build with the `--dev` or `--rel` flag. These are mutually exclusive options. Include only one in your command.
141
142To add development status metadata, use a command like this:
143
144```
145$ font-v write --dev Example-Regular.ttf
146```
147
148and the version string is modified to the following format:
149
150```
151Version 1.000;DEV
152```
153
154To add release status metadata, use a command like this:
155
156```
157$ font-v write --rel Example-Regular.ttf
158```
159
160and the version string is modified with the following format:
161
162```
163Version 1.000;RELEASE
164```
165
166Include the `--sha1` flag with either the `--dev` or `--rel` flag in the command to include both status and state metadata to the version string:
167
168```
169$ font-v write --sha1 --dev Example-Regular.ttf
170$ font-v report Example-Regular.ttf
171
172Example-Regular.ttf:
173----- name.ID = 5:
174Version 1.000;[cf8dc25]-dev
175----- head.fontRevision:
1761.000
177```
178
179or
180
181```
182$ git write --sha1 --rel Example-Regular.ttf
183$ git report Example-Regular.ttf
184
185Example-Regular.ttf:
186----- name.ID = 5:
187Version 1.000;[cf8dc25]-release
188----- head.fontRevision:
1891.000
190```
191
192Any data that followed the original version number substring are maintained and appended after the status metadata in a semicolon delimited format.
193
194These options do not modify the head fontRevision record.
195
196## libfv Usage
197
198The libfv Python library exposes the `FontVersion` object along with an associated set of attributes and public methods for reads, modifications, and writes of the OpenType head fontRevision record version number and the name ID 5 record(s) version string. The `font-v` executable is built on the public methods available in this library.
199
200Full documentation of the libfv API is available at http://font-v.readthedocs.io/
201
202### Import `libfv` Library into Your Project
203
204To use the libfv library, install the font-v project with the instructions above and import the `FontVersion` class into your Python script with the following:
205
206```python
207from fontv.libfv import FontVersion
208```
209
210### Create an Instance of the `FontVersion` Class
211
212Next, create an instance of the `FontVersion` class with one of the following approaches:
213
214```python
215# Instantiate with a file path to the .ttf or .otf font
216fv = FontVersion("path/to/font")
217```
218
219or
220
221```python
222# Instantiate with a fontTools TTFont object
223#  See the fonttools documentation for details (https://github.com/fonttools/fonttools)
224fv = FontVersion(fontToolsTTFont)
225```
226
227The libfv library will automate parsing of the version string to a set of public `FontVersion` class attributes and expose public methods that you can use to examine and modify the version string. Modified version strings can then be written back out to the font file or to a new font at a different file path.
228
229Note that all modifications to the version string are made in memory. File writes with these modified data occur when the calling code explicitly calls the write method `FontVersion.write_version_string()` (details are available below).
230
231### What You Can Do with the `FontVersion` Object
232
233#### Read/write version string
234
235You can examine the full name ID 5 version string and the head fontRevision version number in memory (including after modifications that you make with calling code) with the following:
236
237##### Get name ID 5 version string (including associated metadata)
238
239```python
240fv = FontVersion("path/to/font")
241vs = fv.get_name_id5_version_string()
242```
243
244##### Get head fontRevision version number
245
246```python
247fv = FontVersion("path/to/font")
248vs = fv.get_head_fontrevision_version_number()
249```
250
251All version modifications with the public methods are made in memory. When you are ready to write them out to a font file, call the following method:
252
253##### Write version string modifications to font file
254
255```python
256fv = FontVersion("path/to/font")
257# do things to version string
258fv.write_version_string()  # writes to file used to instantiate FontVersion object
259fv.write_version_string(fontpath="path/to/differentfont") # writes to a different file path
260```
261
262`FontVersion.write_version_string()` provides an optional parameter `fontpath=` that can be used to define a different file path than that which was used to instantiate the `FontVersion` object.
263
264#### Compare Version Strings
265
266##### Test version equality / inequality
267
268Compare name table ID 5 record equality between two fonts:
269
270```python
271fv1 = FontVersion("path/to/font1")
272fv2 = FontVersion("path/to/font2")
273
274print(fv1 == fv2)
275print(fv1 != fv2)
276```
277
278#### Modify Version String
279
280Some common font version string modification tasks that are supported by the `libfv` library include the following:
281
282##### Set version number
283
284Set the version number in the name ID 5 and head fontRevision records:
285
286```python
287fv = FontVersion("path/to/font")
288fv.set_version_number("1.001")
289```
290
291##### Set entire version string with associated metadata
292
293Set the full version string in the name ID 5 record. The version number is parsed and used to define the head fontRevision record.
294
295```python
296fv = FontVersion("path/to/font")
297fv.set_version_string("Version 2.015; my metadata; more metadata")
298```
299
300##### Work with major/minor version number integers
301
302```python
303fv = FontVersion("path/to/font")
304# version number = "Version 1.234"
305vno = fv.get_version_number_tuple()
306print(vno)
307>>> (1, 2, 3, 4)
308fv2 = FontVersion("path/to/font2")
309# version number = "Version 10.234"
310vno2 = fv2.get_version_number_tuple()
311print(vno2)
312>>> (10, 2, 3, 4)
313```
314
315##### Eliminate all metadata from a version string
316
317Remove all metadata from the version string:
318
319```python
320fv = FontVersion("path/to/font")
321# pre modification version string = "Version 1.000; some metadata; other metadata"
322fv.clear_metadata()
323# post modification version string = "Version 1.000"
324```
325
326##### Set development/release status metadata of the font build
327
328Add a development/release status substring to the name ID 5 record:
329
330```python
331fv = FontVersion("path/to/font")
332# Label as development build
333fv.set_development_status()
334# --> adds `DEV` status metadata to version string
335
336# Label as release build
337fv.set_release_status()
338# --> adds `RELEASE` status metadata to version string
339```
340
341##### Set git commit SHA1 hash state metadata to maintain documentation of build time source state
342
343Add source code state metadata to the name ID 5 record:
344
345```python
346fv = FontVersion("path/to/font")
347
348# Set git commit SHA1 only
349fv.set_state_git_commit_sha1()
350# --> adds "[sha1 hash]" state metadata to build
351
352# Set git commit SHA1 with development status indicator
353fv.set_state_git_commit_sha1(development=True)
354# --> adds "[sha1 hash]-dev" state metadata to build
355
356# Set git commit SHA1 with release status indicator
357fv.set_state_git_commit_sha1(release=True)
358# --> adds "[sha1 hash]-release" state metadata to build
359```
360
361### libfv API
362
363Full documentation of the `libfv` API is available at http://font-v.readthedocs.io/
364
365## Contributing to font-v
366
367Source contributions to the libfv library and font-v executable are encouraged and welcomed! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) documentation for details.
368
369## Acknowledgments
370
371Built with the fantastic [fonttools](https://github.com/fonttools/fonttools) and [GitPython](https://github.com/gitpython-developers/GitPython) Python libraries.
372
373## License
374
375[MIT License](https://github.com/source-foundry/font-v/blob/master/docs/LICENSE)
376