import { PDFResource } from '../document/pdf-resource.ts'; /** * Options for text shaping. */ export type ShapeOptions = { /** * The OpenType script tag (e.g., 'latn' for Latin, 'arab' for Arabic). * If not specified, or if the specified script is not found in the font, * the 'DFLT' script will be used if available. * * See the OpenType specification for a list of script tags: * https://learn.microsoft.com/en-us/typography/opentype/spec/scripttags */ scriptTag?: string; /** * The OpenType language system tag (e.g., 'ENG' for English, 'DEU' for German). * If not specified, or if the specified language is not found in the font, * the default language for the script will be used. * * See the OpenType specification for a list of language system tags: * https://learn.microsoft.com/en-us/typography/opentype/spec/languagetags */ langSysTag?: string; /** * Whether to enable the default font features (ligatures and kerning). * Defaults to `true`. * To disable all default features, set this to `false`. */ defaultFeatures?: boolean; /** * Font features to apply beyond the defaults. * To enable additional features, set them to `true`. * To disable specific default features, set them to `false`. * * See the OpenType specification for a list of feature tags: * https://learn.microsoft.com/en-us/typography/opentype/spec/featuretags */ features?: Record; }; /** * Represents a single glyph in a shaped glyph run, including * positioning information for text rendering. */ export type ShapedGlyph = { /** * The glyph ID in the font. */ glyphId: number; /** * The Unicode code points that this glyph represents. For simple glyphs, * this is a single code point. For ligatures (e.g., "ffi"), this contains * all constituent code points [0x66, 0x66, 0x69]. */ codePoints: number[]; /** * Base horizontal advance in PDF text space units (1/1000 em). * Multiply by `font size / 1000` to obtain user space units. * * This is the default pen movement after rendering this glyph, before * any positioning adjustments. */ advance: number; /** * Adjustment to the horizontal advance (e.g., kerning) in PDF text * space units (1/1000 em). Multiply by `font size / 1000` to obtain * user space units. * * Added to `advance` to get the total pen movement. Affects placement * of all subsequent glyphs. Negative values bring glyphs closer * together. */ advanceAdjust?: number; /** * Horizontal offset for positioning this glyph (e.g., from GPOS * mark-to-base rules) in PDF text space units (1/1000 em). * * Shifts the glyph's rendering position without affecting the pen * advance. Positive values shift right. */ xOffset?: number; /** * Vertical offset for positioning this glyph (e.g., from GPOS * mark-to-base rules) in PDF text space units (1/1000 em). * * Shifts the glyph's rendering position without affecting the pen * advance. Positive values shift up. */ yOffset?: number; }; /** * Returns the width of a shaped glyph run in user space units (points). */ export declare function getTextWidth(glyphs: readonly ShapedGlyph[], fontSize: number): number; export type FontStyle = 'normal' | 'italic' | 'oblique'; /** * Represents a font resource within a PDF document. */ export declare abstract class PDFFont extends PDFResource { /** * The full name of the font. */ abstract readonly fontName: string; /** * The family name of the font. */ abstract readonly familyName: string; /** * The style of the font, either 'normal', 'italic', or 'oblique'. */ abstract readonly style: FontStyle; /** * The weight of the font (e.g., 400 for normal, 700 for bold). */ abstract readonly weight: number; /** * The ascent of the font in PDF text space units (1/1000 em). * Multiply by `font size / 1000` to obtain user space units. */ abstract readonly ascent: number; /** * The descent of the font in PDF text space units (1/1000 em). * Multiply by `font size / 1000` to obtain user space units. */ abstract readonly descent: number; /** * The line gap of the font in PDF text space units (1/1000 em). * Multiply by `font size / 1000` to obtain user space units. */ abstract readonly lineGap: number; /** * Encodes a Unicode text string for use in a PDF content stream with this font. */ abstract shapeText(text: string, opts?: ShapeOptions): ShapedGlyph[]; }