gfngfn / otfed

An OpenType font format encoder & decoder written in OCaml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

otfed: OpenType Font Format Encoder & Decoder

Table of Contents

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

Usage of an example CLI otfedcli

$ dune exec otfedcli <path/to/font-file> <command> ... <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.
  | vhea                               # Prints the contents of `vhea` table.
  | maxp                               # Prints the contents of `maxp` table.
  | hmtx <glyph-id>                    # Consults the `hmtx` table by the glyph of ID <glyph-id>.
  | vmtx <glyph-id>                    # Consults the `vmtx` 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

Development status

  • Support:
    • V = supported
    • - = not supported yet
  • Test:
    • V = having automated tests
    • - = not supported
    • o = no automated test has been given, but seems to be working fine for many inputs
    • x = not well-tested
Tables Encoding operationsDecoding operations
SupportedTestedSupportedTested
RequiredcmapFormat 0 ----
Format 2 ----
Format 4 --VV
Format 6 ----
Format 8 ----
Format 10 ----
Format 12 VVVV
Format 13 --VV
Format 14 VVVV
head VVVV
hhea VVVV
hmtx VVVV
maxp VVVV
name VVVV
OS/2ver. 0 VoVo
ver. 1 VoVo
ver. 2 VVVV
ver. 3, 4, & 5VoVo
post VVVV
TTF cvt␣ ----
fpgm ----
glyf VVVV
locashort VVVo
long VoVV
prep ----
gasp ----
CFF CFF␣ VoVV
CFF2 ----
VORG ----
SVG SVG␣ ----
Optional DSIG ----
kernFormat 0 --VV
other ----
vheaver. 1.0 VVVV
ver. 1.1 VxVx
vmtx VVVV
AdvancedBASE ----
GDEF ----
GPOSLookupType 1 --Vo
LookupType 2 --Vo
LookupType 3 --Vx
LookupType 4 --Vo
LookupType 5 --Vo
LookupType 6 --Vo
LookupType 7 ----
LookupType 8 ----
LookupType 9 --Vo
GSUBLookupType 1 --Vo
LookupType 2 --Vo
LookupType 3 ----
LookupType 4 --Vo
LookupType 5 ----
LookupType 6 ----
LookupType 7 ----
LookupType 8 ----
JSTF ----
MATH --VV

How to develop this library

Assumes that Dune (≥2.7) is installed.

How to build

$ dune build

How to run tests

$ dune test

Remarks

Origin

This library has been developed with the intension of reformulating otfm.

See also:

Data used in unit tests

Some unit tests use data extracted from the following fonts:

About

An OpenType font format encoder & decoder written in OCaml

License:MIT License


Languages

Language:OCaml 99.9%Language:Standard ML 0.1%