/** * TrueType font subsetting and PDF embedding. * * Takes a parsed TrueType font and a set of used Unicode code points, * and produces: * 1. A subsetted font program (binary TTF with only the needed glyphs) * 2. A CID-to-GID mapping for the CIDFont dictionary * 3. A ToUnicode CMap for text extraction/search * 4. Width arrays for the PDF font descriptor * * PDF embedding uses a Type0 (composite) font structure: * Type0 font → CIDFont (CIDFontType2) → embedded TrueType font program * * The CID-to-GID mapping is Identity (CID = new GID in the subset). * Character codes in the content stream are 2-byte big-endian glyph IDs. * * @see PDF Reference 1.7, §5.6 - Composite Fonts * @see PDF Reference 1.7, §5.9 - ToUnicode CMaps */ import type { PdfWriter } from "../core/pdf-writer.js"; import type { TtfFont } from "./ttf-parser.js"; /** * Result of embedding a font into a PDF. */ export interface EmbeddedFont { /** PDF resource name (e.g., "EF1") */ resourceName: string; /** Object number of the Type0 font dictionary */ fontObjNum: number; /** The parsed TTF font */ font: TtfFont; /** * Map from Unicode code point → CID (= new glyph index in subset). * Only contains characters that were actually used. */ unicodeToCid: Map; /** Advance widths in font units, indexed by CID */ cidWidths: number[]; } /** * Embed a TrueType font into a PDF document. * * @param writer - The PDF writer to add objects to * @param font - Parsed TrueType font * @param usedCodePoints - Set of Unicode code points used in the document * @param resourceName - PDF resource name (e.g., "EF1") * @returns Embedded font info */ export declare function embedTtfFont(writer: PdfWriter, font: TtfFont, usedCodePoints: Set, resourceName: string): EmbeddedFont;