@lightningjs/renderer 2.18.4 → 2.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/utils.d.ts +2 -1
- package/dist/exports/utils.js +2 -1
- package/dist/exports/utils.js.map +1 -1
- package/dist/src/core/CoreNode.js +11 -11
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/TextureMemoryManager.js +1 -1
- package/dist/src/core/TextureMemoryManager.js.map +1 -1
- package/dist/src/core/renderers/CoreRenderer.d.ts +2 -2
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +6 -12
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +23 -18
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.d.ts +1 -0
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +31 -4
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js.map +1 -1
- package/dist/src/core/shaders/webgl/LinearGradient.js +26 -3
- package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -1
- package/dist/src/core/shaders/webgl/RadialGradient.js +49 -27
- package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -1
- package/dist/src/core/text-rendering/CanvasFont.d.ts +14 -0
- package/dist/src/core/text-rendering/CanvasFont.js +111 -0
- package/dist/src/core/text-rendering/CanvasFont.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.d.ts +6 -4
- package/dist/src/core/text-rendering/CanvasTextRenderer.js +17 -9
- package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/CoreFont.d.ts +33 -0
- package/dist/src/core/text-rendering/CoreFont.js +48 -0
- package/dist/src/core/text-rendering/CoreFont.js.map +1 -0
- package/dist/src/core/text-rendering/FontManager.d.ts +11 -0
- package/dist/src/core/text-rendering/FontManager.js +42 -0
- package/dist/src/core/text-rendering/FontManager.js.map +1 -0
- package/dist/src/core/text-rendering/SdfFont.d.ts +29 -0
- package/dist/src/core/text-rendering/SdfFont.js +142 -0
- package/dist/src/core/text-rendering/SdfFont.js.map +1 -0
- package/dist/src/core/text-rendering/SdfFontHandler.d.ts +28 -125
- package/dist/src/core/text-rendering/SdfFontHandler.js +4 -334
- package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -1
- package/dist/src/core/text-rendering/SdfTextRenderer.d.ts +6 -5
- package/dist/src/core/text-rendering/SdfTextRenderer.js +19 -15
- package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/TextLayoutEngine.d.ts +9 -8
- package/dist/src/core/text-rendering/TextLayoutEngine.js +22 -22
- package/dist/src/core/text-rendering/TextLayoutEngine.js.map +1 -1
- package/dist/src/core/text-rendering/TextRenderer.d.ts +4 -3
- package/dist/src/main-api/Inspector.js +1 -1
- package/dist/src/main-api/Inspector.js.map +1 -1
- package/dist/src/main-api/Renderer.js +1 -1
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/src/utils.d.ts +1 -6
- package/dist/src/utils.js +2 -9
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/utils.ts +7 -1
- package/package.json +1 -1
- package/src/core/CoreNode.ts +12 -14
- package/src/core/TextureMemoryManager.ts +1 -1
- package/src/core/renderers/CoreRenderer.ts +2 -2
- package/src/core/renderers/webgl/WebGlCoreRenderer.ts +9 -21
- package/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.ts +23 -18
- package/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.ts +32 -4
- package/src/main-api/Inspector.ts +1 -1
- package/src/main-api/Renderer.ts +1 -1
- package/src/utils.ts +4 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Stage } from '../Stage.js';
|
|
2
|
+
import type { ImageTexture } from '../textures/ImageTexture.js';
|
|
3
|
+
import { CoreFont, type CoreFontProps } from './CoreFont.js';
|
|
4
|
+
import { type SdfFontData } from './SdfFontHandler.js';
|
|
5
|
+
import type { NormalizedFontMetrics, TextRenderer } from './TextRenderer.js';
|
|
6
|
+
export type SdfFontProps = CoreFontProps & {
|
|
7
|
+
atlasUrl: string;
|
|
8
|
+
atlasDataUrl: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class SdfFont extends CoreFont {
|
|
11
|
+
private stage;
|
|
12
|
+
type: string;
|
|
13
|
+
atlasUrl: string;
|
|
14
|
+
atlasDataUrl: string;
|
|
15
|
+
atlasTexture?: ImageTexture;
|
|
16
|
+
private glyphMap?;
|
|
17
|
+
private kerningTable?;
|
|
18
|
+
private data?;
|
|
19
|
+
constructor(textRenderer: TextRenderer, props: SdfFontProps, stage: Stage);
|
|
20
|
+
load(): void;
|
|
21
|
+
private hardFail;
|
|
22
|
+
private processFontData;
|
|
23
|
+
measureText(text: string, letterSpacing: number): number;
|
|
24
|
+
getMetrics(fontSize: number): NormalizedFontMetrics;
|
|
25
|
+
getGlyph(codepoint: number): import("./SdfFontHandler.js").SdfGlyph | null;
|
|
26
|
+
getKerning(firstGlyph: number, secondGlyph: number): number;
|
|
27
|
+
getAtlas(): ImageTexture;
|
|
28
|
+
getData(): SdfFontData;
|
|
29
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2025 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { CoreFont, FontState } from './CoreFont.js';
|
|
20
|
+
import { buildGlyphMap, buildKerningTable, } from './SdfFontHandler.js';
|
|
21
|
+
import { normalizeFontMetrics } from './TextLayoutEngine.js';
|
|
22
|
+
import { hasZeroWidthSpace } from './Utils.js';
|
|
23
|
+
export class SdfFont extends CoreFont {
|
|
24
|
+
stage;
|
|
25
|
+
type = 'sdf';
|
|
26
|
+
atlasUrl;
|
|
27
|
+
atlasDataUrl;
|
|
28
|
+
atlasTexture;
|
|
29
|
+
glyphMap;
|
|
30
|
+
kerningTable;
|
|
31
|
+
data;
|
|
32
|
+
constructor(textRenderer, props, stage) {
|
|
33
|
+
super(textRenderer, props);
|
|
34
|
+
this.stage = stage;
|
|
35
|
+
this.atlasUrl = props.atlasUrl;
|
|
36
|
+
this.atlasDataUrl = props.atlasDataUrl;
|
|
37
|
+
}
|
|
38
|
+
load() {
|
|
39
|
+
new Promise(async () => {
|
|
40
|
+
const atlasData = await fetch(this.atlasDataUrl);
|
|
41
|
+
if (atlasData.ok === false) {
|
|
42
|
+
this.hardFail(`Failed to load font data: ${atlasData.statusText}`);
|
|
43
|
+
}
|
|
44
|
+
const fontData = (await atlasData.json());
|
|
45
|
+
if (fontData.chars === undefined) {
|
|
46
|
+
this.hardFail('Invalid SDF font data format');
|
|
47
|
+
}
|
|
48
|
+
const atlasTexture = this.stage.txManager.createTexture('ImageTexture', {
|
|
49
|
+
src: this.atlasUrl,
|
|
50
|
+
premultiplyAlpha: false,
|
|
51
|
+
});
|
|
52
|
+
atlasTexture.setRenderableOwner(this.family, true);
|
|
53
|
+
atlasTexture.preventCleanup = true;
|
|
54
|
+
atlasTexture.on('loaded', () => {
|
|
55
|
+
this.onLoaded();
|
|
56
|
+
});
|
|
57
|
+
atlasTexture.on('failed', (error) => {
|
|
58
|
+
console.error(`Failed to load SDF font: ${this.family}`, error);
|
|
59
|
+
this.emit('failed');
|
|
60
|
+
});
|
|
61
|
+
this.atlasTexture = atlasTexture;
|
|
62
|
+
this.processFontData(fontData);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
hardFail(message) {
|
|
66
|
+
this.state = FontState.Failed;
|
|
67
|
+
throw new Error(message);
|
|
68
|
+
}
|
|
69
|
+
processFontData(fontData) {
|
|
70
|
+
this.glyphMap = buildGlyphMap(fontData.chars);
|
|
71
|
+
this.kerningTable = buildKerningTable(fontData.kernings);
|
|
72
|
+
this.metrics = this.metrics ||
|
|
73
|
+
fontData.lightningMetrics || {
|
|
74
|
+
ascender: 800,
|
|
75
|
+
descender: -200,
|
|
76
|
+
lineGap: 200,
|
|
77
|
+
unitsPerEm: 1000,
|
|
78
|
+
};
|
|
79
|
+
this.data = fontData;
|
|
80
|
+
}
|
|
81
|
+
measureText(text, letterSpacing) {
|
|
82
|
+
if (text.length === 1) {
|
|
83
|
+
const char = text.charAt(0);
|
|
84
|
+
const codepoint = text.codePointAt(0);
|
|
85
|
+
if (codepoint === undefined)
|
|
86
|
+
return 0;
|
|
87
|
+
if (hasZeroWidthSpace(char) === true)
|
|
88
|
+
return 0;
|
|
89
|
+
const glyph = this.getGlyph(codepoint);
|
|
90
|
+
if (glyph === null)
|
|
91
|
+
return 0;
|
|
92
|
+
return glyph.xadvance + letterSpacing;
|
|
93
|
+
}
|
|
94
|
+
let width = 0;
|
|
95
|
+
let prevCodepoint = 0;
|
|
96
|
+
for (let i = 0; i < text.length; i++) {
|
|
97
|
+
const char = text.charAt(i);
|
|
98
|
+
const codepoint = text.codePointAt(i);
|
|
99
|
+
if (codepoint === undefined)
|
|
100
|
+
continue;
|
|
101
|
+
// Skip zero-width spaces in width calculations
|
|
102
|
+
if (hasZeroWidthSpace(char)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const glyph = this.getGlyph(codepoint);
|
|
106
|
+
if (glyph === null)
|
|
107
|
+
continue;
|
|
108
|
+
let advance = glyph.xadvance;
|
|
109
|
+
// Add kerning if there's a previous character
|
|
110
|
+
if (prevCodepoint !== 0) {
|
|
111
|
+
const kerning = this.getKerning(prevCodepoint, codepoint);
|
|
112
|
+
advance += kerning;
|
|
113
|
+
}
|
|
114
|
+
width += advance + letterSpacing;
|
|
115
|
+
prevCodepoint = codepoint;
|
|
116
|
+
}
|
|
117
|
+
return width;
|
|
118
|
+
}
|
|
119
|
+
getMetrics(fontSize) {
|
|
120
|
+
let m = this.normalizedMetrics[fontSize];
|
|
121
|
+
if (m !== undefined) {
|
|
122
|
+
return m;
|
|
123
|
+
}
|
|
124
|
+
m = this.normalizedMetrics[fontSize] = normalizeFontMetrics(this.metrics, fontSize);
|
|
125
|
+
return m;
|
|
126
|
+
}
|
|
127
|
+
getGlyph(codepoint) {
|
|
128
|
+
const gm = this.glyphMap;
|
|
129
|
+
return gm[codepoint] || gm[63] || null;
|
|
130
|
+
}
|
|
131
|
+
getKerning(firstGlyph, secondGlyph) {
|
|
132
|
+
const seconds = this.kerningTable[secondGlyph];
|
|
133
|
+
return (seconds !== undefined && seconds[firstGlyph]) || 0;
|
|
134
|
+
}
|
|
135
|
+
getAtlas() {
|
|
136
|
+
return this.atlasTexture;
|
|
137
|
+
}
|
|
138
|
+
getData() {
|
|
139
|
+
return this.data;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=SdfFont.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdfFont.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/SdfFont.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAsB,MAAM,eAAe,CAAC;AACxE,OAAO,EACL,aAA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AC;YACrB,CAAC;YAED,KAAK,IAAI,OAAO,GAAG,aAAa,CAAC;YACjC,aAAa,GAAG,SAAS,CAAC;QAC5B,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,UAAU,CAAC,QAAgB;QACzB,IAAI,CAAC,GAAG,IAAI,CAAC,iBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACpB,OAAO,CAAC,CAAC;QACX,CAAC;QACD,CAAC,GAAG,IAAI,CAAC,iBAAkB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAC1D,IAAI,CAAC,OAAQ,EACb,QAAQ,CACT,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;IAED,QAAQ,CAAC,SAAiB;QACxB,MAAM,EAAE,GAAG,IAAI,CAAC,QAAuB,CAAC;QACxC,OAAO,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,UAAU,CAAC,UAAkB,EAAE,WAAmB;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAa,CAAC,WAAW,CAAC,CAAC;QAChD,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,YAAa,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { FontMetrics } from './TextRenderer.js';
|
|
2
|
+
export interface SdfGlyph {
|
|
3
|
+
id: number;
|
|
4
|
+
char: string;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
xoffset: number;
|
|
10
|
+
yoffset: number;
|
|
11
|
+
xadvance: number;
|
|
12
|
+
page: number;
|
|
13
|
+
chnl: number;
|
|
14
|
+
}
|
|
15
|
+
export type SdfGlyphMap = Record<number, SdfGlyph>;
|
|
16
|
+
export interface SdfKerning {
|
|
17
|
+
first: number;
|
|
18
|
+
second: number;
|
|
19
|
+
amount: number;
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* SDF Font Data structure matching msdf-bmfont-xml output
|
|
7
23
|
*/
|
|
8
24
|
export interface SdfFontData {
|
|
9
25
|
pages: string[];
|
|
10
|
-
chars:
|
|
11
|
-
|
|
12
|
-
char: string;
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
width: number;
|
|
16
|
-
height: number;
|
|
17
|
-
xoffset: number;
|
|
18
|
-
yoffset: number;
|
|
19
|
-
xadvance: number;
|
|
20
|
-
page: number;
|
|
21
|
-
chnl: number;
|
|
22
|
-
}>;
|
|
23
|
-
kernings: Array<{
|
|
24
|
-
first: number;
|
|
25
|
-
second: number;
|
|
26
|
-
amount: number;
|
|
27
|
-
}>;
|
|
26
|
+
chars: SdfGlyph[];
|
|
27
|
+
kernings: SdfKerning[];
|
|
28
28
|
info: {
|
|
29
29
|
face: string;
|
|
30
30
|
size: number;
|
|
@@ -75,108 +75,11 @@ export interface SdfFontData {
|
|
|
75
75
|
* @typedef {Object} KerningTable
|
|
76
76
|
* Fast lookup table for kerning values
|
|
77
77
|
*/
|
|
78
|
-
type KerningTable = Record<number, Record<number, number | undefined> | undefined>;
|
|
79
|
-
/**
|
|
80
|
-
* @typedef {Object} SdfFontCache
|
|
81
|
-
* Cached font data for performance
|
|
82
|
-
*/
|
|
83
|
-
export interface SdfFont {
|
|
84
|
-
data: SdfFontData;
|
|
85
|
-
glyphMap: Map<number, SdfFontData['chars'][0]>;
|
|
86
|
-
kernings: KerningTable;
|
|
87
|
-
atlasTexture: ImageTexture;
|
|
88
|
-
metrics: FontMetrics;
|
|
89
|
-
maxCharHeight: number;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Check if the SDF font handler can render a font
|
|
93
|
-
* @param {TrProps} trProps - Text rendering properties
|
|
94
|
-
* @returns {boolean} True if the font can be rendered
|
|
95
|
-
*/
|
|
96
|
-
export declare const canRenderFont: (trProps: TrProps) => boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Load SDF font from JSON + PNG atlas
|
|
99
|
-
* @param {Object} options - Font loading options
|
|
100
|
-
* @param {string} options.fontFamily - Font family name
|
|
101
|
-
* @param {string} options.fontUrl - JSON font data URL (atlasDataUrl)
|
|
102
|
-
* @param {string} options.atlasUrl - PNG atlas texture URL
|
|
103
|
-
* @param {FontMetrics} options.metrics - Optional font metrics
|
|
104
|
-
*/
|
|
105
|
-
export declare const loadFont: (stage: Stage, options: FontLoadOptions) => Promise<void>;
|
|
106
|
-
/**
|
|
107
|
-
* Stop waiting for a font to load
|
|
108
|
-
* @param {string} fontFamily - Font family name
|
|
109
|
-
* @param {CoreTextNode} node - Node that was waiting for the font
|
|
110
|
-
*/
|
|
111
|
-
export declare const waitingForFont: (fontFamily: string, node: CoreTextNode) => void;
|
|
112
|
-
/**
|
|
113
|
-
* Stop waiting for a font to load
|
|
114
|
-
*
|
|
115
|
-
* @param fontFamily
|
|
116
|
-
* @param node
|
|
117
|
-
* @returns
|
|
118
|
-
*/
|
|
119
|
-
export declare const stopWaitingForFont: (fontFamily: string, node: CoreTextNode) => void;
|
|
120
|
-
/**
|
|
121
|
-
* Get the font families map for resolving fonts
|
|
122
|
-
*/
|
|
123
|
-
export declare const getFontFamilies: () => FontFamilyMap;
|
|
124
|
-
/**
|
|
125
|
-
* Initialize the SDF font handler
|
|
126
|
-
*/
|
|
127
|
-
export declare const init: (c?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D) => void;
|
|
128
|
-
export declare const type = "sdf";
|
|
129
|
-
/**
|
|
130
|
-
* Check if a font is already loaded by font family
|
|
131
|
-
*/
|
|
132
|
-
export declare const isFontLoaded: (fontFamily: string) => boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Get normalized font metrics for a font family
|
|
135
|
-
*/
|
|
136
|
-
export declare const getFontMetrics: (fontFamily: string, fontSize: number) => NormalizedFontMetrics;
|
|
137
|
-
export declare const processFontMetrics: (fontFamily: string, fontSize: number, metrics: FontMetrics) => NormalizedFontMetrics;
|
|
138
|
-
/**
|
|
139
|
-
* Get glyph data for a character in a specific font
|
|
140
|
-
* @param {string} fontFamily - Font family name
|
|
141
|
-
* @param {number} codepoint - Character codepoint
|
|
142
|
-
* @returns {Object|null} Glyph data or null if not found
|
|
143
|
-
*/
|
|
144
|
-
export declare const getGlyph: (fontFamily: string, codepoint: number) => SdfFontData["chars"][0] | null;
|
|
145
|
-
/**
|
|
146
|
-
* Get kerning value between two glyphs
|
|
147
|
-
* @param {string} fontFamily - Font family name
|
|
148
|
-
* @param {number} firstGlyph - First glyph ID
|
|
149
|
-
* @param {number} secondGlyph - Second glyph ID
|
|
150
|
-
* @returns {number} Kerning value or 0
|
|
151
|
-
*/
|
|
152
|
-
export declare const getKerning: (fontFamily: string, firstGlyph: number, secondGlyph: number) => number;
|
|
153
|
-
/**
|
|
154
|
-
* Get atlas texture for a font family
|
|
155
|
-
* @param {string} fontFamily - Font family name
|
|
156
|
-
* @returns {ImageTexture|null} Atlas texture or null
|
|
157
|
-
*/
|
|
158
|
-
export declare const getAtlas: (fontFamily: string) => ImageTexture | null;
|
|
159
|
-
/**
|
|
160
|
-
* Get font data for a font family
|
|
161
|
-
* @param {string} fontFamily - Font family name
|
|
162
|
-
* @returns {SdfFontData|null} Font data or null
|
|
163
|
-
*/
|
|
164
|
-
export declare const getFontData: (fontFamily: string) => SdfFont | undefined;
|
|
165
|
-
/**
|
|
166
|
-
* Get maximum character height for a font family
|
|
167
|
-
* @param {string} fontFamily - Font family name
|
|
168
|
-
* @returns {number} Max character height or 0
|
|
169
|
-
*/
|
|
170
|
-
export declare const getMaxCharHeight: (fontFamily: string) => number;
|
|
171
|
-
/**
|
|
172
|
-
* Get all loaded font families
|
|
173
|
-
* @returns {string[]} Array of font family names
|
|
174
|
-
*/
|
|
175
|
-
export declare const getLoadedFonts: () => string[];
|
|
78
|
+
export type KerningTable = Record<number, Record<number, number | undefined> | undefined>;
|
|
176
79
|
/**
|
|
177
|
-
*
|
|
178
|
-
* @param {
|
|
80
|
+
* Build kerning lookup table for fast access
|
|
81
|
+
* @param {Array} kernings - Kerning data from font
|
|
82
|
+
* @returns {KerningTable} Optimized kerning lookup table
|
|
179
83
|
*/
|
|
180
|
-
export declare const
|
|
181
|
-
export declare const
|
|
182
|
-
export {};
|
|
84
|
+
export declare const buildKerningTable: (kernings: SdfKerning[]) => KerningTable;
|
|
85
|
+
export declare const buildGlyphMap: (chars: SdfGlyph[]) => SdfGlyphMap;
|