The Encoding maps character codes to glyph identifiers
Note: CFF is seldomly used on its own. For instance in OpenType fonts, there is a separate character map (
cmap
) table that does the encoding. Therefore, the code in this module is untested. If you have a font file actually uses the CFF encodings that you can share, please open an issue on the repository.
The Encoding
maps a character code to a glyph identifier.
The character code can be found using Char.toCode : Char -> Int
. The glyph identifier is used as an index into the array of charstrings.
It can also be used to get a character's name from the Charset
.
A pseudo-code example:
charstrings : Array Charstring
encoding : Encoding
toGlyph : Char -> Maybe Charstring
toGlyph character =
let
gid =
Encoding.forChar character
in
Array.get gid charstrings
Note: In most cases the CFF encoding is not used. For instance, OpenType fonts define their own encoding in the cmap
table.
In those cases, the encoding is still present in the CFF (it often defaults to 0
, the standard encoding) but using it will give wrong results.
forChar : Encoding -> Char -> Basics.Int
Returns the glyph identifier for a character
forIndex : Encoding -> Basics.Int -> Basics.Int
Returns the glyph identifier for an index
Defaults to 0
(.notdef
).
decode : { offset : Basics.Int } -> Bytes.Decode.Decoder Encoding
Decode and encoding given the encoding format
The offset value is (a)bused to indicate the encoding format.
When the offset is 0 or 1 the encoding is not encoded at all.