Optional module · pdftoolkit/pdf-fonts 0.1.7
English | Français
Two formats, two responsibilities
ISO 32000-1 describes /FontFile2 as a stream containing a TrueType program,
a descriptor as a dictionary of metrics in PDF units, and a composite font as
an object graph: /Type0, /CIDFontType2, /CIDToGIDMap, /W and /ToUnicode.
The core can construct each of these objects from known values. It does not
decode the sfnt tables of an external font.
The TrueType format defines its tables and the rules required to read metrics and outlines. This package's classes perform that reading, then pass only normalised values to the core.
Example steps
- The application supplies bytes to the
FontProgramconstructor, which validates offsets, sizes, metrics and embedding permissions. CIDFontProgrampreserves all glyphs and rebuilds the program intended for/FontFile2. It removescmap, as required by section 9.9 for a/CIDFontType2, and theDSIGsignature invalidated by the conversion. The sfnt directory and checksums are recalculated.- The core receives these bytes in
FontFile2. It calculates/Length1without reading or validating TrueType tables; PDF filters encode the stream. UnicodeTextdeclares the repertoire before the document is built.CharacterMapFactoryfinds GIDs incmap, assigns distinct CIDs to Unicode characters and converts advances into 1,000-unit PDF metrics. Two characters sharing a glyph retain distinct CIDs and/ToUnicodemappings.FontDescriptorFactoryconverts dimensions, the bounding box, angle and heights into coreNumericTypevalues and aRectangle.StemVand flags are supplied explicitly because the format does not provide a universal measurement of stem thickness.CapHeightcan be supplied explicitly if the font does not declare it and the height of theHglyph is insufficient.CIDWidths,CIDToGIDMap,ToUnicodeCMap,CIDFontType2andType0Fontthen compose only PDF objects. They know nothing aboutFontProgram,cmapor units per em.TextEncoderconverts previously declared characters into two-byte codes. A character absent from the repertoire raises an exception; the encoder does not modify the font without the application's knowledge.
Both factories verify that the supplied FontFile2 bytes correspond to the
CIDFontProgram in use. Core objects then verify the identity of the embedded
stream, the font name and the shared repertoire.
Limits
The example sets French and Greek text without contextual shaping. It does not claim to handle Arabic, scripts that require shaping, ligatures, kerning, variations or vertical writing automatically.
The demonstration Noto Sans font is redistributed under its OFL licence in
examples/assets/fonts/OFL.txt. Files are read by the application; the
package's classes have no implicit access to the file system.