@lightningjs/renderer 3.0.0-beta4 → 3.0.0-beta5
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.js +1 -1
- 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 -0
- package/dist/src/core/CoreTextNode.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/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/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/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/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/webgl/Border.js +59 -59
- 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 +66 -66
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +79 -79
- 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/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/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/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 -1
- package/scripts/please-use-pnpm.js +13 -13
- 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 +203 -203
- package/src/core/CoreNode.ts +2494 -2494
- package/src/core/CoreShaderManager.ts +188 -188
- package/src/core/CoreTextNode.ts +449 -448
- package/src/core/CoreTextureManager.ts +601 -601
- package/src/core/Stage.ts +754 -754
- package/src/core/TextureMemoryManager.ts +395 -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/platform.ts +64 -64
- 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 +68 -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 +96 -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 +114 -114
- package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +133 -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 +846 -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 +675 -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/dist/src/core/{temp.d.ts → CoreStuff.d.ts} +0 -0
|
@@ -1,497 +1,497 @@
|
|
|
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 { assertTruthy } from '../../../../../utils.js';
|
|
21
|
-
import type { Bound } from '../../../../lib/utils.js';
|
|
22
|
-
import type {
|
|
23
|
-
FontShaperProps,
|
|
24
|
-
MappedGlyphInfo,
|
|
25
|
-
UnmappedCharacterInfo,
|
|
26
|
-
} from '../../../font-face-types/SdfTrFontFace/internal/FontShaper.js';
|
|
27
|
-
import type { TrProps, TextRendererState } from '../../TextRenderer.js';
|
|
28
|
-
import type { SdfTextRendererState } from '../SdfTextRenderer.js';
|
|
29
|
-
import { PeekableIterator } from './PeekableGenerator.js';
|
|
30
|
-
import { getUnicodeCodepoints } from './getUnicodeCodepoints.js';
|
|
31
|
-
import { measureText } from './measureText.js';
|
|
32
|
-
|
|
33
|
-
export function layoutText(
|
|
34
|
-
curLineIndex: number,
|
|
35
|
-
startX: number,
|
|
36
|
-
startY: number,
|
|
37
|
-
text: TrProps['text'],
|
|
38
|
-
textAlign: TrProps['textAlign'],
|
|
39
|
-
width: TrProps['width'],
|
|
40
|
-
height: TrProps['height'],
|
|
41
|
-
fontSize: TrProps['fontSize'],
|
|
42
|
-
lineHeight: number,
|
|
43
|
-
letterSpacing: TrProps['letterSpacing'],
|
|
44
|
-
/**
|
|
45
|
-
* Mutated
|
|
46
|
-
*/
|
|
47
|
-
vertexBuffer: NonNullable<SdfTextRendererState['vertexBuffer']>,
|
|
48
|
-
contain: TrProps['contain'],
|
|
49
|
-
/**
|
|
50
|
-
* Mutated
|
|
51
|
-
*/
|
|
52
|
-
lineCache: SdfTextRendererState['lineCache'],
|
|
53
|
-
rwSdf: Bound,
|
|
54
|
-
trFontFace: SdfTextRendererState['trFontFace'],
|
|
55
|
-
forceFullLayoutCalc: TextRendererState['forceFullLayoutCalc'],
|
|
56
|
-
scrollable: TrProps['scrollable'],
|
|
57
|
-
overflowSuffix: TrProps['overflowSuffix'],
|
|
58
|
-
wordBreak: TrProps['wordBreak'],
|
|
59
|
-
maxLines: TrProps['maxLines'],
|
|
60
|
-
): {
|
|
61
|
-
bufferNumFloats: number;
|
|
62
|
-
bufferNumQuads: number;
|
|
63
|
-
layoutNumCharacters: number;
|
|
64
|
-
fullyProcessed: boolean;
|
|
65
|
-
maxX: number;
|
|
66
|
-
maxY: number;
|
|
67
|
-
numLines: number;
|
|
68
|
-
} {
|
|
69
|
-
assertTruthy(trFontFace, 'Font face must be loaded');
|
|
70
|
-
assertTruthy(trFontFace.loaded, 'Font face must be loaded');
|
|
71
|
-
assertTruthy(trFontFace.data, 'Font face must be loaded');
|
|
72
|
-
assertTruthy(trFontFace.shaper, 'Font face must be loaded');
|
|
73
|
-
|
|
74
|
-
// Regardless of fontSize (or other scaling properties), we layout the vertices of each glyph
|
|
75
|
-
// using the fixed coordinate space determined by font size used to produce the atlas.
|
|
76
|
-
// Scaling for display is handled by shader uniforms inexpensively.
|
|
77
|
-
// So we have:
|
|
78
|
-
// - vertex space: the space in which the vertices of each glyph are laid out
|
|
79
|
-
// - screen space: the screen pixel space
|
|
80
|
-
// Input properties such as x, y, w, fontSize, letterSpacing, etc. are all expressed in screen space.
|
|
81
|
-
// We convert these to the vertex space by dividing them the `fontSizeRatio` factor.
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* See above
|
|
85
|
-
*/
|
|
86
|
-
const fontSizeRatio = fontSize / trFontFace.data.info.size;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* `lineHeight` in vertex coordinates
|
|
90
|
-
*/
|
|
91
|
-
const vertexLineHeight = lineHeight / fontSizeRatio;
|
|
92
|
-
/**
|
|
93
|
-
* `w` in vertex coordinates
|
|
94
|
-
*/
|
|
95
|
-
const vertexW = width / fontSizeRatio;
|
|
96
|
-
/**
|
|
97
|
-
* `letterSpacing` in vertex coordinates
|
|
98
|
-
*/
|
|
99
|
-
const vertexLSpacing = letterSpacing / fontSizeRatio;
|
|
100
|
-
|
|
101
|
-
const startingLineCacheEntry = lineCache[curLineIndex];
|
|
102
|
-
const startingCodepointIndex = startingLineCacheEntry?.codepointIndex || 0;
|
|
103
|
-
const startingMaxX = startingLineCacheEntry?.maxX || 0;
|
|
104
|
-
const startingMaxY = startingLineCacheEntry?.maxY || 0;
|
|
105
|
-
|
|
106
|
-
let maxX = startingMaxX;
|
|
107
|
-
let maxY = startingMaxY;
|
|
108
|
-
let curX = startX;
|
|
109
|
-
let curY = startY;
|
|
110
|
-
|
|
111
|
-
let bufferOffset = 0;
|
|
112
|
-
/**
|
|
113
|
-
* Buffer offset to last word boundry. This is -1 when we aren't in a word boundry.
|
|
114
|
-
*/
|
|
115
|
-
const lastWord: {
|
|
116
|
-
codepointIndex: number;
|
|
117
|
-
bufferOffset: number;
|
|
118
|
-
xStart: number;
|
|
119
|
-
} = {
|
|
120
|
-
codepointIndex: -1,
|
|
121
|
-
bufferOffset: -1,
|
|
122
|
-
xStart: -1,
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
let previousWord: {
|
|
126
|
-
bufferOffset: number;
|
|
127
|
-
xStart: number;
|
|
128
|
-
} = {
|
|
129
|
-
bufferOffset: -1,
|
|
130
|
-
xStart: -1,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const shaper = trFontFace.shaper;
|
|
134
|
-
|
|
135
|
-
const shaperProps: FontShaperProps = {
|
|
136
|
-
letterSpacing: vertexLSpacing,
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// HACK: The space is used as a word boundary. When a text ends with a space, we need to
|
|
140
|
-
// add an extra space to ensure the space is included in the line width calculation.
|
|
141
|
-
if (text.endsWith(' ')) {
|
|
142
|
-
text += ' ';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Get glyphs
|
|
146
|
-
let glyphs = shaper.shapeText(
|
|
147
|
-
shaperProps,
|
|
148
|
-
new PeekableIterator(
|
|
149
|
-
getUnicodeCodepoints(text, startingCodepointIndex),
|
|
150
|
-
startingCodepointIndex,
|
|
151
|
-
),
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
let glyphResult:
|
|
155
|
-
| IteratorResult<MappedGlyphInfo | UnmappedCharacterInfo, void>
|
|
156
|
-
| undefined;
|
|
157
|
-
|
|
158
|
-
let curLineBufferStart = -1;
|
|
159
|
-
|
|
160
|
-
const bufferLineInfos: {
|
|
161
|
-
bufferStart: number;
|
|
162
|
-
bufferEnd: number;
|
|
163
|
-
}[] = [];
|
|
164
|
-
|
|
165
|
-
const vertexTruncateHeight = height / fontSizeRatio;
|
|
166
|
-
const overflowSuffVertexWidth = measureText(
|
|
167
|
-
overflowSuffix,
|
|
168
|
-
shaperProps,
|
|
169
|
-
shaper,
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
// Line-by-line layout
|
|
173
|
-
let moreLines = true;
|
|
174
|
-
while (moreLines) {
|
|
175
|
-
const nextLineWillFit =
|
|
176
|
-
(maxLines === 0 || curLineIndex + 1 < maxLines) &&
|
|
177
|
-
(contain !== 'both' ||
|
|
178
|
-
scrollable ||
|
|
179
|
-
curY + vertexLineHeight + trFontFace.maxCharHeight <=
|
|
180
|
-
vertexTruncateHeight);
|
|
181
|
-
/**
|
|
182
|
-
* Vertex X position to the beginning of the last word boundary. This becomes -1 when we start traversing a word.
|
|
183
|
-
*/
|
|
184
|
-
let xStartLastWordBoundary = 0;
|
|
185
|
-
|
|
186
|
-
const lineIsBelowWindowTop = curY + trFontFace.maxCharHeight >= rwSdf.y1;
|
|
187
|
-
const lineIsAboveWindowBottom = curY <= rwSdf.y2;
|
|
188
|
-
const lineIsWithinWindow = lineIsBelowWindowTop && lineIsAboveWindowBottom;
|
|
189
|
-
// Layout glyphs in this line
|
|
190
|
-
// Any break statements in this while loop will trigger a line break
|
|
191
|
-
while ((glyphResult = glyphs.next()) && !glyphResult.done) {
|
|
192
|
-
const glyph = glyphResult.value;
|
|
193
|
-
|
|
194
|
-
if (curLineIndex === lineCache.length) {
|
|
195
|
-
lineCache.push({
|
|
196
|
-
codepointIndex: glyph.cluster,
|
|
197
|
-
maxY,
|
|
198
|
-
maxX,
|
|
199
|
-
});
|
|
200
|
-
} else if (curLineIndex > lineCache.length) {
|
|
201
|
-
throw new Error('Unexpected lineCache length');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// If we encounter a word boundary (white space or newline) we invalidate
|
|
205
|
-
// the lastWord and set the xStartLastWordBoundary if we haven't already.
|
|
206
|
-
if (
|
|
207
|
-
glyph.codepoint === 32 ||
|
|
208
|
-
glyph.codepoint === 10 ||
|
|
209
|
-
glyph.codepoint === 8203
|
|
210
|
-
) {
|
|
211
|
-
if (lastWord.codepointIndex !== -1) {
|
|
212
|
-
lastWord.codepointIndex = -1;
|
|
213
|
-
xStartLastWordBoundary = curX;
|
|
214
|
-
previousWord.bufferOffset = lastWord.bufferOffset;
|
|
215
|
-
previousWord.xStart = lastWord.xStart;
|
|
216
|
-
}
|
|
217
|
-
} else if (lastWord.codepointIndex === -1) {
|
|
218
|
-
lastWord.codepointIndex = glyph.cluster;
|
|
219
|
-
lastWord.bufferOffset = bufferOffset;
|
|
220
|
-
lastWord.xStart = xStartLastWordBoundary;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (glyph.mapped) {
|
|
224
|
-
// Mapped glyph
|
|
225
|
-
const charEndX = curX + glyph.xOffset + glyph.width;
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
wordBreak === 'break-all' &&
|
|
229
|
-
charEndX >= vertexW &&
|
|
230
|
-
nextLineWillFit
|
|
231
|
-
) {
|
|
232
|
-
// wordBreak: break-all - the current letter is about to go of the edge
|
|
233
|
-
// of the container width and the next line will fit, so we break to the next line
|
|
234
|
-
glyphs = shaper.shapeText(
|
|
235
|
-
shaperProps,
|
|
236
|
-
new PeekableIterator(
|
|
237
|
-
getUnicodeCodepoints(text, glyph.cluster),
|
|
238
|
-
glyph.cluster,
|
|
239
|
-
),
|
|
240
|
-
);
|
|
241
|
-
break;
|
|
242
|
-
} else if (
|
|
243
|
-
contain !== 'none' &&
|
|
244
|
-
wordBreak === 'break-all' &&
|
|
245
|
-
charEndX + overflowSuffVertexWidth >= vertexW &&
|
|
246
|
-
nextLineWillFit === false
|
|
247
|
-
) {
|
|
248
|
-
// wordBreak: break-all - the current letter is about to go of the edge
|
|
249
|
-
// of the container width and the next line will not fit, so we add the overflow suffix
|
|
250
|
-
glyphs = shaper.shapeText(
|
|
251
|
-
shaperProps,
|
|
252
|
-
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
253
|
-
);
|
|
254
|
-
contain = 'none';
|
|
255
|
-
} else if (
|
|
256
|
-
// Word wrap check
|
|
257
|
-
// We are containing the text
|
|
258
|
-
contain !== 'none' &&
|
|
259
|
-
// The current glyph reaches outside the contained width
|
|
260
|
-
charEndX >= vertexW &&
|
|
261
|
-
// There is a last word that we can break to the next line
|
|
262
|
-
lastWord.codepointIndex !== -1 &&
|
|
263
|
-
// Prevents infinite loop when a single word is longer than the width
|
|
264
|
-
lastWord.xStart > 0
|
|
265
|
-
) {
|
|
266
|
-
// The current word is about to go off the edge of the container width
|
|
267
|
-
// Reinitialize the iterator starting at the last word
|
|
268
|
-
// and proceeding to the next line
|
|
269
|
-
if (nextLineWillFit) {
|
|
270
|
-
glyphs = shaper.shapeText(
|
|
271
|
-
shaperProps,
|
|
272
|
-
new PeekableIterator(
|
|
273
|
-
getUnicodeCodepoints(text, lastWord.codepointIndex),
|
|
274
|
-
lastWord.codepointIndex,
|
|
275
|
-
),
|
|
276
|
-
);
|
|
277
|
-
bufferOffset = lastWord.bufferOffset;
|
|
278
|
-
break;
|
|
279
|
-
} else {
|
|
280
|
-
glyphs = shaper.shapeText(
|
|
281
|
-
shaperProps,
|
|
282
|
-
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
283
|
-
);
|
|
284
|
-
if (lastWord.xStart + overflowSuffVertexWidth < vertexW) {
|
|
285
|
-
curX = lastWord.xStart;
|
|
286
|
-
bufferOffset = lastWord.bufferOffset;
|
|
287
|
-
} else if (
|
|
288
|
-
previousWord.xStart + overflowSuffVertexWidth <
|
|
289
|
-
vertexW
|
|
290
|
-
) {
|
|
291
|
-
curX = previousWord.xStart;
|
|
292
|
-
bufferOffset = previousWord.bufferOffset;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// HACK: For the rest of the line when inserting the overflow suffix,
|
|
296
|
-
// set contain = 'none' to prevent an infinite loop.
|
|
297
|
-
contain = 'none';
|
|
298
|
-
}
|
|
299
|
-
} else if (
|
|
300
|
-
wordBreak === 'break-word' &&
|
|
301
|
-
charEndX >= vertexW &&
|
|
302
|
-
lastWord.xStart === 0 &&
|
|
303
|
-
nextLineWillFit
|
|
304
|
-
) {
|
|
305
|
-
// The current word which starts the line is wider than the line width
|
|
306
|
-
// proceed to next line
|
|
307
|
-
glyphs = shaper.shapeText(
|
|
308
|
-
shaperProps,
|
|
309
|
-
new PeekableIterator(
|
|
310
|
-
getUnicodeCodepoints(text, glyph.cluster),
|
|
311
|
-
glyph.cluster,
|
|
312
|
-
),
|
|
313
|
-
);
|
|
314
|
-
break;
|
|
315
|
-
} else if (
|
|
316
|
-
contain !== 'none' &&
|
|
317
|
-
wordBreak === 'break-word' &&
|
|
318
|
-
lastWord.xStart === 0 &&
|
|
319
|
-
charEndX + overflowSuffVertexWidth >= vertexW &&
|
|
320
|
-
nextLineWillFit === false
|
|
321
|
-
) {
|
|
322
|
-
// wordBreak: break-word - the current letter is about to go of the edge
|
|
323
|
-
// and the next line will not fit, so we add the overflow suffix
|
|
324
|
-
glyphs = shaper.shapeText(
|
|
325
|
-
shaperProps,
|
|
326
|
-
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
327
|
-
);
|
|
328
|
-
contain = 'none';
|
|
329
|
-
} else {
|
|
330
|
-
// This glyph fits, so we can add it to the buffer
|
|
331
|
-
const quadX = curX + glyph.xOffset;
|
|
332
|
-
const quadY = curY + glyph.yOffset;
|
|
333
|
-
|
|
334
|
-
// Only add to buffer for rendering if the line is within the render window
|
|
335
|
-
if (lineIsWithinWindow) {
|
|
336
|
-
if (curLineBufferStart === -1) {
|
|
337
|
-
curLineBufferStart = bufferOffset;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const atlasEntry = trFontFace.getAtlasEntry(glyph.glyphId);
|
|
341
|
-
|
|
342
|
-
// Add texture coordinates
|
|
343
|
-
const u = atlasEntry.x / trFontFace.data.common.scaleW;
|
|
344
|
-
const v = atlasEntry.y / trFontFace.data.common.scaleH;
|
|
345
|
-
const uvWidth = atlasEntry.width / trFontFace.data.common.scaleW;
|
|
346
|
-
const uvHeight = atlasEntry.height / trFontFace.data.common.scaleH;
|
|
347
|
-
|
|
348
|
-
// TODO: (Performance) We can optimize this by using ELEMENT_ARRAY_BUFFER
|
|
349
|
-
// eliminating the need to duplicate vertices
|
|
350
|
-
|
|
351
|
-
// Top-left
|
|
352
|
-
vertexBuffer[bufferOffset++] = quadX;
|
|
353
|
-
vertexBuffer[bufferOffset++] = quadY;
|
|
354
|
-
vertexBuffer[bufferOffset++] = u;
|
|
355
|
-
vertexBuffer[bufferOffset++] = v;
|
|
356
|
-
|
|
357
|
-
// Top-right
|
|
358
|
-
vertexBuffer[bufferOffset++] = quadX + glyph.width;
|
|
359
|
-
vertexBuffer[bufferOffset++] = quadY;
|
|
360
|
-
vertexBuffer[bufferOffset++] = u + uvWidth;
|
|
361
|
-
vertexBuffer[bufferOffset++] = v;
|
|
362
|
-
|
|
363
|
-
// Bottom-left
|
|
364
|
-
vertexBuffer[bufferOffset++] = quadX;
|
|
365
|
-
vertexBuffer[bufferOffset++] = quadY + glyph.height;
|
|
366
|
-
vertexBuffer[bufferOffset++] = u;
|
|
367
|
-
vertexBuffer[bufferOffset++] = v + uvHeight;
|
|
368
|
-
|
|
369
|
-
// Bottom-right
|
|
370
|
-
vertexBuffer[bufferOffset++] = quadX + glyph.width;
|
|
371
|
-
vertexBuffer[bufferOffset++] = quadY + glyph.height;
|
|
372
|
-
vertexBuffer[bufferOffset++] = u + uvWidth;
|
|
373
|
-
vertexBuffer[bufferOffset++] = v + uvHeight;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
maxY = Math.max(maxY, quadY + glyph.height);
|
|
377
|
-
maxX = Math.max(maxX, quadX + glyph.width);
|
|
378
|
-
curX += glyph.xAdvance;
|
|
379
|
-
}
|
|
380
|
-
} else {
|
|
381
|
-
// Unmapped character
|
|
382
|
-
|
|
383
|
-
// Handle newlines
|
|
384
|
-
if (glyph.codepoint === 10) {
|
|
385
|
-
if (nextLineWillFit) {
|
|
386
|
-
// The whole line fit, so we can break to the next line
|
|
387
|
-
break;
|
|
388
|
-
} else {
|
|
389
|
-
// Check if the overflow suffix will fit
|
|
390
|
-
if (curX + overflowSuffVertexWidth >= vertexW) {
|
|
391
|
-
if (lastWord.xStart + overflowSuffVertexWidth < vertexW) {
|
|
392
|
-
curX = lastWord.xStart;
|
|
393
|
-
bufferOffset = lastWord.bufferOffset;
|
|
394
|
-
} else if (
|
|
395
|
-
previousWord.xStart + overflowSuffVertexWidth <
|
|
396
|
-
vertexW
|
|
397
|
-
) {
|
|
398
|
-
curX = previousWord.xStart;
|
|
399
|
-
bufferOffset = previousWord.bufferOffset;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
// The whole line won't fit, so we need to add the overflow suffix
|
|
403
|
-
glyphs = shaper.shapeText(
|
|
404
|
-
shaperProps,
|
|
405
|
-
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
406
|
-
);
|
|
407
|
-
// HACK: For the rest of the line when inserting the overflow suffix,
|
|
408
|
-
// set contain = 'none' to prevent an infinite loop.
|
|
409
|
-
contain = 'none';
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// Prepare for the next line...
|
|
416
|
-
if (curLineBufferStart !== -1) {
|
|
417
|
-
bufferLineInfos.push({
|
|
418
|
-
bufferStart: curLineBufferStart,
|
|
419
|
-
bufferEnd: bufferOffset,
|
|
420
|
-
});
|
|
421
|
-
curLineBufferStart = -1;
|
|
422
|
-
}
|
|
423
|
-
curX = 0;
|
|
424
|
-
curY += vertexLineHeight;
|
|
425
|
-
curLineIndex++;
|
|
426
|
-
lastWord.codepointIndex = -1;
|
|
427
|
-
xStartLastWordBoundary = 0;
|
|
428
|
-
|
|
429
|
-
// Figure out if there are any more lines to render...
|
|
430
|
-
if (!forceFullLayoutCalc && contain === 'both' && curY > rwSdf.y2) {
|
|
431
|
-
// Stop layout calculation early (for performance purposes) if:
|
|
432
|
-
// - We're not forcing a full layout calculation (for width/height calculation)
|
|
433
|
-
// - ...and we're containing the text vertically+horizontally (contain === 'both')
|
|
434
|
-
// - ...and we have a render window
|
|
435
|
-
// - ...and the next line is below the bottom of the render window
|
|
436
|
-
moreLines = false;
|
|
437
|
-
} else if (glyphResult && glyphResult.done) {
|
|
438
|
-
// If we've reached the end of the text, we know we're done
|
|
439
|
-
moreLines = false;
|
|
440
|
-
} else if (!nextLineWillFit) {
|
|
441
|
-
// If we're contained vertically+horizontally (contain === 'both')
|
|
442
|
-
// but not scrollable and the next line won't fit, we're done.
|
|
443
|
-
moreLines = false;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// Use textAlign to determine if we need to adjust the x position of the text
|
|
448
|
-
// in the buffer line by line
|
|
449
|
-
if (textAlign === 'center') {
|
|
450
|
-
const vertexTextW = contain === 'none' ? maxX : vertexW;
|
|
451
|
-
|
|
452
|
-
for (let i = 0; i < bufferLineInfos.length; i++) {
|
|
453
|
-
const line = bufferLineInfos[i]!;
|
|
454
|
-
// - 4 = the x position of a rightmost vertex
|
|
455
|
-
const lineWidth =
|
|
456
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
457
|
-
vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
|
|
458
|
-
|
|
459
|
-
const xOffset = (vertexTextW - lineWidth) / 2;
|
|
460
|
-
for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
|
|
461
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
462
|
-
vertexBuffer[j]! += xOffset;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
} else if (textAlign === 'right') {
|
|
466
|
-
const vertexTextW = contain === 'none' ? maxX : vertexW;
|
|
467
|
-
|
|
468
|
-
for (let i = 0; i < bufferLineInfos.length; i++) {
|
|
469
|
-
const line = bufferLineInfos[i]!;
|
|
470
|
-
const lineWidth =
|
|
471
|
-
line.bufferEnd === line.bufferStart
|
|
472
|
-
? 0
|
|
473
|
-
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
474
|
-
vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
|
|
475
|
-
|
|
476
|
-
const xOffset = vertexTextW - lineWidth;
|
|
477
|
-
for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
|
|
478
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
479
|
-
vertexBuffer[j]! += xOffset;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
assertTruthy(glyphResult);
|
|
485
|
-
|
|
486
|
-
return {
|
|
487
|
-
bufferNumFloats: bufferOffset,
|
|
488
|
-
bufferNumQuads: bufferOffset / 16,
|
|
489
|
-
layoutNumCharacters: glyphResult.done
|
|
490
|
-
? text.length - startingCodepointIndex
|
|
491
|
-
: glyphResult.value.cluster - startingCodepointIndex + 1,
|
|
492
|
-
fullyProcessed: !!glyphResult.done,
|
|
493
|
-
maxX,
|
|
494
|
-
maxY,
|
|
495
|
-
numLines: lineCache.length,
|
|
496
|
-
};
|
|
497
|
-
}
|
|
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 { assertTruthy } from '../../../../../utils.js';
|
|
21
|
+
import type { Bound } from '../../../../lib/utils.js';
|
|
22
|
+
import type {
|
|
23
|
+
FontShaperProps,
|
|
24
|
+
MappedGlyphInfo,
|
|
25
|
+
UnmappedCharacterInfo,
|
|
26
|
+
} from '../../../font-face-types/SdfTrFontFace/internal/FontShaper.js';
|
|
27
|
+
import type { TrProps, TextRendererState } from '../../TextRenderer.js';
|
|
28
|
+
import type { SdfTextRendererState } from '../SdfTextRenderer.js';
|
|
29
|
+
import { PeekableIterator } from './PeekableGenerator.js';
|
|
30
|
+
import { getUnicodeCodepoints } from './getUnicodeCodepoints.js';
|
|
31
|
+
import { measureText } from './measureText.js';
|
|
32
|
+
|
|
33
|
+
export function layoutText(
|
|
34
|
+
curLineIndex: number,
|
|
35
|
+
startX: number,
|
|
36
|
+
startY: number,
|
|
37
|
+
text: TrProps['text'],
|
|
38
|
+
textAlign: TrProps['textAlign'],
|
|
39
|
+
width: TrProps['width'],
|
|
40
|
+
height: TrProps['height'],
|
|
41
|
+
fontSize: TrProps['fontSize'],
|
|
42
|
+
lineHeight: number,
|
|
43
|
+
letterSpacing: TrProps['letterSpacing'],
|
|
44
|
+
/**
|
|
45
|
+
* Mutated
|
|
46
|
+
*/
|
|
47
|
+
vertexBuffer: NonNullable<SdfTextRendererState['vertexBuffer']>,
|
|
48
|
+
contain: TrProps['contain'],
|
|
49
|
+
/**
|
|
50
|
+
* Mutated
|
|
51
|
+
*/
|
|
52
|
+
lineCache: SdfTextRendererState['lineCache'],
|
|
53
|
+
rwSdf: Bound,
|
|
54
|
+
trFontFace: SdfTextRendererState['trFontFace'],
|
|
55
|
+
forceFullLayoutCalc: TextRendererState['forceFullLayoutCalc'],
|
|
56
|
+
scrollable: TrProps['scrollable'],
|
|
57
|
+
overflowSuffix: TrProps['overflowSuffix'],
|
|
58
|
+
wordBreak: TrProps['wordBreak'],
|
|
59
|
+
maxLines: TrProps['maxLines'],
|
|
60
|
+
): {
|
|
61
|
+
bufferNumFloats: number;
|
|
62
|
+
bufferNumQuads: number;
|
|
63
|
+
layoutNumCharacters: number;
|
|
64
|
+
fullyProcessed: boolean;
|
|
65
|
+
maxX: number;
|
|
66
|
+
maxY: number;
|
|
67
|
+
numLines: number;
|
|
68
|
+
} {
|
|
69
|
+
assertTruthy(trFontFace, 'Font face must be loaded');
|
|
70
|
+
assertTruthy(trFontFace.loaded, 'Font face must be loaded');
|
|
71
|
+
assertTruthy(trFontFace.data, 'Font face must be loaded');
|
|
72
|
+
assertTruthy(trFontFace.shaper, 'Font face must be loaded');
|
|
73
|
+
|
|
74
|
+
// Regardless of fontSize (or other scaling properties), we layout the vertices of each glyph
|
|
75
|
+
// using the fixed coordinate space determined by font size used to produce the atlas.
|
|
76
|
+
// Scaling for display is handled by shader uniforms inexpensively.
|
|
77
|
+
// So we have:
|
|
78
|
+
// - vertex space: the space in which the vertices of each glyph are laid out
|
|
79
|
+
// - screen space: the screen pixel space
|
|
80
|
+
// Input properties such as x, y, w, fontSize, letterSpacing, etc. are all expressed in screen space.
|
|
81
|
+
// We convert these to the vertex space by dividing them the `fontSizeRatio` factor.
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* See above
|
|
85
|
+
*/
|
|
86
|
+
const fontSizeRatio = fontSize / trFontFace.data.info.size;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `lineHeight` in vertex coordinates
|
|
90
|
+
*/
|
|
91
|
+
const vertexLineHeight = lineHeight / fontSizeRatio;
|
|
92
|
+
/**
|
|
93
|
+
* `w` in vertex coordinates
|
|
94
|
+
*/
|
|
95
|
+
const vertexW = width / fontSizeRatio;
|
|
96
|
+
/**
|
|
97
|
+
* `letterSpacing` in vertex coordinates
|
|
98
|
+
*/
|
|
99
|
+
const vertexLSpacing = letterSpacing / fontSizeRatio;
|
|
100
|
+
|
|
101
|
+
const startingLineCacheEntry = lineCache[curLineIndex];
|
|
102
|
+
const startingCodepointIndex = startingLineCacheEntry?.codepointIndex || 0;
|
|
103
|
+
const startingMaxX = startingLineCacheEntry?.maxX || 0;
|
|
104
|
+
const startingMaxY = startingLineCacheEntry?.maxY || 0;
|
|
105
|
+
|
|
106
|
+
let maxX = startingMaxX;
|
|
107
|
+
let maxY = startingMaxY;
|
|
108
|
+
let curX = startX;
|
|
109
|
+
let curY = startY;
|
|
110
|
+
|
|
111
|
+
let bufferOffset = 0;
|
|
112
|
+
/**
|
|
113
|
+
* Buffer offset to last word boundry. This is -1 when we aren't in a word boundry.
|
|
114
|
+
*/
|
|
115
|
+
const lastWord: {
|
|
116
|
+
codepointIndex: number;
|
|
117
|
+
bufferOffset: number;
|
|
118
|
+
xStart: number;
|
|
119
|
+
} = {
|
|
120
|
+
codepointIndex: -1,
|
|
121
|
+
bufferOffset: -1,
|
|
122
|
+
xStart: -1,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
let previousWord: {
|
|
126
|
+
bufferOffset: number;
|
|
127
|
+
xStart: number;
|
|
128
|
+
} = {
|
|
129
|
+
bufferOffset: -1,
|
|
130
|
+
xStart: -1,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const shaper = trFontFace.shaper;
|
|
134
|
+
|
|
135
|
+
const shaperProps: FontShaperProps = {
|
|
136
|
+
letterSpacing: vertexLSpacing,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// HACK: The space is used as a word boundary. When a text ends with a space, we need to
|
|
140
|
+
// add an extra space to ensure the space is included in the line width calculation.
|
|
141
|
+
if (text.endsWith(' ')) {
|
|
142
|
+
text += ' ';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Get glyphs
|
|
146
|
+
let glyphs = shaper.shapeText(
|
|
147
|
+
shaperProps,
|
|
148
|
+
new PeekableIterator(
|
|
149
|
+
getUnicodeCodepoints(text, startingCodepointIndex),
|
|
150
|
+
startingCodepointIndex,
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
let glyphResult:
|
|
155
|
+
| IteratorResult<MappedGlyphInfo | UnmappedCharacterInfo, void>
|
|
156
|
+
| undefined;
|
|
157
|
+
|
|
158
|
+
let curLineBufferStart = -1;
|
|
159
|
+
|
|
160
|
+
const bufferLineInfos: {
|
|
161
|
+
bufferStart: number;
|
|
162
|
+
bufferEnd: number;
|
|
163
|
+
}[] = [];
|
|
164
|
+
|
|
165
|
+
const vertexTruncateHeight = height / fontSizeRatio;
|
|
166
|
+
const overflowSuffVertexWidth = measureText(
|
|
167
|
+
overflowSuffix,
|
|
168
|
+
shaperProps,
|
|
169
|
+
shaper,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// Line-by-line layout
|
|
173
|
+
let moreLines = true;
|
|
174
|
+
while (moreLines) {
|
|
175
|
+
const nextLineWillFit =
|
|
176
|
+
(maxLines === 0 || curLineIndex + 1 < maxLines) &&
|
|
177
|
+
(contain !== 'both' ||
|
|
178
|
+
scrollable ||
|
|
179
|
+
curY + vertexLineHeight + trFontFace.maxCharHeight <=
|
|
180
|
+
vertexTruncateHeight);
|
|
181
|
+
/**
|
|
182
|
+
* Vertex X position to the beginning of the last word boundary. This becomes -1 when we start traversing a word.
|
|
183
|
+
*/
|
|
184
|
+
let xStartLastWordBoundary = 0;
|
|
185
|
+
|
|
186
|
+
const lineIsBelowWindowTop = curY + trFontFace.maxCharHeight >= rwSdf.y1;
|
|
187
|
+
const lineIsAboveWindowBottom = curY <= rwSdf.y2;
|
|
188
|
+
const lineIsWithinWindow = lineIsBelowWindowTop && lineIsAboveWindowBottom;
|
|
189
|
+
// Layout glyphs in this line
|
|
190
|
+
// Any break statements in this while loop will trigger a line break
|
|
191
|
+
while ((glyphResult = glyphs.next()) && !glyphResult.done) {
|
|
192
|
+
const glyph = glyphResult.value;
|
|
193
|
+
|
|
194
|
+
if (curLineIndex === lineCache.length) {
|
|
195
|
+
lineCache.push({
|
|
196
|
+
codepointIndex: glyph.cluster,
|
|
197
|
+
maxY,
|
|
198
|
+
maxX,
|
|
199
|
+
});
|
|
200
|
+
} else if (curLineIndex > lineCache.length) {
|
|
201
|
+
throw new Error('Unexpected lineCache length');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// If we encounter a word boundary (white space or newline) we invalidate
|
|
205
|
+
// the lastWord and set the xStartLastWordBoundary if we haven't already.
|
|
206
|
+
if (
|
|
207
|
+
glyph.codepoint === 32 ||
|
|
208
|
+
glyph.codepoint === 10 ||
|
|
209
|
+
glyph.codepoint === 8203
|
|
210
|
+
) {
|
|
211
|
+
if (lastWord.codepointIndex !== -1) {
|
|
212
|
+
lastWord.codepointIndex = -1;
|
|
213
|
+
xStartLastWordBoundary = curX;
|
|
214
|
+
previousWord.bufferOffset = lastWord.bufferOffset;
|
|
215
|
+
previousWord.xStart = lastWord.xStart;
|
|
216
|
+
}
|
|
217
|
+
} else if (lastWord.codepointIndex === -1) {
|
|
218
|
+
lastWord.codepointIndex = glyph.cluster;
|
|
219
|
+
lastWord.bufferOffset = bufferOffset;
|
|
220
|
+
lastWord.xStart = xStartLastWordBoundary;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (glyph.mapped) {
|
|
224
|
+
// Mapped glyph
|
|
225
|
+
const charEndX = curX + glyph.xOffset + glyph.width;
|
|
226
|
+
|
|
227
|
+
if (
|
|
228
|
+
wordBreak === 'break-all' &&
|
|
229
|
+
charEndX >= vertexW &&
|
|
230
|
+
nextLineWillFit
|
|
231
|
+
) {
|
|
232
|
+
// wordBreak: break-all - the current letter is about to go of the edge
|
|
233
|
+
// of the container width and the next line will fit, so we break to the next line
|
|
234
|
+
glyphs = shaper.shapeText(
|
|
235
|
+
shaperProps,
|
|
236
|
+
new PeekableIterator(
|
|
237
|
+
getUnicodeCodepoints(text, glyph.cluster),
|
|
238
|
+
glyph.cluster,
|
|
239
|
+
),
|
|
240
|
+
);
|
|
241
|
+
break;
|
|
242
|
+
} else if (
|
|
243
|
+
contain !== 'none' &&
|
|
244
|
+
wordBreak === 'break-all' &&
|
|
245
|
+
charEndX + overflowSuffVertexWidth >= vertexW &&
|
|
246
|
+
nextLineWillFit === false
|
|
247
|
+
) {
|
|
248
|
+
// wordBreak: break-all - the current letter is about to go of the edge
|
|
249
|
+
// of the container width and the next line will not fit, so we add the overflow suffix
|
|
250
|
+
glyphs = shaper.shapeText(
|
|
251
|
+
shaperProps,
|
|
252
|
+
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
253
|
+
);
|
|
254
|
+
contain = 'none';
|
|
255
|
+
} else if (
|
|
256
|
+
// Word wrap check
|
|
257
|
+
// We are containing the text
|
|
258
|
+
contain !== 'none' &&
|
|
259
|
+
// The current glyph reaches outside the contained width
|
|
260
|
+
charEndX >= vertexW &&
|
|
261
|
+
// There is a last word that we can break to the next line
|
|
262
|
+
lastWord.codepointIndex !== -1 &&
|
|
263
|
+
// Prevents infinite loop when a single word is longer than the width
|
|
264
|
+
lastWord.xStart > 0
|
|
265
|
+
) {
|
|
266
|
+
// The current word is about to go off the edge of the container width
|
|
267
|
+
// Reinitialize the iterator starting at the last word
|
|
268
|
+
// and proceeding to the next line
|
|
269
|
+
if (nextLineWillFit) {
|
|
270
|
+
glyphs = shaper.shapeText(
|
|
271
|
+
shaperProps,
|
|
272
|
+
new PeekableIterator(
|
|
273
|
+
getUnicodeCodepoints(text, lastWord.codepointIndex),
|
|
274
|
+
lastWord.codepointIndex,
|
|
275
|
+
),
|
|
276
|
+
);
|
|
277
|
+
bufferOffset = lastWord.bufferOffset;
|
|
278
|
+
break;
|
|
279
|
+
} else {
|
|
280
|
+
glyphs = shaper.shapeText(
|
|
281
|
+
shaperProps,
|
|
282
|
+
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
283
|
+
);
|
|
284
|
+
if (lastWord.xStart + overflowSuffVertexWidth < vertexW) {
|
|
285
|
+
curX = lastWord.xStart;
|
|
286
|
+
bufferOffset = lastWord.bufferOffset;
|
|
287
|
+
} else if (
|
|
288
|
+
previousWord.xStart + overflowSuffVertexWidth <
|
|
289
|
+
vertexW
|
|
290
|
+
) {
|
|
291
|
+
curX = previousWord.xStart;
|
|
292
|
+
bufferOffset = previousWord.bufferOffset;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// HACK: For the rest of the line when inserting the overflow suffix,
|
|
296
|
+
// set contain = 'none' to prevent an infinite loop.
|
|
297
|
+
contain = 'none';
|
|
298
|
+
}
|
|
299
|
+
} else if (
|
|
300
|
+
wordBreak === 'break-word' &&
|
|
301
|
+
charEndX >= vertexW &&
|
|
302
|
+
lastWord.xStart === 0 &&
|
|
303
|
+
nextLineWillFit
|
|
304
|
+
) {
|
|
305
|
+
// The current word which starts the line is wider than the line width
|
|
306
|
+
// proceed to next line
|
|
307
|
+
glyphs = shaper.shapeText(
|
|
308
|
+
shaperProps,
|
|
309
|
+
new PeekableIterator(
|
|
310
|
+
getUnicodeCodepoints(text, glyph.cluster),
|
|
311
|
+
glyph.cluster,
|
|
312
|
+
),
|
|
313
|
+
);
|
|
314
|
+
break;
|
|
315
|
+
} else if (
|
|
316
|
+
contain !== 'none' &&
|
|
317
|
+
wordBreak === 'break-word' &&
|
|
318
|
+
lastWord.xStart === 0 &&
|
|
319
|
+
charEndX + overflowSuffVertexWidth >= vertexW &&
|
|
320
|
+
nextLineWillFit === false
|
|
321
|
+
) {
|
|
322
|
+
// wordBreak: break-word - the current letter is about to go of the edge
|
|
323
|
+
// and the next line will not fit, so we add the overflow suffix
|
|
324
|
+
glyphs = shaper.shapeText(
|
|
325
|
+
shaperProps,
|
|
326
|
+
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
327
|
+
);
|
|
328
|
+
contain = 'none';
|
|
329
|
+
} else {
|
|
330
|
+
// This glyph fits, so we can add it to the buffer
|
|
331
|
+
const quadX = curX + glyph.xOffset;
|
|
332
|
+
const quadY = curY + glyph.yOffset;
|
|
333
|
+
|
|
334
|
+
// Only add to buffer for rendering if the line is within the render window
|
|
335
|
+
if (lineIsWithinWindow) {
|
|
336
|
+
if (curLineBufferStart === -1) {
|
|
337
|
+
curLineBufferStart = bufferOffset;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const atlasEntry = trFontFace.getAtlasEntry(glyph.glyphId);
|
|
341
|
+
|
|
342
|
+
// Add texture coordinates
|
|
343
|
+
const u = atlasEntry.x / trFontFace.data.common.scaleW;
|
|
344
|
+
const v = atlasEntry.y / trFontFace.data.common.scaleH;
|
|
345
|
+
const uvWidth = atlasEntry.width / trFontFace.data.common.scaleW;
|
|
346
|
+
const uvHeight = atlasEntry.height / trFontFace.data.common.scaleH;
|
|
347
|
+
|
|
348
|
+
// TODO: (Performance) We can optimize this by using ELEMENT_ARRAY_BUFFER
|
|
349
|
+
// eliminating the need to duplicate vertices
|
|
350
|
+
|
|
351
|
+
// Top-left
|
|
352
|
+
vertexBuffer[bufferOffset++] = quadX;
|
|
353
|
+
vertexBuffer[bufferOffset++] = quadY;
|
|
354
|
+
vertexBuffer[bufferOffset++] = u;
|
|
355
|
+
vertexBuffer[bufferOffset++] = v;
|
|
356
|
+
|
|
357
|
+
// Top-right
|
|
358
|
+
vertexBuffer[bufferOffset++] = quadX + glyph.width;
|
|
359
|
+
vertexBuffer[bufferOffset++] = quadY;
|
|
360
|
+
vertexBuffer[bufferOffset++] = u + uvWidth;
|
|
361
|
+
vertexBuffer[bufferOffset++] = v;
|
|
362
|
+
|
|
363
|
+
// Bottom-left
|
|
364
|
+
vertexBuffer[bufferOffset++] = quadX;
|
|
365
|
+
vertexBuffer[bufferOffset++] = quadY + glyph.height;
|
|
366
|
+
vertexBuffer[bufferOffset++] = u;
|
|
367
|
+
vertexBuffer[bufferOffset++] = v + uvHeight;
|
|
368
|
+
|
|
369
|
+
// Bottom-right
|
|
370
|
+
vertexBuffer[bufferOffset++] = quadX + glyph.width;
|
|
371
|
+
vertexBuffer[bufferOffset++] = quadY + glyph.height;
|
|
372
|
+
vertexBuffer[bufferOffset++] = u + uvWidth;
|
|
373
|
+
vertexBuffer[bufferOffset++] = v + uvHeight;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
maxY = Math.max(maxY, quadY + glyph.height);
|
|
377
|
+
maxX = Math.max(maxX, quadX + glyph.width);
|
|
378
|
+
curX += glyph.xAdvance;
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
// Unmapped character
|
|
382
|
+
|
|
383
|
+
// Handle newlines
|
|
384
|
+
if (glyph.codepoint === 10) {
|
|
385
|
+
if (nextLineWillFit) {
|
|
386
|
+
// The whole line fit, so we can break to the next line
|
|
387
|
+
break;
|
|
388
|
+
} else {
|
|
389
|
+
// Check if the overflow suffix will fit
|
|
390
|
+
if (curX + overflowSuffVertexWidth >= vertexW) {
|
|
391
|
+
if (lastWord.xStart + overflowSuffVertexWidth < vertexW) {
|
|
392
|
+
curX = lastWord.xStart;
|
|
393
|
+
bufferOffset = lastWord.bufferOffset;
|
|
394
|
+
} else if (
|
|
395
|
+
previousWord.xStart + overflowSuffVertexWidth <
|
|
396
|
+
vertexW
|
|
397
|
+
) {
|
|
398
|
+
curX = previousWord.xStart;
|
|
399
|
+
bufferOffset = previousWord.bufferOffset;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// The whole line won't fit, so we need to add the overflow suffix
|
|
403
|
+
glyphs = shaper.shapeText(
|
|
404
|
+
shaperProps,
|
|
405
|
+
new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
|
|
406
|
+
);
|
|
407
|
+
// HACK: For the rest of the line when inserting the overflow suffix,
|
|
408
|
+
// set contain = 'none' to prevent an infinite loop.
|
|
409
|
+
contain = 'none';
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Prepare for the next line...
|
|
416
|
+
if (curLineBufferStart !== -1) {
|
|
417
|
+
bufferLineInfos.push({
|
|
418
|
+
bufferStart: curLineBufferStart,
|
|
419
|
+
bufferEnd: bufferOffset,
|
|
420
|
+
});
|
|
421
|
+
curLineBufferStart = -1;
|
|
422
|
+
}
|
|
423
|
+
curX = 0;
|
|
424
|
+
curY += vertexLineHeight;
|
|
425
|
+
curLineIndex++;
|
|
426
|
+
lastWord.codepointIndex = -1;
|
|
427
|
+
xStartLastWordBoundary = 0;
|
|
428
|
+
|
|
429
|
+
// Figure out if there are any more lines to render...
|
|
430
|
+
if (!forceFullLayoutCalc && contain === 'both' && curY > rwSdf.y2) {
|
|
431
|
+
// Stop layout calculation early (for performance purposes) if:
|
|
432
|
+
// - We're not forcing a full layout calculation (for width/height calculation)
|
|
433
|
+
// - ...and we're containing the text vertically+horizontally (contain === 'both')
|
|
434
|
+
// - ...and we have a render window
|
|
435
|
+
// - ...and the next line is below the bottom of the render window
|
|
436
|
+
moreLines = false;
|
|
437
|
+
} else if (glyphResult && glyphResult.done) {
|
|
438
|
+
// If we've reached the end of the text, we know we're done
|
|
439
|
+
moreLines = false;
|
|
440
|
+
} else if (!nextLineWillFit) {
|
|
441
|
+
// If we're contained vertically+horizontally (contain === 'both')
|
|
442
|
+
// but not scrollable and the next line won't fit, we're done.
|
|
443
|
+
moreLines = false;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Use textAlign to determine if we need to adjust the x position of the text
|
|
448
|
+
// in the buffer line by line
|
|
449
|
+
if (textAlign === 'center') {
|
|
450
|
+
const vertexTextW = contain === 'none' ? maxX : vertexW;
|
|
451
|
+
|
|
452
|
+
for (let i = 0; i < bufferLineInfos.length; i++) {
|
|
453
|
+
const line = bufferLineInfos[i]!;
|
|
454
|
+
// - 4 = the x position of a rightmost vertex
|
|
455
|
+
const lineWidth =
|
|
456
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
457
|
+
vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
|
|
458
|
+
|
|
459
|
+
const xOffset = (vertexTextW - lineWidth) / 2;
|
|
460
|
+
for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
|
|
461
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
462
|
+
vertexBuffer[j]! += xOffset;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
} else if (textAlign === 'right') {
|
|
466
|
+
const vertexTextW = contain === 'none' ? maxX : vertexW;
|
|
467
|
+
|
|
468
|
+
for (let i = 0; i < bufferLineInfos.length; i++) {
|
|
469
|
+
const line = bufferLineInfos[i]!;
|
|
470
|
+
const lineWidth =
|
|
471
|
+
line.bufferEnd === line.bufferStart
|
|
472
|
+
? 0
|
|
473
|
+
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
474
|
+
vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
|
|
475
|
+
|
|
476
|
+
const xOffset = vertexTextW - lineWidth;
|
|
477
|
+
for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
|
|
478
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
479
|
+
vertexBuffer[j]! += xOffset;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
assertTruthy(glyphResult);
|
|
485
|
+
|
|
486
|
+
return {
|
|
487
|
+
bufferNumFloats: bufferOffset,
|
|
488
|
+
bufferNumQuads: bufferOffset / 16,
|
|
489
|
+
layoutNumCharacters: glyphResult.done
|
|
490
|
+
? text.length - startingCodepointIndex
|
|
491
|
+
: glyphResult.value.cluster - startingCodepointIndex + 1,
|
|
492
|
+
fullyProcessed: !!glyphResult.done,
|
|
493
|
+
maxX,
|
|
494
|
+
maxY,
|
|
495
|
+
numLines: lineCache.length,
|
|
496
|
+
};
|
|
497
|
+
}
|