refactor(font): scaffold dualFontLayout module with shared types
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Internal shape of pretext's PreparedTextWithSegments — only `segments` is in
|
||||
* pretext's public TS type; the numeric arrays exist at runtime but are not in
|
||||
* the published signature. Verified against node_modules/@chenglou/pretext/src/layout.ts.
|
||||
*/
|
||||
interface PretextInternals {
|
||||
/**
|
||||
* Per-segment text.
|
||||
*/
|
||||
segments: string[];
|
||||
/**
|
||||
* Per-segment full width in pixels.
|
||||
*/
|
||||
widths: number[];
|
||||
/**
|
||||
* Per-segment per-grapheme advance widths, or null when the segment is a single grapheme.
|
||||
*/
|
||||
breakableFitAdvances: (number[] | null)[];
|
||||
/**
|
||||
* Per-segment line-end fit advance.
|
||||
*/
|
||||
lineEndFitAdvances: number[];
|
||||
/**
|
||||
* Per-segment line-end paint advance.
|
||||
*/
|
||||
lineEndPaintAdvances: number[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-grapheme data computed during dual-font layout. Internal to the engine;
|
||||
* consumed by computeLineRenderModel to derive the per-frame render model.
|
||||
*/
|
||||
export interface ComparisonChar {
|
||||
/**
|
||||
* Grapheme cluster (may be >1 code unit for emoji, combining marks).
|
||||
*/
|
||||
char: string;
|
||||
/**
|
||||
* X offset from line start in fontA, pixels.
|
||||
*/
|
||||
xA: number;
|
||||
/**
|
||||
* Advance width of this grapheme in fontA, pixels.
|
||||
*/
|
||||
widthA: number;
|
||||
/**
|
||||
* X offset from line start in fontB, pixels.
|
||||
*/
|
||||
xB: number;
|
||||
/**
|
||||
* Advance width of this grapheme in fontB, pixels.
|
||||
*/
|
||||
widthB: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single laid-out line. `chars` carries the per-grapheme data needed by
|
||||
* computeLineRenderModel. Consumers should not iterate it directly.
|
||||
*/
|
||||
export interface ComparisonLine {
|
||||
/**
|
||||
* Full text of this line as returned by pretext.
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Rendered width in pixels — maximum across fontA and fontB.
|
||||
*/
|
||||
width: number;
|
||||
/**
|
||||
* Per-grapheme metadata for both fonts.
|
||||
*/
|
||||
chars: ComparisonChar[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregated output of a dual-font layout pass.
|
||||
*/
|
||||
export interface ComparisonResult {
|
||||
/**
|
||||
* Per-line grapheme data. Empty when input text is empty.
|
||||
*/
|
||||
lines: ComparisonLine[];
|
||||
/**
|
||||
* Total height in pixels.
|
||||
*/
|
||||
totalHeight: number;
|
||||
}
|
||||
Reference in New Issue
Block a user