@solidtv/renderer 1.0.5 → 1.0.6

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 (42) hide show
  1. package/dist/src/core/CoreNode.d.ts +2 -1
  2. package/dist/src/core/CoreNode.js +42 -58
  3. package/dist/src/core/CoreNode.js.map +1 -1
  4. package/dist/src/core/CoreTextNode.d.ts +2 -0
  5. package/dist/src/core/CoreTextNode.js +35 -18
  6. package/dist/src/core/CoreTextNode.js.map +1 -1
  7. package/dist/src/core/CoreTextureManager.js +0 -1
  8. package/dist/src/core/CoreTextureManager.js.map +1 -1
  9. package/dist/src/core/TextureMemoryManager.d.ts +0 -13
  10. package/dist/src/core/TextureMemoryManager.js +0 -24
  11. package/dist/src/core/TextureMemoryManager.js.map +1 -1
  12. package/dist/src/core/animations/AnimationManager.d.ts +1 -0
  13. package/dist/src/core/animations/AnimationManager.js.map +1 -1
  14. package/dist/src/core/animations/CoreAnimation.d.ts +1 -0
  15. package/dist/src/core/animations/CoreAnimation.js +1 -0
  16. package/dist/src/core/animations/CoreAnimation.js.map +1 -1
  17. package/dist/src/core/renderers/webgl/WebGlRenderer.js +4 -6
  18. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  19. package/dist/src/core/text-rendering/CanvasTextRenderer.js +12 -1
  20. package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -1
  21. package/dist/src/core/text-rendering/SdfFontHandler.js +5 -4
  22. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -1
  23. package/dist/src/core/text-rendering/SdfTextRenderer.js +16 -6
  24. package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -1
  25. package/dist/src/core/text-rendering/TextRenderer.d.ts +0 -31
  26. package/dist/src/main-api/Renderer.js +4 -2
  27. package/dist/src/main-api/Renderer.js.map +1 -1
  28. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  29. package/package.json +1 -1
  30. package/src/core/CoreNode.test.ts +47 -46
  31. package/src/core/CoreNode.ts +46 -57
  32. package/src/core/CoreTextNode.ts +38 -23
  33. package/src/core/CoreTextureManager.ts +0 -2
  34. package/src/core/TextureMemoryManager.ts +0 -27
  35. package/src/core/animations/AnimationManager.ts +1 -0
  36. package/src/core/animations/CoreAnimation.ts +2 -1
  37. package/src/core/renderers/webgl/WebGlRenderer.ts +4 -6
  38. package/src/core/text-rendering/CanvasTextRenderer.ts +14 -1
  39. package/src/core/text-rendering/SdfFontHandler.ts +6 -5
  40. package/src/core/text-rendering/SdfTextRenderer.ts +19 -6
  41. package/src/core/text-rendering/TextRenderer.ts +0 -31
  42. package/src/main-api/Renderer.ts +4 -2
@@ -417,12 +417,13 @@ export const isFontLoaded = (fontFamily: string): boolean => {
417
417
  */
418
418
  export const getFontMetrics = (
419
419
  fontFamily: string,
420
-
421
420
  fontSize: number,
422
421
  ): NormalizedFontMetrics => {
423
- const out = normalizedMetrics.get(fontFamily);
424
- if (out !== undefined) {
425
- return out;
422
+ const label = fontFamily + '_' + fontSize;
423
+ const metricsCache = normalizedMetrics.get(label);
424
+
425
+ if (metricsCache !== undefined) {
426
+ return metricsCache;
426
427
  }
427
428
  let metrics = fontCache.get(fontFamily)!.metrics;
428
429
  return processFontMetrics(fontFamily, fontSize, metrics);
@@ -433,7 +434,7 @@ export const processFontMetrics = (
433
434
  fontSize: number,
434
435
  metrics: FontMetrics,
435
436
  ): NormalizedFontMetrics => {
436
- const label = fontFamily + fontSize;
437
+ const label = fontFamily + '_' + fontSize;
437
438
  const normalized = normalizeFontMetrics(metrics, fontSize);
438
439
  normalizedMetrics.set(label, normalized);
439
440
  return normalized;
@@ -32,6 +32,10 @@ const init = (stage: Stage): void => {
32
32
  };
33
33
 
34
34
  const font: FontHandler = SdfFontHandler;
35
+ const layoutCache = new Map<string, TextLayout>();
36
+
37
+ const getLayoutCacheKey = (props: CoreTextNodeProps): string =>
38
+ `${props.fontFamily}-${props.fontSize}-${props.letterSpacing}-${props.lineHeight}-${props.maxHeight}-${props.maxWidth}-${props.textAlign}-${props.text}`;
35
39
 
36
40
  /**
37
41
  * SDF text renderer using MSDF/SDF fonts with WebGL
@@ -49,6 +53,18 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => {
49
53
  };
50
54
  }
51
55
 
56
+ const cacheKey = getLayoutCacheKey(props);
57
+ let layout = layoutCache.get(cacheKey);
58
+ if (layout !== undefined) {
59
+ return {
60
+ remainingLines: 0,
61
+ hasRemainingText: false,
62
+ width: layout.width,
63
+ height: layout.height,
64
+ layout,
65
+ };
66
+ }
67
+
52
68
  // Get font cache for this font family
53
69
  const fontData = SdfFontHandler.getFontData(props.fontFamily);
54
70
  if (fontData === undefined) {
@@ -60,7 +76,8 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => {
60
76
  }
61
77
 
62
78
  // Calculate text layout and generate glyph data for caching
63
- const layout = generateTextLayout(props, fontData);
79
+ layout = generateTextLayout(props, fontData);
80
+ layoutCache.set(cacheKey, layout);
64
81
 
65
82
  // For SDF renderer, ImageData is null since we render via WebGL
66
83
  return {
@@ -68,7 +85,7 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => {
68
85
  hasRemainingText: false,
69
86
  width: layout.width,
70
87
  height: layout.height,
71
- layout, // Cache layout for addQuads
88
+ layout,
72
89
  };
73
90
  };
74
91
 
@@ -302,14 +319,10 @@ const generateTextLayout = (
302
319
 
303
320
  // Calculate glyph position and atlas coordinates (in design units)
304
321
  const glyphLayout: GlyphLayout = {
305
- codepoint,
306
- glyphId: glyph.id,
307
322
  x: currentX + glyph.xoffset,
308
323
  y: currentY + glyph.yoffset,
309
324
  width: glyph.width,
310
325
  height: glyph.height,
311
- xOffset: glyph.xoffset,
312
- yOffset: glyph.yoffset,
313
326
  atlasX: glyph.x * invAtlasWidth,
314
327
  atlasY: glyph.y * invAtlasHeight,
315
328
  atlasWidth: glyph.width * invAtlasWidth,
@@ -236,41 +236,10 @@ export interface TrProps extends TrFontProps {
236
236
  * Glyph layout information for WebGL rendering
237
237
  */
238
238
  export interface GlyphLayout {
239
- /**
240
- * Unicode codepoint
241
- */
242
- codepoint: number;
243
- /**
244
- * Glyph ID in the font atlas
245
- */
246
- glyphId: number;
247
- /**
248
- * X position relative to text origin
249
- */
250
239
  x: number;
251
- /**
252
- * Y position relative to text origin
253
- */
254
240
  y: number;
255
- /**
256
- * Width of glyph in font units
257
- */
258
241
  width: number;
259
- /**
260
- * Height of glyph in font units
261
- */
262
242
  height: number;
263
- /**
264
- * X offset for glyph positioning
265
- */
266
- xOffset: number;
267
- /**
268
- * Y offset for glyph positioning
269
- */
270
- yOffset: number;
271
- /**
272
- * Atlas texture coordinates (normalized 0-1)
273
- */
274
243
  atlasX: number;
275
244
  atlasY: number;
276
245
  atlasWidth: number;
@@ -957,8 +957,10 @@ export class RendererMain extends EventEmitter {
957
957
  this.canvas.width = deviceLogicalWidth * devicePhysicalPixelRatio;
958
958
  this.canvas.height = deviceLogicalHeight * devicePhysicalPixelRatio;
959
959
 
960
- this.canvas.style.width = `${deviceLogicalWidth}px`;
961
- this.canvas.style.height = `${deviceLogicalHeight}px`;
960
+ if (this.canvas.style) {
961
+ this.canvas.style.width = `${deviceLogicalWidth}px`;
962
+ this.canvas.style.height = `${deviceLogicalHeight}px`;
963
+ }
962
964
 
963
965
  this.stage.renderer.updateViewport();
964
966