File: README.md

package info (click to toggle)
font-v 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,084 kB
  • sloc: python: 1,870; makefile: 22; sh: 4
file content (375 lines) | stat: -rw-r--r-- 12,958 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
![](https://github.com/source-foundry/font-v/raw/images/images/font-v-crunch.png)

[![PyPI](https://img.shields.io/pypi/v/font-v.svg)](https://pypi.org/project/font-v)
![Python CI](https://github.com/source-foundry/font-v/workflows/Python%20CI/badge.svg)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/09e28ad7bc31400a806704ac1d2da70c)](https://app.codacy.com/app/SourceFoundry/font-v)

## About

font-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.

font-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.

## Contents

- [Installation](#installation)
- [font-v Executable Usage](#font-v-executable-usage)
- [libfv Library Usage](https://github.com/source-foundry/font-v/tree/dev#libfv-usage)
- [libfv Library API Documentation](http://font-v.readthedocs.io)
- [Contributing to font-v](#contributing-to-font-v)
- [License](#license)

## Installation

The `libfv` library and the `font-v` executable are installed simultaneously with the following installation instructions.

Installation with the [pip package manager](https://pip.pypa.io/en/stable/) is the recommended approach.

### Install with pip

Install with pip using the following command:

```
$ pip install font-v
```

### Upgrade with pip

Upgrade to a new version of font-v with the following command:

```
$ pip install --upgrade font-v
```

## font-v Executable Usage

font-v is executed with a set of subcommands and options that define your command line request.

```
$ font-v [subcommand] (options) [font path 1] ([font path ...])
```

### Available subcommands and options

#### Subcommands

#### `report`

Report OpenType name table ID 5 and head table fontRevision records

**_Option_**:

- `--dev` - include all name table ID 5 x platformID records in report

#### `write`

Write version number to head table fontRevision records and version string to name table ID 5 records.

**_Options_**:

The following option is used with `write` to modify the version number in both the head fontRevision record and the name ID 5 record(s):

- `--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)

The following options can be used with `write` to modify the version string in name ID 5:

- `--dev` - add development status metadata to the version string (mutually exclusive with `--rel`)
- `--rel` - add release status metadata to the version string (mutually exclusive with `--dev`)
- `--sha1` - add git commit sha1 short hash state metadata to the version string (requires source under git version control)

### Examples

### Version string reporting with `report`

Enter the following to display the head fontRevision version number and name ID 5 font version string for the font Example-Regular.ttf:

```
$ font-v report Example-Regular.ttf
```

Include the `--dev` flag to include the version string (nameID 5) contained in all platformID records:

```
$ font-v report --dev Example-Regular.ttf
```

### Version number modification with `write`

The name ID 5 record(s) and head fontRevision record are modified when `--ver=` is used in your command.

Enter 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.

All of the following result in modification of the version number to `2.020`:

```
$ font-v write --ver=2.020 Example-Regular.ttf
```

```
$ font-v write --ver=2_020 Example-Regular.ttf
```

```
$ font-v write --ver=2-020 Example-Regular.ttf
```

This request can be combined with other options to include state and status metadata simultaneously.

### git SHA1 commit short hash state metadata with `write`

If 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. 

Use the `--sha1` option with the `write` subcommand like this:

```
$ font-v write --sha1 Example-Regular.ttf
```

The short SHA1 hash digest is added with the following version string formatting:

```
Version 1.000;[cf8dc25]
```

This 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.

This option does not modify the head fontRevision record.

### Add development / release status metadata with `write`

You 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.

To add development status metadata, use a command like this:

```
$ font-v write --dev Example-Regular.ttf
```

and the version string is modified to the following format:

```
Version 1.000;DEV
```

To add release status metadata, use a command like this:

```
$ font-v write --rel Example-Regular.ttf
```

and the version string is modified with the following format:

```
Version 1.000;RELEASE
```

Include the `--sha1` flag with either the `--dev` or `--rel` flag in the command to include both status and state metadata to the version string:

```
$ font-v write --sha1 --dev Example-Regular.ttf
$ font-v report Example-Regular.ttf

Example-Regular.ttf:
----- name.ID = 5:
Version 1.000;[cf8dc25]-dev
----- head.fontRevision:
1.000
```

or

```
$ git write --sha1 --rel Example-Regular.ttf
$ git report Example-Regular.ttf

Example-Regular.ttf:
----- name.ID = 5:
Version 1.000;[cf8dc25]-release
----- head.fontRevision:
1.000
```

Any data that followed the original version number substring are maintained and appended after the status metadata in a semicolon delimited format.

These options do not modify the head fontRevision record.

## libfv Usage

The 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.

Full documentation of the libfv API is available at http://font-v.readthedocs.io/

### Import `libfv` Library into Your Project

To 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:

```python
from fontv.libfv import FontVersion
```

### Create an Instance of the `FontVersion` Class

Next, create an instance of the `FontVersion` class with one of the following approaches:

```python
# Instantiate with a file path to the .ttf or .otf font
fv = FontVersion("path/to/font")
```

or

```python
# Instantiate with a fontTools TTFont object
#  See the fonttools documentation for details (https://github.com/fonttools/fonttools)
fv = FontVersion(fontToolsTTFont)
```

The 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.

Note 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).

### What You Can Do with the `FontVersion` Object

#### Read/write version string

You 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:

##### Get name ID 5 version string (including associated metadata)

```python
fv = FontVersion("path/to/font")
vs = fv.get_name_id5_version_string()
```

##### Get head fontRevision version number

```python
fv = FontVersion("path/to/font")
vs = fv.get_head_fontrevision_version_number()
```

All 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:

##### Write version string modifications to font file

```python
fv = FontVersion("path/to/font")
# do things to version string
fv.write_version_string()  # writes to file used to instantiate FontVersion object
fv.write_version_string(fontpath="path/to/differentfont") # writes to a different file path
```

`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.

#### Compare Version Strings

##### Test version equality / inequality

Compare name table ID 5 record equality between two fonts:

```python
fv1 = FontVersion("path/to/font1")
fv2 = FontVersion("path/to/font2")

print(fv1 == fv2)
print(fv1 != fv2)
```

#### Modify Version String

Some common font version string modification tasks that are supported by the `libfv` library include the following:

##### Set version number

Set the version number in the name ID 5 and head fontRevision records:

```python
fv = FontVersion("path/to/font")
fv.set_version_number("1.001")
```

##### Set entire version string with associated metadata

Set the full version string in the name ID 5 record. The version number is parsed and used to define the head fontRevision record.

```python
fv = FontVersion("path/to/font")
fv.set_version_string("Version 2.015; my metadata; more metadata")
```

##### Work with major/minor version number integers

```python
fv = FontVersion("path/to/font")
# version number = "Version 1.234"
vno = fv.get_version_number_tuple()
print(vno)
>>> (1, 2, 3, 4)
fv2 = FontVersion("path/to/font2")
# version number = "Version 10.234"
vno2 = fv2.get_version_number_tuple()
print(vno2)
>>> (10, 2, 3, 4)
```

##### Eliminate all metadata from a version string

Remove all metadata from the version string:

```python
fv = FontVersion("path/to/font")
# pre modification version string = "Version 1.000; some metadata; other metadata"
fv.clear_metadata()
# post modification version string = "Version 1.000"
```

##### Set development/release status metadata of the font build

Add a development/release status substring to the name ID 5 record:

```python
fv = FontVersion("path/to/font")
# Label as development build
fv.set_development_status()
# --> adds `DEV` status metadata to version string

# Label as release build
fv.set_release_status()
# --> adds `RELEASE` status metadata to version string
```

##### Set git commit SHA1 hash state metadata to maintain documentation of build time source state

Add source code state metadata to the name ID 5 record:

```python
fv = FontVersion("path/to/font")

# Set git commit SHA1 only
fv.set_state_git_commit_sha1()
# --> adds "[sha1 hash]" state metadata to build

# Set git commit SHA1 with development status indicator
fv.set_state_git_commit_sha1(development=True)
# --> adds "[sha1 hash]-dev" state metadata to build

# Set git commit SHA1 with release status indicator
fv.set_state_git_commit_sha1(release=True)
# --> adds "[sha1 hash]-release" state metadata to build
```

### libfv API

Full documentation of the `libfv` API is available at http://font-v.readthedocs.io/

## Contributing to font-v

Source contributions to the libfv library and font-v executable are encouraged and welcomed! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) documentation for details.

## Acknowledgments

Built with the fantastic [fonttools](https://github.com/fonttools/fonttools) and [GitPython](https://github.com/gitpython-developers/GitPython) Python libraries.

## License

[MIT License](https://github.com/source-foundry/font-v/blob/master/docs/LICENSE)