@pdfa-lab/fontkit / OpenTypeFont
Type Alias: OpenTypeFont ​
OpenTypeFont =
OpenTypeTrueTypeFont|OpenTypePostScriptFont|OpenTypeNoOutlinesFont
Defined in: src/open-type-font.ts:202
The final Discriminated Union representing any upcast, structurally conformant OpenType font. You will usually get an object implementing the interface with Font.asOpenTypeFont.
Fonts that implement this interface, have all 8 core OpenType tables (@{link requiredOpenTypeTables}) present and successfully decoded.
You can discriminate the different sub types in your code like this:
TypeScript
const openTypeFont = font.asOpenTypeFont();
if (!openTypeFont) {
// This font is a legacy font without the complete set of OpenType core
// tables.
} else if (openTypeFont.outlines === 'TrueType') {
// openTypeFont is now an OpenTypeTrueTypeFont in the scope of this branch.
// All tables for TrueType outlines are guaranteed to be present.
} else if (openTypeFont.outlines === 'PostScript') {
// openTypeFont is now an OpenTypePostScriptFont in the scope of this branch.
// All tables for PostScript outlines are guaranteed to be present.
} else if (openTypeFont.outlines === 'none') {
// openTypeFont is now an OpenTypeNoOutlinesFont in the scope of this
// branch. All 8 OpenType core tables are present.
}