@lightningjs/renderer 0.7.2 → 0.7.3

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.
Files changed (188) hide show
  1. package/COPYING +1 -0
  2. package/LICENSE +202 -202
  3. package/NOTICE +3 -3
  4. package/README.md +221 -221
  5. package/dist/src/common/CommonTypes.d.ts +7 -0
  6. package/dist/src/core/Stage.d.ts +2 -1
  7. package/dist/src/core/Stage.js +4 -0
  8. package/dist/src/core/Stage.js.map +1 -1
  9. package/dist/src/core/animations/CoreAnimation.js +3 -0
  10. package/dist/src/core/animations/CoreAnimation.js.map +1 -1
  11. package/dist/src/core/animations/CoreAnimationController.d.ts +8 -0
  12. package/dist/src/core/animations/CoreAnimationController.js +26 -0
  13. package/dist/src/core/animations/CoreAnimationController.js.map +1 -1
  14. package/dist/src/core/lib/ImageWorker.js +21 -21
  15. package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +47 -47
  16. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +61 -61
  17. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +93 -93
  18. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +63 -63
  19. package/dist/src/core/renderers/webgl/shaders/SdfShader.js +49 -49
  20. package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +15 -15
  21. package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +5 -5
  22. package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +15 -15
  23. package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +15 -15
  24. package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +15 -15
  25. package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +42 -42
  26. package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +44 -44
  27. package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +3 -3
  28. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +31 -31
  29. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +13 -13
  30. package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +37 -37
  31. package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +19 -19
  32. package/dist/src/main-api/ICoreDriver.d.ts +2 -1
  33. package/dist/src/main-api/Inspector.d.ts +6 -0
  34. package/dist/src/main-api/Inspector.js +105 -19
  35. package/dist/src/main-api/Inspector.js.map +1 -1
  36. package/dist/src/main-api/RendererMain.d.ts +12 -0
  37. package/dist/src/main-api/RendererMain.js +19 -1
  38. package/dist/src/main-api/RendererMain.js.map +1 -1
  39. package/dist/src/render-drivers/main/MainCoreDriver.d.ts +2 -1
  40. package/dist/src/render-drivers/main/MainCoreDriver.js +7 -1
  41. package/dist/src/render-drivers/main/MainCoreDriver.js.map +1 -1
  42. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +2 -1
  43. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +7 -0
  44. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +1 -1
  45. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +9 -1
  46. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +1 -1
  47. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  48. package/exports/core-api.ts +102 -102
  49. package/exports/main-api.ts +60 -60
  50. package/exports/utils.ts +41 -41
  51. package/package.json +5 -3
  52. package/scripts/please-use-pnpm.js +13 -0
  53. package/src/common/CommonTypes.ts +113 -105
  54. package/src/common/EventEmitter.ts +77 -77
  55. package/src/common/IAnimationController.ts +29 -29
  56. package/src/core/CoreExtension.ts +32 -32
  57. package/src/core/CoreNode.ts +926 -926
  58. package/src/core/CoreShaderManager.ts +243 -243
  59. package/src/core/CoreTextNode.ts +391 -391
  60. package/src/core/CoreTextureManager.ts +326 -326
  61. package/src/core/Stage.ts +354 -342
  62. package/src/core/animations/AnimationManager.ts +38 -38
  63. package/src/core/animations/CoreAnimation.ts +181 -177
  64. package/src/core/animations/CoreAnimationController.ts +148 -117
  65. package/src/core/lib/ContextSpy.ts +41 -41
  66. package/src/core/lib/ImageWorker.ts +124 -124
  67. package/src/core/lib/Matrix3d.ts +290 -290
  68. package/src/core/lib/WebGlContextWrapper.ts +992 -992
  69. package/src/core/lib/textureCompression.ts +152 -152
  70. package/src/core/lib/utils.ts +241 -241
  71. package/src/core/platform.ts +46 -46
  72. package/src/core/renderers/CoreContextTexture.ts +30 -30
  73. package/src/core/renderers/CoreRenderOp.ts +22 -22
  74. package/src/core/renderers/CoreRenderer.ts +63 -63
  75. package/src/core/renderers/CoreShader.ts +41 -41
  76. package/src/core/renderers/webgl/WebGlCoreCtxSubTexture.ts +37 -37
  77. package/src/core/renderers/webgl/WebGlCoreCtxTexture.ts +231 -231
  78. package/src/core/renderers/webgl/WebGlCoreRenderOp.ts +107 -107
  79. package/src/core/renderers/webgl/WebGlCoreRenderer.ts +520 -520
  80. package/src/core/renderers/webgl/WebGlCoreShader.ts +337 -337
  81. package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
  82. package/src/core/renderers/webgl/internal/RendererUtils.ts +131 -131
  83. package/src/core/renderers/webgl/internal/ShaderUtils.ts +136 -136
  84. package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
  85. package/src/core/renderers/webgl/shaders/DefaultShader.ts +95 -95
  86. package/src/core/renderers/webgl/shaders/DefaultShaderBatched.ts +132 -132
  87. package/src/core/renderers/webgl/shaders/DynamicShader.ts +474 -474
  88. package/src/core/renderers/webgl/shaders/RoundedRectangle.ts +161 -161
  89. package/src/core/renderers/webgl/shaders/SdfShader.ts +174 -174
  90. package/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.ts +101 -101
  91. package/src/core/renderers/webgl/shaders/effects/BorderEffect.ts +86 -86
  92. package/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.ts +101 -101
  93. package/src/core/renderers/webgl/shaders/effects/BorderRightEffect.ts +101 -101
  94. package/src/core/renderers/webgl/shaders/effects/BorderTopEffect.ts +101 -101
  95. package/src/core/renderers/webgl/shaders/effects/EffectUtils.ts +33 -33
  96. package/src/core/renderers/webgl/shaders/effects/FadeOutEffect.ts +135 -135
  97. package/src/core/renderers/webgl/shaders/effects/GlitchEffect.ts +145 -145
  98. package/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.ts +67 -67
  99. package/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.ts +176 -176
  100. package/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.ts +159 -159
  101. package/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.ts +186 -186
  102. package/src/core/renderers/webgl/shaders/effects/RadiusEffect.ts +121 -121
  103. package/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts +114 -114
  104. package/src/core/text-rendering/TextTextureRendererUtils.ts +189 -189
  105. package/src/core/text-rendering/TrFontManager.ts +96 -96
  106. package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +141 -141
  107. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
  108. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
  109. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +169 -169
  110. package/src/core/text-rendering/font-face-types/TrFontFace.ts +105 -105
  111. package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +77 -77
  112. package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +751 -751
  113. package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +741 -741
  114. package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +775 -775
  115. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
  116. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
  117. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
  118. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
  119. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +84 -84
  120. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
  121. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
  122. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +393 -393
  123. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
  124. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +51 -51
  125. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
  126. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
  127. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
  128. package/src/core/text-rendering/renderers/TextRenderer.ts +504 -504
  129. package/src/core/textures/ColorTexture.ts +86 -86
  130. package/src/core/textures/ImageTexture.ts +133 -133
  131. package/src/core/textures/NoiseTexture.ts +96 -96
  132. package/src/core/textures/SubTexture.ts +143 -143
  133. package/src/core/textures/Texture.ts +218 -218
  134. package/src/core/utils.ts +224 -224
  135. package/src/env.d.ts +7 -7
  136. package/src/main-api/ICoreDriver.ts +66 -61
  137. package/src/main-api/INode.ts +470 -470
  138. package/src/main-api/Inspector.ts +432 -0
  139. package/src/main-api/RendererMain.ts +649 -610
  140. package/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.ts +45 -45
  141. package/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.ts +154 -154
  142. package/src/main-api/texture-usage-trackers/TextureUsageTracker.ts +54 -54
  143. package/src/render-drivers/main/MainCoreDriver.ts +148 -133
  144. package/src/render-drivers/main/MainOnlyNode.ts +453 -453
  145. package/src/render-drivers/main/MainOnlyTextNode.ts +261 -261
  146. package/src/render-drivers/threadx/NodeStruct.ts +300 -300
  147. package/src/render-drivers/threadx/SharedNode.ts +97 -97
  148. package/src/render-drivers/threadx/TextNodeStruct.ts +211 -211
  149. package/src/render-drivers/threadx/ThreadXCoreDriver.ts +285 -273
  150. package/src/render-drivers/threadx/ThreadXMainAnimationController.ts +99 -99
  151. package/src/render-drivers/threadx/ThreadXMainNode.ts +178 -178
  152. package/src/render-drivers/threadx/ThreadXMainTextNode.ts +85 -85
  153. package/src/render-drivers/threadx/ThreadXRendererMessage.ts +110 -97
  154. package/src/render-drivers/threadx/worker/ThreadXRendererNode.ts +238 -238
  155. package/src/render-drivers/threadx/worker/ThreadXRendererTextNode.ts +149 -149
  156. package/src/render-drivers/threadx/worker/renderer.ts +151 -151
  157. package/src/render-drivers/utils.ts +57 -57
  158. package/src/utils.ts +207 -207
  159. package/dist/src/core/lib/WebGlContext.d.ts +0 -414
  160. package/dist/src/core/lib/WebGlContext.js +0 -640
  161. package/dist/src/core/lib/WebGlContext.js.map +0 -1
  162. package/dist/src/core/scene/Scene.d.ts +0 -59
  163. package/dist/src/core/scene/Scene.js +0 -106
  164. package/dist/src/core/scene/Scene.js.map +0 -1
  165. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/findNearestMultiple.d.ts +0 -8
  166. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/findNearestMultiple.js +0 -29
  167. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/findNearestMultiple.js.map +0 -1
  168. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/SdfBufferHelper.d.ts +0 -19
  169. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/SdfBufferHelper.js +0 -84
  170. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/SdfBufferHelper.js.map +0 -1
  171. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutLine.d.ts +0 -8
  172. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutLine.js +0 -40
  173. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutLine.js.map +0 -1
  174. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutText2.d.ts +0 -2
  175. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutText2.js +0 -41
  176. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutText2.js.map +0 -1
  177. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/utils.d.ts +0 -1
  178. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/utils.js +0 -4
  179. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/utils.js.map +0 -1
  180. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2.d.ts +0 -1
  181. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2.js +0 -2
  182. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2.js.map +0 -1
  183. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.d.ts +0 -20
  184. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js +0 -55
  185. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js.map +0 -1
  186. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/roundUpToMultiple.d.ts +0 -9
  187. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/roundUpToMultiple.js +0 -32
  188. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/roundUpToMultiple.js.map +0 -1
@@ -1,393 +1,393 @@
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: TrProps['lineHeight'],
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
- maxLines: TrProps['maxLines'],
59
- ): {
60
- bufferNumFloats: number;
61
- bufferNumQuads: number;
62
- layoutNumCharacters: number;
63
- fullyProcessed: boolean;
64
- maxX: number;
65
- maxY: number;
66
- } {
67
- assertTruthy(trFontFace, 'Font face must be loaded');
68
- assertTruthy(trFontFace.loaded, 'Font face must be loaded');
69
- assertTruthy(trFontFace.data, 'Font face must be loaded');
70
- assertTruthy(trFontFace.shaper, 'Font face must be loaded');
71
-
72
- // Regardless of fontSize (or other scaling properties), we layout the vertices of each glyph
73
- // using the fixed coordinate space determined by font size used to produce the atlas.
74
- // Scaling for display is handled by shader uniforms inexpensively.
75
- // So we have:
76
- // - vertex space: the space in which the vertices of each glyph are laid out
77
- // - screen space: the screen pixel space
78
- // Input properties such as x, y, w, fontSize, letterSpacing, etc. are all expressed in screen space.
79
- // We convert these to the vertex space by dividing them the `fontSizeRatio` factor.
80
-
81
- /**
82
- * See above
83
- */
84
- const fontSizeRatio = fontSize / trFontFace.data.info.size;
85
- /**
86
- * `lineHeight` in vertex coordinates
87
- */
88
- const vertexLineHeight = lineHeight / fontSizeRatio;
89
- /**
90
- * `w` in vertex coordinates
91
- */
92
- const vertexW = width / fontSizeRatio;
93
- /**
94
- * `letterSpacing` in vertex coordinates
95
- */
96
- const vertexLSpacing = letterSpacing / fontSizeRatio;
97
-
98
- const startingLineCacheEntry = lineCache[curLineIndex];
99
- const startingCodepointIndex = startingLineCacheEntry?.codepointIndex || 0;
100
- const startingMaxX = startingLineCacheEntry?.maxX || 0;
101
- const startingMaxY = startingLineCacheEntry?.maxY || 0;
102
-
103
- let maxX = startingMaxX;
104
- let maxY = startingMaxY;
105
- let curX = startX;
106
- let curY = startY;
107
-
108
- let bufferOffset = 0;
109
- /**
110
- * Buffer offset to last word boundry. This is -1 when we aren't in a word boundry.
111
- */
112
- const lastWord: {
113
- codepointIndex: number;
114
- bufferOffset: number;
115
- xStart: number;
116
- } = {
117
- codepointIndex: -1,
118
- bufferOffset: -1,
119
- xStart: -1,
120
- };
121
-
122
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
123
- const shaper = trFontFace.shaper;
124
-
125
- const shaperProps: FontShaperProps = {
126
- letterSpacing: vertexLSpacing,
127
- };
128
-
129
- // Get glyphs
130
- let glyphs = shaper.shapeText(
131
- shaperProps,
132
- new PeekableIterator(
133
- getUnicodeCodepoints(text, startingCodepointIndex),
134
- startingCodepointIndex,
135
- ),
136
- );
137
-
138
- let glyphResult:
139
- | IteratorResult<MappedGlyphInfo | UnmappedCharacterInfo, void>
140
- | undefined;
141
-
142
- let curLineBufferStart = -1;
143
-
144
- const bufferLineInfos: {
145
- bufferStart: number;
146
- bufferEnd: number;
147
- }[] = [];
148
-
149
- const vertexTruncateHeight = height / fontSizeRatio;
150
- const overflowSuffVertexWidth = measureText(
151
- overflowSuffix,
152
- shaperProps,
153
- shaper,
154
- );
155
-
156
- // Line-by-line layout
157
- let moreLines = true;
158
- while (moreLines) {
159
- const nextLineWillFit =
160
- (maxLines === 0 || curLineIndex + 1 < maxLines) &&
161
- (contain !== 'both' ||
162
- scrollable ||
163
- curY + vertexLineHeight + trFontFace.maxCharHeight <=
164
- vertexTruncateHeight);
165
- const lineVertexW = nextLineWillFit
166
- ? vertexW
167
- : vertexW - overflowSuffVertexWidth;
168
- /**
169
- * Vertex X position to the beginning of the last word boundary. This becomes -1 when we start traversing a word.
170
- */
171
- let xStartLastWordBoundary = 0;
172
-
173
- const lineIsBelowWindowTop = curY + vertexLineHeight >= rwSdf.y1;
174
- const lineIsAboveWindowBottom = curY <= rwSdf.y2;
175
- const lineIsWithinWindow = lineIsBelowWindowTop && lineIsAboveWindowBottom;
176
- // Layout glyphs in this line
177
- // Any break statements in this while loop will trigger a line break
178
- while ((glyphResult = glyphs.next()) && !glyphResult.done) {
179
- const glyph = glyphResult.value;
180
-
181
- if (curLineIndex === lineCache.length) {
182
- lineCache.push({
183
- codepointIndex: glyph.cluster,
184
- maxY,
185
- maxX,
186
- });
187
- } else if (curLineIndex > lineCache.length) {
188
- throw new Error('Unexpected lineCache length');
189
- }
190
-
191
- // If we encounter a word boundary (white space or newline) we invalidate
192
- // the lastWord and set the xStartLastWordBoundary if we haven't already.
193
- if (glyph.codepoint === 32 || glyph.codepoint === 10) {
194
- if (lastWord.codepointIndex !== -1) {
195
- lastWord.codepointIndex = -1;
196
- xStartLastWordBoundary = curX;
197
- }
198
- } else if (lastWord.codepointIndex === -1) {
199
- lastWord.codepointIndex = glyph.cluster;
200
- lastWord.bufferOffset = bufferOffset;
201
- lastWord.xStart = xStartLastWordBoundary;
202
- }
203
-
204
- if (glyph.mapped) {
205
- // Mapped glyph
206
- const charEndX = curX + glyph.xOffset + glyph.width;
207
- // Word wrap check
208
- if (
209
- // We are containing the text
210
- contain !== 'none' &&
211
- // The current glyph reaches outside the contained width
212
- charEndX >= lineVertexW &&
213
- // There is a last word that we can break to the next line
214
- lastWord.codepointIndex !== -1 &&
215
- // We have advanced at least one character since the last word started
216
- lastWord.codepointIndex < glyph.cluster &&
217
- // Prevents infinite loop when a single word is longer than the width
218
- lastWord.xStart > 0
219
- ) {
220
- // The current word is about to go off the edge of the container width
221
- // Reinitialize the iterator starting at the last word
222
- // and proceeding to the next line
223
- if (nextLineWillFit) {
224
- glyphs = shaper.shapeText(
225
- shaperProps,
226
- new PeekableIterator(
227
- getUnicodeCodepoints(text, lastWord.codepointIndex),
228
- lastWord.codepointIndex,
229
- ),
230
- );
231
- bufferOffset = lastWord.bufferOffset;
232
- break;
233
- } else {
234
- glyphs = shaper.shapeText(
235
- shaperProps,
236
- new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
237
- );
238
- curX = lastWord.xStart;
239
- bufferOffset = lastWord.bufferOffset;
240
- }
241
- } else {
242
- // This glyph fits, so we can add it to the buffer
243
- const quadX = curX + glyph.xOffset;
244
- const quadY = curY + glyph.yOffset;
245
-
246
- // Only add to buffer for rendering if the line is within the render window
247
- if (lineIsWithinWindow) {
248
- if (curLineBufferStart === -1) {
249
- curLineBufferStart = bufferOffset;
250
- }
251
-
252
- const atlasEntry = trFontFace.getAtlasEntry(glyph.glyphId);
253
-
254
- // Add texture coordinates
255
- const u = atlasEntry.x / trFontFace.data.common.scaleW;
256
- const v = atlasEntry.y / trFontFace.data.common.scaleH;
257
- const uvWidth = atlasEntry.width / trFontFace.data.common.scaleW;
258
- const uvHeight = atlasEntry.height / trFontFace.data.common.scaleH;
259
-
260
- // TODO: (Performance) We can optimize this by using ELEMENT_ARRAY_BUFFER
261
- // eliminating the need to duplicate vertices
262
-
263
- // Top-left
264
- vertexBuffer[bufferOffset++] = quadX;
265
- vertexBuffer[bufferOffset++] = quadY;
266
- vertexBuffer[bufferOffset++] = u;
267
- vertexBuffer[bufferOffset++] = v;
268
-
269
- // Top-right
270
- vertexBuffer[bufferOffset++] = quadX + glyph.width;
271
- vertexBuffer[bufferOffset++] = quadY;
272
- vertexBuffer[bufferOffset++] = u + uvWidth;
273
- vertexBuffer[bufferOffset++] = v;
274
-
275
- // Bottom-left
276
- vertexBuffer[bufferOffset++] = quadX;
277
- vertexBuffer[bufferOffset++] = quadY + glyph.height;
278
- vertexBuffer[bufferOffset++] = u;
279
- vertexBuffer[bufferOffset++] = v + uvHeight;
280
-
281
- // Bottom-right
282
- vertexBuffer[bufferOffset++] = quadX + glyph.width;
283
- vertexBuffer[bufferOffset++] = quadY + glyph.height;
284
- vertexBuffer[bufferOffset++] = u + uvWidth;
285
- vertexBuffer[bufferOffset++] = v + uvHeight;
286
- }
287
-
288
- maxY = Math.max(maxY, quadY + glyph.height);
289
- curX += glyph.xAdvance;
290
- maxX = Math.max(maxX, curX);
291
- }
292
- } else {
293
- // Unmapped character
294
-
295
- // Handle newlines
296
- if (glyph.codepoint === 10) {
297
- if (nextLineWillFit) {
298
- // The whole line fit, so we can break to the next line
299
- break;
300
- } else {
301
- // The whole line won't fit, so we need to add the overflow suffix
302
- glyphs = shaper.shapeText(
303
- shaperProps,
304
- new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
305
- );
306
- // HACK: For the rest of the line when inserting the overflow suffix,
307
- // set contain = 'none' to prevent an infinite loop.
308
- contain = 'none';
309
- }
310
- }
311
- }
312
- }
313
-
314
- // Prepare for the next line...
315
- if (curLineBufferStart !== -1) {
316
- bufferLineInfos.push({
317
- bufferStart: curLineBufferStart,
318
- bufferEnd: bufferOffset,
319
- });
320
- curLineBufferStart = -1;
321
- }
322
- curX = 0;
323
- curY += vertexLineHeight;
324
- curLineIndex++;
325
- lastWord.codepointIndex = -1;
326
- xStartLastWordBoundary = 0;
327
-
328
- // Figure out if there are any more lines to render...
329
- if (!forceFullLayoutCalc && contain === 'both' && curY > rwSdf.y2) {
330
- // Stop layout calculation early (for performance purposes) if:
331
- // - We're not forcing a full layout calculation (for width/height calculation)
332
- // - ...and we're containing the text vertically+horizontally (contain === 'both')
333
- // - ...and we have a render window
334
- // - ...and the next line is below the bottom of the render window
335
- moreLines = false;
336
- } else if (glyphResult && glyphResult.done) {
337
- // If we've reached the end of the text, we know we're done
338
- moreLines = false;
339
- } else if (!nextLineWillFit) {
340
- // If we're contained vertically+horizontally (contain === 'both')
341
- // but not scrollable and the next line won't fit, we're done.
342
- moreLines = false;
343
- }
344
- }
345
-
346
- // Use textAlign to determine if we need to adjust the x position of the text
347
- // in the buffer line by line
348
- if (textAlign === 'center') {
349
- const vertexTextW = contain === 'none' ? maxX : vertexW;
350
-
351
- for (let i = 0; i < bufferLineInfos.length; i++) {
352
- const line = bufferLineInfos[i]!;
353
- // - 4 = the x position of a rightmost vertex
354
- const lineWidth =
355
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
356
- vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
357
-
358
- const xOffset = (vertexTextW - lineWidth) / 2;
359
- for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
360
- vertexBuffer[j] += xOffset;
361
- }
362
- }
363
- } else if (textAlign === 'right') {
364
- const vertexTextW = contain === 'none' ? maxX : vertexW;
365
-
366
- for (let i = 0; i < bufferLineInfos.length; i++) {
367
- const line = bufferLineInfos[i]!;
368
- const lineWidth =
369
- line.bufferEnd === line.bufferStart
370
- ? 0
371
- : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
372
- vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
373
-
374
- const xOffset = vertexTextW - lineWidth;
375
- for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
376
- vertexBuffer[j] += xOffset;
377
- }
378
- }
379
- }
380
-
381
- assertTruthy(glyphResult);
382
-
383
- return {
384
- bufferNumFloats: bufferOffset,
385
- bufferNumQuads: bufferOffset / 16,
386
- layoutNumCharacters: glyphResult.done
387
- ? text.length - startingCodepointIndex
388
- : glyphResult.value.cluster - startingCodepointIndex + 1,
389
- fullyProcessed: !!glyphResult.done,
390
- maxX,
391
- maxY,
392
- };
393
- }
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: TrProps['lineHeight'],
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
+ maxLines: TrProps['maxLines'],
59
+ ): {
60
+ bufferNumFloats: number;
61
+ bufferNumQuads: number;
62
+ layoutNumCharacters: number;
63
+ fullyProcessed: boolean;
64
+ maxX: number;
65
+ maxY: number;
66
+ } {
67
+ assertTruthy(trFontFace, 'Font face must be loaded');
68
+ assertTruthy(trFontFace.loaded, 'Font face must be loaded');
69
+ assertTruthy(trFontFace.data, 'Font face must be loaded');
70
+ assertTruthy(trFontFace.shaper, 'Font face must be loaded');
71
+
72
+ // Regardless of fontSize (or other scaling properties), we layout the vertices of each glyph
73
+ // using the fixed coordinate space determined by font size used to produce the atlas.
74
+ // Scaling for display is handled by shader uniforms inexpensively.
75
+ // So we have:
76
+ // - vertex space: the space in which the vertices of each glyph are laid out
77
+ // - screen space: the screen pixel space
78
+ // Input properties such as x, y, w, fontSize, letterSpacing, etc. are all expressed in screen space.
79
+ // We convert these to the vertex space by dividing them the `fontSizeRatio` factor.
80
+
81
+ /**
82
+ * See above
83
+ */
84
+ const fontSizeRatio = fontSize / trFontFace.data.info.size;
85
+ /**
86
+ * `lineHeight` in vertex coordinates
87
+ */
88
+ const vertexLineHeight = lineHeight / fontSizeRatio;
89
+ /**
90
+ * `w` in vertex coordinates
91
+ */
92
+ const vertexW = width / fontSizeRatio;
93
+ /**
94
+ * `letterSpacing` in vertex coordinates
95
+ */
96
+ const vertexLSpacing = letterSpacing / fontSizeRatio;
97
+
98
+ const startingLineCacheEntry = lineCache[curLineIndex];
99
+ const startingCodepointIndex = startingLineCacheEntry?.codepointIndex || 0;
100
+ const startingMaxX = startingLineCacheEntry?.maxX || 0;
101
+ const startingMaxY = startingLineCacheEntry?.maxY || 0;
102
+
103
+ let maxX = startingMaxX;
104
+ let maxY = startingMaxY;
105
+ let curX = startX;
106
+ let curY = startY;
107
+
108
+ let bufferOffset = 0;
109
+ /**
110
+ * Buffer offset to last word boundry. This is -1 when we aren't in a word boundry.
111
+ */
112
+ const lastWord: {
113
+ codepointIndex: number;
114
+ bufferOffset: number;
115
+ xStart: number;
116
+ } = {
117
+ codepointIndex: -1,
118
+ bufferOffset: -1,
119
+ xStart: -1,
120
+ };
121
+
122
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
123
+ const shaper = trFontFace.shaper;
124
+
125
+ const shaperProps: FontShaperProps = {
126
+ letterSpacing: vertexLSpacing,
127
+ };
128
+
129
+ // Get glyphs
130
+ let glyphs = shaper.shapeText(
131
+ shaperProps,
132
+ new PeekableIterator(
133
+ getUnicodeCodepoints(text, startingCodepointIndex),
134
+ startingCodepointIndex,
135
+ ),
136
+ );
137
+
138
+ let glyphResult:
139
+ | IteratorResult<MappedGlyphInfo | UnmappedCharacterInfo, void>
140
+ | undefined;
141
+
142
+ let curLineBufferStart = -1;
143
+
144
+ const bufferLineInfos: {
145
+ bufferStart: number;
146
+ bufferEnd: number;
147
+ }[] = [];
148
+
149
+ const vertexTruncateHeight = height / fontSizeRatio;
150
+ const overflowSuffVertexWidth = measureText(
151
+ overflowSuffix,
152
+ shaperProps,
153
+ shaper,
154
+ );
155
+
156
+ // Line-by-line layout
157
+ let moreLines = true;
158
+ while (moreLines) {
159
+ const nextLineWillFit =
160
+ (maxLines === 0 || curLineIndex + 1 < maxLines) &&
161
+ (contain !== 'both' ||
162
+ scrollable ||
163
+ curY + vertexLineHeight + trFontFace.maxCharHeight <=
164
+ vertexTruncateHeight);
165
+ const lineVertexW = nextLineWillFit
166
+ ? vertexW
167
+ : vertexW - overflowSuffVertexWidth;
168
+ /**
169
+ * Vertex X position to the beginning of the last word boundary. This becomes -1 when we start traversing a word.
170
+ */
171
+ let xStartLastWordBoundary = 0;
172
+
173
+ const lineIsBelowWindowTop = curY + vertexLineHeight >= rwSdf.y1;
174
+ const lineIsAboveWindowBottom = curY <= rwSdf.y2;
175
+ const lineIsWithinWindow = lineIsBelowWindowTop && lineIsAboveWindowBottom;
176
+ // Layout glyphs in this line
177
+ // Any break statements in this while loop will trigger a line break
178
+ while ((glyphResult = glyphs.next()) && !glyphResult.done) {
179
+ const glyph = glyphResult.value;
180
+
181
+ if (curLineIndex === lineCache.length) {
182
+ lineCache.push({
183
+ codepointIndex: glyph.cluster,
184
+ maxY,
185
+ maxX,
186
+ });
187
+ } else if (curLineIndex > lineCache.length) {
188
+ throw new Error('Unexpected lineCache length');
189
+ }
190
+
191
+ // If we encounter a word boundary (white space or newline) we invalidate
192
+ // the lastWord and set the xStartLastWordBoundary if we haven't already.
193
+ if (glyph.codepoint === 32 || glyph.codepoint === 10) {
194
+ if (lastWord.codepointIndex !== -1) {
195
+ lastWord.codepointIndex = -1;
196
+ xStartLastWordBoundary = curX;
197
+ }
198
+ } else if (lastWord.codepointIndex === -1) {
199
+ lastWord.codepointIndex = glyph.cluster;
200
+ lastWord.bufferOffset = bufferOffset;
201
+ lastWord.xStart = xStartLastWordBoundary;
202
+ }
203
+
204
+ if (glyph.mapped) {
205
+ // Mapped glyph
206
+ const charEndX = curX + glyph.xOffset + glyph.width;
207
+ // Word wrap check
208
+ if (
209
+ // We are containing the text
210
+ contain !== 'none' &&
211
+ // The current glyph reaches outside the contained width
212
+ charEndX >= lineVertexW &&
213
+ // There is a last word that we can break to the next line
214
+ lastWord.codepointIndex !== -1 &&
215
+ // We have advanced at least one character since the last word started
216
+ lastWord.codepointIndex < glyph.cluster &&
217
+ // Prevents infinite loop when a single word is longer than the width
218
+ lastWord.xStart > 0
219
+ ) {
220
+ // The current word is about to go off the edge of the container width
221
+ // Reinitialize the iterator starting at the last word
222
+ // and proceeding to the next line
223
+ if (nextLineWillFit) {
224
+ glyphs = shaper.shapeText(
225
+ shaperProps,
226
+ new PeekableIterator(
227
+ getUnicodeCodepoints(text, lastWord.codepointIndex),
228
+ lastWord.codepointIndex,
229
+ ),
230
+ );
231
+ bufferOffset = lastWord.bufferOffset;
232
+ break;
233
+ } else {
234
+ glyphs = shaper.shapeText(
235
+ shaperProps,
236
+ new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
237
+ );
238
+ curX = lastWord.xStart;
239
+ bufferOffset = lastWord.bufferOffset;
240
+ }
241
+ } else {
242
+ // This glyph fits, so we can add it to the buffer
243
+ const quadX = curX + glyph.xOffset;
244
+ const quadY = curY + glyph.yOffset;
245
+
246
+ // Only add to buffer for rendering if the line is within the render window
247
+ if (lineIsWithinWindow) {
248
+ if (curLineBufferStart === -1) {
249
+ curLineBufferStart = bufferOffset;
250
+ }
251
+
252
+ const atlasEntry = trFontFace.getAtlasEntry(glyph.glyphId);
253
+
254
+ // Add texture coordinates
255
+ const u = atlasEntry.x / trFontFace.data.common.scaleW;
256
+ const v = atlasEntry.y / trFontFace.data.common.scaleH;
257
+ const uvWidth = atlasEntry.width / trFontFace.data.common.scaleW;
258
+ const uvHeight = atlasEntry.height / trFontFace.data.common.scaleH;
259
+
260
+ // TODO: (Performance) We can optimize this by using ELEMENT_ARRAY_BUFFER
261
+ // eliminating the need to duplicate vertices
262
+
263
+ // Top-left
264
+ vertexBuffer[bufferOffset++] = quadX;
265
+ vertexBuffer[bufferOffset++] = quadY;
266
+ vertexBuffer[bufferOffset++] = u;
267
+ vertexBuffer[bufferOffset++] = v;
268
+
269
+ // Top-right
270
+ vertexBuffer[bufferOffset++] = quadX + glyph.width;
271
+ vertexBuffer[bufferOffset++] = quadY;
272
+ vertexBuffer[bufferOffset++] = u + uvWidth;
273
+ vertexBuffer[bufferOffset++] = v;
274
+
275
+ // Bottom-left
276
+ vertexBuffer[bufferOffset++] = quadX;
277
+ vertexBuffer[bufferOffset++] = quadY + glyph.height;
278
+ vertexBuffer[bufferOffset++] = u;
279
+ vertexBuffer[bufferOffset++] = v + uvHeight;
280
+
281
+ // Bottom-right
282
+ vertexBuffer[bufferOffset++] = quadX + glyph.width;
283
+ vertexBuffer[bufferOffset++] = quadY + glyph.height;
284
+ vertexBuffer[bufferOffset++] = u + uvWidth;
285
+ vertexBuffer[bufferOffset++] = v + uvHeight;
286
+ }
287
+
288
+ maxY = Math.max(maxY, quadY + glyph.height);
289
+ curX += glyph.xAdvance;
290
+ maxX = Math.max(maxX, curX);
291
+ }
292
+ } else {
293
+ // Unmapped character
294
+
295
+ // Handle newlines
296
+ if (glyph.codepoint === 10) {
297
+ if (nextLineWillFit) {
298
+ // The whole line fit, so we can break to the next line
299
+ break;
300
+ } else {
301
+ // The whole line won't fit, so we need to add the overflow suffix
302
+ glyphs = shaper.shapeText(
303
+ shaperProps,
304
+ new PeekableIterator(getUnicodeCodepoints(overflowSuffix, 0), 0),
305
+ );
306
+ // HACK: For the rest of the line when inserting the overflow suffix,
307
+ // set contain = 'none' to prevent an infinite loop.
308
+ contain = 'none';
309
+ }
310
+ }
311
+ }
312
+ }
313
+
314
+ // Prepare for the next line...
315
+ if (curLineBufferStart !== -1) {
316
+ bufferLineInfos.push({
317
+ bufferStart: curLineBufferStart,
318
+ bufferEnd: bufferOffset,
319
+ });
320
+ curLineBufferStart = -1;
321
+ }
322
+ curX = 0;
323
+ curY += vertexLineHeight;
324
+ curLineIndex++;
325
+ lastWord.codepointIndex = -1;
326
+ xStartLastWordBoundary = 0;
327
+
328
+ // Figure out if there are any more lines to render...
329
+ if (!forceFullLayoutCalc && contain === 'both' && curY > rwSdf.y2) {
330
+ // Stop layout calculation early (for performance purposes) if:
331
+ // - We're not forcing a full layout calculation (for width/height calculation)
332
+ // - ...and we're containing the text vertically+horizontally (contain === 'both')
333
+ // - ...and we have a render window
334
+ // - ...and the next line is below the bottom of the render window
335
+ moreLines = false;
336
+ } else if (glyphResult && glyphResult.done) {
337
+ // If we've reached the end of the text, we know we're done
338
+ moreLines = false;
339
+ } else if (!nextLineWillFit) {
340
+ // If we're contained vertically+horizontally (contain === 'both')
341
+ // but not scrollable and the next line won't fit, we're done.
342
+ moreLines = false;
343
+ }
344
+ }
345
+
346
+ // Use textAlign to determine if we need to adjust the x position of the text
347
+ // in the buffer line by line
348
+ if (textAlign === 'center') {
349
+ const vertexTextW = contain === 'none' ? maxX : vertexW;
350
+
351
+ for (let i = 0; i < bufferLineInfos.length; i++) {
352
+ const line = bufferLineInfos[i]!;
353
+ // - 4 = the x position of a rightmost vertex
354
+ const lineWidth =
355
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
356
+ vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
357
+
358
+ const xOffset = (vertexTextW - lineWidth) / 2;
359
+ for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
360
+ vertexBuffer[j] += xOffset;
361
+ }
362
+ }
363
+ } else if (textAlign === 'right') {
364
+ const vertexTextW = contain === 'none' ? maxX : vertexW;
365
+
366
+ for (let i = 0; i < bufferLineInfos.length; i++) {
367
+ const line = bufferLineInfos[i]!;
368
+ const lineWidth =
369
+ line.bufferEnd === line.bufferStart
370
+ ? 0
371
+ : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
372
+ vertexBuffer[line.bufferEnd - 4]! - vertexBuffer[line.bufferStart]!;
373
+
374
+ const xOffset = vertexTextW - lineWidth;
375
+ for (let j = line.bufferStart; j < line.bufferEnd; j += 4) {
376
+ vertexBuffer[j] += xOffset;
377
+ }
378
+ }
379
+ }
380
+
381
+ assertTruthy(glyphResult);
382
+
383
+ return {
384
+ bufferNumFloats: bufferOffset,
385
+ bufferNumQuads: bufferOffset / 16,
386
+ layoutNumCharacters: glyphResult.done
387
+ ? text.length - startingCodepointIndex
388
+ : glyphResult.value.cluster - startingCodepointIndex + 1,
389
+ fullyProcessed: !!glyphResult.done,
390
+ maxX,
391
+ maxY,
392
+ };
393
+ }