otfed
: OpenType Font Format Encoder & Decoder
This library is intended to be a reformulation and extension of otfm
.
See also:
Note
Some unit tests use data extracted from the following fonts:
- IPAex明朝 (IPAex Mincho):
ipaexm.ttf
- See the license here
- Latin Modern:
lmroman10-regular.otf
andlmmono10-regular.otf
- See the license here
- Junicode
- See the license here
How to install
Under the condition that opam
(a package manager for OCaml, Coq, etc.) is installed, invoke the following commands:
$ cd <your-workspace>
$ git clone https://github.com/gfngfn/otfed
$ cd otfed
$ opam pin add otfed .
Probably the last command above will ask you whether to install otfed
. Then answer y
.
If not, invoking the following command will do:
$ opam install otfed
otfedcli
Usage of an example CLI $ dune exec otfedcli <path/to/font-file> <commands>
<commands> ::= [<command>]*
<command> ::=
| tables # Prints all the tags of tables contained in the font.
| cmap # Prints all the Unicode-aware `cmap` subtables.
| cmap_word "<arbitrary-utf8-text>" # Consults `cmap` subtables for each character in the given text.
| head # Prints the contents of `head` table.
| hhea # Prints the contents of `hhea` table.
| maxp # Prints the contents of `maxp` table.
| hmtx <glyph-id> # Consults the `hmtx` table by the glyph of ID <glyph-id>.
| glyf <glyph-id> <output-svg-file> # Outputs the glyph of ID <glyph-id> that has TrueType outlines.
| cff <glyph-id> <output-svg-file> # Outputs the glyph of ID <glyph-id> that has CFF outlines.
| cff_lex <glyph-id> # Prints the tokenized CharString of the glyph of ID <glyph-id>.
| cff_top # Prints the Top DICT in the `CFF␣` table.
| charset <glyph-id> # Prints the name of the glyph by consulting the charset in `CFF␣`.
| gsub <script> <langsys> <feature> # Prints the contents of `GSUB` subtables.
| gpos <script> <langsys> <feature> # Prints the contents of `GPOS` subtables.
| subset <glyph-ids> <output-ttf> # Makes a subset font by using given glyph IDs.
<glyph-ids> ::= (comma-separated glyph IDs where no space is allowed around commas)
Example usage
Consults cmap
subtables by Unicode code points:
$ dune exec otfedcli input/ipaexm.ttf cmap_word "田中太郎"
* subtable (platform: 0, encoding: 3)
- U+7530 --> 2900
- U+4E2D --> 2746
- U+592A --> 2614
- U+90CE --> 3830
* subtable (platform: 3, encoding: 1)
- U+7530 --> 2900
- U+4E2D --> 2746
- U+592A --> 2614
- U+90CE --> 3830
* subtable (platform: 3, encoding: 10)
- U+7530 --> 2900
- U+4E2D --> 2746
- U+592A --> 2614
- U+90CE --> 3830
Prints all of the Unicode-aware cmap
subtables in IPAex Mincho (please be careful of large outputs on stdout):
$ dune exec otfedcli input/ipaexm.ttf cmap
(omitted)
Outputs the glyph of ID 1000 in IPAex Mincho as an SVG file:
$ dune exec otfedcli input/ipaexm.ttf glyf 1000 output/ipaexm1000.svg
(omitted)
Outputs the glyph of ID 50 in Computer Modern Typewriter Italic as an SVG file:
$ dune exec otfedcli input/cmunit.otf cff 50 output/cmunit1000.svg
(omitted)
Outputs the subset of Junicode which contains .notdef
, “Q”, and “f” only:
$ dune exec otfedcli input/Junicode.ttf subset 0,113,302 output/Junicode-subset.ttf
Status
- v: done
- o: no automated test has been given, but seems working correctly for many inputs.
Tables | Encoding operations | Decoding operations | ||||
---|---|---|---|---|---|---|
Supported | Tested | Supported | Tested | |||
Required | cmap | v (Format 12 only) | v (Format 12 only) | v (Format 4, 12, and 13 only) | v (Format 4 and 12 only) | |
head | v | v | v | v | ||
hhea | v | v | v | v | ||
hmtx | v | v | v | v | ||
maxp | v | v | v | v | ||
name | v | v | v | v | ||
OS/2 | v | v (version 2 only) | v | v (version 2 only) | ||
post | v | v | v | v | ||
TTF | cvt␣ | - | - | - | - | |
fpgm | - | - | - | - | ||
glyf | v | v | v | v | ||
loca | v | v (short only) | v | v (long only) | ||
prep | - | - | - | - | ||
gasp | - | - | - | - | ||
CFF | CFF␣ | v | o | v | v | |
CFF2 | - | - | - | - | ||
VORG | - | - | - | - | ||
SVG | SVG␣ | - | - | - | - | |
Optional | DSIG | - | - | - | - | |
kern | - | - | v (Format 0 only) | o | ||
vhea | - | - | - | - | ||
vmtx | - | - | - | - | ||
Advanced | BASE | - | - | - | - | |
GDEF | - | - | - | - | ||
GPOS | - | - | v (LookupType 1, 2, 4, 5, 6, and 9 only) | o | ||
GSUB | - | - | v (LookupType 1, 2, and 4 only) | o | ||
JSTF | - | - | - | - | ||
MATH | - | - | v | o |
How to develop
Assumes that Dune (≥2.7) is installed.
How to build
$ dune build
How to run tests
$ dune test