@lightningjs/renderer 3.0.0-beta16 → 3.0.0-beta17
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/src/common/CommonTypes.d.ts +11 -0
- package/dist/src/core/CoreNode.js +8 -0
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreTextNode.d.ts +13 -0
- package/dist/src/core/CoreTextNode.js +68 -17
- package/dist/src/core/CoreTextNode.js.map +1 -1
- package/dist/src/core/Stage.js +2 -1
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/animations/Animation.d.ts +16 -0
- package/dist/src/core/animations/Animation.js +111 -0
- package/dist/src/core/animations/Animation.js.map +1 -0
- package/dist/src/core/animations/CoreTransition.d.ts +24 -0
- package/dist/src/core/animations/CoreTransition.js +63 -0
- package/dist/src/core/animations/CoreTransition.js.map +1 -0
- package/dist/src/core/animations/Playback.d.ts +62 -0
- package/dist/src/core/animations/Playback.js +155 -0
- package/dist/src/core/animations/Playback.js.map +1 -0
- package/dist/src/core/animations/Transition.d.ts +25 -0
- package/dist/src/core/animations/Transition.js +63 -0
- package/dist/src/core/animations/Transition.js.map +1 -0
- package/dist/src/core/animations/utils.d.ts +2 -0
- package/dist/src/core/animations/utils.js +137 -0
- package/dist/src/core/animations/utils.js.map +1 -0
- package/dist/src/core/lib/collectionUtils.d.ts +5 -0
- package/dist/src/core/lib/collectionUtils.js +100 -0
- package/dist/src/core/lib/collectionUtils.js.map +1 -0
- package/dist/src/core/platforms/Platform.d.ts +5 -0
- package/dist/src/core/platforms/Platform.js.map +1 -1
- package/dist/src/core/platforms/web/WebPlatform.d.ts +1 -0
- package/dist/src/core/platforms/web/WebPlatform.js +3 -0
- package/dist/src/core/platforms/web/WebPlatform.js.map +1 -1
- package/dist/src/core/text-rendering/CanvasFontHandler.js +1 -1
- package/dist/src/core/text-rendering/CanvasFontHandler.js.map +1 -1
- package/dist/src/core/text-rendering/CanvasTextRenderer.js +3 -3
- package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/SdfTextRenderer.js +3 -3
- package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/TextLayoutEngine.d.ts +12 -13
- package/dist/src/core/text-rendering/TextLayoutEngine.js +239 -181
- package/dist/src/core/text-rendering/TextLayoutEngine.js.map +1 -1
- package/dist/src/core/text-rendering/TextRenderer.d.ts +22 -7
- package/dist/src/core/utils.d.ts +1 -1
- package/dist/src/main-api/Renderer.js +3 -2
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/CommonTypes.ts +16 -0
- package/src/core/CoreNode.test.ts +50 -1
- package/src/core/CoreNode.ts +11 -0
- package/src/core/CoreTextNode.ts +78 -17
- package/src/core/Stage.ts +2 -1
- package/src/core/platforms/Platform.ts +6 -0
- package/src/core/platforms/web/WebPlatform.ts +11 -0
- package/src/core/text-rendering/CanvasFontHandler.ts +1 -7
- package/src/core/text-rendering/CanvasTextRenderer.ts +2 -4
- package/src/core/text-rendering/SdfTextRenderer.ts +2 -3
- package/src/core/text-rendering/TextLayoutEngine.ts +393 -223
- package/src/core/text-rendering/TextRenderer.ts +22 -7
- package/src/core/text-rendering/tests/{SdfTests.test.ts → TextLayoutEngine.test.ts} +103 -64
- package/src/main-api/Renderer.ts +3 -2
- package/dist/src/core/TextureError.d.ts +0 -11
- package/dist/src/core/TextureError.js +0 -37
- package/dist/src/core/TextureError.js.map +0 -1
- package/dist/src/core/platform.d.ts +0 -10
- package/dist/src/core/platform.js +0 -81
- package/dist/src/core/platform.js.map +0 -1
- package/dist/src/core/renderers/CoreShader.d.ts +0 -9
- package/dist/src/core/renderers/CoreShader.js +0 -28
- package/dist/src/core/renderers/CoreShader.js.map +0 -1
- package/dist/src/core/renderers/canvas/CanvasCoreRenderer.d.ts +0 -33
- package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js +0 -250
- package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js.map +0 -1
- package/dist/src/core/renderers/canvas/CanvasCoreTexture.d.ts +0 -17
- package/dist/src/core/renderers/canvas/CanvasCoreTexture.js +0 -125
- package/dist/src/core/renderers/canvas/CanvasCoreTexture.js.map +0 -1
- package/dist/src/core/renderers/canvas/internal/C2DShaderUtils.d.ts +0 -14
- package/dist/src/core/renderers/canvas/internal/C2DShaderUtils.js +0 -138
- package/dist/src/core/renderers/canvas/internal/C2DShaderUtils.js.map +0 -1
- package/dist/src/core/renderers/canvas/internal/ColorUtils.d.ts +0 -19
- package/dist/src/core/renderers/canvas/internal/ColorUtils.js +0 -58
- package/dist/src/core/renderers/canvas/internal/ColorUtils.js.map +0 -1
- package/dist/src/core/renderers/canvas/shaders/UnsupportedShader.d.ts +0 -10
- package/dist/src/core/renderers/canvas/shaders/UnsupportedShader.js +0 -43
- package/dist/src/core/renderers/canvas/shaders/UnsupportedShader.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.d.ts +0 -12
- package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.js +0 -58
- package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.d.ts +0 -9
- package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.js +0 -38
- package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.d.ts +0 -69
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js +0 -272
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.d.ts +0 -34
- package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.js +0 -114
- package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.d.ts +0 -133
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +0 -641
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreShader.d.ts +0 -78
- package/dist/src/core/renderers/webgl/WebGlCoreShader.js +0 -202
- package/dist/src/core/renderers/webgl/WebGlCoreShader.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.d.ts +0 -9
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +0 -84
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.d.ts +0 -10
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +0 -108
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.d.ts +0 -29
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +0 -408
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.d.ts +0 -28
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +0 -126
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/SdfShader.d.ts +0 -47
- package/dist/src/core/renderers/webgl/shaders/SdfShader.js +0 -148
- package/dist/src/core/renderers/webgl/shaders/SdfShader.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.d.ts +0 -31
- package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +0 -71
- package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.d.ts +0 -30
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +0 -58
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.d.ts +0 -31
- package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +0 -71
- package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.d.ts +0 -31
- package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +0 -71
- package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.d.ts +0 -31
- package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +0 -71
- package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/EffectUtils.d.ts +0 -9
- package/dist/src/core/renderers/webgl/shaders/effects/EffectUtils.js +0 -136
- package/dist/src/core/renderers/webgl/shaders/effects/EffectUtils.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.d.ts +0 -36
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +0 -85
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.d.ts +0 -45
- package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +0 -104
- package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.d.ts +0 -22
- package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +0 -45
- package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.d.ts +0 -58
- package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js +0 -80
- package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.d.ts +0 -35
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +0 -134
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.d.ts +0 -40
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +0 -143
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.d.ts +0 -61
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +0 -127
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.d.ts +0 -40
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +0 -71
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js.map +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.d.ts +0 -115
- package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.js +0 -61
- package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.js.map +0 -1
- package/dist/src/core/text-rendering/CanvasFont.d.ts +0 -14
- package/dist/src/core/text-rendering/CanvasFont.js +0 -111
- package/dist/src/core/text-rendering/CanvasFont.js.map +0 -1
- package/dist/src/core/text-rendering/CoreFont.d.ts +0 -33
- package/dist/src/core/text-rendering/CoreFont.js +0 -48
- package/dist/src/core/text-rendering/CoreFont.js.map +0 -1
- package/dist/src/core/text-rendering/FontManager.d.ts +0 -11
- package/dist/src/core/text-rendering/FontManager.js +0 -42
- package/dist/src/core/text-rendering/FontManager.js.map +0 -1
- package/dist/src/core/text-rendering/SdfFont.d.ts +0 -29
- package/dist/src/core/text-rendering/SdfFont.js +0 -142
- package/dist/src/core/text-rendering/SdfFont.js.map +0 -1
- package/dist/src/core/text-rendering/TextRenderingUtils.d.ts +0 -12
- package/dist/src/core/text-rendering/TextRenderingUtils.js +0 -14
- package/dist/src/core/text-rendering/TextRenderingUtils.js.map +0 -1
- package/dist/src/core/text-rendering/TextTextureRendererUtils.d.ts +0 -72
- package/dist/src/core/text-rendering/TextTextureRendererUtils.js +0 -217
- package/dist/src/core/text-rendering/TextTextureRendererUtils.js.map +0 -1
- package/dist/src/core/text-rendering/TrFontManager.d.ts +0 -26
- package/dist/src/core/text-rendering/TrFontManager.js +0 -131
- package/dist/src/core/text-rendering/TrFontManager.js.map +0 -1
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.d.ts +0 -39
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.js +0 -125
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.js.map +0 -1
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.d.ts +0 -103
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.js +0 -21
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.js.map +0 -1
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.d.ts +0 -62
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.js +0 -88
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.js.map +0 -1
- package/dist/src/core/text-rendering/font-face-types/TrFontFace.d.ts +0 -118
- package/dist/src/core/text-rendering/font-face-types/TrFontFace.js +0 -63
- package/dist/src/core/text-rendering/font-face-types/TrFontFace.js.map +0 -1
- package/dist/src/core/text-rendering/font-face-types/WebTrFontFace.d.ts +0 -14
- package/dist/src/core/text-rendering/font-face-types/WebTrFontFace.js +0 -66
- package/dist/src/core/text-rendering/font-face-types/WebTrFontFace.js.map +0 -1
- package/dist/src/core/text-rendering/font-face-types/utils.d.ts +0 -1
- package/dist/src/core/text-rendering/font-face-types/utils.js +0 -38
- package/dist/src/core/text-rendering/font-face-types/utils.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.d.ts +0 -59
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js +0 -397
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.d.ts +0 -120
- package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.js +0 -551
- package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.d.ts +0 -92
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +0 -607
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.d.ts +0 -12
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.js +0 -61
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.d.ts +0 -33
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.js +0 -52
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.d.ts +0 -13
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.js +0 -32
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.d.ts +0 -23
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.js +0 -84
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.d.ts +0 -4
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.js +0 -34
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.d.ts +0 -20
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.js +0 -308
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.d.ts +0 -10
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.js +0 -40
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.d.ts +0 -26
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.js +0 -70
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.d.ts +0 -16
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.js +0 -39
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/TextRenderer.d.ts +0 -373
- package/dist/src/core/text-rendering/renderers/TextRenderer.js +0 -178
- package/dist/src/core/text-rendering/renderers/TextRenderer.js.map +0 -1
- package/dist/src/main-api/DynamicShaderController.d.ts +0 -29
- package/dist/src/main-api/DynamicShaderController.js +0 -58
- package/dist/src/main-api/DynamicShaderController.js.map +0 -1
- package/dist/src/main-api/ShaderController.d.ts +0 -31
- package/dist/src/main-api/ShaderController.js +0 -37
- package/dist/src/main-api/ShaderController.js.map +0 -1
- package/src/core/text-rendering/tests/Canvas.test.ts +0 -378
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculate the default line height given normalized font metrics
|
|
3
|
-
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* This method may be used for both the WebTrFontFace and SdfTrFontFace font types.
|
|
6
|
-
*
|
|
7
|
-
* @param metrics
|
|
8
|
-
* @param fontSize
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
export function calcDefaultLineHeight(metrics, fontSize) {
|
|
12
|
-
return fontSize * (metrics.ascender - metrics.descender + metrics.lineGap);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=TextRenderingUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextRenderingUtils.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/TextRenderingUtils.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAA8B,EAC9B,QAAgB;IAEhB,OAAO,QAAQ,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { NormalizedFontMetrics } from './font-face-types/TrFontFace.js';
|
|
2
|
-
import type { WebTrFontFace } from './font-face-types/WebTrFontFace.js';
|
|
3
|
-
/**
|
|
4
|
-
* Returns CSS font setting string for use in canvas context.
|
|
5
|
-
*
|
|
6
|
-
* @param fontFace
|
|
7
|
-
* @param fontStyle
|
|
8
|
-
* @param fontSize
|
|
9
|
-
* @param precision
|
|
10
|
-
* @param defaultFontFace
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export declare function getFontSetting(fontFace: string | string[], fontStyle: string, fontSize: number, precision: number, defaultFontFace: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Returns true if the given character is a zero-width space.
|
|
16
|
-
*
|
|
17
|
-
* @param space
|
|
18
|
-
*/
|
|
19
|
-
export declare function isZeroWidthSpace(space: string): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Returns true if the given character is a zero-width space or a regular space.
|
|
22
|
-
*
|
|
23
|
-
* @param space
|
|
24
|
-
*/
|
|
25
|
-
export declare function isSpace(space: string): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Converts a string into an array of tokens and the words between them.
|
|
28
|
-
*
|
|
29
|
-
* @param tokenRegex
|
|
30
|
-
* @param text
|
|
31
|
-
*/
|
|
32
|
-
export declare function tokenizeString(tokenRegex: RegExp, text: string): string[];
|
|
33
|
-
/**
|
|
34
|
-
* Measure the width of a string accounting for letter spacing.
|
|
35
|
-
*
|
|
36
|
-
* @param context
|
|
37
|
-
* @param word
|
|
38
|
-
* @param space
|
|
39
|
-
*/
|
|
40
|
-
export declare function measureText(context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, word: string, space?: number): number;
|
|
41
|
-
/**
|
|
42
|
-
* Get the font metrics for a font face.
|
|
43
|
-
*
|
|
44
|
-
* @remarks
|
|
45
|
-
* This function will attempt to grab the explicitly defined metrics from the
|
|
46
|
-
* font face first. If the font face does not have metrics defined, it will
|
|
47
|
-
* attempt to calculate the metrics using the browser's measureText method.
|
|
48
|
-
*
|
|
49
|
-
* If the browser does not support the font metrics API, it will use some
|
|
50
|
-
* default values.
|
|
51
|
-
*
|
|
52
|
-
* @param context
|
|
53
|
-
* @param fontFace
|
|
54
|
-
* @param fontSize
|
|
55
|
-
* @returns
|
|
56
|
-
*/
|
|
57
|
-
export declare function getWebFontMetrics(context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, fontFace: WebTrFontFace, fontSize: number): NormalizedFontMetrics;
|
|
58
|
-
export interface WrapTextResult {
|
|
59
|
-
l: string[];
|
|
60
|
-
n: number[];
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Applies newlines to a string to have it optimally fit into the horizontal
|
|
64
|
-
* bounds set by the Text object's wordWrapWidth property.
|
|
65
|
-
*
|
|
66
|
-
* @param context
|
|
67
|
-
* @param text
|
|
68
|
-
* @param wordWrapWidth
|
|
69
|
-
* @param letterSpacing
|
|
70
|
-
* @param indent
|
|
71
|
-
*/
|
|
72
|
-
export declare function wrapText(context: CanvasRenderingContext2D, text: string, wordWrapWidth: number, letterSpacing: number, indent: number): WrapTextResult;
|
|
@@ -1,217 +0,0 @@
|
|
|
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
|
-
/**
|
|
20
|
-
* Returns CSS font setting string for use in canvas context.
|
|
21
|
-
*
|
|
22
|
-
* @param fontFace
|
|
23
|
-
* @param fontStyle
|
|
24
|
-
* @param fontSize
|
|
25
|
-
* @param precision
|
|
26
|
-
* @param defaultFontFace
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
export function getFontSetting(fontFace, fontStyle, fontSize, precision, defaultFontFace) {
|
|
30
|
-
let ff = fontFace;
|
|
31
|
-
if (!Array.isArray(ff)) {
|
|
32
|
-
ff = [ff];
|
|
33
|
-
}
|
|
34
|
-
const ffs = [];
|
|
35
|
-
for (let i = 0, n = ff.length; i < n; i++) {
|
|
36
|
-
let curFf = ff[i];
|
|
37
|
-
// Replace the default font face `null` with the actual default font face set
|
|
38
|
-
// on the stage.
|
|
39
|
-
if (curFf === null || curFf === undefined) {
|
|
40
|
-
curFf = defaultFontFace;
|
|
41
|
-
}
|
|
42
|
-
if (curFf === 'serif' || curFf === 'sans-serif') {
|
|
43
|
-
ffs.push(curFf);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
ffs.push(`"${curFf}"`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return `${fontStyle} ${fontSize * precision}px ${ffs.join(',')}`;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns true if the given character is a zero-width space.
|
|
53
|
-
*
|
|
54
|
-
* @param space
|
|
55
|
-
*/
|
|
56
|
-
export function isZeroWidthSpace(space) {
|
|
57
|
-
return space === '' || space === '\u200B';
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Returns true if the given character is a zero-width space or a regular space.
|
|
61
|
-
*
|
|
62
|
-
* @param space
|
|
63
|
-
*/
|
|
64
|
-
export function isSpace(space) {
|
|
65
|
-
return isZeroWidthSpace(space) || space === ' ';
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Converts a string into an array of tokens and the words between them.
|
|
69
|
-
*
|
|
70
|
-
* @param tokenRegex
|
|
71
|
-
* @param text
|
|
72
|
-
*/
|
|
73
|
-
export function tokenizeString(tokenRegex, text) {
|
|
74
|
-
const delimeters = text.match(tokenRegex) || [];
|
|
75
|
-
const words = text.split(tokenRegex) || [];
|
|
76
|
-
const final = [];
|
|
77
|
-
for (let i = 0; i < words.length; i++) {
|
|
78
|
-
final.push(words[i], delimeters[i]);
|
|
79
|
-
}
|
|
80
|
-
final.pop();
|
|
81
|
-
return final.filter((word) => word != '');
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Measure the width of a string accounting for letter spacing.
|
|
85
|
-
*
|
|
86
|
-
* @param context
|
|
87
|
-
* @param word
|
|
88
|
-
* @param space
|
|
89
|
-
*/
|
|
90
|
-
export function measureText(context, word, space = 0) {
|
|
91
|
-
if (!space) {
|
|
92
|
-
return context.measureText(word).width;
|
|
93
|
-
}
|
|
94
|
-
return word.split('').reduce((acc, char) => {
|
|
95
|
-
// Zero-width spaces should not include letter spacing.
|
|
96
|
-
// And since we know the width of a zero-width space is 0, we can skip
|
|
97
|
-
// measuring it.
|
|
98
|
-
if (isZeroWidthSpace(char)) {
|
|
99
|
-
return acc;
|
|
100
|
-
}
|
|
101
|
-
return acc + context.measureText(char).width + space;
|
|
102
|
-
}, 0);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Get the font metrics for a font face.
|
|
106
|
-
*
|
|
107
|
-
* @remarks
|
|
108
|
-
* This function will attempt to grab the explicitly defined metrics from the
|
|
109
|
-
* font face first. If the font face does not have metrics defined, it will
|
|
110
|
-
* attempt to calculate the metrics using the browser's measureText method.
|
|
111
|
-
*
|
|
112
|
-
* If the browser does not support the font metrics API, it will use some
|
|
113
|
-
* default values.
|
|
114
|
-
*
|
|
115
|
-
* @param context
|
|
116
|
-
* @param fontFace
|
|
117
|
-
* @param fontSize
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
export function getWebFontMetrics(context, fontFace, fontSize) {
|
|
121
|
-
if (fontFace.metrics) {
|
|
122
|
-
return fontFace.metrics;
|
|
123
|
-
}
|
|
124
|
-
// If the font face doesn't have metrics defined, we fallback to using the
|
|
125
|
-
// browser's measureText method to calculate take a best guess at the font
|
|
126
|
-
// actual font's metrics.
|
|
127
|
-
// - fontBoundingBox[Ascent|Descent] is the best estimate but only supported
|
|
128
|
-
// in Chrome 87+ (2020), Firefox 116+ (2023), and Safari 11.1+ (2018).
|
|
129
|
-
// - It is an estimate as it can vary between browsers.
|
|
130
|
-
// - actualBoundingBox[Ascent|Descent] is less accurate and supported in
|
|
131
|
-
// Chrome 77+ (2019), Firefox 74+ (2020), and Safari 11.1+ (2018).
|
|
132
|
-
// - If neither are supported, we'll use some default values which will
|
|
133
|
-
// get text on the screen but likely not be great.
|
|
134
|
-
// NOTE: It's been decided not to rely on fontBoundingBox[Ascent|Descent]
|
|
135
|
-
// as it's browser support is limited and it also tends to produce higher than
|
|
136
|
-
// expected values. It is instead HIGHLY RECOMMENDED that developers provide
|
|
137
|
-
// explicit metrics in the font face definition.
|
|
138
|
-
const browserMetrics = context.measureText('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
|
|
139
|
-
console.warn(`Font metrics not provided for Canvas Web font ${fontFace.fontFamily}. ` +
|
|
140
|
-
'Using fallback values. It is HIGHLY recommended you use the latest ' +
|
|
141
|
-
'version of the Lightning 3 `msdf-generator` tool to extract the default ' +
|
|
142
|
-
'metrics for the font and provide them in the Canvas Web font definition.');
|
|
143
|
-
let metrics;
|
|
144
|
-
if (browserMetrics.actualBoundingBoxDescent &&
|
|
145
|
-
browserMetrics.actualBoundingBoxAscent) {
|
|
146
|
-
metrics = {
|
|
147
|
-
ascender: browserMetrics.actualBoundingBoxAscent / fontSize,
|
|
148
|
-
descender: -browserMetrics.actualBoundingBoxDescent / fontSize,
|
|
149
|
-
lineGap: 0.2,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
// If the browser doesn't support the font metrics API, we'll use some
|
|
154
|
-
// default values.
|
|
155
|
-
metrics = {
|
|
156
|
-
ascender: 0.8,
|
|
157
|
-
descender: -0.2,
|
|
158
|
-
lineGap: 0.2,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
// Save the calculated metrics to the font face for future use.
|
|
162
|
-
fontFace.metrics = metrics;
|
|
163
|
-
return metrics;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Applies newlines to a string to have it optimally fit into the horizontal
|
|
167
|
-
* bounds set by the Text object's wordWrapWidth property.
|
|
168
|
-
*
|
|
169
|
-
* @param context
|
|
170
|
-
* @param text
|
|
171
|
-
* @param wordWrapWidth
|
|
172
|
-
* @param letterSpacing
|
|
173
|
-
* @param indent
|
|
174
|
-
*/
|
|
175
|
-
export function wrapText(context, text, wordWrapWidth, letterSpacing, indent) {
|
|
176
|
-
// Greedy wrapping algorithm that will wrap words as the line grows longer.
|
|
177
|
-
// than its horizontal bounds.
|
|
178
|
-
const spaceRegex = / |\u200B/g;
|
|
179
|
-
const lines = text.split(/\r?\n/g);
|
|
180
|
-
let allLines = [];
|
|
181
|
-
const realNewlines = [];
|
|
182
|
-
for (let i = 0; i < lines.length; i++) {
|
|
183
|
-
const resultLines = [];
|
|
184
|
-
let result = '';
|
|
185
|
-
let spaceLeft = wordWrapWidth - indent;
|
|
186
|
-
const words = lines[i].split(spaceRegex);
|
|
187
|
-
const spaces = lines[i].match(spaceRegex) || [];
|
|
188
|
-
for (let j = 0; j < words.length; j++) {
|
|
189
|
-
const space = spaces[j - 1] || '';
|
|
190
|
-
const word = words[j];
|
|
191
|
-
const wordWidth = measureText(context, word, letterSpacing);
|
|
192
|
-
const wordWidthWithSpace = wordWidth + measureText(context, space, letterSpacing);
|
|
193
|
-
if (j === 0 || wordWidthWithSpace > spaceLeft) {
|
|
194
|
-
// Skip printing the newline if it's the first word of the line that is.
|
|
195
|
-
// greater than the word wrap width.
|
|
196
|
-
if (j > 0) {
|
|
197
|
-
resultLines.push(result);
|
|
198
|
-
result = '';
|
|
199
|
-
}
|
|
200
|
-
result += word;
|
|
201
|
-
spaceLeft = wordWrapWidth - wordWidth - (j === 0 ? indent : 0);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
spaceLeft -= wordWidthWithSpace;
|
|
205
|
-
result += space + word;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
resultLines.push(result);
|
|
209
|
-
result = '';
|
|
210
|
-
allLines = allLines.concat(resultLines);
|
|
211
|
-
if (i < lines.length - 1) {
|
|
212
|
-
realNewlines.push(allLines.length);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return { l: allLines, n: realNewlines };
|
|
216
|
-
}
|
|
217
|
-
//# sourceMappingURL=TextTextureRendererUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextTextureRendererUtils.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/TextTextureRendererUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,QAA2B,EAC3B,SAAiB,EACjB,QAAgB,EAChB,SAAiB,EACjB,eAAuB;IAEvB,IAAI,EAAE,GAAG,QAAQ,CAAC;IAElB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACvB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;IAED,MAAM,GAAG,GAAG,EAAE,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAI,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAClB,6EAA6E;QAC7E,gBAAgB;QAChB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,KAAK,GAAG,eAAe,CAAC;QAC1B,CAAC;QACD,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;YAChD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,SAAS,IAAI,QAAQ,GAAG,SAAS,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACnE,CAAC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AAK,CAAC,IAAI,kBAAkB,GAAG,SAAS,EAAE,CAAC;gBAC9C,wEAAwE;gBACxE,oCAAoC;gBACpC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;oBACV,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBACzB,MAAM,GAAG,EAAE,CAAC;gBACd,CAAC;gBACD,MAAM,IAAI,IAAI,CAAC;gBACf,SAAS,GAAG,aAAa,GAAG,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACjE,CAAC;iBAAM,CAAC;gBACN,SAAS,IAAI,kBAAkB,CAAC;gBAChC,MAAM,IAAI,KAAK,GAAG,IAAI,CAAC;YACzB,CAAC;QACH,CAAC;QAED,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzB,MAAM,GAAG,EAAE,CAAC;QAEZ,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAExC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { TrFontFace } from './font-face-types/TrFontFace.js';
|
|
2
|
-
import type { TextRendererMap, TrFontProps } from './renderers/TextRenderer.js';
|
|
3
|
-
/**
|
|
4
|
-
* Structure mapping font family names to a set of font faces.
|
|
5
|
-
*/
|
|
6
|
-
export interface FontFamilyMap {
|
|
7
|
-
[familyName: string]: Set<TrFontFace>;
|
|
8
|
-
}
|
|
9
|
-
export declare class TrFontManager {
|
|
10
|
-
private textRenderers;
|
|
11
|
-
private fontCache;
|
|
12
|
-
constructor(textRenderers: Partial<TextRendererMap>);
|
|
13
|
-
addFontFace(font: TrFontFace): void;
|
|
14
|
-
/**
|
|
15
|
-
* Utility method to resolve a single font face from a list of prioritized family maps based on
|
|
16
|
-
* a set of font properties.
|
|
17
|
-
*
|
|
18
|
-
* @remarks
|
|
19
|
-
* These are to be used by a text renderer to resolve a font face if needed.
|
|
20
|
-
*
|
|
21
|
-
* @param familyMapsByPriority
|
|
22
|
-
* @param props
|
|
23
|
-
* @returns
|
|
24
|
-
*/
|
|
25
|
-
resolveFontFace(familyMapsByPriority: FontFamilyMap[], props: TrFontProps, rendererType: 'canvas' | 'sdf'): TrFontFace | undefined;
|
|
26
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
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
|
-
const weightConversions = {
|
|
20
|
-
normal: 400,
|
|
21
|
-
bold: 700,
|
|
22
|
-
bolder: 900,
|
|
23
|
-
lighter: 100,
|
|
24
|
-
};
|
|
25
|
-
const fontWeightToNumber = (weight) => {
|
|
26
|
-
if (typeof weight === 'number') {
|
|
27
|
-
return weight;
|
|
28
|
-
}
|
|
29
|
-
return weightConversions[weight] || 400;
|
|
30
|
-
};
|
|
31
|
-
function resolveFontToUse(familyMapsByPriority, family, weightIn, style, stretch) {
|
|
32
|
-
let weight = fontWeightToNumber(weightIn);
|
|
33
|
-
for (const fontFamiles of familyMapsByPriority) {
|
|
34
|
-
const fontFaces = fontFamiles[family];
|
|
35
|
-
if (!fontFaces) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (fontFaces.size === 1) {
|
|
39
|
-
// No Exact match found, find nearest weight match
|
|
40
|
-
console.warn(`TrFontManager: Only one font face found for family: '${family}' - will be used for all weights and styles`);
|
|
41
|
-
return fontFaces.values().next().value;
|
|
42
|
-
}
|
|
43
|
-
const weightMap = new Map();
|
|
44
|
-
for (const fontFace of fontFaces) {
|
|
45
|
-
const fontFamilyWeight = fontWeightToNumber(fontFace.descriptors.weight);
|
|
46
|
-
if (fontFamilyWeight === weight &&
|
|
47
|
-
fontFace.descriptors.style === style &&
|
|
48
|
-
fontFace.descriptors.stretch === stretch) {
|
|
49
|
-
return fontFace;
|
|
50
|
-
}
|
|
51
|
-
weightMap.set(fontFamilyWeight, fontFace);
|
|
52
|
-
}
|
|
53
|
-
// No Exact match found, find nearest weight match
|
|
54
|
-
const msg = `TrFontManager: No exact match: '${family} Weight: ${weight} Style: ${style} Stretch: ${stretch}'`;
|
|
55
|
-
console.error(msg);
|
|
56
|
-
// Follow the CSS font-weight algorithm to find the nearest weight match
|
|
57
|
-
// https://www.w3.org/TR/2018/REC-css-fonts-3-20180920/#font-matching-algorithm
|
|
58
|
-
if (weight === 400 && weightMap.has(500)) {
|
|
59
|
-
return weightMap.get(500);
|
|
60
|
-
}
|
|
61
|
-
if (weight === 500 && weightMap.has(400)) {
|
|
62
|
-
return weightMap.get(400);
|
|
63
|
-
}
|
|
64
|
-
if (weight < 400) {
|
|
65
|
-
while (weight > 0) {
|
|
66
|
-
if (weightMap.has(weight)) {
|
|
67
|
-
return weightMap.get(weight);
|
|
68
|
-
}
|
|
69
|
-
weight -= 100;
|
|
70
|
-
}
|
|
71
|
-
// reset back for the next loop
|
|
72
|
-
weight = 600;
|
|
73
|
-
}
|
|
74
|
-
while (weight < 1000) {
|
|
75
|
-
if (weightMap.has(weight)) {
|
|
76
|
-
return weightMap.get(weight);
|
|
77
|
-
}
|
|
78
|
-
weight += 100;
|
|
79
|
-
}
|
|
80
|
-
// finally check lower again
|
|
81
|
-
weight = 500;
|
|
82
|
-
while (weight > 0) {
|
|
83
|
-
if (weightMap.has(weight)) {
|
|
84
|
-
return weightMap.get(weight);
|
|
85
|
-
}
|
|
86
|
-
weight -= 100;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
export class TrFontManager {
|
|
92
|
-
textRenderers;
|
|
93
|
-
fontCache = new Map();
|
|
94
|
-
constructor(textRenderers) {
|
|
95
|
-
this.textRenderers = textRenderers;
|
|
96
|
-
// Intentionally left blank
|
|
97
|
-
}
|
|
98
|
-
addFontFace(font) {
|
|
99
|
-
// All the font face to all of the text renderers that support it
|
|
100
|
-
for (const trId in this.textRenderers) {
|
|
101
|
-
const tr = this.textRenderers[trId];
|
|
102
|
-
if (tr && tr.isFontFaceSupported(font)) {
|
|
103
|
-
tr.addFontFace(font);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Utility method to resolve a single font face from a list of prioritized family maps based on
|
|
109
|
-
* a set of font properties.
|
|
110
|
-
*
|
|
111
|
-
* @remarks
|
|
112
|
-
* These are to be used by a text renderer to resolve a font face if needed.
|
|
113
|
-
*
|
|
114
|
-
* @param familyMapsByPriority
|
|
115
|
-
* @param props
|
|
116
|
-
* @returns
|
|
117
|
-
*/
|
|
118
|
-
resolveFontFace(familyMapsByPriority, props, rendererType) {
|
|
119
|
-
const { fontFamily, fontWeight, fontStyle, fontStretch } = props;
|
|
120
|
-
const fontCacheString = `${rendererType}_${fontFamily}_${fontStyle}_${fontWeight}_${fontStretch}`;
|
|
121
|
-
if (this.fontCache.has(fontCacheString) === true) {
|
|
122
|
-
return this.fontCache.get(fontCacheString);
|
|
123
|
-
}
|
|
124
|
-
const resolvedFont = resolveFontToUse(familyMapsByPriority, fontFamily, fontWeight, fontStyle, fontStretch);
|
|
125
|
-
if (resolvedFont !== undefined) {
|
|
126
|
-
this.fontCache.set(fontCacheString, resolvedFont);
|
|
127
|
-
}
|
|
128
|
-
return resolvedFont;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=TrFontManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TrFontManager.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/TrFontManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,MAAM,iBAAiB,GAA8B;IACnD,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,GAAG;CACb,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAuB,EAAU,EAAE;IAC7D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,iBAAiB,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;AAC1C,CAAC,CAAC;AAEF,SAAS,gBAAgB,CACvB,oBAAqC,EACrC,MAAc,EACd,QAAyB,EACzB,KAAa,EACb,OAAe;IAEf,IAAI,MAAM,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAE1C,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAEtC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS;QACX,CAAC;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACzB,kDAAkD;YAClD,OAAO,CAAC,IAAI,CACV,wDAAwD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AW,EAAE,GAAG,KAAK,CAAC;QACjE,MAAM,eAAe,GAAG,GAAG,YAAY,IAAI,UAAU,IAAI,SAAS,IAAI,UAAU,IAAI,WAAW,EAAE,CAAC;QAElG,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE,CAAC;YACjD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,YAAY,GAAG,gBAAgB,CACnC,oBAAoB,EACpB,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,CACZ,CAAC;QACF,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Stage } from '../../../Stage.js';
|
|
2
|
-
import { ImageTexture } from '../../../textures/ImageTexture.js';
|
|
3
|
-
import { TrFontFace, type TrFontFaceOptions } from '../TrFontFace.js';
|
|
4
|
-
import type { FontShaper } from './internal/FontShaper.js';
|
|
5
|
-
import { type SdfFontData } from './internal/SdfFontShaper.js';
|
|
6
|
-
type SdfFontType = 'ssdf' | 'msdf';
|
|
7
|
-
declare module '../TrFontFace.js' {
|
|
8
|
-
interface TrFontFaceMap {
|
|
9
|
-
ssdf: SdfTrFontFace<'ssdf'>;
|
|
10
|
-
msdf: SdfTrFontFace<'msdf'>;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
interface GlyphAtlasEntry {
|
|
14
|
-
x: number;
|
|
15
|
-
y: number;
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
}
|
|
19
|
-
export interface SdfTrFontFaceOptions extends TrFontFaceOptions {
|
|
20
|
-
atlasUrl: string;
|
|
21
|
-
atlasDataUrl: string;
|
|
22
|
-
stage: Stage;
|
|
23
|
-
}
|
|
24
|
-
export declare class SdfTrFontFace<FontTypeT extends SdfFontType = SdfFontType> extends TrFontFace {
|
|
25
|
-
readonly type: FontTypeT;
|
|
26
|
-
readonly texture: ImageTexture;
|
|
27
|
-
/**
|
|
28
|
-
* Height of the tallest character in the font including the whitespace above it
|
|
29
|
-
* in SDF/vertex units.
|
|
30
|
-
*/
|
|
31
|
-
readonly maxCharHeight: number;
|
|
32
|
-
readonly shaper: FontShaper | undefined;
|
|
33
|
-
readonly glyphMap: Map<number, SdfFontData['chars'][0]>;
|
|
34
|
-
data: SdfFontData | undefined;
|
|
35
|
-
constructor(type: FontTypeT, options: SdfTrFontFaceOptions);
|
|
36
|
-
getAtlasEntry(glyphId: number): GlyphAtlasEntry;
|
|
37
|
-
private checkLoaded;
|
|
38
|
-
}
|
|
39
|
-
export {};
|
|
@@ -1,125 +0,0 @@
|
|
|
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 type { Renderer } from '../../../Renderer';
|
|
20
|
-
import { assertTruthy } from '../../../../utils.js';
|
|
21
|
-
import { WebGlCoreRenderer } from '../../../renderers/webgl/WebGlCoreRenderer.js';
|
|
22
|
-
import { ImageTexture } from '../../../textures/ImageTexture.js';
|
|
23
|
-
import { TrFontFace, } from '../TrFontFace.js';
|
|
24
|
-
import { fetchJson } from '../utils.js';
|
|
25
|
-
import { SdfFontShaper } from './internal/SdfFontShaper.js';
|
|
26
|
-
export class SdfTrFontFace extends TrFontFace {
|
|
27
|
-
type;
|
|
28
|
-
texture;
|
|
29
|
-
/**
|
|
30
|
-
* Height of the tallest character in the font including the whitespace above it
|
|
31
|
-
* in SDF/vertex units.
|
|
32
|
-
*/
|
|
33
|
-
maxCharHeight = 0;
|
|
34
|
-
shaper;
|
|
35
|
-
glyphMap = new Map();
|
|
36
|
-
data;
|
|
37
|
-
constructor(type, options) {
|
|
38
|
-
super(options);
|
|
39
|
-
const { atlasUrl, atlasDataUrl, stage } = options;
|
|
40
|
-
this.type = type;
|
|
41
|
-
const renderer = stage.renderer;
|
|
42
|
-
assertTruthy(renderer instanceof WebGlCoreRenderer, 'SDF Font Faces can only be used with the WebGL Renderer');
|
|
43
|
-
// Load image
|
|
44
|
-
this.texture = stage.txManager.createTexture('ImageTexture', {
|
|
45
|
-
src: atlasUrl,
|
|
46
|
-
// IMPORTANT: The SDF shader requires the alpha channel to NOT be
|
|
47
|
-
// premultiplied on the atlas texture. If it is premultiplied, the
|
|
48
|
-
// rendering of SDF glyphs (especially single-channel SDF fonts) will
|
|
49
|
-
// be very jagged.
|
|
50
|
-
premultiplyAlpha: false,
|
|
51
|
-
});
|
|
52
|
-
// Load the texture
|
|
53
|
-
stage.txManager.loadTexture(this.texture, true);
|
|
54
|
-
// FIXME This is a stop-gap solution to avoid Font Face textures to be cleaned up
|
|
55
|
-
// Ideally we do want to clean up the textures if they're not being used to save as much memory as possible
|
|
56
|
-
// However, we need to make sure that the font face is reloaded if the texture is cleaned up and needed again
|
|
57
|
-
// and make sure the SdfFontRenderer is properly guarded against textures being reloaded
|
|
58
|
-
// for now this will do the trick and the increase on memory is not that big
|
|
59
|
-
this.texture.preventCleanup = true;
|
|
60
|
-
this.texture.on('loaded', () => {
|
|
61
|
-
this.checkLoaded();
|
|
62
|
-
// Make sure we mark the stage for a re-render (in case the font's texture was freed and reloaded)
|
|
63
|
-
stage.requestRender();
|
|
64
|
-
});
|
|
65
|
-
// Set this.data to the fetched data from dataUrl
|
|
66
|
-
fetchJson(atlasDataUrl)
|
|
67
|
-
.then((response) => {
|
|
68
|
-
this.data = JSON.parse(response);
|
|
69
|
-
assertTruthy(this.data);
|
|
70
|
-
// Add all the glyphs to the glyph map
|
|
71
|
-
let maxCharHeight = 0;
|
|
72
|
-
this.data.chars.forEach((glyph) => {
|
|
73
|
-
this.glyphMap.set(glyph.id, glyph);
|
|
74
|
-
const charHeight = glyph.yoffset + glyph.height;
|
|
75
|
-
if (charHeight > maxCharHeight) {
|
|
76
|
-
maxCharHeight = charHeight;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
this.maxCharHeight = maxCharHeight;
|
|
80
|
-
// We know `data` is defined here, because we just set it
|
|
81
|
-
this.shaper = new SdfFontShaper(this.data, this.glyphMap);
|
|
82
|
-
// If the metrics aren't provided explicitly in the font face options,
|
|
83
|
-
// Gather them from the metrics added by the msdf-generator tool ()
|
|
84
|
-
// If they are missing then we throw an error.
|
|
85
|
-
if (!this.metrics) {
|
|
86
|
-
if (this.data?.lightningMetrics) {
|
|
87
|
-
const { ascender, descender, lineGap, unitsPerEm } = this.data.lightningMetrics;
|
|
88
|
-
this.metrics = {
|
|
89
|
-
ascender: ascender / unitsPerEm,
|
|
90
|
-
descender: descender / unitsPerEm,
|
|
91
|
-
lineGap: lineGap / unitsPerEm,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw new Error(`Font metrics not found in ${this.type} font ${this.fontFamily}. ` +
|
|
96
|
-
'Make sure you are using the latest version of the Lightning ' +
|
|
97
|
-
'3 `msdf-generator` tool to generate your SDF fonts.');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
this.checkLoaded();
|
|
101
|
-
})
|
|
102
|
-
.catch(console.error);
|
|
103
|
-
}
|
|
104
|
-
getAtlasEntry(glyphId) {
|
|
105
|
-
const glyph = this.glyphMap.get(glyphId);
|
|
106
|
-
if (glyph === undefined) {
|
|
107
|
-
throw new Error(`Glyph ${glyphId} not found in font ${this.fontFamily}`);
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
x: glyph.x,
|
|
111
|
-
y: glyph.y,
|
|
112
|
-
width: glyph.width,
|
|
113
|
-
height: glyph.height,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
checkLoaded() {
|
|
117
|
-
if (this.loaded)
|
|
118
|
-
return;
|
|
119
|
-
if (this.texture.state === 'loaded' && this.data) {
|
|
120
|
-
this.loaded = true;
|
|
121
|
-
this.emit('loaded');
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=SdfTrFontFace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SdfTrFontFace.js","sourceRoot":"","sources":["../../../../../../src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,qDAAqD;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EACL,UAAU,GAGX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,aAAa,EAAoB,MAAM,6BAA6B,CAAC;AAwB9E,MAAM,OAAO,aAEX,SAAQ,UAAU;IACF,IAAI,CAAY;IAChB,OAAO,CAAe;IACtC;;;OAGG;IACa,aAAa,GAAW,CAAC,CAAC;IAC1B,MAAM,CAAyB;IAC/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