@deck.gl-community/infovis-layers 9.3.2 → 9.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2998 -114
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/layers/animation-layer/animation-layer.d.ts +30 -0
- package/dist/layers/animation-layer/animation-layer.d.ts.map +1 -0
- package/dist/layers/animation-layer/animation-layer.js +53 -0
- package/dist/layers/animation-layer/animation-layer.js.map +1 -0
- package/dist/layers/animation-layer/animation.d.ts +86 -0
- package/dist/layers/animation-layer/animation.d.ts.map +1 -0
- package/dist/layers/animation-layer/animation.js +214 -0
- package/dist/layers/animation-layer/animation.js.map +1 -0
- package/dist/layers/block-layer/block-layer-fragment.glsl.d.ts +3 -0
- package/dist/layers/block-layer/block-layer-fragment.glsl.d.ts.map +1 -0
- package/dist/layers/block-layer/block-layer-fragment.glsl.js +41 -0
- package/dist/layers/block-layer/block-layer-fragment.glsl.js.map +1 -0
- package/dist/layers/block-layer/block-layer-uniforms.d.ts +27 -0
- package/dist/layers/block-layer/block-layer-uniforms.d.ts.map +1 -0
- package/dist/layers/block-layer/block-layer-uniforms.js +26 -0
- package/dist/layers/block-layer/block-layer-uniforms.js.map +1 -0
- package/dist/layers/block-layer/block-layer-vertex.glsl.d.ts +3 -0
- package/dist/layers/block-layer/block-layer-vertex.glsl.d.ts.map +1 -0
- package/dist/layers/block-layer/block-layer-vertex.glsl.js +67 -0
- package/dist/layers/block-layer/block-layer-vertex.glsl.js.map +1 -0
- package/dist/layers/block-layer/block-layer.d.ts +71 -0
- package/dist/layers/block-layer/block-layer.d.ts.map +1 -0
- package/dist/layers/block-layer/block-layer.js +108 -0
- package/dist/layers/block-layer/block-layer.js.map +1 -0
- package/dist/layers/fast-text-layer/fast-text-layer.d.ts +148 -0
- package/dist/layers/fast-text-layer/fast-text-layer.d.ts.map +1 -0
- package/dist/layers/fast-text-layer/fast-text-layer.js +862 -0
- package/dist/layers/fast-text-layer/fast-text-layer.js.map +1 -0
- package/dist/layers/fast-text-layer/fast-text-layer.test.d.ts +2 -0
- package/dist/layers/fast-text-layer/fast-text-layer.test.d.ts.map +1 -0
- package/dist/layers/fast-text-layer/fast-text-layer.test.js +300 -0
- package/dist/layers/fast-text-layer/fast-text-layer.test.js.map +1 -0
- package/dist/layers/fast-text-layer/fast-text-layout.d.ts +179 -0
- package/dist/layers/fast-text-layer/fast-text-layout.d.ts.map +1 -0
- package/dist/layers/fast-text-layer/fast-text-layout.js +665 -0
- package/dist/layers/fast-text-layer/fast-text-layout.js.map +1 -0
- package/dist/layers/fast-text-layer/font-atlas.d.ts +98 -0
- package/dist/layers/fast-text-layer/font-atlas.d.ts.map +1 -0
- package/dist/layers/fast-text-layer/font-atlas.js +337 -0
- package/dist/layers/fast-text-layer/font-atlas.js.map +1 -0
- package/dist/layers/fast-text-layer/index.d.ts +4 -0
- package/dist/layers/fast-text-layer/index.d.ts.map +1 -0
- package/dist/layers/fast-text-layer/index.js +4 -0
- package/dist/layers/fast-text-layer/index.js.map +1 -0
- package/dist/layers/time-delta-layer.d.ts +22 -60
- package/dist/layers/time-delta-layer.d.ts.map +1 -1
- package/dist/layers/time-delta-layer.js +31 -53
- package/dist/layers/time-delta-layer.js.map +1 -1
- package/dist/synchronized-views/synchronized-views.js +1 -1
- package/dist/synchronized-views/synchronized-views.js.map +1 -1
- package/dist/utils/format-utils.d.ts +27 -3
- package/dist/utils/format-utils.d.ts.map +1 -1
- package/dist/utils/format-utils.js +72 -40
- package/dist/utils/format-utils.js.map +1 -1
- package/dist/utils/utf8-string-view.d.ts +53 -0
- package/dist/utils/utf8-string-view.d.ts.map +1 -0
- package/dist/utils/utf8-string-view.js +169 -0
- package/dist/utils/utf8-string-view.js.map +1 -0
- package/dist/utils/utf8-string-view.test.d.ts +2 -0
- package/dist/utils/utf8-string-view.test.d.ts.map +1 -0
- package/dist/utils/utf8-string-view.test.js +88 -0
- package/dist/utils/utf8-string-view.test.js.map +1 -0
- package/dist/views/bounds-utils.d.ts +23 -0
- package/dist/views/bounds-utils.d.ts.map +1 -0
- package/dist/views/bounds-utils.js +65 -0
- package/dist/views/bounds-utils.js.map +1 -0
- package/dist/views/layer-bounds-filter.d.ts +48 -0
- package/dist/views/layer-bounds-filter.d.ts.map +1 -0
- package/dist/views/layer-bounds-filter.js +99 -0
- package/dist/views/layer-bounds-filter.js.map +1 -0
- package/dist/views/layer-filter.js +4 -4
- package/dist/views/layer-filter.js.map +1 -1
- package/dist/views/orthographic-utils.d.ts +30 -2
- package/dist/views/orthographic-utils.d.ts.map +1 -1
- package/dist/views/orthographic-utils.js +33 -14
- package/dist/views/orthographic-utils.js.map +1 -1
- package/dist/views/view-layout/build-views-from-view-layout.d.ts +37 -0
- package/dist/views/view-layout/build-views-from-view-layout.d.ts.map +1 -0
- package/dist/views/view-layout/build-views-from-view-layout.js +413 -0
- package/dist/views/view-layout/build-views-from-view-layout.js.map +1 -0
- package/dist/views/view-layout/index.d.ts +3 -0
- package/dist/views/view-layout/index.d.ts.map +1 -0
- package/dist/views/view-layout/index.js +3 -0
- package/dist/views/view-layout/index.js.map +1 -0
- package/dist/views/view-layout/view-layout-item.d.ts +74 -0
- package/dist/views/view-layout/view-layout-item.d.ts.map +1 -0
- package/dist/views/view-layout/view-layout-item.js +48 -0
- package/dist/views/view-layout/view-layout-item.js.map +1 -0
- package/dist/views/view-layout/view-layout.test.d.ts +2 -0
- package/dist/views/view-layout/view-layout.test.d.ts.map +1 -0
- package/dist/views/view-layout/view-layout.test.js +112 -0
- package/dist/views/view-layout/view-layout.test.js.map +1 -0
- package/dist/views/viewport-bounds-utils.d.ts +55 -0
- package/dist/views/viewport-bounds-utils.d.ts.map +1 -0
- package/dist/views/viewport-bounds-utils.js +70 -0
- package/dist/views/viewport-bounds-utils.js.map +1 -0
- package/package.json +15 -5
- package/src/index.ts +91 -2
- package/src/layers/animation-layer/animation-layer.ts +92 -0
- package/src/layers/animation-layer/animation.ts +328 -0
- package/src/layers/block-layer/block-layer-fragment.glsl.ts +41 -0
- package/src/layers/block-layer/block-layer-uniforms.ts +43 -0
- package/src/layers/block-layer/block-layer-vertex.glsl.ts +67 -0
- package/src/layers/block-layer/block-layer.ts +199 -0
- package/src/layers/fast-text-layer/fast-text-layer.test.ts +359 -0
- package/src/layers/fast-text-layer/fast-text-layer.ts +1208 -0
- package/src/layers/fast-text-layer/fast-text-layout.ts +1124 -0
- package/src/layers/fast-text-layer/font-atlas.ts +574 -0
- package/src/layers/fast-text-layer/index.ts +37 -0
- package/src/layers/time-delta-layer.ts +55 -70
- package/src/synchronized-views/synchronized-views.ts +1 -1
- package/src/utils/format-utils.ts +90 -40
- package/src/utils/utf8-string-view.test.ts +119 -0
- package/src/utils/utf8-string-view.ts +273 -0
- package/src/views/bounds-utils.ts +88 -0
- package/src/views/layer-bounds-filter.ts +160 -0
- package/src/views/layer-filter.ts +4 -4
- package/src/views/orthographic-utils.ts +65 -18
- package/src/views/view-layout/build-views-from-view-layout.ts +547 -0
- package/src/views/view-layout/index.ts +18 -0
- package/src/views/view-layout/view-layout-item.ts +125 -0
- package/src/views/view-layout/view-layout.test.ts +129 -0
- package/src/views/viewport-bounds-utils.ts +104 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
buildFastTextGlyphData,
|
|
6
|
+
buildFastTextUtf8ColumnSource,
|
|
7
|
+
collectFastTextCharacterSet,
|
|
8
|
+
FAST_TEXT_GLYPH_VERTEX_BYTE_STRIDE,
|
|
9
|
+
updateFastTextDynamicGlyphAttributes
|
|
10
|
+
} from './fast-text-layout';
|
|
11
|
+
import {DEFAULT_FAST_TEXT_FONT_SETTINGS} from './font-atlas';
|
|
12
|
+
|
|
13
|
+
import type {FastTextCharacterMapping} from './font-atlas';
|
|
14
|
+
import type {Position} from '@deck.gl/core';
|
|
15
|
+
|
|
16
|
+
type TestDatum = {
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly position: Position;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const TEST_MAPPING: FastTextCharacterMapping = {
|
|
22
|
+
A: {
|
|
23
|
+
x: 0,
|
|
24
|
+
y: 0,
|
|
25
|
+
width: 10,
|
|
26
|
+
height: 20,
|
|
27
|
+
anchorX: 5,
|
|
28
|
+
anchorY: 15,
|
|
29
|
+
advance: 12
|
|
30
|
+
},
|
|
31
|
+
B: {
|
|
32
|
+
x: 10,
|
|
33
|
+
y: 0,
|
|
34
|
+
width: 8,
|
|
35
|
+
height: 20,
|
|
36
|
+
anchorX: 4,
|
|
37
|
+
anchorY: 15,
|
|
38
|
+
advance: 9
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe('FastTextLayer glyph expansion', () => {
|
|
43
|
+
it('uses SDF atlas generation by default', () => {
|
|
44
|
+
expect(DEFAULT_FAST_TEXT_FONT_SETTINGS.sdf).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('builds packed glyph attributes for single-line labels', () => {
|
|
48
|
+
const glyphData = buildFastTextGlyphData({
|
|
49
|
+
data: [{text: 'AB', position: [1, 2, 3]}] satisfies TestDatum[],
|
|
50
|
+
getText: datum => datum.text,
|
|
51
|
+
singleLine: true,
|
|
52
|
+
getPosition: datum => datum.position,
|
|
53
|
+
getColor: [10, 20, 30, 200],
|
|
54
|
+
textAnchor: 'start',
|
|
55
|
+
alignmentBaseline: 'top',
|
|
56
|
+
getClipRect: [0, -1, 10, 2],
|
|
57
|
+
mapping: TEST_MAPPING,
|
|
58
|
+
baselineOffset: 5,
|
|
59
|
+
fontSize: 20,
|
|
60
|
+
lineHeight: 1
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(glyphData.length).toBe(2);
|
|
64
|
+
expect(Array.from(glyphData.startIndices)).toEqual([0, 2]);
|
|
65
|
+
expect(Array.from(glyphData.attributes.instancePositions)).toEqual([1, 2, 1, 2]);
|
|
66
|
+
expect(readGlyphOffsets(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
67
|
+
0, 0, 12, 0
|
|
68
|
+
]);
|
|
69
|
+
expect(readGlyphFrames(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
70
|
+
0, 0, 10, 20, 10, 0, 8, 20
|
|
71
|
+
]);
|
|
72
|
+
expect(readGlyphClipRects(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
73
|
+
0, -1, 10, 2, 0, -1, 10, 2
|
|
74
|
+
]);
|
|
75
|
+
expect(readGlyphColors(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
76
|
+
10, 20, 30, 200, 10, 20, 30, 200
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('keeps positive fractional clip dimensions visible after int16 packing', () => {
|
|
81
|
+
const glyphData = buildFastTextGlyphData({
|
|
82
|
+
data: [{text: 'A', position: [1, 2, 3]}] satisfies TestDatum[],
|
|
83
|
+
getText: datum => datum.text,
|
|
84
|
+
singleLine: true,
|
|
85
|
+
getPosition: datum => datum.position,
|
|
86
|
+
getColor: [10, 20, 30, 200],
|
|
87
|
+
textAnchor: 'start',
|
|
88
|
+
alignmentBaseline: 'top',
|
|
89
|
+
getClipRect: [0, -1, 0.25, 0.25],
|
|
90
|
+
mapping: TEST_MAPPING,
|
|
91
|
+
baselineOffset: 5,
|
|
92
|
+
fontSize: 20,
|
|
93
|
+
lineHeight: 1
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(readGlyphClipRects(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
97
|
+
0, -1, 1, 1
|
|
98
|
+
]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('applies horizontal and vertical alignment in atlas pixels', () => {
|
|
102
|
+
const glyphData = buildFastTextGlyphData({
|
|
103
|
+
data: [{text: 'AB', position: [0, 0]}] satisfies TestDatum[],
|
|
104
|
+
getText: datum => datum.text,
|
|
105
|
+
singleLine: true,
|
|
106
|
+
getPosition: datum => datum.position,
|
|
107
|
+
getColor: [0, 0, 0, 255],
|
|
108
|
+
textAnchor: 'middle',
|
|
109
|
+
alignmentBaseline: 'center',
|
|
110
|
+
getClipRect: [0, 0, -1, -1],
|
|
111
|
+
mapping: TEST_MAPPING,
|
|
112
|
+
baselineOffset: 5,
|
|
113
|
+
fontSize: 20,
|
|
114
|
+
lineHeight: 1
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
expect(readGlyphOffsets(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
118
|
+
-10, -10, 2, -10
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('advances missing characters with zero-size glyph records', () => {
|
|
123
|
+
const glyphData = buildFastTextGlyphData({
|
|
124
|
+
data: [{text: 'A?B', position: [0, 0]}] satisfies TestDatum[],
|
|
125
|
+
getText: datum => datum.text,
|
|
126
|
+
singleLine: true,
|
|
127
|
+
getPosition: datum => datum.position,
|
|
128
|
+
getColor: [0, 0, 0, 255],
|
|
129
|
+
textAnchor: 'start',
|
|
130
|
+
alignmentBaseline: 'top',
|
|
131
|
+
getClipRect: [0, 0, -1, -1],
|
|
132
|
+
mapping: TEST_MAPPING,
|
|
133
|
+
baselineOffset: 5,
|
|
134
|
+
fontSize: 20,
|
|
135
|
+
lineHeight: 1
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(glyphData.length).toBe(3);
|
|
139
|
+
expect(readGlyphOffsets(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
140
|
+
0, 0, 12, 15, 44, 0
|
|
141
|
+
]);
|
|
142
|
+
expect(readGlyphFrames(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
143
|
+
0, 0, 10, 20, 0, 0, 0, 0, 10, 0, 8, 20
|
|
144
|
+
]);
|
|
145
|
+
expect(Array.from(glyphData.characterSet).sort()).toEqual(['?', 'A', 'B']);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('builds glyphs from a UTF-8 column without calling getText', () => {
|
|
149
|
+
const column = buildFastTextUtf8ColumnSource(arrow.vectorFromArray(['AB'], new arrow.Utf8()));
|
|
150
|
+
if (!column) {
|
|
151
|
+
throw new Error('Expected test Utf8 column to expose direct buffers');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const glyphData = buildFastTextGlyphData({
|
|
155
|
+
data: [{position: [1, 2, 3]}] satisfies Pick<TestDatum, 'position'>[],
|
|
156
|
+
textUtf8Column: column,
|
|
157
|
+
getTextUtf8Row: 0,
|
|
158
|
+
getText: () => {
|
|
159
|
+
throw new Error('getText should not be called for UTF-8 column mode');
|
|
160
|
+
},
|
|
161
|
+
singleLine: true,
|
|
162
|
+
getPosition: datum => datum.position,
|
|
163
|
+
getColor: [10, 20, 30, 200],
|
|
164
|
+
textAnchor: 'start',
|
|
165
|
+
alignmentBaseline: 'top',
|
|
166
|
+
getClipRect: [0, -1, 10, 2],
|
|
167
|
+
mapping: TEST_MAPPING,
|
|
168
|
+
baselineOffset: 5,
|
|
169
|
+
fontSize: 20,
|
|
170
|
+
lineHeight: 1
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(glyphData.length).toBe(2);
|
|
174
|
+
expect(readGlyphOffsets(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
175
|
+
0, 0, 12, 0
|
|
176
|
+
]);
|
|
177
|
+
expect(readGlyphFrames(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
178
|
+
0, 0, 10, 20, 10, 0, 8, 20
|
|
179
|
+
]);
|
|
180
|
+
expect(Array.from(glyphData.characterSet)).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('builds glyphs from a reused UTF-8 view without calling getText', () => {
|
|
184
|
+
const bytes = new Uint8Array([65, 66]);
|
|
185
|
+
const glyphData = buildFastTextGlyphData({
|
|
186
|
+
data: [{position: [1, 2, 3]}] satisfies Pick<TestDatum, 'position'>[],
|
|
187
|
+
getTextUtf8: (_datum, out) => {
|
|
188
|
+
out.data = bytes;
|
|
189
|
+
out.start = 0;
|
|
190
|
+
out.end = bytes.length;
|
|
191
|
+
return true;
|
|
192
|
+
},
|
|
193
|
+
getText: () => {
|
|
194
|
+
throw new Error('getText should not be called for UTF-8 view mode');
|
|
195
|
+
},
|
|
196
|
+
singleLine: true,
|
|
197
|
+
getPosition: datum => datum.position,
|
|
198
|
+
getColor: [10, 20, 30, 200],
|
|
199
|
+
textAnchor: 'start',
|
|
200
|
+
alignmentBaseline: 'top',
|
|
201
|
+
getClipRect: [0, -1, 10, 2],
|
|
202
|
+
mapping: TEST_MAPPING,
|
|
203
|
+
baselineOffset: 5,
|
|
204
|
+
fontSize: 20,
|
|
205
|
+
lineHeight: 1
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(glyphData.length).toBe(2);
|
|
209
|
+
expect(readGlyphOffsets(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
210
|
+
0, 0, 12, 0
|
|
211
|
+
]);
|
|
212
|
+
expect(Array.from(glyphData.characterSet)).toEqual([]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('does not treat newline bytes specially in single-line UTF-8 column mode', () => {
|
|
216
|
+
const column = buildFastTextUtf8ColumnSource(arrow.vectorFromArray(['A\nB'], new arrow.Utf8()));
|
|
217
|
+
if (!column) {
|
|
218
|
+
throw new Error('Expected test Utf8 column to expose direct buffers');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const glyphData = buildFastTextGlyphData({
|
|
222
|
+
data: [{position: [0, 0]}] satisfies Pick<TestDatum, 'position'>[],
|
|
223
|
+
textUtf8Column: column,
|
|
224
|
+
getTextUtf8Row: 0,
|
|
225
|
+
getText: () => {
|
|
226
|
+
throw new Error('getText should not be called for UTF-8 column mode');
|
|
227
|
+
},
|
|
228
|
+
singleLine: true,
|
|
229
|
+
getPosition: datum => datum.position,
|
|
230
|
+
getColor: [0, 0, 0, 255],
|
|
231
|
+
textAnchor: 'start',
|
|
232
|
+
alignmentBaseline: 'top',
|
|
233
|
+
getClipRect: [0, 0, -1, -1],
|
|
234
|
+
mapping: TEST_MAPPING,
|
|
235
|
+
baselineOffset: 5,
|
|
236
|
+
fontSize: 20,
|
|
237
|
+
lineHeight: 1
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
expect(glyphData.length).toBe(3);
|
|
241
|
+
expect(readGlyphOffsets(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
242
|
+
0, 0, 12, 15, 44, 0
|
|
243
|
+
]);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('collects characters for auto atlas generation without newline entries', () => {
|
|
247
|
+
const characterSet = collectFastTextCharacterSet({
|
|
248
|
+
data: [{text: 'A\nB'}],
|
|
249
|
+
getText: datum => datum.text
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(Array.from(characterSet).sort()).toEqual(['A', 'B']);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('rewrites dynamic positions and clip rects without changing glyph layout or colors', () => {
|
|
256
|
+
const glyphData = buildFastTextGlyphData({
|
|
257
|
+
data: [{text: 'AB', position: [1, 2, 3]}] satisfies TestDatum[],
|
|
258
|
+
getText: datum => datum.text,
|
|
259
|
+
singleLine: true,
|
|
260
|
+
getPosition: datum => datum.position,
|
|
261
|
+
getColor: [10, 20, 30, 200],
|
|
262
|
+
textAnchor: 'start',
|
|
263
|
+
alignmentBaseline: 'top',
|
|
264
|
+
getClipRect: [0, -1, 10, 2],
|
|
265
|
+
mapping: TEST_MAPPING,
|
|
266
|
+
baselineOffset: 5,
|
|
267
|
+
fontSize: 20,
|
|
268
|
+
lineHeight: 1
|
|
269
|
+
});
|
|
270
|
+
const previousGlyphData = new Uint8Array(glyphData.attributes.instanceGlyphData);
|
|
271
|
+
|
|
272
|
+
const stats = updateFastTextDynamicGlyphAttributes({
|
|
273
|
+
data: [{text: 'AB', position: [5, 6, 7]}] satisfies TestDatum[],
|
|
274
|
+
glyphData,
|
|
275
|
+
getPosition: datum => datum.position,
|
|
276
|
+
getColor: () => {
|
|
277
|
+
throw new Error('getColor should not be called when colors are unchanged');
|
|
278
|
+
},
|
|
279
|
+
getClipRect: [3, -2, 4, 5],
|
|
280
|
+
updatePositions: true,
|
|
281
|
+
updateColors: false,
|
|
282
|
+
updateClipRects: true
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
expect(stats.rowCount).toBe(1);
|
|
286
|
+
expect(stats.glyphCount).toBe(2);
|
|
287
|
+
expect(Array.from(glyphData.attributes.instancePositions)).toEqual([5, 6, 5, 6]);
|
|
288
|
+
expect(readGlyphOffsets(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
289
|
+
0, 0, 12, 0
|
|
290
|
+
]);
|
|
291
|
+
expect(readGlyphFrames(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
292
|
+
0, 0, 10, 20, 10, 0, 8, 20
|
|
293
|
+
]);
|
|
294
|
+
expect(readGlyphClipRects(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
295
|
+
3, -2, 4, 5, 3, -2, 4, 5
|
|
296
|
+
]);
|
|
297
|
+
expect(readGlyphColors(glyphData.attributes.instanceGlyphData, glyphData.length)).toEqual([
|
|
298
|
+
10, 20, 30, 200, 10, 20, 30, 200
|
|
299
|
+
]);
|
|
300
|
+
expect(readGlyphOffsets(previousGlyphData, glyphData.length)).toEqual([0, 0, 12, 0]);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
function readGlyphOffsets(instanceGlyphData: Uint8Array, glyphCount: number): number[] {
|
|
305
|
+
const int16Values = new Int16Array(instanceGlyphData.buffer);
|
|
306
|
+
const offsets: number[] = [];
|
|
307
|
+
for (let glyphIndex = 0; glyphIndex < glyphCount; glyphIndex++) {
|
|
308
|
+
const recordInt16Index =
|
|
309
|
+
(glyphIndex * FAST_TEXT_GLYPH_VERTEX_BYTE_STRIDE) / Int16Array.BYTES_PER_ELEMENT;
|
|
310
|
+
offsets.push(int16Values[recordInt16Index], int16Values[recordInt16Index + 1]);
|
|
311
|
+
}
|
|
312
|
+
return offsets;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function readGlyphFrames(instanceGlyphData: Uint8Array, glyphCount: number): number[] {
|
|
316
|
+
const uint16Values = new Uint16Array(instanceGlyphData.buffer);
|
|
317
|
+
const frames: number[] = [];
|
|
318
|
+
for (let glyphIndex = 0; glyphIndex < glyphCount; glyphIndex++) {
|
|
319
|
+
const recordInt16Index =
|
|
320
|
+
(glyphIndex * FAST_TEXT_GLYPH_VERTEX_BYTE_STRIDE) / Int16Array.BYTES_PER_ELEMENT;
|
|
321
|
+
frames.push(
|
|
322
|
+
uint16Values[recordInt16Index + 2],
|
|
323
|
+
uint16Values[recordInt16Index + 3],
|
|
324
|
+
uint16Values[recordInt16Index + 4],
|
|
325
|
+
uint16Values[recordInt16Index + 5]
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
return frames;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function readGlyphClipRects(instanceGlyphData: Uint8Array, glyphCount: number): number[] {
|
|
332
|
+
const int16Values = new Int16Array(instanceGlyphData.buffer);
|
|
333
|
+
const clipRects: number[] = [];
|
|
334
|
+
for (let glyphIndex = 0; glyphIndex < glyphCount; glyphIndex++) {
|
|
335
|
+
const recordInt16Index =
|
|
336
|
+
(glyphIndex * FAST_TEXT_GLYPH_VERTEX_BYTE_STRIDE) / Int16Array.BYTES_PER_ELEMENT;
|
|
337
|
+
clipRects.push(
|
|
338
|
+
int16Values[recordInt16Index + 6],
|
|
339
|
+
int16Values[recordInt16Index + 7],
|
|
340
|
+
int16Values[recordInt16Index + 8],
|
|
341
|
+
int16Values[recordInt16Index + 9]
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
return clipRects;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function readGlyphColors(instanceGlyphData: Uint8Array, glyphCount: number): number[] {
|
|
348
|
+
const colors: number[] = [];
|
|
349
|
+
for (let glyphIndex = 0; glyphIndex < glyphCount; glyphIndex++) {
|
|
350
|
+
const recordByteIndex = glyphIndex * FAST_TEXT_GLYPH_VERTEX_BYTE_STRIDE;
|
|
351
|
+
colors.push(
|
|
352
|
+
instanceGlyphData[recordByteIndex + Int16Array.BYTES_PER_ELEMENT * 10],
|
|
353
|
+
instanceGlyphData[recordByteIndex + Int16Array.BYTES_PER_ELEMENT * 10 + 1],
|
|
354
|
+
instanceGlyphData[recordByteIndex + Int16Array.BYTES_PER_ELEMENT * 10 + 2],
|
|
355
|
+
instanceGlyphData[recordByteIndex + Int16Array.BYTES_PER_ELEMENT * 10 + 3]
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
return colors;
|
|
359
|
+
}
|