@lightningjs/renderer 3.0.0-beta4 → 3.0.0-beta6
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/LICENSE +202 -202
- package/NOTICE +3 -3
- package/README.md +147 -147
- package/dist/exports/core-api.d.ts +74 -0
- package/dist/exports/core-api.js +96 -0
- package/dist/exports/core-api.js.map +1 -0
- package/dist/exports/main-api.d.ts +30 -0
- package/dist/exports/main-api.js +45 -0
- package/dist/exports/main-api.js.map +1 -0
- package/dist/src/core/CoreExtension.d.ts +12 -0
- package/dist/src/core/CoreExtension.js +29 -0
- package/dist/src/core/CoreExtension.js.map +1 -0
- package/dist/src/core/CoreNode.d.ts +6 -16
- package/dist/src/core/CoreNode.js +25 -38
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreStuff.js +138 -0
- package/dist/src/core/CoreStuff.js.map +1 -0
- package/dist/src/core/CoreTextNode.js +1 -1
- package/dist/src/core/CoreTextNode.js.map +1 -1
- package/dist/src/core/CoreTextureManager.js +4 -5
- package/dist/src/core/CoreTextureManager.js.map +1 -1
- package/dist/src/core/CoreTexturizer.d.ts +14 -0
- package/dist/src/core/CoreTexturizer.js +47 -0
- package/dist/src/core/CoreTexturizer.js.map +1 -0
- package/dist/src/core/LngNode.d.ts +736 -0
- package/dist/src/core/LngNode.js +1174 -0
- package/dist/src/core/LngNode.js.map +1 -0
- package/dist/src/core/Matrix2DContext.d.ts +15 -0
- package/dist/src/core/Matrix2DContext.js +45 -0
- package/dist/src/core/Matrix2DContext.js.map +1 -0
- package/dist/src/core/ShaderNode.d.ts +10 -0
- package/dist/src/core/ShaderNode.js +30 -0
- package/dist/src/core/ShaderNode.js.map +1 -0
- package/dist/src/core/Stage.js +0 -3
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/TextNode.d.ts +103 -0
- package/dist/src/core/TextNode.js +331 -0
- package/dist/src/core/TextNode.js.map +1 -0
- package/dist/src/core/TextureMemoryManager.js +3 -4
- package/dist/src/core/TextureMemoryManager.js.map +1 -1
- package/dist/src/core/lib/Coords.d.ts +14 -0
- package/dist/src/core/lib/Coords.js +55 -0
- package/dist/src/core/lib/Coords.js.map +1 -0
- package/dist/src/core/lib/glm/common.d.ts +162 -0
- package/dist/src/core/lib/glm/common.js +81 -0
- package/dist/src/core/lib/glm/common.js.map +1 -0
- package/dist/src/core/lib/glm/index.d.ts +11 -0
- package/dist/src/core/lib/glm/index.js +30 -0
- package/dist/src/core/lib/glm/index.js.map +1 -0
- package/dist/src/core/lib/glm/mat2.d.ts +219 -0
- package/dist/src/core/lib/glm/mat2.js +396 -0
- package/dist/src/core/lib/glm/mat2.js.map +1 -0
- package/dist/src/core/lib/glm/mat2d.d.ts +237 -0
- package/dist/src/core/lib/glm/mat2d.js +442 -0
- package/dist/src/core/lib/glm/mat2d.js.map +1 -0
- package/dist/src/core/lib/glm/mat3.d.ts +283 -0
- package/dist/src/core/lib/glm/mat3.js +680 -0
- package/dist/src/core/lib/glm/mat3.js.map +1 -0
- package/dist/src/core/lib/glm/mat4.d.ts +550 -0
- package/dist/src/core/lib/glm/mat4.js +1802 -0
- package/dist/src/core/lib/glm/mat4.js.map +1 -0
- package/dist/src/core/lib/glm/quat.d.ts +363 -0
- package/dist/src/core/lib/glm/quat.js +693 -0
- package/dist/src/core/lib/glm/quat.js.map +1 -0
- package/dist/src/core/lib/glm/quat2.d.ts +356 -0
- package/dist/src/core/lib/glm/quat2.js +754 -0
- package/dist/src/core/lib/glm/quat2.js.map +1 -0
- package/dist/src/core/lib/glm/vec2.d.ts +365 -0
- package/dist/src/core/lib/glm/vec2.js +569 -0
- package/dist/src/core/lib/glm/vec2.js.map +1 -0
- package/dist/src/core/lib/glm/vec3.d.ts +406 -0
- package/dist/src/core/lib/glm/vec3.js +720 -0
- package/dist/src/core/lib/glm/vec3.js.map +1 -0
- package/dist/src/core/lib/glm/vec4.d.ts +330 -0
- package/dist/src/core/lib/glm/vec4.js +608 -0
- package/dist/src/core/lib/glm/vec4.js.map +1 -0
- package/dist/src/core/renderers/CoreRenderer.d.ts +1 -1
- package/dist/src/core/renderers/CoreShaderManager.d.ts +19 -0
- package/dist/src/core/renderers/CoreShaderManager.js +33 -0
- package/dist/src/core/renderers/CoreShaderManager.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.d.ts +27 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js +82 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.d.ts +11 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js +34 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +1 -1
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -1
- package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +35 -35
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +45 -45
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +61 -61
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +93 -93
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +63 -63
- package/dist/src/core/renderers/webgl/shaders/SdfShader.js +62 -62
- package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +6 -6
- package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +42 -42
- package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +44 -44
- package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +3 -3
- package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js +22 -22
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +28 -28
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +10 -10
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +37 -37
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +19 -19
- package/dist/src/core/scene/Scene.d.ts +59 -0
- package/dist/src/core/scene/Scene.js +106 -0
- package/dist/src/core/scene/Scene.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js +8 -2
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -1
- package/dist/src/core/shaders/webgl/Border.js +86 -63
- package/dist/src/core/shaders/webgl/Border.js.map +1 -1
- package/dist/src/core/shaders/webgl/Default.js +47 -47
- package/dist/src/core/shaders/webgl/DefaultBatched.js +61 -61
- package/dist/src/core/shaders/webgl/HolePunch.js +32 -32
- package/dist/src/core/shaders/webgl/LinearGradient.js +36 -36
- package/dist/src/core/shaders/webgl/RadialGradient.js +33 -33
- package/dist/src/core/shaders/webgl/Rounded.js +71 -71
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js +104 -72
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +123 -86
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js +54 -54
- package/dist/src/core/shaders/webgl/SdfShader.js +62 -62
- package/dist/src/core/shaders/webgl/Shadow.js +83 -83
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +3 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.d.ts +20 -0
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js +55 -0
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js.map +1 -0
- package/dist/src/main-api/ICoreDriver.d.ts +27 -0
- package/dist/src/main-api/ICoreDriver.js +20 -0
- package/dist/src/main-api/ICoreDriver.js.map +1 -0
- package/dist/src/main-api/IRenderDriver.d.ts +20 -0
- package/dist/src/main-api/IRenderDriver.js +20 -0
- package/dist/src/main-api/IRenderDriver.js.map +1 -0
- package/dist/src/main-api/IShaderController.d.ts +14 -0
- package/dist/src/main-api/IShaderController.js +30 -0
- package/dist/src/main-api/IShaderController.js.map +1 -0
- package/dist/src/main-api/IShaderNode.d.ts +17 -0
- package/dist/src/main-api/IShaderNode.js +19 -0
- package/dist/src/main-api/IShaderNode.js.map +1 -0
- package/dist/src/main-api/Inspector.js +1 -1
- package/dist/src/main-api/Inspector.js.map +1 -1
- package/dist/src/main-api/Renderer.js +2 -3
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/src/main-api/RendererMain.d.ts +375 -0
- package/dist/src/main-api/RendererMain.js +365 -0
- package/dist/src/main-api/RendererMain.js.map +1 -0
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.d.ts +9 -0
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js +38 -0
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js.map +1 -0
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.d.ts +56 -0
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js +101 -0
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js.map +1 -0
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.d.ts +32 -0
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js +28 -0
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js.map +1 -0
- package/dist/src/render-drivers/main/MainCoreDriver.d.ts +24 -0
- package/dist/src/render-drivers/main/MainCoreDriver.js +118 -0
- package/dist/src/render-drivers/main/MainCoreDriver.js.map +1 -0
- package/dist/src/render-drivers/main/MainOnlyNode.d.ts +99 -0
- package/dist/src/render-drivers/main/MainOnlyNode.js +396 -0
- package/dist/src/render-drivers/main/MainOnlyNode.js.map +1 -0
- package/dist/src/render-drivers/main/MainOnlyShaderController.d.ts +6 -0
- package/dist/src/render-drivers/main/MainOnlyShaderController.js +15 -0
- package/dist/src/render-drivers/main/MainOnlyShaderController.js.map +1 -0
- package/dist/src/render-drivers/main/MainOnlyShaderNode.d.ts +7 -0
- package/dist/src/render-drivers/main/MainOnlyShaderNode.js +34 -0
- package/dist/src/render-drivers/main/MainOnlyShaderNode.js.map +1 -0
- package/dist/src/render-drivers/main/MainOnlyTextNode.d.ts +47 -0
- package/dist/src/render-drivers/main/MainOnlyTextNode.js +205 -0
- package/dist/src/render-drivers/main/MainOnlyTextNode.js.map +1 -0
- package/dist/src/render-drivers/main/MainRenderDriver.d.ts +17 -0
- package/dist/src/render-drivers/main/MainRenderDriver.js +88 -0
- package/dist/src/render-drivers/main/MainRenderDriver.js.map +1 -0
- package/dist/src/render-drivers/threadx/NodeStruct.d.ts +90 -0
- package/dist/src/render-drivers/threadx/NodeStruct.js +281 -0
- package/dist/src/render-drivers/threadx/NodeStruct.js.map +1 -0
- package/dist/src/render-drivers/threadx/SharedNode.d.ts +39 -0
- package/dist/src/render-drivers/threadx/SharedNode.js +60 -0
- package/dist/src/render-drivers/threadx/SharedNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/TextNodeStruct.d.ts +44 -0
- package/dist/src/render-drivers/threadx/TextNodeStruct.js +201 -0
- package/dist/src/render-drivers/threadx/TextNodeStruct.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +28 -0
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +234 -0
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.d.ts +20 -0
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js +84 -0
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +44 -0
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js +154 -0
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainShaderController.d.ts +6 -0
- package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js +16 -0
- package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.d.ts +7 -0
- package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js +15 -0
- package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.d.ts +28 -0
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js +55 -0
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXRenderDriver.d.ts +21 -0
- package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js +198 -0
- package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +70 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js +32 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +1 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.d.ts +19 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js +177 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.d.ts +27 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js +108 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/worker/renderer.d.ts +1 -0
- package/dist/src/render-drivers/threadx/worker/renderer.js +145 -0
- package/dist/src/render-drivers/threadx/worker/renderer.js.map +1 -0
- package/dist/src/render-drivers/utils.d.ts +12 -0
- package/dist/src/render-drivers/utils.js +69 -0
- package/dist/src/render-drivers/utils.js.map +1 -0
- package/dist/src/utils.d.ts +1 -6
- package/dist/src/utils.js +2 -9
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/canvas-shaders.ts +28 -28
- package/exports/canvas.ts +45 -45
- package/exports/index.ts +90 -90
- package/exports/inspector.ts +24 -24
- package/exports/utils.ts +44 -44
- package/exports/webgl-shaders.ts +28 -28
- package/exports/webgl.ts +50 -50
- package/package.json +2 -2
- package/src/common/CommonTypes.ts +146 -146
- package/src/common/EventEmitter.ts +77 -77
- package/src/common/IAnimationController.ts +92 -92
- package/src/common/IEventEmitter.ts +28 -28
- package/src/core/CoreNode.test.ts +202 -203
- package/src/core/CoreNode.ts +2469 -2494
- package/src/core/CoreShaderManager.ts +188 -188
- package/src/core/CoreTextNode.ts +448 -448
- package/src/core/CoreTextureManager.ts +600 -601
- package/src/core/Stage.ts +751 -754
- package/src/core/TextureMemoryManager.ts +394 -395
- package/src/core/animations/AnimationManager.ts +38 -38
- package/src/core/animations/CoreAnimation.ts +284 -284
- package/src/core/animations/CoreAnimationController.ts +157 -157
- package/src/core/lib/ContextSpy.ts +41 -41
- package/src/core/lib/ImageWorker.ts +280 -280
- package/src/core/lib/Matrix3d.ts +244 -244
- package/src/core/lib/RenderCoords.ts +71 -71
- package/src/core/lib/WebGlContextWrapper.ts +1374 -1374
- package/src/core/lib/textureCompression.ts +152 -152
- package/src/core/lib/textureSvg.ts +78 -78
- package/src/core/lib/utils.ts +386 -386
- package/src/core/lib/validateImageBitmap.ts +87 -87
- package/src/core/platforms/Platform.ts +77 -77
- package/src/core/platforms/web/WebPlatform.ts +84 -84
- package/src/core/renderers/CoreContextTexture.ts +43 -43
- package/src/core/renderers/CoreRenderOp.ts +22 -22
- package/src/core/renderers/CoreRenderer.ts +109 -109
- package/src/core/renderers/CoreShaderNode.ts +165 -165
- package/src/core/renderers/CoreShaderProgram.ts +23 -23
- package/src/core/renderers/canvas/CanvasRenderer.ts +298 -298
- package/src/core/renderers/canvas/CanvasShaderNode.ts +99 -99
- package/src/core/renderers/canvas/CanvasTexture.ts +156 -156
- package/src/core/renderers/canvas/internal/C2DShaderUtils.ts +220 -220
- package/src/core/renderers/canvas/internal/ColorUtils.ts +85 -85
- package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +86 -86
- package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +50 -50
- package/src/core/renderers/webgl/WebGlCtxTexture.ts +301 -301
- package/src/core/renderers/webgl/WebGlRenderOp.ts +161 -161
- package/src/core/renderers/webgl/WebGlRenderer.ts +750 -750
- package/src/core/renderers/webgl/WebGlShaderNode.ts +437 -437
- package/src/core/renderers/webgl/WebGlShaderProgram.ts +318 -318
- package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
- package/src/core/renderers/webgl/internal/RendererUtils.ts +155 -155
- package/src/core/renderers/webgl/internal/ShaderUtils.ts +281 -281
- package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
- package/src/core/shaders/canvas/Border.ts +78 -78
- package/src/core/shaders/canvas/HolePunch.ts +62 -62
- package/src/core/shaders/canvas/LinearGradient.ts +69 -69
- package/src/core/shaders/canvas/RadialGradient.ts +113 -113
- package/src/core/shaders/canvas/Rounded.ts +55 -55
- package/src/core/shaders/canvas/RoundedWithBorder.ts +72 -68
- package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +88 -88
- package/src/core/shaders/canvas/RoundedWithShadow.ts +69 -69
- package/src/core/shaders/canvas/Shadow.ts +52 -52
- package/src/core/shaders/canvas/utils/render.ts +151 -151
- package/src/core/shaders/templates/BorderTemplate.ts +115 -115
- package/src/core/shaders/templates/HolePunchTemplate.ts +82 -82
- package/src/core/shaders/templates/LinearGradientTemplate.ts +71 -71
- package/src/core/shaders/templates/RadialGradientTemplate.ts +81 -81
- package/src/core/shaders/templates/RoundedTemplate.ts +98 -98
- package/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.ts +38 -38
- package/src/core/shaders/templates/RoundedWithBorderTemplate.ts +35 -35
- package/src/core/shaders/templates/RoundedWithShadowTemplate.ts +35 -35
- package/src/core/shaders/templates/ShadowTemplate.ts +106 -106
- package/src/core/shaders/templates/shaderUtils.ts +47 -47
- package/src/core/shaders/webgl/Border.ts +116 -96
- package/src/core/shaders/webgl/Default.ts +89 -89
- package/src/core/shaders/webgl/DefaultBatched.ts +129 -129
- package/src/core/shaders/webgl/HolePunch.ts +78 -78
- package/src/core/shaders/webgl/LinearGradient.ts +81 -81
- package/src/core/shaders/webgl/RadialGradient.ts +84 -84
- package/src/core/shaders/webgl/Rounded.ts +117 -117
- package/src/core/shaders/webgl/RoundedWithBorder.ts +144 -114
- package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +166 -133
- package/src/core/shaders/webgl/RoundedWithShadow.ts +98 -98
- package/src/core/shaders/webgl/SdfShader.ts +134 -134
- package/src/core/shaders/webgl/Shadow.ts +115 -115
- package/src/core/text-rendering/TextRenderingUtils.ts +36 -36
- package/src/core/text-rendering/TextTextureRendererUtils.ts +263 -263
- package/src/core/text-rendering/TrFontManager.ts +183 -183
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +176 -176
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +171 -171
- package/src/core/text-rendering/font-face-types/TrFontFace.ts +187 -187
- package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +94 -94
- package/src/core/text-rendering/font-face-types/utils.ts +39 -39
- package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +514 -514
- package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +863 -863
- package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +849 -846
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +117 -117
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +497 -497
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +52 -52
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
- package/src/core/text-rendering/renderers/TextRenderer.ts +567 -567
- package/src/core/textures/ColorTexture.ts +102 -102
- package/src/core/textures/ImageTexture.ts +410 -410
- package/src/core/textures/NoiseTexture.ts +104 -104
- package/src/core/textures/RenderTexture.ts +85 -85
- package/src/core/textures/SubTexture.ts +205 -205
- package/src/core/textures/Texture.ts +358 -358
- package/src/core/utils.ts +227 -227
- package/src/env.d.ts +7 -7
- package/src/main-api/INode.ts +100 -100
- package/src/main-api/Inspector.ts +522 -522
- package/src/main-api/Renderer.ts +673 -675
- package/src/main-api/utils.ts +45 -45
- package/src/utils.ts +267 -267
- package/COPYING +0 -1
- package/dist/src/core/temp.js +0 -77
- package/dist/src/core/temp.js.map +0 -1
- package/scripts/please-use-pnpm.js +0 -13
- package/src/core/platform.ts +0 -64
- /package/dist/src/core/{temp.d.ts → CoreStuff.d.ts} +0 -0
|
@@ -1,846 +1,849 @@
|
|
|
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
|
-
import {
|
|
21
|
-
type Bound,
|
|
22
|
-
type Rect,
|
|
23
|
-
createBound,
|
|
24
|
-
type BoundWithValid,
|
|
25
|
-
intersectRect,
|
|
26
|
-
type RectWithValid,
|
|
27
|
-
copyRect,
|
|
28
|
-
boundsOverlap,
|
|
29
|
-
convertBoundToRect,
|
|
30
|
-
} from '../../../lib/utils.js';
|
|
31
|
-
import {
|
|
32
|
-
TextRenderer,
|
|
33
|
-
type TrProps,
|
|
34
|
-
type TextRendererState,
|
|
35
|
-
type TrFontProps,
|
|
36
|
-
type TrPropSetters,
|
|
37
|
-
} from '../TextRenderer.js';
|
|
38
|
-
import { SdfTrFontFace } from '../../font-face-types/SdfTrFontFace/SdfTrFontFace.js';
|
|
39
|
-
import { FLOATS_PER_GLYPH } from './internal/constants.js';
|
|
40
|
-
import { getStartConditions } from './internal/getStartConditions.js';
|
|
41
|
-
import { layoutText } from './internal/layoutText.js';
|
|
42
|
-
import {
|
|
43
|
-
setRenderWindow,
|
|
44
|
-
type SdfRenderWindow,
|
|
45
|
-
} from './internal/setRenderWindow.js';
|
|
46
|
-
import type { TrFontFace } from '../../font-face-types/TrFontFace.js';
|
|
47
|
-
import { type FontFamilyMap } from '../../TrFontManager.js';
|
|
48
|
-
import { assertTruthy, mergeColorAlpha } from '../../../../utils.js';
|
|
49
|
-
import type { Stage } from '../../../Stage.js';
|
|
50
|
-
import { WebGlRenderOp } from '../../../renderers/webgl/WebGlRenderOp.js';
|
|
51
|
-
import { BufferCollection } from '../../../renderers/webgl/internal/BufferCollection.js';
|
|
52
|
-
import { Sdf, type SdfShaderProps } from '../../../shaders/webgl/SdfShader.js';
|
|
53
|
-
import type { WebGlCtxTexture } from '../../../renderers/webgl/WebGlCtxTexture.js';
|
|
54
|
-
import { EventEmitter } from '../../../../common/EventEmitter.js';
|
|
55
|
-
import type { Matrix3d } from '../../../lib/Matrix3d.js';
|
|
56
|
-
import type { Dimensions } from '../../../../common/CommonTypes.js';
|
|
57
|
-
import { WebGlRenderer } from '../../../renderers/webgl/WebGlRenderer.js';
|
|
58
|
-
import { calcDefaultLineHeight } from '../../TextRenderingUtils.js';
|
|
59
|
-
import type { WebGlShaderProgram } from '../../../renderers/webgl/WebGlShaderProgram.js';
|
|
60
|
-
import type { WebGlShaderNode } from '../../../renderers/webgl/WebGlShaderNode.js';
|
|
61
|
-
import type { CoreTextNode } from '../../../CoreTextNode.js';
|
|
62
|
-
|
|
63
|
-
declare module '../TextRenderer.js' {
|
|
64
|
-
interface TextRendererMap {
|
|
65
|
-
sdf: SdfTextRenderer;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Add prefixed SDF-specific props to TextRendererDebugProps
|
|
69
|
-
interface TextRendererDebugProps {
|
|
70
|
-
sdfShaderDebug: boolean;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface LineCacheItem {
|
|
75
|
-
codepointIndex: number;
|
|
76
|
-
maxY: number;
|
|
77
|
-
maxX: number;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface SdfTextRendererState extends TextRendererState {
|
|
81
|
-
/**
|
|
82
|
-
* Cache for layout resume points indexed by the `curY` for each line
|
|
83
|
-
* in the render sequence.
|
|
84
|
-
*
|
|
85
|
-
* Allows faster rendering by skipping parts of the layout loop that are
|
|
86
|
-
* outside of the renderWindow.
|
|
87
|
-
*/
|
|
88
|
-
lineCache: LineCacheItem[];
|
|
89
|
-
|
|
90
|
-
renderWindow: SdfRenderWindow;
|
|
91
|
-
|
|
92
|
-
elementBounds: BoundWithValid;
|
|
93
|
-
|
|
94
|
-
clippingRect: RectWithValid;
|
|
95
|
-
|
|
96
|
-
bufferNumFloats: number;
|
|
97
|
-
|
|
98
|
-
bufferNumQuads: number;
|
|
99
|
-
|
|
100
|
-
vertexBuffer: Float32Array | undefined;
|
|
101
|
-
|
|
102
|
-
webGlBuffers: BufferCollection | null;
|
|
103
|
-
|
|
104
|
-
bufferUploaded: boolean;
|
|
105
|
-
|
|
106
|
-
distanceRange: number;
|
|
107
|
-
|
|
108
|
-
trFontFace: SdfTrFontFace | undefined;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Resolved line height in logical screen pixel units
|
|
112
|
-
*/
|
|
113
|
-
resLineHeight: number | undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Ephemeral rect object used for calculations
|
|
118
|
-
*/
|
|
119
|
-
const tmpRect: Rect = {
|
|
120
|
-
x: 0,
|
|
121
|
-
y: 0,
|
|
122
|
-
width: 0,
|
|
123
|
-
height: 0,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Singleton class for rendering text using signed distance fields.
|
|
128
|
-
*
|
|
129
|
-
* @remarks
|
|
130
|
-
* SdfTextRenderer supports both single-channel and multi-channel signed distance fields.
|
|
131
|
-
*/
|
|
132
|
-
export class SdfTextRenderer extends TextRenderer<SdfTextRendererState> {
|
|
133
|
-
/**
|
|
134
|
-
* Map of font family names to a set of font faces.
|
|
135
|
-
*/
|
|
136
|
-
private ssdfFontFamilies: FontFamilyMap = {};
|
|
137
|
-
private msdfFontFamilies: FontFamilyMap = {};
|
|
138
|
-
private fontFamilyArray: FontFamilyMap[] = [
|
|
139
|
-
this.ssdfFontFamilies,
|
|
140
|
-
this.msdfFontFamilies,
|
|
141
|
-
];
|
|
142
|
-
private sdfShader: WebGlShaderNode;
|
|
143
|
-
private rendererBounds: Bound;
|
|
144
|
-
|
|
145
|
-
public type: 'canvas' | 'sdf' = 'sdf';
|
|
146
|
-
|
|
147
|
-
constructor(stage: Stage) {
|
|
148
|
-
super(stage);
|
|
149
|
-
this.stage.shManager.registerShaderType('Sdf', Sdf);
|
|
150
|
-
this.sdfShader = this.stage.shManager.createShader(
|
|
151
|
-
'Sdf',
|
|
152
|
-
) as WebGlShaderNode;
|
|
153
|
-
this.rendererBounds = {
|
|
154
|
-
x1: 0,
|
|
155
|
-
y1: 0,
|
|
156
|
-
x2: this.stage.options.appWidth,
|
|
157
|
-
y2: this.stage.options.appHeight,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
//#region Overrides
|
|
162
|
-
getPropertySetters(): Partial<TrPropSetters<SdfTextRendererState>> {
|
|
163
|
-
return {
|
|
164
|
-
fontFamily: (state, value) => {
|
|
165
|
-
state.props.fontFamily = value;
|
|
166
|
-
this.releaseFontFace(state);
|
|
167
|
-
this.invalidateLayoutCache(state);
|
|
168
|
-
},
|
|
169
|
-
fontWeight: (state, value) => {
|
|
170
|
-
state.props.fontWeight = value;
|
|
171
|
-
this.releaseFontFace(state);
|
|
172
|
-
this.invalidateLayoutCache(state);
|
|
173
|
-
},
|
|
174
|
-
fontStyle: (state, value) => {
|
|
175
|
-
state.props.fontStyle = value;
|
|
176
|
-
this.releaseFontFace(state);
|
|
177
|
-
this.invalidateLayoutCache(state);
|
|
178
|
-
},
|
|
179
|
-
fontStretch: (state, value) => {
|
|
180
|
-
state.props.fontStretch = value;
|
|
181
|
-
this.releaseFontFace(state);
|
|
182
|
-
this.invalidateLayoutCache(state);
|
|
183
|
-
},
|
|
184
|
-
fontSize: (state, value) => {
|
|
185
|
-
state.props.fontSize = value;
|
|
186
|
-
this.invalidateLayoutCache(state);
|
|
187
|
-
},
|
|
188
|
-
text: (state, value) => {
|
|
189
|
-
state.props.text = value;
|
|
190
|
-
this.invalidateLayoutCache(state);
|
|
191
|
-
},
|
|
192
|
-
textAlign: (state, value) => {
|
|
193
|
-
state.props.textAlign = value;
|
|
194
|
-
this.invalidateLayoutCache(state);
|
|
195
|
-
},
|
|
196
|
-
color: (state, value) => {
|
|
197
|
-
state.props.color = value;
|
|
198
|
-
},
|
|
199
|
-
x: (state, value) => {
|
|
200
|
-
state.props.x = value;
|
|
201
|
-
if (state.elementBounds.valid) {
|
|
202
|
-
this.setElementBoundsX(state);
|
|
203
|
-
// Only schedule an update if the text is not already rendered
|
|
204
|
-
// (renderWindow is invalid) and the element possibly overlaps the screen
|
|
205
|
-
// This is to avoid unnecessary updates when we know text is off-screen
|
|
206
|
-
if (
|
|
207
|
-
!state.renderWindow.valid &&
|
|
208
|
-
boundsOverlap(state.elementBounds, this.rendererBounds)
|
|
209
|
-
) {
|
|
210
|
-
this.scheduleUpdateState(state);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
y: (state, value) => {
|
|
215
|
-
state.props.y = value;
|
|
216
|
-
if (state.elementBounds.valid) {
|
|
217
|
-
this.setElementBoundsY(state);
|
|
218
|
-
// See x() for explanation
|
|
219
|
-
if (
|
|
220
|
-
!state.renderWindow.valid &&
|
|
221
|
-
boundsOverlap(state.elementBounds, this.rendererBounds)
|
|
222
|
-
) {
|
|
223
|
-
this.scheduleUpdateState(state);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
contain: (state, value) => {
|
|
228
|
-
state.props.contain = value;
|
|
229
|
-
this.invalidateLayoutCache(state);
|
|
230
|
-
},
|
|
231
|
-
width: (state, value) => {
|
|
232
|
-
state.props.width = value;
|
|
233
|
-
// Only invalidate layout cache if we're containing in the horizontal direction
|
|
234
|
-
if (state.props.contain !== 'none') {
|
|
235
|
-
this.invalidateLayoutCache(state);
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
height: (state, value) => {
|
|
239
|
-
state.props.height = value;
|
|
240
|
-
// Only invalidate layout cache if we're containing in the vertical direction
|
|
241
|
-
if (state.props.contain === 'both') {
|
|
242
|
-
this.invalidateLayoutCache(state);
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
offsetY: (state, value) => {
|
|
246
|
-
state.props.offsetY = value;
|
|
247
|
-
this.invalidateLayoutCache(state);
|
|
248
|
-
},
|
|
249
|
-
scrollable: (state, value) => {
|
|
250
|
-
state.props.scrollable = value;
|
|
251
|
-
this.invalidateLayoutCache(state);
|
|
252
|
-
},
|
|
253
|
-
scrollY: (state, value) => {
|
|
254
|
-
state.props.scrollY = value;
|
|
255
|
-
// Scrolling doesn't need to invalidate any caches, but it does need to
|
|
256
|
-
// schedule an update
|
|
257
|
-
this.scheduleUpdateState(state);
|
|
258
|
-
},
|
|
259
|
-
letterSpacing: (state, value) => {
|
|
260
|
-
state.props.letterSpacing = value;
|
|
261
|
-
this.invalidateLayoutCache(state);
|
|
262
|
-
},
|
|
263
|
-
lineHeight: (state, value) => {
|
|
264
|
-
state.props.lineHeight = value;
|
|
265
|
-
state.resLineHeight = undefined;
|
|
266
|
-
this.invalidateLayoutCache(state);
|
|
267
|
-
},
|
|
268
|
-
maxLines: (state, value) => {
|
|
269
|
-
state.props.maxLines = value;
|
|
270
|
-
this.invalidateLayoutCache(state);
|
|
271
|
-
},
|
|
272
|
-
textBaseline: (state, value) => {
|
|
273
|
-
state.props.textBaseline = value;
|
|
274
|
-
this.invalidateLayoutCache(state);
|
|
275
|
-
},
|
|
276
|
-
verticalAlign: (state, value) => {
|
|
277
|
-
state.props.verticalAlign = value;
|
|
278
|
-
this.invalidateLayoutCache(state);
|
|
279
|
-
},
|
|
280
|
-
overflowSuffix: (state, value) => {
|
|
281
|
-
state.props.overflowSuffix = value;
|
|
282
|
-
this.invalidateLayoutCache(state);
|
|
283
|
-
},
|
|
284
|
-
wordBreak: (state, value) => {
|
|
285
|
-
state.props.wordBreak = value;
|
|
286
|
-
this.invalidateLayoutCache(state);
|
|
287
|
-
},
|
|
288
|
-
debug: (state, value) => {
|
|
289
|
-
state.props.debug = value;
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
override canRenderFont(props: TrFontProps): boolean {
|
|
295
|
-
// TODO: Support matching on font stretch, weight and style (if/when needed)
|
|
296
|
-
// For now we just match on the font family name
|
|
297
|
-
// '$$SDF_FAILURE_TEST$$' is used to test the 'failure' event coming from text
|
|
298
|
-
const { fontFamily } = props;
|
|
299
|
-
return (
|
|
300
|
-
fontFamily in this.ssdfFontFamilies ||
|
|
301
|
-
fontFamily in this.msdfFontFamilies ||
|
|
302
|
-
fontFamily === '$$SDF_FAILURE_TEST$$'
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
override isFontFaceSupported(fontFace: TrFontFace): boolean {
|
|
307
|
-
return fontFace instanceof SdfTrFontFace;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
override addFontFace(fontFace: TrFontFace): void {
|
|
311
|
-
// Make sure the font face is an SDF font face (it should have already passed
|
|
312
|
-
// the `isFontFaceSupported` check)
|
|
313
|
-
assertTruthy(fontFace instanceof SdfTrFontFace);
|
|
314
|
-
const familyName = fontFace.fontFamily;
|
|
315
|
-
const fontFamiles =
|
|
316
|
-
fontFace.type === 'ssdf'
|
|
317
|
-
? this.ssdfFontFamilies
|
|
318
|
-
: fontFace.type === 'msdf'
|
|
319
|
-
? this.msdfFontFamilies
|
|
320
|
-
: undefined;
|
|
321
|
-
if (!fontFamiles) {
|
|
322
|
-
console.warn(`Invalid font face type: ${fontFace.type as string}`);
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
let faceSet = fontFamiles[familyName];
|
|
326
|
-
if (!faceSet) {
|
|
327
|
-
faceSet = new Set();
|
|
328
|
-
fontFamiles[familyName] = faceSet;
|
|
329
|
-
}
|
|
330
|
-
faceSet.add(fontFace);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
override createState(props: TrProps): SdfTextRendererState {
|
|
334
|
-
return {
|
|
335
|
-
props,
|
|
336
|
-
status: 'initialState',
|
|
337
|
-
updateScheduled: false,
|
|
338
|
-
emitter: new EventEmitter(),
|
|
339
|
-
lineCache: [],
|
|
340
|
-
forceFullLayoutCalc: false,
|
|
341
|
-
renderWindow: {
|
|
342
|
-
screen: {
|
|
343
|
-
x1: 0,
|
|
344
|
-
y1: 0,
|
|
345
|
-
x2: 0,
|
|
346
|
-
y2: 0,
|
|
347
|
-
},
|
|
348
|
-
sdf: {
|
|
349
|
-
x1: 0,
|
|
350
|
-
y1: 0,
|
|
351
|
-
x2: 0,
|
|
352
|
-
y2: 0,
|
|
353
|
-
},
|
|
354
|
-
firstLineIdx: 0,
|
|
355
|
-
numLines: 0,
|
|
356
|
-
valid: false,
|
|
357
|
-
},
|
|
358
|
-
elementBounds: {
|
|
359
|
-
x1: 0,
|
|
360
|
-
y1: 0,
|
|
361
|
-
x2: 0,
|
|
362
|
-
y2: 0,
|
|
363
|
-
valid: false,
|
|
364
|
-
},
|
|
365
|
-
clippingRect: {
|
|
366
|
-
x: 0,
|
|
367
|
-
y: 0,
|
|
368
|
-
width: 0,
|
|
369
|
-
height: 0,
|
|
370
|
-
valid: false,
|
|
371
|
-
},
|
|
372
|
-
bufferNumFloats: 0,
|
|
373
|
-
bufferNumQuads: 0,
|
|
374
|
-
vertexBuffer: undefined,
|
|
375
|
-
webGlBuffers: null,
|
|
376
|
-
bufferUploaded: false,
|
|
377
|
-
textH: undefined,
|
|
378
|
-
textW: undefined,
|
|
379
|
-
distanceRange: 0,
|
|
380
|
-
trFontFace: undefined,
|
|
381
|
-
isRenderable: false,
|
|
382
|
-
resLineHeight: undefined,
|
|
383
|
-
debugData: {
|
|
384
|
-
updateCount: 0,
|
|
385
|
-
layoutCount: 0,
|
|
386
|
-
lastLayoutNumCharacters: 0,
|
|
387
|
-
layoutSum: 0,
|
|
388
|
-
drawSum: 0,
|
|
389
|
-
drawCount: 0,
|
|
390
|
-
bufferSize: 0,
|
|
391
|
-
},
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
override updateState(state: SdfTextRendererState): void {
|
|
396
|
-
let { trFontFace } = state;
|
|
397
|
-
const { textH, lineCache, debugData, forceFullLayoutCalc } = state;
|
|
398
|
-
debugData.updateCount++;
|
|
399
|
-
|
|
400
|
-
// On the first update call we need to set the status to loading
|
|
401
|
-
if (state.status === 'initialState') {
|
|
402
|
-
this.setStatus(state, 'loading');
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// Resolve font face if we haven't yet
|
|
406
|
-
if (trFontFace === undefined) {
|
|
407
|
-
trFontFace = this.resolveFontFace(state.props);
|
|
408
|
-
state.trFontFace = trFontFace;
|
|
409
|
-
if (trFontFace === undefined) {
|
|
410
|
-
const msg = `SdfTextRenderer: Could not resolve font face for family: '${state.props.fontFamily}'`;
|
|
411
|
-
console.error(msg);
|
|
412
|
-
this.setStatus(state, 'failed', new Error(msg));
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
trFontFace.texture.setRenderableOwner(state, true);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// If the font hasn't been loaded yet, stop here.
|
|
419
|
-
// Listen for the 'loaded' event and forward fontLoaded event
|
|
420
|
-
if (trFontFace.loaded === false) {
|
|
421
|
-
trFontFace.once('loaded', () => {
|
|
422
|
-
this.scheduleUpdateState(state);
|
|
423
|
-
});
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
// If the font is loaded then so should the data
|
|
428
|
-
assertTruthy(trFontFace.data, 'Font face data should be loaded');
|
|
429
|
-
assertTruthy(trFontFace.metrics, 'Font face metrics should be loaded');
|
|
430
|
-
|
|
431
|
-
const {
|
|
432
|
-
text,
|
|
433
|
-
fontSize,
|
|
434
|
-
x,
|
|
435
|
-
y,
|
|
436
|
-
contain,
|
|
437
|
-
width,
|
|
438
|
-
height,
|
|
439
|
-
verticalAlign,
|
|
440
|
-
scrollable,
|
|
441
|
-
overflowSuffix,
|
|
442
|
-
wordBreak,
|
|
443
|
-
maxLines,
|
|
444
|
-
} = state.props;
|
|
445
|
-
|
|
446
|
-
// scrollY only has an effect when contain === 'both' and scrollable === true
|
|
447
|
-
const scrollY = contain === 'both' && scrollable ? state.props.scrollY : 0;
|
|
448
|
-
|
|
449
|
-
const { renderWindow } = state;
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* The font size of the SDF font face (the basis for SDF space units)
|
|
453
|
-
*/
|
|
454
|
-
const sdfFontSize = trFontFace.data.info.size;
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Divide screen space units by this to get the SDF space units
|
|
458
|
-
* Mulitple SDF space units by this to get screen space units
|
|
459
|
-
*/
|
|
460
|
-
const fontSizeRatio = fontSize / sdfFontSize;
|
|
461
|
-
|
|
462
|
-
// If not already resolved, resolve the line height and store it in the state
|
|
463
|
-
let resLineHeight = state.resLineHeight;
|
|
464
|
-
if (resLineHeight === undefined) {
|
|
465
|
-
const lineHeight = state.props.lineHeight;
|
|
466
|
-
// If lineHeight is undefined, use the maxCharHeight from the font face
|
|
467
|
-
if (lineHeight === undefined) {
|
|
468
|
-
resLineHeight = calcDefaultLineHeight(trFontFace.metrics, fontSize);
|
|
469
|
-
} else {
|
|
470
|
-
resLineHeight = lineHeight;
|
|
471
|
-
}
|
|
472
|
-
state.resLineHeight = resLineHeight;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// Needed in renderWindow calculation
|
|
476
|
-
const sdfLineHeight = resLineHeight / fontSizeRatio;
|
|
477
|
-
|
|
478
|
-
state.distanceRange =
|
|
479
|
-
fontSizeRatio * trFontFace.data.distanceField.distanceRange;
|
|
480
|
-
|
|
481
|
-
// Allocate buffers if needed
|
|
482
|
-
const neededLength = text.length * FLOATS_PER_GLYPH;
|
|
483
|
-
let vertexBuffer = state.vertexBuffer;
|
|
484
|
-
if (!vertexBuffer || vertexBuffer.length < neededLength) {
|
|
485
|
-
vertexBuffer = new Float32Array(neededLength * 2);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
const elementBounds = state.elementBounds;
|
|
489
|
-
if (!elementBounds.valid) {
|
|
490
|
-
this.setElementBoundsX(state);
|
|
491
|
-
this.setElementBoundsY(state);
|
|
492
|
-
elementBounds.valid = true;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// Return early if we're still viewing inside the established render window
|
|
496
|
-
// No need to re-render what we've already rendered
|
|
497
|
-
// (Only if there's an established renderWindow and we're not suppressing early exit)
|
|
498
|
-
if (!forceFullLayoutCalc && renderWindow.valid) {
|
|
499
|
-
const rwScreen = renderWindow.screen;
|
|
500
|
-
if (
|
|
501
|
-
x + rwScreen.x1 <= elementBounds.x1 &&
|
|
502
|
-
x + rwScreen.x2 >= elementBounds.x2 &&
|
|
503
|
-
y - scrollY + rwScreen.y1 <= elementBounds.y1 &&
|
|
504
|
-
y - scrollY + rwScreen.y2 >= elementBounds.y2
|
|
505
|
-
) {
|
|
506
|
-
this.setStatus(state, 'loaded');
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
// Otherwise invalidate the renderWindow so it can be redone
|
|
510
|
-
renderWindow.valid = false;
|
|
511
|
-
this.setStatus(state, 'loading');
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
const { offsetY, textAlign } = state.props;
|
|
515
|
-
|
|
516
|
-
// Create a new renderWindow if needed
|
|
517
|
-
if (!renderWindow.valid) {
|
|
518
|
-
const isPossiblyOnScreen = boundsOverlap(
|
|
519
|
-
elementBounds,
|
|
520
|
-
this.rendererBounds,
|
|
521
|
-
);
|
|
522
|
-
|
|
523
|
-
if (!isPossiblyOnScreen) {
|
|
524
|
-
// If the element is not possibly on screen, we can skip the layout and rendering completely
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
setRenderWindow(
|
|
529
|
-
renderWindow,
|
|
530
|
-
x,
|
|
531
|
-
y,
|
|
532
|
-
scrollY,
|
|
533
|
-
resLineHeight,
|
|
534
|
-
contain === 'both' ? elementBounds.y2 - elementBounds.y1 : 0,
|
|
535
|
-
elementBounds,
|
|
536
|
-
fontSizeRatio,
|
|
537
|
-
);
|
|
538
|
-
// console.log('newRenderWindow', renderWindow);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
const start = getStartConditions(
|
|
542
|
-
sdfFontSize,
|
|
543
|
-
sdfLineHeight,
|
|
544
|
-
trFontFace,
|
|
545
|
-
verticalAlign,
|
|
546
|
-
offsetY,
|
|
547
|
-
fontSizeRatio,
|
|
548
|
-
renderWindow,
|
|
549
|
-
lineCache,
|
|
550
|
-
textH,
|
|
551
|
-
);
|
|
552
|
-
|
|
553
|
-
if (!start) {
|
|
554
|
-
// Nothing to render, return early, but still mark as loaded (since the text is just scrolled
|
|
555
|
-
// out of view)
|
|
556
|
-
this.setStatus(state, 'loaded');
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const { letterSpacing } = state.props;
|
|
561
|
-
|
|
562
|
-
const out2 = layoutText(
|
|
563
|
-
start.lineIndex,
|
|
564
|
-
start.sdfX,
|
|
565
|
-
start.sdfY,
|
|
566
|
-
text,
|
|
567
|
-
textAlign,
|
|
568
|
-
width,
|
|
569
|
-
height,
|
|
570
|
-
fontSize,
|
|
571
|
-
resLineHeight,
|
|
572
|
-
letterSpacing,
|
|
573
|
-
vertexBuffer,
|
|
574
|
-
contain,
|
|
575
|
-
lineCache,
|
|
576
|
-
renderWindow.sdf,
|
|
577
|
-
trFontFace,
|
|
578
|
-
forceFullLayoutCalc,
|
|
579
|
-
scrollable,
|
|
580
|
-
overflowSuffix,
|
|
581
|
-
wordBreak,
|
|
582
|
-
maxLines,
|
|
583
|
-
);
|
|
584
|
-
|
|
585
|
-
state.bufferUploaded = false;
|
|
586
|
-
state.bufferNumFloats = out2.bufferNumFloats;
|
|
587
|
-
state.bufferNumQuads = out2.bufferNumQuads;
|
|
588
|
-
state.vertexBuffer = vertexBuffer;
|
|
589
|
-
state.renderWindow = renderWindow;
|
|
590
|
-
debugData.lastLayoutNumCharacters = out2.layoutNumCharacters;
|
|
591
|
-
debugData.bufferSize = vertexBuffer.byteLength;
|
|
592
|
-
|
|
593
|
-
// If we didn't exit early, we know we have completely computed w/h
|
|
594
|
-
if (out2.fullyProcessed) {
|
|
595
|
-
state.textW = out2.maxX * fontSizeRatio;
|
|
596
|
-
state.textH = out2.numLines * sdfLineHeight * fontSizeRatio;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// if (state.props.debug.printLayoutTime) {
|
|
600
|
-
// debugData.layoutSum += performance.now() - updateStartTime;
|
|
601
|
-
// debugData.layoutCount++;
|
|
602
|
-
// }
|
|
603
|
-
this.setStatus(state, 'loaded');
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
override renderQuads(node: CoreTextNode): void {
|
|
607
|
-
const state = node.trState as SdfTextRendererState;
|
|
608
|
-
if (!state.vertexBuffer) {
|
|
609
|
-
// Nothing to draw
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const renderer = this.stage.renderer;
|
|
614
|
-
assertTruthy(renderer instanceof WebGlRenderer);
|
|
615
|
-
|
|
616
|
-
const { fontSize, color, contain, scrollable, zIndex, debug } = state.props;
|
|
617
|
-
|
|
618
|
-
// scrollY only has an effect when contain === 'both' and scrollable === true
|
|
619
|
-
const scrollY = contain === 'both' && scrollable ? state.props.scrollY : 0;
|
|
620
|
-
|
|
621
|
-
const {
|
|
622
|
-
textW = 0,
|
|
623
|
-
textH = 0,
|
|
624
|
-
distanceRange,
|
|
625
|
-
vertexBuffer,
|
|
626
|
-
bufferUploaded,
|
|
627
|
-
trFontFace,
|
|
628
|
-
elementBounds,
|
|
629
|
-
} = state;
|
|
630
|
-
|
|
631
|
-
let { webGlBuffers } = state;
|
|
632
|
-
|
|
633
|
-
if (!webGlBuffers) {
|
|
634
|
-
const glw = renderer.glw;
|
|
635
|
-
const stride = 4 * Float32Array.BYTES_PER_ELEMENT;
|
|
636
|
-
const webGlBuffer = glw.createBuffer();
|
|
637
|
-
assertTruthy(webGlBuffer);
|
|
638
|
-
state.webGlBuffers = new BufferCollection([
|
|
639
|
-
{
|
|
640
|
-
buffer: webGlBuffer,
|
|
641
|
-
attributes: {
|
|
642
|
-
a_position: {
|
|
643
|
-
name: 'a_position',
|
|
644
|
-
size: 2, // 2 components per iteration
|
|
645
|
-
type: glw.FLOAT, // the data is 32bit floats
|
|
646
|
-
normalized: false, // don't normalize the data
|
|
647
|
-
stride, // 0 = move forward size * sizeof(type) each iteration to get the next position
|
|
648
|
-
offset: 0, // start at the beginning of the buffer
|
|
649
|
-
},
|
|
650
|
-
a_textureCoords: {
|
|
651
|
-
name: 'a_textureCoords',
|
|
652
|
-
size: 2,
|
|
653
|
-
type: glw.FLOAT,
|
|
654
|
-
normalized: false,
|
|
655
|
-
stride,
|
|
656
|
-
offset: 2 * Float32Array.BYTES_PER_ELEMENT,
|
|
657
|
-
},
|
|
658
|
-
},
|
|
659
|
-
},
|
|
660
|
-
]);
|
|
661
|
-
state.bufferUploaded = false;
|
|
662
|
-
assertTruthy(state.webGlBuffers);
|
|
663
|
-
webGlBuffers = state.webGlBuffers;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
if (!bufferUploaded) {
|
|
667
|
-
const glw = renderer.glw;
|
|
668
|
-
|
|
669
|
-
const buffer = webGlBuffers?.getBuffer('a_textureCoords') ?? null;
|
|
670
|
-
glw.arrayBufferData(buffer, vertexBuffer, glw.STATIC_DRAW);
|
|
671
|
-
state.bufferUploaded = true;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
assertTruthy(trFontFace);
|
|
675
|
-
if (scrollable && contain === 'both') {
|
|
676
|
-
assertTruthy(elementBounds.valid);
|
|
677
|
-
const elementRect = convertBoundToRect(elementBounds, tmpRect);
|
|
678
|
-
|
|
679
|
-
if (node.clippingRect.valid) {
|
|
680
|
-
state.clippingRect.valid = true;
|
|
681
|
-
node.clippingRect = intersectRect(
|
|
682
|
-
node.clippingRect,
|
|
683
|
-
elementRect,
|
|
684
|
-
state.clippingRect,
|
|
685
|
-
);
|
|
686
|
-
} else {
|
|
687
|
-
state.clippingRect.valid = true;
|
|
688
|
-
node.clippingRect = copyRect(elementRect, state.clippingRect);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
const renderOp = new WebGlRenderOp(
|
|
693
|
-
renderer,
|
|
694
|
-
{
|
|
695
|
-
sdfShaderProps: {
|
|
696
|
-
transform: node.globalTransform!.getFloatArr(),
|
|
697
|
-
color: mergeColorAlpha(color, node.worldAlpha),
|
|
698
|
-
size: fontSize / (trFontFace.data?.info.size || 0),
|
|
699
|
-
scrollY,
|
|
700
|
-
distanceRange,
|
|
701
|
-
debug: debug.sdfShaderDebug,
|
|
702
|
-
},
|
|
703
|
-
sdfBuffers: state.webGlBuffers as BufferCollection,
|
|
704
|
-
shader: this.sdfShader,
|
|
705
|
-
alpha: node.worldAlpha,
|
|
706
|
-
clippingRect: node.clippingRect,
|
|
707
|
-
height: textH,
|
|
708
|
-
width: textW,
|
|
709
|
-
rtt: false,
|
|
710
|
-
parentHasRenderTexture: node.parentHasRenderTexture,
|
|
711
|
-
framebufferDimensions:
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
//
|
|
729
|
-
//
|
|
730
|
-
// visibleRect.
|
|
731
|
-
//
|
|
732
|
-
//
|
|
733
|
-
|
|
734
|
-
//
|
|
735
|
-
//
|
|
736
|
-
|
|
737
|
-
//
|
|
738
|
-
//
|
|
739
|
-
//
|
|
740
|
-
|
|
741
|
-
//
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
//
|
|
745
|
-
|
|
746
|
-
//
|
|
747
|
-
//
|
|
748
|
-
//
|
|
749
|
-
// elementRect.
|
|
750
|
-
//
|
|
751
|
-
//
|
|
752
|
-
|
|
753
|
-
//
|
|
754
|
-
//
|
|
755
|
-
|
|
756
|
-
//
|
|
757
|
-
//
|
|
758
|
-
//
|
|
759
|
-
// visibleRect.
|
|
760
|
-
//
|
|
761
|
-
//
|
|
762
|
-
|
|
763
|
-
//
|
|
764
|
-
//
|
|
765
|
-
|
|
766
|
-
//
|
|
767
|
-
//
|
|
768
|
-
//
|
|
769
|
-
//
|
|
770
|
-
//
|
|
771
|
-
//
|
|
772
|
-
//
|
|
773
|
-
//
|
|
774
|
-
//
|
|
775
|
-
//
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
* @
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
state.
|
|
828
|
-
state.
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
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
|
+
import {
|
|
21
|
+
type Bound,
|
|
22
|
+
type Rect,
|
|
23
|
+
createBound,
|
|
24
|
+
type BoundWithValid,
|
|
25
|
+
intersectRect,
|
|
26
|
+
type RectWithValid,
|
|
27
|
+
copyRect,
|
|
28
|
+
boundsOverlap,
|
|
29
|
+
convertBoundToRect,
|
|
30
|
+
} from '../../../lib/utils.js';
|
|
31
|
+
import {
|
|
32
|
+
TextRenderer,
|
|
33
|
+
type TrProps,
|
|
34
|
+
type TextRendererState,
|
|
35
|
+
type TrFontProps,
|
|
36
|
+
type TrPropSetters,
|
|
37
|
+
} from '../TextRenderer.js';
|
|
38
|
+
import { SdfTrFontFace } from '../../font-face-types/SdfTrFontFace/SdfTrFontFace.js';
|
|
39
|
+
import { FLOATS_PER_GLYPH } from './internal/constants.js';
|
|
40
|
+
import { getStartConditions } from './internal/getStartConditions.js';
|
|
41
|
+
import { layoutText } from './internal/layoutText.js';
|
|
42
|
+
import {
|
|
43
|
+
setRenderWindow,
|
|
44
|
+
type SdfRenderWindow,
|
|
45
|
+
} from './internal/setRenderWindow.js';
|
|
46
|
+
import type { TrFontFace } from '../../font-face-types/TrFontFace.js';
|
|
47
|
+
import { type FontFamilyMap } from '../../TrFontManager.js';
|
|
48
|
+
import { assertTruthy, mergeColorAlpha } from '../../../../utils.js';
|
|
49
|
+
import type { Stage } from '../../../Stage.js';
|
|
50
|
+
import { WebGlRenderOp } from '../../../renderers/webgl/WebGlRenderOp.js';
|
|
51
|
+
import { BufferCollection } from '../../../renderers/webgl/internal/BufferCollection.js';
|
|
52
|
+
import { Sdf, type SdfShaderProps } from '../../../shaders/webgl/SdfShader.js';
|
|
53
|
+
import type { WebGlCtxTexture } from '../../../renderers/webgl/WebGlCtxTexture.js';
|
|
54
|
+
import { EventEmitter } from '../../../../common/EventEmitter.js';
|
|
55
|
+
import type { Matrix3d } from '../../../lib/Matrix3d.js';
|
|
56
|
+
import type { Dimensions } from '../../../../common/CommonTypes.js';
|
|
57
|
+
import { WebGlRenderer } from '../../../renderers/webgl/WebGlRenderer.js';
|
|
58
|
+
import { calcDefaultLineHeight } from '../../TextRenderingUtils.js';
|
|
59
|
+
import type { WebGlShaderProgram } from '../../../renderers/webgl/WebGlShaderProgram.js';
|
|
60
|
+
import type { WebGlShaderNode } from '../../../renderers/webgl/WebGlShaderNode.js';
|
|
61
|
+
import type { CoreTextNode } from '../../../CoreTextNode.js';
|
|
62
|
+
|
|
63
|
+
declare module '../TextRenderer.js' {
|
|
64
|
+
interface TextRendererMap {
|
|
65
|
+
sdf: SdfTextRenderer;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Add prefixed SDF-specific props to TextRendererDebugProps
|
|
69
|
+
interface TextRendererDebugProps {
|
|
70
|
+
sdfShaderDebug: boolean;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface LineCacheItem {
|
|
75
|
+
codepointIndex: number;
|
|
76
|
+
maxY: number;
|
|
77
|
+
maxX: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface SdfTextRendererState extends TextRendererState {
|
|
81
|
+
/**
|
|
82
|
+
* Cache for layout resume points indexed by the `curY` for each line
|
|
83
|
+
* in the render sequence.
|
|
84
|
+
*
|
|
85
|
+
* Allows faster rendering by skipping parts of the layout loop that are
|
|
86
|
+
* outside of the renderWindow.
|
|
87
|
+
*/
|
|
88
|
+
lineCache: LineCacheItem[];
|
|
89
|
+
|
|
90
|
+
renderWindow: SdfRenderWindow;
|
|
91
|
+
|
|
92
|
+
elementBounds: BoundWithValid;
|
|
93
|
+
|
|
94
|
+
clippingRect: RectWithValid;
|
|
95
|
+
|
|
96
|
+
bufferNumFloats: number;
|
|
97
|
+
|
|
98
|
+
bufferNumQuads: number;
|
|
99
|
+
|
|
100
|
+
vertexBuffer: Float32Array | undefined;
|
|
101
|
+
|
|
102
|
+
webGlBuffers: BufferCollection | null;
|
|
103
|
+
|
|
104
|
+
bufferUploaded: boolean;
|
|
105
|
+
|
|
106
|
+
distanceRange: number;
|
|
107
|
+
|
|
108
|
+
trFontFace: SdfTrFontFace | undefined;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Resolved line height in logical screen pixel units
|
|
112
|
+
*/
|
|
113
|
+
resLineHeight: number | undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Ephemeral rect object used for calculations
|
|
118
|
+
*/
|
|
119
|
+
const tmpRect: Rect = {
|
|
120
|
+
x: 0,
|
|
121
|
+
y: 0,
|
|
122
|
+
width: 0,
|
|
123
|
+
height: 0,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Singleton class for rendering text using signed distance fields.
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* SdfTextRenderer supports both single-channel and multi-channel signed distance fields.
|
|
131
|
+
*/
|
|
132
|
+
export class SdfTextRenderer extends TextRenderer<SdfTextRendererState> {
|
|
133
|
+
/**
|
|
134
|
+
* Map of font family names to a set of font faces.
|
|
135
|
+
*/
|
|
136
|
+
private ssdfFontFamilies: FontFamilyMap = {};
|
|
137
|
+
private msdfFontFamilies: FontFamilyMap = {};
|
|
138
|
+
private fontFamilyArray: FontFamilyMap[] = [
|
|
139
|
+
this.ssdfFontFamilies,
|
|
140
|
+
this.msdfFontFamilies,
|
|
141
|
+
];
|
|
142
|
+
private sdfShader: WebGlShaderNode;
|
|
143
|
+
private rendererBounds: Bound;
|
|
144
|
+
|
|
145
|
+
public type: 'canvas' | 'sdf' = 'sdf';
|
|
146
|
+
|
|
147
|
+
constructor(stage: Stage) {
|
|
148
|
+
super(stage);
|
|
149
|
+
this.stage.shManager.registerShaderType('Sdf', Sdf);
|
|
150
|
+
this.sdfShader = this.stage.shManager.createShader(
|
|
151
|
+
'Sdf',
|
|
152
|
+
) as WebGlShaderNode;
|
|
153
|
+
this.rendererBounds = {
|
|
154
|
+
x1: 0,
|
|
155
|
+
y1: 0,
|
|
156
|
+
x2: this.stage.options.appWidth,
|
|
157
|
+
y2: this.stage.options.appHeight,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//#region Overrides
|
|
162
|
+
getPropertySetters(): Partial<TrPropSetters<SdfTextRendererState>> {
|
|
163
|
+
return {
|
|
164
|
+
fontFamily: (state, value) => {
|
|
165
|
+
state.props.fontFamily = value;
|
|
166
|
+
this.releaseFontFace(state);
|
|
167
|
+
this.invalidateLayoutCache(state);
|
|
168
|
+
},
|
|
169
|
+
fontWeight: (state, value) => {
|
|
170
|
+
state.props.fontWeight = value;
|
|
171
|
+
this.releaseFontFace(state);
|
|
172
|
+
this.invalidateLayoutCache(state);
|
|
173
|
+
},
|
|
174
|
+
fontStyle: (state, value) => {
|
|
175
|
+
state.props.fontStyle = value;
|
|
176
|
+
this.releaseFontFace(state);
|
|
177
|
+
this.invalidateLayoutCache(state);
|
|
178
|
+
},
|
|
179
|
+
fontStretch: (state, value) => {
|
|
180
|
+
state.props.fontStretch = value;
|
|
181
|
+
this.releaseFontFace(state);
|
|
182
|
+
this.invalidateLayoutCache(state);
|
|
183
|
+
},
|
|
184
|
+
fontSize: (state, value) => {
|
|
185
|
+
state.props.fontSize = value;
|
|
186
|
+
this.invalidateLayoutCache(state);
|
|
187
|
+
},
|
|
188
|
+
text: (state, value) => {
|
|
189
|
+
state.props.text = value;
|
|
190
|
+
this.invalidateLayoutCache(state);
|
|
191
|
+
},
|
|
192
|
+
textAlign: (state, value) => {
|
|
193
|
+
state.props.textAlign = value;
|
|
194
|
+
this.invalidateLayoutCache(state);
|
|
195
|
+
},
|
|
196
|
+
color: (state, value) => {
|
|
197
|
+
state.props.color = value;
|
|
198
|
+
},
|
|
199
|
+
x: (state, value) => {
|
|
200
|
+
state.props.x = value;
|
|
201
|
+
if (state.elementBounds.valid) {
|
|
202
|
+
this.setElementBoundsX(state);
|
|
203
|
+
// Only schedule an update if the text is not already rendered
|
|
204
|
+
// (renderWindow is invalid) and the element possibly overlaps the screen
|
|
205
|
+
// This is to avoid unnecessary updates when we know text is off-screen
|
|
206
|
+
if (
|
|
207
|
+
!state.renderWindow.valid &&
|
|
208
|
+
boundsOverlap(state.elementBounds, this.rendererBounds)
|
|
209
|
+
) {
|
|
210
|
+
this.scheduleUpdateState(state);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
y: (state, value) => {
|
|
215
|
+
state.props.y = value;
|
|
216
|
+
if (state.elementBounds.valid) {
|
|
217
|
+
this.setElementBoundsY(state);
|
|
218
|
+
// See x() for explanation
|
|
219
|
+
if (
|
|
220
|
+
!state.renderWindow.valid &&
|
|
221
|
+
boundsOverlap(state.elementBounds, this.rendererBounds)
|
|
222
|
+
) {
|
|
223
|
+
this.scheduleUpdateState(state);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
contain: (state, value) => {
|
|
228
|
+
state.props.contain = value;
|
|
229
|
+
this.invalidateLayoutCache(state);
|
|
230
|
+
},
|
|
231
|
+
width: (state, value) => {
|
|
232
|
+
state.props.width = value;
|
|
233
|
+
// Only invalidate layout cache if we're containing in the horizontal direction
|
|
234
|
+
if (state.props.contain !== 'none') {
|
|
235
|
+
this.invalidateLayoutCache(state);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
height: (state, value) => {
|
|
239
|
+
state.props.height = value;
|
|
240
|
+
// Only invalidate layout cache if we're containing in the vertical direction
|
|
241
|
+
if (state.props.contain === 'both') {
|
|
242
|
+
this.invalidateLayoutCache(state);
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
offsetY: (state, value) => {
|
|
246
|
+
state.props.offsetY = value;
|
|
247
|
+
this.invalidateLayoutCache(state);
|
|
248
|
+
},
|
|
249
|
+
scrollable: (state, value) => {
|
|
250
|
+
state.props.scrollable = value;
|
|
251
|
+
this.invalidateLayoutCache(state);
|
|
252
|
+
},
|
|
253
|
+
scrollY: (state, value) => {
|
|
254
|
+
state.props.scrollY = value;
|
|
255
|
+
// Scrolling doesn't need to invalidate any caches, but it does need to
|
|
256
|
+
// schedule an update
|
|
257
|
+
this.scheduleUpdateState(state);
|
|
258
|
+
},
|
|
259
|
+
letterSpacing: (state, value) => {
|
|
260
|
+
state.props.letterSpacing = value;
|
|
261
|
+
this.invalidateLayoutCache(state);
|
|
262
|
+
},
|
|
263
|
+
lineHeight: (state, value) => {
|
|
264
|
+
state.props.lineHeight = value;
|
|
265
|
+
state.resLineHeight = undefined;
|
|
266
|
+
this.invalidateLayoutCache(state);
|
|
267
|
+
},
|
|
268
|
+
maxLines: (state, value) => {
|
|
269
|
+
state.props.maxLines = value;
|
|
270
|
+
this.invalidateLayoutCache(state);
|
|
271
|
+
},
|
|
272
|
+
textBaseline: (state, value) => {
|
|
273
|
+
state.props.textBaseline = value;
|
|
274
|
+
this.invalidateLayoutCache(state);
|
|
275
|
+
},
|
|
276
|
+
verticalAlign: (state, value) => {
|
|
277
|
+
state.props.verticalAlign = value;
|
|
278
|
+
this.invalidateLayoutCache(state);
|
|
279
|
+
},
|
|
280
|
+
overflowSuffix: (state, value) => {
|
|
281
|
+
state.props.overflowSuffix = value;
|
|
282
|
+
this.invalidateLayoutCache(state);
|
|
283
|
+
},
|
|
284
|
+
wordBreak: (state, value) => {
|
|
285
|
+
state.props.wordBreak = value;
|
|
286
|
+
this.invalidateLayoutCache(state);
|
|
287
|
+
},
|
|
288
|
+
debug: (state, value) => {
|
|
289
|
+
state.props.debug = value;
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
override canRenderFont(props: TrFontProps): boolean {
|
|
295
|
+
// TODO: Support matching on font stretch, weight and style (if/when needed)
|
|
296
|
+
// For now we just match on the font family name
|
|
297
|
+
// '$$SDF_FAILURE_TEST$$' is used to test the 'failure' event coming from text
|
|
298
|
+
const { fontFamily } = props;
|
|
299
|
+
return (
|
|
300
|
+
fontFamily in this.ssdfFontFamilies ||
|
|
301
|
+
fontFamily in this.msdfFontFamilies ||
|
|
302
|
+
fontFamily === '$$SDF_FAILURE_TEST$$'
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
override isFontFaceSupported(fontFace: TrFontFace): boolean {
|
|
307
|
+
return fontFace instanceof SdfTrFontFace;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
override addFontFace(fontFace: TrFontFace): void {
|
|
311
|
+
// Make sure the font face is an SDF font face (it should have already passed
|
|
312
|
+
// the `isFontFaceSupported` check)
|
|
313
|
+
assertTruthy(fontFace instanceof SdfTrFontFace);
|
|
314
|
+
const familyName = fontFace.fontFamily;
|
|
315
|
+
const fontFamiles =
|
|
316
|
+
fontFace.type === 'ssdf'
|
|
317
|
+
? this.ssdfFontFamilies
|
|
318
|
+
: fontFace.type === 'msdf'
|
|
319
|
+
? this.msdfFontFamilies
|
|
320
|
+
: undefined;
|
|
321
|
+
if (!fontFamiles) {
|
|
322
|
+
console.warn(`Invalid font face type: ${fontFace.type as string}`);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
let faceSet = fontFamiles[familyName];
|
|
326
|
+
if (!faceSet) {
|
|
327
|
+
faceSet = new Set();
|
|
328
|
+
fontFamiles[familyName] = faceSet;
|
|
329
|
+
}
|
|
330
|
+
faceSet.add(fontFace);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
override createState(props: TrProps): SdfTextRendererState {
|
|
334
|
+
return {
|
|
335
|
+
props,
|
|
336
|
+
status: 'initialState',
|
|
337
|
+
updateScheduled: false,
|
|
338
|
+
emitter: new EventEmitter(),
|
|
339
|
+
lineCache: [],
|
|
340
|
+
forceFullLayoutCalc: false,
|
|
341
|
+
renderWindow: {
|
|
342
|
+
screen: {
|
|
343
|
+
x1: 0,
|
|
344
|
+
y1: 0,
|
|
345
|
+
x2: 0,
|
|
346
|
+
y2: 0,
|
|
347
|
+
},
|
|
348
|
+
sdf: {
|
|
349
|
+
x1: 0,
|
|
350
|
+
y1: 0,
|
|
351
|
+
x2: 0,
|
|
352
|
+
y2: 0,
|
|
353
|
+
},
|
|
354
|
+
firstLineIdx: 0,
|
|
355
|
+
numLines: 0,
|
|
356
|
+
valid: false,
|
|
357
|
+
},
|
|
358
|
+
elementBounds: {
|
|
359
|
+
x1: 0,
|
|
360
|
+
y1: 0,
|
|
361
|
+
x2: 0,
|
|
362
|
+
y2: 0,
|
|
363
|
+
valid: false,
|
|
364
|
+
},
|
|
365
|
+
clippingRect: {
|
|
366
|
+
x: 0,
|
|
367
|
+
y: 0,
|
|
368
|
+
width: 0,
|
|
369
|
+
height: 0,
|
|
370
|
+
valid: false,
|
|
371
|
+
},
|
|
372
|
+
bufferNumFloats: 0,
|
|
373
|
+
bufferNumQuads: 0,
|
|
374
|
+
vertexBuffer: undefined,
|
|
375
|
+
webGlBuffers: null,
|
|
376
|
+
bufferUploaded: false,
|
|
377
|
+
textH: undefined,
|
|
378
|
+
textW: undefined,
|
|
379
|
+
distanceRange: 0,
|
|
380
|
+
trFontFace: undefined,
|
|
381
|
+
isRenderable: false,
|
|
382
|
+
resLineHeight: undefined,
|
|
383
|
+
debugData: {
|
|
384
|
+
updateCount: 0,
|
|
385
|
+
layoutCount: 0,
|
|
386
|
+
lastLayoutNumCharacters: 0,
|
|
387
|
+
layoutSum: 0,
|
|
388
|
+
drawSum: 0,
|
|
389
|
+
drawCount: 0,
|
|
390
|
+
bufferSize: 0,
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
override updateState(state: SdfTextRendererState): void {
|
|
396
|
+
let { trFontFace } = state;
|
|
397
|
+
const { textH, lineCache, debugData, forceFullLayoutCalc } = state;
|
|
398
|
+
debugData.updateCount++;
|
|
399
|
+
|
|
400
|
+
// On the first update call we need to set the status to loading
|
|
401
|
+
if (state.status === 'initialState') {
|
|
402
|
+
this.setStatus(state, 'loading');
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Resolve font face if we haven't yet
|
|
406
|
+
if (trFontFace === undefined) {
|
|
407
|
+
trFontFace = this.resolveFontFace(state.props);
|
|
408
|
+
state.trFontFace = trFontFace;
|
|
409
|
+
if (trFontFace === undefined) {
|
|
410
|
+
const msg = `SdfTextRenderer: Could not resolve font face for family: '${state.props.fontFamily}'`;
|
|
411
|
+
console.error(msg);
|
|
412
|
+
this.setStatus(state, 'failed', new Error(msg));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
trFontFace.texture.setRenderableOwner(state, true);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// If the font hasn't been loaded yet, stop here.
|
|
419
|
+
// Listen for the 'loaded' event and forward fontLoaded event
|
|
420
|
+
if (trFontFace.loaded === false) {
|
|
421
|
+
trFontFace.once('loaded', () => {
|
|
422
|
+
this.scheduleUpdateState(state);
|
|
423
|
+
});
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// If the font is loaded then so should the data
|
|
428
|
+
assertTruthy(trFontFace.data, 'Font face data should be loaded');
|
|
429
|
+
assertTruthy(trFontFace.metrics, 'Font face metrics should be loaded');
|
|
430
|
+
|
|
431
|
+
const {
|
|
432
|
+
text,
|
|
433
|
+
fontSize,
|
|
434
|
+
x,
|
|
435
|
+
y,
|
|
436
|
+
contain,
|
|
437
|
+
width,
|
|
438
|
+
height,
|
|
439
|
+
verticalAlign,
|
|
440
|
+
scrollable,
|
|
441
|
+
overflowSuffix,
|
|
442
|
+
wordBreak,
|
|
443
|
+
maxLines,
|
|
444
|
+
} = state.props;
|
|
445
|
+
|
|
446
|
+
// scrollY only has an effect when contain === 'both' and scrollable === true
|
|
447
|
+
const scrollY = contain === 'both' && scrollable ? state.props.scrollY : 0;
|
|
448
|
+
|
|
449
|
+
const { renderWindow } = state;
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* The font size of the SDF font face (the basis for SDF space units)
|
|
453
|
+
*/
|
|
454
|
+
const sdfFontSize = trFontFace.data.info.size;
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Divide screen space units by this to get the SDF space units
|
|
458
|
+
* Mulitple SDF space units by this to get screen space units
|
|
459
|
+
*/
|
|
460
|
+
const fontSizeRatio = fontSize / sdfFontSize;
|
|
461
|
+
|
|
462
|
+
// If not already resolved, resolve the line height and store it in the state
|
|
463
|
+
let resLineHeight = state.resLineHeight;
|
|
464
|
+
if (resLineHeight === undefined) {
|
|
465
|
+
const lineHeight = state.props.lineHeight;
|
|
466
|
+
// If lineHeight is undefined, use the maxCharHeight from the font face
|
|
467
|
+
if (lineHeight === undefined) {
|
|
468
|
+
resLineHeight = calcDefaultLineHeight(trFontFace.metrics, fontSize);
|
|
469
|
+
} else {
|
|
470
|
+
resLineHeight = lineHeight;
|
|
471
|
+
}
|
|
472
|
+
state.resLineHeight = resLineHeight;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Needed in renderWindow calculation
|
|
476
|
+
const sdfLineHeight = resLineHeight / fontSizeRatio;
|
|
477
|
+
|
|
478
|
+
state.distanceRange =
|
|
479
|
+
fontSizeRatio * trFontFace.data.distanceField.distanceRange;
|
|
480
|
+
|
|
481
|
+
// Allocate buffers if needed
|
|
482
|
+
const neededLength = text.length * FLOATS_PER_GLYPH;
|
|
483
|
+
let vertexBuffer = state.vertexBuffer;
|
|
484
|
+
if (!vertexBuffer || vertexBuffer.length < neededLength) {
|
|
485
|
+
vertexBuffer = new Float32Array(neededLength * 2);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const elementBounds = state.elementBounds;
|
|
489
|
+
if (!elementBounds.valid) {
|
|
490
|
+
this.setElementBoundsX(state);
|
|
491
|
+
this.setElementBoundsY(state);
|
|
492
|
+
elementBounds.valid = true;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Return early if we're still viewing inside the established render window
|
|
496
|
+
// No need to re-render what we've already rendered
|
|
497
|
+
// (Only if there's an established renderWindow and we're not suppressing early exit)
|
|
498
|
+
if (!forceFullLayoutCalc && renderWindow.valid) {
|
|
499
|
+
const rwScreen = renderWindow.screen;
|
|
500
|
+
if (
|
|
501
|
+
x + rwScreen.x1 <= elementBounds.x1 &&
|
|
502
|
+
x + rwScreen.x2 >= elementBounds.x2 &&
|
|
503
|
+
y - scrollY + rwScreen.y1 <= elementBounds.y1 &&
|
|
504
|
+
y - scrollY + rwScreen.y2 >= elementBounds.y2
|
|
505
|
+
) {
|
|
506
|
+
this.setStatus(state, 'loaded');
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
// Otherwise invalidate the renderWindow so it can be redone
|
|
510
|
+
renderWindow.valid = false;
|
|
511
|
+
this.setStatus(state, 'loading');
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const { offsetY, textAlign } = state.props;
|
|
515
|
+
|
|
516
|
+
// Create a new renderWindow if needed
|
|
517
|
+
if (!renderWindow.valid) {
|
|
518
|
+
const isPossiblyOnScreen = boundsOverlap(
|
|
519
|
+
elementBounds,
|
|
520
|
+
this.rendererBounds,
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
if (!isPossiblyOnScreen) {
|
|
524
|
+
// If the element is not possibly on screen, we can skip the layout and rendering completely
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
setRenderWindow(
|
|
529
|
+
renderWindow,
|
|
530
|
+
x,
|
|
531
|
+
y,
|
|
532
|
+
scrollY,
|
|
533
|
+
resLineHeight,
|
|
534
|
+
contain === 'both' ? elementBounds.y2 - elementBounds.y1 : 0,
|
|
535
|
+
elementBounds,
|
|
536
|
+
fontSizeRatio,
|
|
537
|
+
);
|
|
538
|
+
// console.log('newRenderWindow', renderWindow);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const start = getStartConditions(
|
|
542
|
+
sdfFontSize,
|
|
543
|
+
sdfLineHeight,
|
|
544
|
+
trFontFace,
|
|
545
|
+
verticalAlign,
|
|
546
|
+
offsetY,
|
|
547
|
+
fontSizeRatio,
|
|
548
|
+
renderWindow,
|
|
549
|
+
lineCache,
|
|
550
|
+
textH,
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
if (!start) {
|
|
554
|
+
// Nothing to render, return early, but still mark as loaded (since the text is just scrolled
|
|
555
|
+
// out of view)
|
|
556
|
+
this.setStatus(state, 'loaded');
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const { letterSpacing } = state.props;
|
|
561
|
+
|
|
562
|
+
const out2 = layoutText(
|
|
563
|
+
start.lineIndex,
|
|
564
|
+
start.sdfX,
|
|
565
|
+
start.sdfY,
|
|
566
|
+
text,
|
|
567
|
+
textAlign,
|
|
568
|
+
width,
|
|
569
|
+
height,
|
|
570
|
+
fontSize,
|
|
571
|
+
resLineHeight,
|
|
572
|
+
letterSpacing,
|
|
573
|
+
vertexBuffer,
|
|
574
|
+
contain,
|
|
575
|
+
lineCache,
|
|
576
|
+
renderWindow.sdf,
|
|
577
|
+
trFontFace,
|
|
578
|
+
forceFullLayoutCalc,
|
|
579
|
+
scrollable,
|
|
580
|
+
overflowSuffix,
|
|
581
|
+
wordBreak,
|
|
582
|
+
maxLines,
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
state.bufferUploaded = false;
|
|
586
|
+
state.bufferNumFloats = out2.bufferNumFloats;
|
|
587
|
+
state.bufferNumQuads = out2.bufferNumQuads;
|
|
588
|
+
state.vertexBuffer = vertexBuffer;
|
|
589
|
+
state.renderWindow = renderWindow;
|
|
590
|
+
debugData.lastLayoutNumCharacters = out2.layoutNumCharacters;
|
|
591
|
+
debugData.bufferSize = vertexBuffer.byteLength;
|
|
592
|
+
|
|
593
|
+
// If we didn't exit early, we know we have completely computed w/h
|
|
594
|
+
if (out2.fullyProcessed) {
|
|
595
|
+
state.textW = out2.maxX * fontSizeRatio;
|
|
596
|
+
state.textH = out2.numLines * sdfLineHeight * fontSizeRatio;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// if (state.props.debug.printLayoutTime) {
|
|
600
|
+
// debugData.layoutSum += performance.now() - updateStartTime;
|
|
601
|
+
// debugData.layoutCount++;
|
|
602
|
+
// }
|
|
603
|
+
this.setStatus(state, 'loaded');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
override renderQuads(node: CoreTextNode): void {
|
|
607
|
+
const state = node.trState as SdfTextRendererState;
|
|
608
|
+
if (!state.vertexBuffer) {
|
|
609
|
+
// Nothing to draw
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const renderer = this.stage.renderer;
|
|
614
|
+
assertTruthy(renderer instanceof WebGlRenderer);
|
|
615
|
+
|
|
616
|
+
const { fontSize, color, contain, scrollable, zIndex, debug } = state.props;
|
|
617
|
+
|
|
618
|
+
// scrollY only has an effect when contain === 'both' and scrollable === true
|
|
619
|
+
const scrollY = contain === 'both' && scrollable ? state.props.scrollY : 0;
|
|
620
|
+
|
|
621
|
+
const {
|
|
622
|
+
textW = 0,
|
|
623
|
+
textH = 0,
|
|
624
|
+
distanceRange,
|
|
625
|
+
vertexBuffer,
|
|
626
|
+
bufferUploaded,
|
|
627
|
+
trFontFace,
|
|
628
|
+
elementBounds,
|
|
629
|
+
} = state;
|
|
630
|
+
|
|
631
|
+
let { webGlBuffers } = state;
|
|
632
|
+
|
|
633
|
+
if (!webGlBuffers) {
|
|
634
|
+
const glw = renderer.glw;
|
|
635
|
+
const stride = 4 * Float32Array.BYTES_PER_ELEMENT;
|
|
636
|
+
const webGlBuffer = glw.createBuffer();
|
|
637
|
+
assertTruthy(webGlBuffer);
|
|
638
|
+
state.webGlBuffers = new BufferCollection([
|
|
639
|
+
{
|
|
640
|
+
buffer: webGlBuffer,
|
|
641
|
+
attributes: {
|
|
642
|
+
a_position: {
|
|
643
|
+
name: 'a_position',
|
|
644
|
+
size: 2, // 2 components per iteration
|
|
645
|
+
type: glw.FLOAT, // the data is 32bit floats
|
|
646
|
+
normalized: false, // don't normalize the data
|
|
647
|
+
stride, // 0 = move forward size * sizeof(type) each iteration to get the next position
|
|
648
|
+
offset: 0, // start at the beginning of the buffer
|
|
649
|
+
},
|
|
650
|
+
a_textureCoords: {
|
|
651
|
+
name: 'a_textureCoords',
|
|
652
|
+
size: 2,
|
|
653
|
+
type: glw.FLOAT,
|
|
654
|
+
normalized: false,
|
|
655
|
+
stride,
|
|
656
|
+
offset: 2 * Float32Array.BYTES_PER_ELEMENT,
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
},
|
|
660
|
+
]);
|
|
661
|
+
state.bufferUploaded = false;
|
|
662
|
+
assertTruthy(state.webGlBuffers);
|
|
663
|
+
webGlBuffers = state.webGlBuffers;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if (!bufferUploaded) {
|
|
667
|
+
const glw = renderer.glw;
|
|
668
|
+
|
|
669
|
+
const buffer = webGlBuffers?.getBuffer('a_textureCoords') ?? null;
|
|
670
|
+
glw.arrayBufferData(buffer, vertexBuffer, glw.STATIC_DRAW);
|
|
671
|
+
state.bufferUploaded = true;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
assertTruthy(trFontFace);
|
|
675
|
+
if (scrollable && contain === 'both') {
|
|
676
|
+
assertTruthy(elementBounds.valid);
|
|
677
|
+
const elementRect = convertBoundToRect(elementBounds, tmpRect);
|
|
678
|
+
|
|
679
|
+
if (node.clippingRect.valid) {
|
|
680
|
+
state.clippingRect.valid = true;
|
|
681
|
+
node.clippingRect = intersectRect(
|
|
682
|
+
node.clippingRect,
|
|
683
|
+
elementRect,
|
|
684
|
+
state.clippingRect,
|
|
685
|
+
);
|
|
686
|
+
} else {
|
|
687
|
+
state.clippingRect.valid = true;
|
|
688
|
+
node.clippingRect = copyRect(elementRect, state.clippingRect);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const renderOp = new WebGlRenderOp(
|
|
693
|
+
renderer,
|
|
694
|
+
{
|
|
695
|
+
sdfShaderProps: {
|
|
696
|
+
transform: node.globalTransform!.getFloatArr(),
|
|
697
|
+
color: mergeColorAlpha(color, node.worldAlpha),
|
|
698
|
+
size: fontSize / (trFontFace.data?.info.size || 0),
|
|
699
|
+
scrollY,
|
|
700
|
+
distanceRange,
|
|
701
|
+
debug: debug.sdfShaderDebug,
|
|
702
|
+
},
|
|
703
|
+
sdfBuffers: state.webGlBuffers as BufferCollection,
|
|
704
|
+
shader: this.sdfShader,
|
|
705
|
+
alpha: node.worldAlpha,
|
|
706
|
+
clippingRect: node.clippingRect,
|
|
707
|
+
height: textH,
|
|
708
|
+
width: textW,
|
|
709
|
+
rtt: false,
|
|
710
|
+
parentHasRenderTexture: node.parentHasRenderTexture,
|
|
711
|
+
framebufferDimensions:
|
|
712
|
+
node.parentHasRenderTexture === true
|
|
713
|
+
? node.parentFramebufferDimensions
|
|
714
|
+
: null,
|
|
715
|
+
},
|
|
716
|
+
0,
|
|
717
|
+
);
|
|
718
|
+
|
|
719
|
+
const texture = state.trFontFace?.texture;
|
|
720
|
+
assertTruthy(texture);
|
|
721
|
+
const ctxTexture = texture.ctxTexture;
|
|
722
|
+
|
|
723
|
+
renderOp.addTexture(ctxTexture as WebGlCtxTexture);
|
|
724
|
+
renderOp.numQuads = state.bufferNumQuads;
|
|
725
|
+
|
|
726
|
+
renderer.addRenderOp(renderOp);
|
|
727
|
+
|
|
728
|
+
// if (!debug.disableScissor) {
|
|
729
|
+
// renderer.enableScissor(
|
|
730
|
+
// visibleRect.x,
|
|
731
|
+
// visibleRect.y,
|
|
732
|
+
// visibleRect.w,
|
|
733
|
+
// visibleRect.h,
|
|
734
|
+
// );
|
|
735
|
+
// }
|
|
736
|
+
|
|
737
|
+
// Draw the arrays
|
|
738
|
+
// gl.drawArrays(
|
|
739
|
+
// gl.TRIANGLES, // Primitive type
|
|
740
|
+
// 0,
|
|
741
|
+
// bufferNumVertices, // Number of verticies
|
|
742
|
+
// );
|
|
743
|
+
|
|
744
|
+
// renderer.disableScissor();
|
|
745
|
+
|
|
746
|
+
// if (debug.showElementRect) {
|
|
747
|
+
// this.renderer.drawBorder(
|
|
748
|
+
// Colors.Blue,
|
|
749
|
+
// elementRect.x,
|
|
750
|
+
// elementRect.y,
|
|
751
|
+
// elementRect.w,
|
|
752
|
+
// elementRect.h,
|
|
753
|
+
// );
|
|
754
|
+
// }
|
|
755
|
+
|
|
756
|
+
// if (debug.showVisibleRect) {
|
|
757
|
+
// this.renderer.drawBorder(
|
|
758
|
+
// Colors.Green,
|
|
759
|
+
// visibleRect.x,
|
|
760
|
+
// visibleRect.y,
|
|
761
|
+
// visibleRect.w,
|
|
762
|
+
// visibleRect.h,
|
|
763
|
+
// );
|
|
764
|
+
// }
|
|
765
|
+
|
|
766
|
+
// if (debug.showRenderWindow && renderWindow) {
|
|
767
|
+
// this.renderer.drawBorder(
|
|
768
|
+
// Colors.Red,
|
|
769
|
+
// x + renderWindow.x1,
|
|
770
|
+
// y + renderWindow.y1 - scrollY,
|
|
771
|
+
// x + renderWindow.x2 - (x + renderWindow.x1),
|
|
772
|
+
// y + renderWindow.y2 - scrollY - (y + renderWindow.y1 - scrollY),
|
|
773
|
+
// );
|
|
774
|
+
// }
|
|
775
|
+
// if (debug.printLayoutTime) {
|
|
776
|
+
// debugData.drawSum += performance.now() - drawStartTime;
|
|
777
|
+
// debugData.drawCount++;
|
|
778
|
+
// }
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
override setIsRenderable(
|
|
782
|
+
state: SdfTextRendererState,
|
|
783
|
+
renderable: boolean,
|
|
784
|
+
): void {
|
|
785
|
+
super.setIsRenderable(state, renderable);
|
|
786
|
+
state.trFontFace?.texture.setRenderableOwner(state, renderable);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
override destroyState(state: SdfTextRendererState): void {
|
|
790
|
+
super.destroyState(state);
|
|
791
|
+
// If there's a Font Face assigned we must free the owner relation to its texture
|
|
792
|
+
state.trFontFace?.texture.setRenderableOwner(state, false);
|
|
793
|
+
}
|
|
794
|
+
//#endregion Overrides
|
|
795
|
+
|
|
796
|
+
public resolveFontFace(props: TrFontProps): SdfTrFontFace | undefined {
|
|
797
|
+
return this.stage.fontManager.resolveFontFace(
|
|
798
|
+
this.fontFamilyArray,
|
|
799
|
+
props,
|
|
800
|
+
'sdf',
|
|
801
|
+
) as SdfTrFontFace | undefined;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Release the loaded SDF font face
|
|
806
|
+
*
|
|
807
|
+
* @param state
|
|
808
|
+
*/
|
|
809
|
+
protected releaseFontFace(state: SdfTextRendererState) {
|
|
810
|
+
state.resLineHeight = undefined;
|
|
811
|
+
if (state.trFontFace) {
|
|
812
|
+
state.trFontFace.texture.setRenderableOwner(state, false);
|
|
813
|
+
state.trFontFace = undefined;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Invalidate the layout cache stored in the state. This will cause the text
|
|
819
|
+
* to be re-layed out on the next update.
|
|
820
|
+
*
|
|
821
|
+
* @remarks
|
|
822
|
+
* This also invalidates the visible window cache.
|
|
823
|
+
*
|
|
824
|
+
* @param state
|
|
825
|
+
*/
|
|
826
|
+
protected invalidateLayoutCache(state: SdfTextRendererState): void {
|
|
827
|
+
state.renderWindow.valid = false;
|
|
828
|
+
state.elementBounds.valid = false;
|
|
829
|
+
state.textH = undefined;
|
|
830
|
+
state.textW = undefined;
|
|
831
|
+
state.lineCache = [];
|
|
832
|
+
this.setStatus(state, 'loading');
|
|
833
|
+
this.scheduleUpdateState(state);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
protected setElementBoundsX(state: SdfTextRendererState): void {
|
|
837
|
+
const { x, contain, width } = state.props;
|
|
838
|
+
const { elementBounds } = state;
|
|
839
|
+
elementBounds.x1 = x;
|
|
840
|
+
elementBounds.x2 = contain !== 'none' ? x + width : Infinity;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
protected setElementBoundsY(state: SdfTextRendererState): void {
|
|
844
|
+
const { y, contain, height } = state.props;
|
|
845
|
+
const { elementBounds } = state;
|
|
846
|
+
elementBounds.y1 = y;
|
|
847
|
+
elementBounds.y2 = contain === 'both' ? y + height : Infinity;
|
|
848
|
+
}
|
|
849
|
+
}
|