-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretext.d.ts
More file actions
79 lines (62 loc) · 2.57 KB
/
Copy pathpretext.d.ts
File metadata and controls
79 lines (62 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Type declarations for pretext.js — a text layout and line-breaking library.
*/
/** Opaque handle returned by prepare / prepareWithSegments. Do not access internals. */
export interface PreparedText {
readonly widths: readonly number[];
}
export interface LinePosition {
segmentIndex: number;
graphemeIndex: number;
}
/** A fully materialised line with its display text and character range. */
export interface LayoutLine {
text: string;
width: number;
start: LinePosition;
end: LinePosition;
}
/** A line range without materialised text — cheaper to produce. */
export interface LayoutLineRange {
width: number;
start: LinePosition;
end: LinePosition;
}
export interface LayoutResult {
lineCount: number;
height: number;
lines: LayoutLine[];
}
export interface LayoutCountResult {
lineCount: number;
height: number;
}
export interface ProfileResult {
analysisMs: number;
measureMs: number;
totalMs: number;
analysisSegments: number;
preparedSegments: number;
breakableSegments: number;
}
export interface PrepareOptions {
whiteSpace?: string;
}
/** Prepare text for layout without grapheme segment data. */
export function prepare(text: string, font: string, options?: PrepareOptions): PreparedText;
/** Prepare text for layout, including grapheme segment data (needed for layoutWithLines). */
export function prepareWithSegments(text: string, font: string, options?: PrepareOptions): PreparedText;
/** Profile the prepare phase and return timing/segment counts. */
export function profilePrepare(text: string, font: string, options?: PrepareOptions): ProfileResult;
/** Count lines and total height without materialising line text. */
export function layout(prepared: PreparedText, maxWidth: number, lineHeight: number): LayoutCountResult;
/** Layout all lines and return their text and dimensions. */
export function layoutWithLines(prepared: PreparedText, maxWidth: number, lineHeight: number): LayoutResult;
/** Return the next line starting from `start` (pass null for the first line). */
export function layoutNextLine(prepared: PreparedText, start: LayoutLineRange | null, maxWidth: number): LayoutLine | null;
/** Walk each line range without materialising text, calling onLine for each. Returns line count. */
export function walkLineRanges(prepared: PreparedText, maxWidth: number, onLine: (line: LayoutLineRange) => void): number;
/** Change the locale used for text analysis. Clears internal caches. */
export function setLocale(locale: string): void;
/** Clear all internal measurement and analysis caches. */
export function clearCache(): void;