PDF FontDescriptor dict —
buildFontDescriptor(font, opts).
Module embedFontDescriptor | Source packages/front/office/fonts/src/embed-pdf/fontDescriptor.js | Deps fontErrors | Worker-safe yes
Builds the FontDescriptor dictionary (PDF 32000-1 §9.8) from a parsed Font: flags, ItalicAngle, Ascent, Descent, CapHeight, StemV, FontBBox, and FontFile2 (TTF) or FontFile3 (CFF).
Exports
| Symbol | Type | Description |
|---|---|---|
PDF_FONT_FLAG |
const | Flag bitfield { FIXED_PITCH, SERIF, SYMBOLIC, SCRIPT, NONSYMBOLIC, ITALIC, ALL_CAP, SMALL_CAP, FORCE_BOLD }. |
buildFontDescriptor |
function | (font, opts?) => DescriptorDict. |
embedFontDescriptor |
factory | Factory. |
Usage
import fw from '@awacloud/fw';
import { fw_require, modules } from '@awacloud/fonts';
for (const m of [...fw_require, ...modules]) fw.runtime.register(m);
const { buildFontDescriptor, PDF_FONT_FLAG } = fw.runtime.resolve('embedFontDescriptor');
const desc = buildFontDescriptor(font, { subsetBytes: subset.subsetBytes, namePrefix: 'ABCDEF' });
Notes
- Flags derived from
post.isFixedPitch(FixedPitch),os2.sFamilyClass(Serif/Script/Symbolic, high byte of the class ID),post.italicAngleandhead.macStylebit 1 (Italic),head.macStylebit 0 (ForceBold); Nonsymbolic is set whenever Symbolic isn't. FontFile2vsFontFile3is chosen viaopts.isCff(defaults tofont.flavor === 'opentype') — not by scanning for aCFFtable.opts.subsetBytesis only attached to the output (FontFile2/FontFile3) when provided; the caller must supply it,buildFontDescriptordoes not readfont.rawSfntfor this.