@lightningjs/renderer 2.15.0 → 2.16.0
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/canvas-shaders.d.ts +10 -0
- package/dist/exports/canvas-shaders.js +27 -0
- package/dist/exports/canvas-shaders.js.map +1 -0
- package/dist/exports/webgl-shaders.d.ts +11 -0
- package/dist/exports/webgl-shaders.js +28 -0
- package/dist/exports/webgl-shaders.js.map +1 -0
- package/dist/src/core/CoreNode.d.ts +8 -0
- package/dist/src/core/CoreNode.js +11 -0
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/Stage.d.ts +16 -0
- package/dist/src/core/Stage.js +39 -1
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/lib/utils.d.ts +1 -0
- package/dist/src/core/lib/utils.js +3 -0
- package/dist/src/core/lib/utils.js.map +1 -1
- package/dist/src/core/platforms/Platform.d.ts +37 -0
- package/dist/src/core/platforms/Platform.js +22 -0
- package/dist/src/core/platforms/Platform.js.map +1 -0
- package/dist/src/core/platforms/web/WebPlatform.d.ts +9 -0
- package/dist/src/core/platforms/web/WebPlatform.js +58 -0
- package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
- package/dist/src/core/renderers/CoreShaderNode.d.ts +59 -0
- package/dist/src/core/renderers/CoreShaderNode.js +113 -0
- package/dist/src/core/renderers/CoreShaderNode.js.map +1 -0
- package/dist/src/core/renderers/CoreShaderProgram.d.ts +4 -0
- package/dist/src/core/renderers/CoreShaderProgram.js +20 -0
- package/dist/src/core/renderers/CoreShaderProgram.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +37 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.js +215 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +21 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.js +57 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +16 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.js +124 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +12 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +55 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +9 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +38 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +57 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +224 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +44 -0
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js +125 -0
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +136 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.js +573 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +222 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.js +331 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +35 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +201 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -0
- package/dist/src/core/shaders/canvas/Border.d.ts +9 -0
- package/dist/src/core/shaders/canvas/Border.js +57 -0
- package/dist/src/core/shaders/canvas/Border.js.map +1 -0
- package/dist/src/core/shaders/canvas/HolePunch.d.ts +7 -0
- package/dist/src/core/shaders/canvas/HolePunch.js +38 -0
- package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -0
- package/dist/src/core/shaders/canvas/LinearGradient.d.ts +10 -0
- package/dist/src/core/shaders/canvas/LinearGradient.js +48 -0
- package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -0
- package/dist/src/core/shaders/canvas/RadialGradient.d.ts +11 -0
- package/dist/src/core/shaders/canvas/RadialGradient.js +70 -0
- package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -0
- package/dist/src/core/shaders/canvas/Rounded.d.ts +7 -0
- package/dist/src/core/shaders/canvas/Rounded.js +33 -0
- package/dist/src/core/shaders/canvas/Rounded.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +7 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js +43 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +8 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +41 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.d.ts +7 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js +40 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/Shadow.d.ts +8 -0
- package/dist/src/core/shaders/canvas/Shadow.js +31 -0
- package/dist/src/core/shaders/canvas/Shadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/utils/render.d.ts +5 -0
- package/dist/src/core/shaders/canvas/utils/render.js +84 -0
- package/dist/src/core/shaders/canvas/utils/render.js.map +1 -0
- package/dist/src/core/shaders/templates/BorderTemplate.d.ts +37 -0
- package/dist/src/core/shaders/templates/BorderTemplate.js +73 -0
- package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +46 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.js +35 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.d.ts +23 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.js +47 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +31 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.js +49 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.d.ts +29 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.js +67 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +7 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js +24 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +6 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js +23 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +6 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js +23 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +34 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.js +66 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/shaderUtils.d.ts +5 -0
- package/dist/src/core/shaders/templates/shaderUtils.js +41 -0
- package/dist/src/core/shaders/templates/shaderUtils.js.map +1 -0
- package/dist/src/core/shaders/utils.d.ts +5 -0
- package/dist/src/core/shaders/utils.js +41 -0
- package/dist/src/core/shaders/utils.js.map +1 -0
- package/dist/src/core/shaders/webgl/Border.d.ts +3 -0
- package/dist/src/core/shaders/webgl/Border.js +110 -0
- package/dist/src/core/shaders/webgl/Border.js.map +1 -0
- package/dist/src/core/shaders/webgl/Default.d.ts +2 -0
- package/dist/src/core/shaders/webgl/Default.js +86 -0
- package/dist/src/core/shaders/webgl/Default.js.map +1 -0
- package/dist/src/core/shaders/webgl/DefaultBatched.d.ts +2 -0
- package/dist/src/core/shaders/webgl/DefaultBatched.js +104 -0
- package/dist/src/core/shaders/webgl/DefaultBatched.js.map +1 -0
- package/dist/src/core/shaders/webgl/HolePunch.d.ts +3 -0
- package/dist/src/core/shaders/webgl/HolePunch.js +65 -0
- package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -0
- package/dist/src/core/shaders/webgl/LinearGradient.d.ts +3 -0
- package/dist/src/core/shaders/webgl/LinearGradient.js +76 -0
- package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -0
- package/dist/src/core/shaders/webgl/RadialGradient.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RadialGradient.js +74 -0
- package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -0
- package/dist/src/core/shaders/webgl/Rounded.d.ts +7 -0
- package/dist/src/core/shaders/webgl/Rounded.js +86 -0
- package/dist/src/core/shaders/webgl/Rounded.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js +140 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +162 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js +84 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -0
- package/dist/src/core/shaders/webgl/SdfShader.d.ts +32 -0
- package/dist/src/core/shaders/webgl/SdfShader.js +116 -0
- package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -0
- package/dist/src/core/shaders/webgl/Shadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/Shadow.js +110 -0
- package/dist/src/core/shaders/webgl/Shadow.js.map +1 -0
- package/dist/src/core/shaders/webgl/Spinner.js +2 -0
- package/dist/src/core/shaders/webgl/Spinner.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.d.ts +25 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.js +117 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.d.ts +6 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.js +139 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/SdfFontHandler.d.ts +137 -0
- package/dist/src/core/text-rendering/SdfFontHandler.js +336 -0
- package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.d.ts +21 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.js +324 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/TextRenderer.d.ts +425 -0
- package/dist/src/core/text-rendering/TextRenderer.js +70 -0
- package/dist/src/core/text-rendering/TextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/Utils.d.ts +71 -0
- package/dist/src/core/text-rendering/Utils.js +212 -0
- package/dist/src/core/text-rendering/Utils.js.map +1 -0
- package/dist/src/core/text-rendering/canvas/Settings.d.ts +53 -0
- package/dist/src/core/text-rendering/canvas/Settings.js +20 -0
- package/dist/src/core/text-rendering/canvas/Settings.js.map +1 -0
- package/dist/src/core/text-rendering/canvas/Utils.d.ts +19 -0
- package/dist/src/core/text-rendering/canvas/Utils.js +139 -0
- package/dist/src/core/text-rendering/canvas/Utils.js.map +1 -0
- package/dist/src/core/text-rendering/canvas/calculateRenderInfo.d.ts +37 -0
- package/dist/src/core/text-rendering/canvas/calculateRenderInfo.js +188 -0
- package/dist/src/core/text-rendering/canvas/calculateRenderInfo.js.map +1 -0
- package/dist/src/core/text-rendering/canvas/draw.d.ts +12 -0
- package/dist/src/core/text-rendering/canvas/draw.js +133 -0
- package/dist/src/core/text-rendering/canvas/draw.js.map +1 -0
- package/dist/src/core/text-rendering/sdf/PeekableGenerator.d.ts +12 -0
- package/dist/src/core/text-rendering/sdf/PeekableGenerator.js +61 -0
- package/dist/src/core/text-rendering/sdf/PeekableGenerator.js.map +1 -0
- package/dist/src/core/text-rendering/sdf/SimpleFontShaper.d.ts +45 -0
- package/dist/src/core/text-rendering/sdf/SimpleFontShaper.js +69 -0
- package/dist/src/core/text-rendering/sdf/SimpleFontShaper.js.map +1 -0
- package/dist/src/core/utils.d.ts +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/core/CoreNode.ts +19 -0
- package/src/core/Stage.ts +50 -1
- package/src/core/lib/utils.ts +4 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js +0 -2
- package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js.map +0 -1
- /package/dist/src/core/{renderers/webgl/WebGlCoreShader.destroy.d.ts → shaders/webgl/Spinner.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasFontHandler.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/CanvasFontHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,aAAa,GAKd,MAAM,mBAAmB,CAAC;AAG3B;;GAEG;AACH,wEAAwE;AACxE,iFAAiF;AAEjF,yCAAyC;AACzC,MAAM,YAAY,GAA6B,EA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AM,CAAC,MAAM,cAAc,GAAG,CAC5B,UAAkB,EACY,EAAE;IAChC,OAAO,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC;AACnD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,UAAkB,EAClB,OAA8B,EACxB,EAAE;IACR,iBAAiB,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
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 2023 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 { assertTruthy } from '../../utils.js';
|
|
20
|
+
import { TextAlign, TextBaseline, TextContain, TextRenderers, TextVerticalAlign, TextWordBreak } from './TextRenderer.js';
|
|
21
|
+
import * as CanvasFontHandler from './CanvasFontHandler.js';
|
|
22
|
+
import { calculateRenderInfo } from './canvas/calculateRenderInfo.js';
|
|
23
|
+
import { draw } from './canvas/draw.js';
|
|
24
|
+
const type = TextRenderers.canvas;
|
|
25
|
+
const font = CanvasFontHandler;
|
|
26
|
+
let canvas = null;
|
|
27
|
+
let context = null;
|
|
28
|
+
// Initialize the Text Renderer
|
|
29
|
+
const init = (stage) => {
|
|
30
|
+
canvas = stage.platform.createCanvas();
|
|
31
|
+
context = canvas.getContext('2d');
|
|
32
|
+
font.init();
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Canvas text renderer
|
|
36
|
+
*
|
|
37
|
+
* @param stage - Stage instance for font resolution
|
|
38
|
+
* @param props - Text rendering properties
|
|
39
|
+
* @returns Object containing ImageData and dimensions
|
|
40
|
+
*/
|
|
41
|
+
const renderText = (stage, props) => {
|
|
42
|
+
assertTruthy(canvas, 'Canvas is not initialized');
|
|
43
|
+
assertTruthy(context, 'Canvas context is not available');
|
|
44
|
+
const settings = Object.create(null);
|
|
45
|
+
// Props to settings mapping
|
|
46
|
+
settings.text = props.text;
|
|
47
|
+
settings.fontFamily = props.fontFamily;
|
|
48
|
+
settings.fontSize = props.fontSize;
|
|
49
|
+
settings.fontStyle = props.fontStyle;
|
|
50
|
+
settings.textAlign = props.textAlign || TextAlign.left;
|
|
51
|
+
settings.letterSpacing =
|
|
52
|
+
typeof props.letterSpacing === 'number' ? props.letterSpacing : 0;
|
|
53
|
+
settings.lineHeight =
|
|
54
|
+
typeof props.lineHeight === 'number' ? props.lineHeight : null;
|
|
55
|
+
settings.maxLines = typeof props.maxLines === 'number' ? props.maxLines : 0;
|
|
56
|
+
settings.textBaseline = props.textBaseline || TextBaseline.alphabetic;
|
|
57
|
+
settings.verticalAlign = props.verticalAlign || TextVerticalAlign.top;
|
|
58
|
+
settings.overflowSuffix = props.overflowSuffix || '';
|
|
59
|
+
settings.wordBreak = props.wordBreak || TextWordBreak.normal;
|
|
60
|
+
settings.offsetY = props.offsetY || 0;
|
|
61
|
+
// Computed properties
|
|
62
|
+
settings.wordWrap = props.contain !== TextContain.none;
|
|
63
|
+
settings.wordWrapWidth = props.contain === TextContain.none ? 0 : props.width || 0;
|
|
64
|
+
settings.w = props.contain !== TextContain.none ? props.width || 0 : 0;
|
|
65
|
+
settings.h = props.height || 0;
|
|
66
|
+
settings.maxHeight =
|
|
67
|
+
props.contain === TextContain.both
|
|
68
|
+
? (props.height || 0) - (props.offsetY || 0)
|
|
69
|
+
: null;
|
|
70
|
+
settings.textOverflow = props.overflowSuffix ? 'ellipsis' : null;
|
|
71
|
+
// Set defaults
|
|
72
|
+
settings.precision = 1;
|
|
73
|
+
settings.fontBaselineRatio = 1.0;
|
|
74
|
+
settings.textColor = [1, 1, 1, 1];
|
|
75
|
+
settings.paddingLeft = 0;
|
|
76
|
+
settings.paddingRight = 0;
|
|
77
|
+
settings.shadow = false;
|
|
78
|
+
settings.shadowColor = [0, 0, 0, 1];
|
|
79
|
+
settings.shadowOffsetX = 0;
|
|
80
|
+
settings.shadowOffsetY = 0;
|
|
81
|
+
settings.shadowBlur = 0;
|
|
82
|
+
settings.highlight = false;
|
|
83
|
+
settings.highlightHeight = 0;
|
|
84
|
+
settings.highlightColor = [1, 1, 0, 0.5];
|
|
85
|
+
settings.highlightOffset = 0;
|
|
86
|
+
settings.highlightPaddingLeft = 0;
|
|
87
|
+
settings.highlightPaddingRight = 0;
|
|
88
|
+
settings.textIndent = 0;
|
|
89
|
+
settings.cutSx = 0;
|
|
90
|
+
settings.cutSy = 0;
|
|
91
|
+
settings.cutEx = 0;
|
|
92
|
+
settings.cutEy = 0;
|
|
93
|
+
settings.advancedRenderer = false;
|
|
94
|
+
settings.textRenderIssueMargin = 0;
|
|
95
|
+
const renderInfo = calculateRenderInfo({ context, settings });
|
|
96
|
+
draw({
|
|
97
|
+
canvas,
|
|
98
|
+
context,
|
|
99
|
+
renderInfo,
|
|
100
|
+
settings,
|
|
101
|
+
});
|
|
102
|
+
let imageData = null;
|
|
103
|
+
if (canvas.width > 0 && canvas.height > 0) {
|
|
104
|
+
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
imageData,
|
|
108
|
+
width: renderInfo.width,
|
|
109
|
+
height: renderInfo.lineHeight * renderInfo.lines.length,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Add quads for rendering (Canvas doesn't use quads)
|
|
114
|
+
*/
|
|
115
|
+
const addQuads = () => {
|
|
116
|
+
// Canvas renderer doesn't use quad-based rendering
|
|
117
|
+
// Return null for interface compatibility
|
|
118
|
+
return null;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Render quads for Canvas renderer (Canvas doesn't use quad-based rendering)
|
|
122
|
+
*/
|
|
123
|
+
const renderQuads = () => {
|
|
124
|
+
// Canvas renderer doesn't use quad-based rendering
|
|
125
|
+
// This method is for interface compatibility only
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Canvas Text Renderer - implements TextRenderer interface
|
|
129
|
+
*/
|
|
130
|
+
const CanvasTextRenderer = {
|
|
131
|
+
type,
|
|
132
|
+
font,
|
|
133
|
+
renderText,
|
|
134
|
+
addQuads,
|
|
135
|
+
renderQuads,
|
|
136
|
+
init,
|
|
137
|
+
};
|
|
138
|
+
export default CanvasTextRenderer;
|
|
139
|
+
//# sourceMappingURL=CanvasTextRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasTextRenderer.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/CanvasTextRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAsG,MAAM,mBAAmB,CAAC;AAE9N,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC;AAClC,MAAM,IAAI,GA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AAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE9D,IAAI,CAAC;QACH,MAAM;QACN,OAAO;QACP,UAAU;QACV,QAAQ;KACT,CAAC,CAAC;IAEH,IAAI,SAAS,GAAqB,IAAI,CAAC;IACvC,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtE,CAAC;IAED,OAAO;QACL,SAAS;QACT,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,MAAM,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM;KACxD,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,QAAQ,GAAG,GAAwB,EAAE;IACzC,mDAAmD;IACnD,0CAA0C;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,GAAS,EAAE;IAC7B,mDAAmD;IACnD,kDAAkD;AACpD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAkB;IACxC,IAAI;IACJ,IAAI;IACJ,UAAU;IACV,QAAQ;IACR,WAAW;IACX,IAAI;CACL,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { type FontFamilyMap, type FontMetrics, type NormalizedFontMetrics, type TrProps, type FontLoadOptions, TextRenderers } from './TextRenderer.js';
|
|
2
|
+
import type { ImageTexture } from '../textures/ImageTexture.js';
|
|
3
|
+
import type { Stage } from '../Stage.js';
|
|
4
|
+
/**
|
|
5
|
+
* SDF Font Data structure matching msdf-bmfont-xml output
|
|
6
|
+
*/
|
|
7
|
+
export interface SdfFontData {
|
|
8
|
+
pages: string[];
|
|
9
|
+
chars: Array<{
|
|
10
|
+
id: number;
|
|
11
|
+
char: string;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
xoffset: number;
|
|
17
|
+
yoffset: number;
|
|
18
|
+
xadvance: number;
|
|
19
|
+
page: number;
|
|
20
|
+
chnl: number;
|
|
21
|
+
}>;
|
|
22
|
+
kernings: Array<{
|
|
23
|
+
first: number;
|
|
24
|
+
second: number;
|
|
25
|
+
amount: number;
|
|
26
|
+
}>;
|
|
27
|
+
info: {
|
|
28
|
+
face: string;
|
|
29
|
+
size: number;
|
|
30
|
+
bold: number;
|
|
31
|
+
italic: number;
|
|
32
|
+
charset: string[];
|
|
33
|
+
unicode: number;
|
|
34
|
+
stretchH: number;
|
|
35
|
+
smooth: number;
|
|
36
|
+
aa: number;
|
|
37
|
+
padding: [number, number, number, number];
|
|
38
|
+
spacing: [number, number];
|
|
39
|
+
outline: number;
|
|
40
|
+
};
|
|
41
|
+
common: {
|
|
42
|
+
lineHeight: number;
|
|
43
|
+
base: number;
|
|
44
|
+
scaleW: number;
|
|
45
|
+
scaleH: number;
|
|
46
|
+
pages: number;
|
|
47
|
+
packed: number;
|
|
48
|
+
alphaChnl: number;
|
|
49
|
+
redChnl: number;
|
|
50
|
+
greenChnl: number;
|
|
51
|
+
blueChnl: number;
|
|
52
|
+
};
|
|
53
|
+
distanceField: {
|
|
54
|
+
fieldType: 'sdf' | 'msdf';
|
|
55
|
+
distanceRange: number;
|
|
56
|
+
};
|
|
57
|
+
lightningMetrics?: FontMetrics;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if the SDF font handler can render a font
|
|
61
|
+
* @param {TrProps} trProps - Text rendering properties
|
|
62
|
+
* @returns {boolean} True if the font can be rendered
|
|
63
|
+
*/
|
|
64
|
+
export declare const canRenderFont: (trProps: TrProps) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Load SDF font from JSON + PNG atlas
|
|
67
|
+
* @param {Object} options - Font loading options
|
|
68
|
+
* @param {string} options.fontFamily - Font family name
|
|
69
|
+
* @param {string} options.fontUrl - JSON font data URL (atlasDataUrl)
|
|
70
|
+
* @param {string} options.atlasUrl - PNG atlas texture URL
|
|
71
|
+
* @param {FontMetrics} options.metrics - Optional font metrics
|
|
72
|
+
*/
|
|
73
|
+
export declare const loadFont: (stage: Stage, options: FontLoadOptions) => Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the font families map for resolving fonts
|
|
76
|
+
*/
|
|
77
|
+
export declare const getFontFamilies: () => FontFamilyMap;
|
|
78
|
+
/**
|
|
79
|
+
* Initialize the SDF font handler
|
|
80
|
+
*/
|
|
81
|
+
export declare const init: () => void;
|
|
82
|
+
export declare const type = TextRenderers.sdf;
|
|
83
|
+
/**
|
|
84
|
+
* Check if a font is already loaded by font family
|
|
85
|
+
*/
|
|
86
|
+
export declare const isFontLoaded: (fontFamily: string) => boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Get normalized font metrics for a font family
|
|
89
|
+
*/
|
|
90
|
+
export declare const getFontMetrics: (fontFamily: string, _trProps: TrProps) => NormalizedFontMetrics | null;
|
|
91
|
+
/**
|
|
92
|
+
* Set font metrics for a font family
|
|
93
|
+
*/
|
|
94
|
+
export declare const setFontMetrics: (fontFamily: string, metrics: NormalizedFontMetrics) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Get glyph data for a character in a specific font
|
|
97
|
+
* @param {string} fontFamily - Font family name
|
|
98
|
+
* @param {number} codepoint - Character codepoint
|
|
99
|
+
* @returns {Object|null} Glyph data or null if not found
|
|
100
|
+
*/
|
|
101
|
+
export declare const getGlyph: (fontFamily: string, codepoint: number) => SdfFontData["chars"][0] | null;
|
|
102
|
+
/**
|
|
103
|
+
* Get kerning value between two glyphs
|
|
104
|
+
* @param {string} fontFamily - Font family name
|
|
105
|
+
* @param {number} firstGlyph - First glyph ID
|
|
106
|
+
* @param {number} secondGlyph - Second glyph ID
|
|
107
|
+
* @returns {number} Kerning value or 0
|
|
108
|
+
*/
|
|
109
|
+
export declare const getKerning: (fontFamily: string, firstGlyph: number, secondGlyph: number) => number;
|
|
110
|
+
/**
|
|
111
|
+
* Get atlas texture for a font family
|
|
112
|
+
* @param {string} fontFamily - Font family name
|
|
113
|
+
* @returns {ImageTexture|null} Atlas texture or null
|
|
114
|
+
*/
|
|
115
|
+
export declare const getAtlas: (fontFamily: string) => ImageTexture | null;
|
|
116
|
+
/**
|
|
117
|
+
* Get font data for a font family
|
|
118
|
+
* @param {string} fontFamily - Font family name
|
|
119
|
+
* @returns {SdfFontData|null} Font data or null
|
|
120
|
+
*/
|
|
121
|
+
export declare const getFontData: (fontFamily: string) => SdfFontData | null;
|
|
122
|
+
/**
|
|
123
|
+
* Get maximum character height for a font family
|
|
124
|
+
* @param {string} fontFamily - Font family name
|
|
125
|
+
* @returns {number} Max character height or 0
|
|
126
|
+
*/
|
|
127
|
+
export declare const getMaxCharHeight: (fontFamily: string) => number;
|
|
128
|
+
/**
|
|
129
|
+
* Get all loaded font families
|
|
130
|
+
* @returns {string[]} Array of font family names
|
|
131
|
+
*/
|
|
132
|
+
export declare const getLoadedFonts: () => string[];
|
|
133
|
+
/**
|
|
134
|
+
* Unload a font and free resources
|
|
135
|
+
* @param {string} fontFamily - Font family name
|
|
136
|
+
*/
|
|
137
|
+
export declare const unloadFont: (fontFamily: string) => void;
|
|
@@ -0,0 +1,336 @@
|
|
|
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 { TextRenderers, } from './TextRenderer.js';
|
|
20
|
+
//global state variables for SdfFontHandler
|
|
21
|
+
const fontCache = Object.create(null);
|
|
22
|
+
const loadedFonts = new Set();
|
|
23
|
+
const fontLoadPromises = new Map();
|
|
24
|
+
let initialized = false;
|
|
25
|
+
/**
|
|
26
|
+
* Normalize font metrics to be in the range of 0 to 1
|
|
27
|
+
*/
|
|
28
|
+
const normalizeMetrics = (metrics) => ({
|
|
29
|
+
ascender: metrics.ascender / metrics.unitsPerEm,
|
|
30
|
+
descender: metrics.descender / metrics.unitsPerEm,
|
|
31
|
+
lineGap: metrics.lineGap / metrics.unitsPerEm,
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Build kerning lookup table for fast access
|
|
35
|
+
* @param {Array} kernings - Kerning data from font
|
|
36
|
+
* @returns {KerningTable} Optimized kerning lookup table
|
|
37
|
+
*/
|
|
38
|
+
const buildKerningTable = (kernings) => {
|
|
39
|
+
const kerningTable = {};
|
|
40
|
+
let i = 0;
|
|
41
|
+
const length = kernings.length;
|
|
42
|
+
while (i < length) {
|
|
43
|
+
const kerning = kernings[i];
|
|
44
|
+
i++;
|
|
45
|
+
if (kerning === undefined) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const second = kerning.second;
|
|
49
|
+
let firsts = kerningTable[second];
|
|
50
|
+
if (!firsts) {
|
|
51
|
+
firsts = {};
|
|
52
|
+
kerningTable[second] = firsts;
|
|
53
|
+
}
|
|
54
|
+
firsts[kerning.first] = kerning.amount;
|
|
55
|
+
}
|
|
56
|
+
return kerningTable;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Build glyph map from font data for fast character lookup
|
|
60
|
+
* @param {Array} chars - Character data from font
|
|
61
|
+
* @returns {Map} Glyph map for character to glyph lookup
|
|
62
|
+
*/
|
|
63
|
+
const buildGlyphMap = (chars) => {
|
|
64
|
+
const glyphMap = new Map();
|
|
65
|
+
let maxCharHeight = 0;
|
|
66
|
+
let i = 0;
|
|
67
|
+
const length = chars.length;
|
|
68
|
+
while (i < length) {
|
|
69
|
+
const glyph = chars[i];
|
|
70
|
+
i++;
|
|
71
|
+
if (glyph === undefined) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
glyphMap.set(glyph.id, glyph);
|
|
75
|
+
const charHeight = glyph.yoffset + glyph.height;
|
|
76
|
+
if (charHeight > maxCharHeight) {
|
|
77
|
+
maxCharHeight = charHeight;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return glyphMap;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Process font data and create optimized cache entry
|
|
84
|
+
* @param {string} fontFamily - Font family name
|
|
85
|
+
* @param {SdfFontData} fontData - Raw font data
|
|
86
|
+
* @param {ImageTexture} atlasTexture - Atlas texture
|
|
87
|
+
* @param {FontMetrics} metrics - Font metrics
|
|
88
|
+
*/
|
|
89
|
+
const processFontData = (fontFamily, fontData, atlasTexture, metrics) => {
|
|
90
|
+
// Build optimized data structures
|
|
91
|
+
const glyphMap = buildGlyphMap(fontData.chars);
|
|
92
|
+
const kernings = buildKerningTable(fontData.kernings);
|
|
93
|
+
// Calculate max char height
|
|
94
|
+
let maxCharHeight = 0;
|
|
95
|
+
let i = 0;
|
|
96
|
+
const length = fontData.chars.length;
|
|
97
|
+
while (i < length) {
|
|
98
|
+
const glyph = fontData.chars[i];
|
|
99
|
+
if (glyph !== undefined) {
|
|
100
|
+
const charHeight = glyph.yoffset + glyph.height;
|
|
101
|
+
if (charHeight > maxCharHeight) {
|
|
102
|
+
maxCharHeight = charHeight;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
i++;
|
|
106
|
+
}
|
|
107
|
+
// Determine metrics
|
|
108
|
+
let normalizedMetrics;
|
|
109
|
+
if (metrics !== undefined) {
|
|
110
|
+
normalizedMetrics = normalizeMetrics(metrics);
|
|
111
|
+
}
|
|
112
|
+
else if (fontData.lightningMetrics !== undefined) {
|
|
113
|
+
normalizedMetrics = normalizeMetrics(fontData.lightningMetrics);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.warn(`Font metrics not found for SDF font ${fontFamily}. ` +
|
|
117
|
+
'Make sure you are using the latest version of the Lightning ' +
|
|
118
|
+
'3 msdf-generator tool to generate your SDF fonts. Using default metrics.');
|
|
119
|
+
// Use default metrics
|
|
120
|
+
normalizedMetrics = {
|
|
121
|
+
ascender: 0.8,
|
|
122
|
+
descender: -0.2,
|
|
123
|
+
lineGap: 0.2,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Cache processed data
|
|
127
|
+
fontCache[fontFamily] = {
|
|
128
|
+
data: fontData,
|
|
129
|
+
glyphMap,
|
|
130
|
+
kernings,
|
|
131
|
+
atlasTexture,
|
|
132
|
+
metrics: normalizedMetrics,
|
|
133
|
+
maxCharHeight,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Check if the SDF font handler can render a font
|
|
138
|
+
* @param {TrProps} trProps - Text rendering properties
|
|
139
|
+
* @returns {boolean} True if the font can be rendered
|
|
140
|
+
*/
|
|
141
|
+
export const canRenderFont = (trProps) => {
|
|
142
|
+
return isFontLoaded(trProps.fontFamily);
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Load SDF font from JSON + PNG atlas
|
|
146
|
+
* @param {Object} options - Font loading options
|
|
147
|
+
* @param {string} options.fontFamily - Font family name
|
|
148
|
+
* @param {string} options.fontUrl - JSON font data URL (atlasDataUrl)
|
|
149
|
+
* @param {string} options.atlasUrl - PNG atlas texture URL
|
|
150
|
+
* @param {FontMetrics} options.metrics - Optional font metrics
|
|
151
|
+
*/
|
|
152
|
+
export const loadFont = async (stage, options) => {
|
|
153
|
+
const { fontFamily, atlasUrl, atlasDataUrl, metrics } = options;
|
|
154
|
+
// Early return if already loaded
|
|
155
|
+
if (loadedFonts.has(fontFamily) === true) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// Early return if already loading
|
|
159
|
+
const existingPromise = fontLoadPromises.get(fontFamily);
|
|
160
|
+
if (existingPromise !== undefined) {
|
|
161
|
+
return existingPromise;
|
|
162
|
+
}
|
|
163
|
+
if (atlasDataUrl === undefined) {
|
|
164
|
+
throw new Error(`Atlas data URL must be provided for SDF font: ${fontFamily}`);
|
|
165
|
+
}
|
|
166
|
+
// Create loading promise
|
|
167
|
+
const loadPromise = (async () => {
|
|
168
|
+
// Load font JSON data
|
|
169
|
+
const response = await fetch(atlasDataUrl);
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
throw new Error(`Failed to load font data: ${response.statusText}`);
|
|
172
|
+
}
|
|
173
|
+
const fontData = (await response.json());
|
|
174
|
+
if (!fontData || !fontData.chars) {
|
|
175
|
+
throw new Error('Invalid SDF font data format');
|
|
176
|
+
}
|
|
177
|
+
// Atlas texture should be provided externally
|
|
178
|
+
if (!atlasUrl) {
|
|
179
|
+
throw new Error('Atlas texture must be provided for SDF fonts');
|
|
180
|
+
}
|
|
181
|
+
// Wait for atlas texture to load
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
// create new atlas texture using ImageTexture
|
|
184
|
+
const atlasTexture = stage.txManager.createTexture('ImageTexture', {
|
|
185
|
+
src: atlasUrl,
|
|
186
|
+
});
|
|
187
|
+
atlasTexture.preventCleanup = true; // Prevent automatic cleanup
|
|
188
|
+
if (atlasTexture.state === 'loaded') {
|
|
189
|
+
// If already loaded, process immediately
|
|
190
|
+
processFontData(fontFamily, fontData, atlasTexture, metrics);
|
|
191
|
+
loadedFonts.add(fontFamily);
|
|
192
|
+
fontLoadPromises.delete(fontFamily);
|
|
193
|
+
return resolve();
|
|
194
|
+
}
|
|
195
|
+
atlasTexture.on('loaded', () => {
|
|
196
|
+
// Process and cache font data
|
|
197
|
+
processFontData(fontFamily, fontData, atlasTexture, metrics);
|
|
198
|
+
// Mark as loaded
|
|
199
|
+
loadedFonts.add(fontFamily);
|
|
200
|
+
fontLoadPromises.delete(fontFamily);
|
|
201
|
+
resolve();
|
|
202
|
+
});
|
|
203
|
+
atlasTexture.on('failed', (error) => {
|
|
204
|
+
// Cleanup on error
|
|
205
|
+
fontLoadPromises.delete(fontFamily);
|
|
206
|
+
if (fontCache[fontFamily]) {
|
|
207
|
+
delete fontCache[fontFamily];
|
|
208
|
+
}
|
|
209
|
+
console.error(`Failed to load SDF font: ${fontFamily}`, error);
|
|
210
|
+
reject(error);
|
|
211
|
+
});
|
|
212
|
+
atlasTexture.setRenderableOwner(stage, true);
|
|
213
|
+
});
|
|
214
|
+
})();
|
|
215
|
+
fontLoadPromises.set(fontFamily, loadPromise);
|
|
216
|
+
return loadPromise;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Get the font families map for resolving fonts
|
|
220
|
+
*/
|
|
221
|
+
export const getFontFamilies = () => {
|
|
222
|
+
const families = {};
|
|
223
|
+
// SDF fonts don't use the traditional FontFamilyMap structure
|
|
224
|
+
// Return empty map since SDF fonts are handled differently
|
|
225
|
+
return families;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Initialize the SDF font handler
|
|
229
|
+
*/
|
|
230
|
+
export const init = () => {
|
|
231
|
+
if (initialized === true) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
initialized = true;
|
|
235
|
+
};
|
|
236
|
+
export const type = TextRenderers.sdf;
|
|
237
|
+
/**
|
|
238
|
+
* Check if a font is already loaded by font family
|
|
239
|
+
*/
|
|
240
|
+
export const isFontLoaded = (fontFamily) => {
|
|
241
|
+
return loadedFonts.has(fontFamily);
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Get normalized font metrics for a font family
|
|
245
|
+
*/
|
|
246
|
+
export const getFontMetrics = (fontFamily,
|
|
247
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
248
|
+
_trProps) => {
|
|
249
|
+
const cache = fontCache[fontFamily];
|
|
250
|
+
return cache ? cache.metrics : null;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Set font metrics for a font family
|
|
254
|
+
*/
|
|
255
|
+
export const setFontMetrics = (fontFamily, metrics) => {
|
|
256
|
+
const cache = fontCache[fontFamily];
|
|
257
|
+
if (cache !== undefined) {
|
|
258
|
+
cache.metrics = metrics;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Get glyph data for a character in a specific font
|
|
263
|
+
* @param {string} fontFamily - Font family name
|
|
264
|
+
* @param {number} codepoint - Character codepoint
|
|
265
|
+
* @returns {Object|null} Glyph data or null if not found
|
|
266
|
+
*/
|
|
267
|
+
export const getGlyph = (fontFamily, codepoint) => {
|
|
268
|
+
const cache = fontCache[fontFamily];
|
|
269
|
+
if (cache === undefined)
|
|
270
|
+
return null;
|
|
271
|
+
return cache.glyphMap.get(codepoint) || cache.glyphMap.get(63) || null; // 63 = '?'
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Get kerning value between two glyphs
|
|
275
|
+
* @param {string} fontFamily - Font family name
|
|
276
|
+
* @param {number} firstGlyph - First glyph ID
|
|
277
|
+
* @param {number} secondGlyph - Second glyph ID
|
|
278
|
+
* @returns {number} Kerning value or 0
|
|
279
|
+
*/
|
|
280
|
+
export const getKerning = (fontFamily, firstGlyph, secondGlyph) => {
|
|
281
|
+
const cache = fontCache[fontFamily];
|
|
282
|
+
if (cache === undefined)
|
|
283
|
+
return 0;
|
|
284
|
+
const seconds = cache.kernings[secondGlyph];
|
|
285
|
+
return seconds ? seconds[firstGlyph] || 0 : 0;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Get atlas texture for a font family
|
|
289
|
+
* @param {string} fontFamily - Font family name
|
|
290
|
+
* @returns {ImageTexture|null} Atlas texture or null
|
|
291
|
+
*/
|
|
292
|
+
export const getAtlas = (fontFamily) => {
|
|
293
|
+
const cache = fontCache[fontFamily];
|
|
294
|
+
return cache !== undefined ? cache.atlasTexture : null;
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* Get font data for a font family
|
|
298
|
+
* @param {string} fontFamily - Font family name
|
|
299
|
+
* @returns {SdfFontData|null} Font data or null
|
|
300
|
+
*/
|
|
301
|
+
export const getFontData = (fontFamily) => {
|
|
302
|
+
const cache = fontCache[fontFamily];
|
|
303
|
+
return cache !== undefined ? cache.data : null;
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Get maximum character height for a font family
|
|
307
|
+
* @param {string} fontFamily - Font family name
|
|
308
|
+
* @returns {number} Max character height or 0
|
|
309
|
+
*/
|
|
310
|
+
export const getMaxCharHeight = (fontFamily) => {
|
|
311
|
+
const cache = fontCache[fontFamily];
|
|
312
|
+
return cache !== undefined ? cache.maxCharHeight : 0;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Get all loaded font families
|
|
316
|
+
* @returns {string[]} Array of font family names
|
|
317
|
+
*/
|
|
318
|
+
export const getLoadedFonts = () => {
|
|
319
|
+
return Array.from(loadedFonts);
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Unload a font and free resources
|
|
323
|
+
* @param {string} fontFamily - Font family name
|
|
324
|
+
*/
|
|
325
|
+
export const unloadFont = (fontFamily) => {
|
|
326
|
+
const cache = fontCache[fontFamily];
|
|
327
|
+
if (cache !== undefined) {
|
|
328
|
+
// Free texture if needed
|
|
329
|
+
if (typeof cache.atlasTexture.free === 'function') {
|
|
330
|
+
cache.atlasTexture.free();
|
|
331
|
+
}
|
|
332
|
+
delete fontCache[fontFamily];
|
|
333
|
+
loadedFonts.delete(fontFamily);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
//# sourceMappingURL=SdfFontHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdfFontHandler.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/SdfFontHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAML,aAAa,GACd,MAAM,mBAAmB,CAAC;AAmG3B,2CAA2C;AAC3C,MAAM,SAAS,GAAiC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACpE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;AACtC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAyB,CAAC;AAC1D,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,OAAoB,EAAyB,EAAE,CAAC,CAAC;IACzE,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,UAAU;IAC/C,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,UAAU;IACjD,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,UAAU;CAC9C,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,QAAiC,EAAgB,EAAE;IAC5E,MAAM,YAAY,GAAiB,EAAE,CAAC;IAEtC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAE/B,OAAO,CAAC,GAAG,MAAM,EAAE,CAAC;QAClB,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC,EAAE,CAAC;QACJ,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAE9B,IAAI,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CA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AAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACpC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAU,EAAE;IAC7D,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACpC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAa,EAAE;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAQ,EAAE;IACrD,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,yBAAyB;QACzB,IAAI,OAAO,KAAK,CAAC,YAAY,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAClD,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QAC5B,CAAC;QAED,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC;QAC7B,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Stage } from '../Stage.js';
|
|
2
|
+
import { TextRenderers, type FontHandler, type TextRenderProps, type TrProps } from './TextRenderer.js';
|
|
3
|
+
import type { CoreRenderer } from '../renderers/CoreRenderer.js';
|
|
4
|
+
import type { TextLayout } from './TextRenderer.js';
|
|
5
|
+
/**
|
|
6
|
+
* SDF Text Renderer - implements TextRenderer interface
|
|
7
|
+
*/
|
|
8
|
+
declare const SdfTextRenderer: {
|
|
9
|
+
type: TextRenderers;
|
|
10
|
+
font: FontHandler;
|
|
11
|
+
renderText: (stage: Stage, props: TrProps) => {
|
|
12
|
+
imageData: ImageData | null;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
layout?: TextLayout;
|
|
16
|
+
};
|
|
17
|
+
addQuads: (layout?: TextLayout) => Float32Array | null;
|
|
18
|
+
renderQuads: (renderer: CoreRenderer, layout: TextLayout, vertexBuffer: Float32Array, renderProps: TextRenderProps) => void;
|
|
19
|
+
init: (stage: Stage) => void;
|
|
20
|
+
};
|
|
21
|
+
export default SdfTextRenderer;
|