@mapwhit/tilerenderer 0.47.1 → 0.48.0
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/build/min/package.json +1 -1
- package/package.json +1 -2
- package/src/data/array_types.js +1 -1
- package/src/data/bucket/circle_bucket.js +1 -1
- package/src/data/bucket/fill_bucket.js +1 -1
- package/src/data/bucket/fill_extrusion_bucket.js +1 -1
- package/src/data/bucket/heatmap_bucket.js +1 -1
- package/src/data/bucket/line_bucket.js +1 -1
- package/src/data/bucket/symbol_bucket.js +26 -12
- package/src/data/dem_data.js +1 -1
- package/src/data/feature_index.js +43 -82
- package/src/data/program_configuration.js +19 -11
- package/src/data/segment.js +2 -2
- package/src/geo/transform.js +4 -2
- package/src/gl/color_mode.js +6 -6
- package/src/index.js +3 -1
- package/src/render/glyph_atlas.js +1 -1
- package/src/render/glyph_manager.js +43 -48
- package/src/render/image_atlas.js +1 -1
- package/src/render/image_manager.js +9 -37
- package/src/source/geojson_source.js +49 -93
- package/src/source/geojson_worker_source.js +33 -134
- package/src/source/image_source.js +9 -14
- package/src/source/load_tilejson.js +27 -34
- package/src/source/raster_dem_tile_source.js +27 -40
- package/src/source/raster_tile_source.js +53 -62
- package/src/source/rtl_text_plugin.js +3 -1
- package/src/source/source_cache.js +23 -21
- package/src/source/source_state.js +17 -26
- package/src/source/tile.js +6 -5
- package/src/source/tile_id.js +1 -1
- package/src/source/vector_tile_source.js +56 -73
- package/src/source/vector_tile_worker_source.js +20 -85
- package/src/source/worker.js +37 -103
- package/src/source/worker_tile.js +39 -84
- package/src/style/load_sprite.js +14 -17
- package/src/style/properties.js +1 -1
- package/src/style/style.js +22 -37
- package/src/style/style_layer/symbol_style_layer_properties.js +1 -1
- package/src/style/style_layer_index.js +17 -23
- package/src/style-spec/expression/compound_expression.js +30 -16
- package/src/style-spec/expression/definitions/coercion.js +13 -0
- package/src/style-spec/expression/definitions/comparison.js +193 -0
- package/src/style-spec/expression/definitions/formatted.js +123 -0
- package/src/style-spec/expression/definitions/index.js +10 -60
- package/src/style-spec/expression/definitions/interpolate.js +17 -7
- package/src/style-spec/expression/definitions/literal.js +5 -0
- package/src/style-spec/expression/parsing_context.js +4 -0
- package/src/style-spec/expression/types.js +12 -1
- package/src/style-spec/feature_filter/index.js +1 -1
- package/src/style-spec/reference/v8.json +120 -49
- package/src/symbol/anchor.js +1 -1
- package/src/symbol/collision_index.js +23 -16
- package/src/symbol/get_anchors.js +11 -22
- package/src/symbol/grid_index.js +176 -182
- package/src/symbol/mergelines.js +51 -48
- package/src/symbol/opacity_state.js +1 -1
- package/src/symbol/placement.js +8 -2
- package/src/symbol/quads.js +7 -6
- package/src/symbol/shaping.js +185 -40
- package/src/symbol/symbol_layout.js +9 -6
- package/src/symbol/transform_text.js +12 -1
- package/src/ui/camera.js +82 -85
- package/src/ui/map.js +13 -57
- package/src/util/actor.js +46 -42
- package/src/util/browser.js +6 -0
- package/src/util/dictionary_coder.js +13 -21
- package/src/util/dispatcher.js +14 -17
- package/src/util/image.js +1 -1
- package/src/util/loader/image.js +11 -11
- package/src/util/polyfill.js +16 -0
- package/src/util/task_queue.js +39 -43
- package/src/util/transfer_registry.js +167 -0
- package/src/util/web_worker_transfer.js +5 -190
- package/src/source/raster_dem_tile_worker_source.js +0 -26
- package/src/style-spec/expression/definitions/equals.js +0 -93
package/src/symbol/placement.js
CHANGED
|
@@ -398,11 +398,17 @@ class Placement {
|
|
|
398
398
|
|
|
399
399
|
const layout = bucket.layers[0].layout;
|
|
400
400
|
const duplicateOpacityState = new JointOpacityState(null, 0, false, false, true);
|
|
401
|
+
const textAllowOverlap = layout.get('text-allow-overlap');
|
|
402
|
+
const iconAllowOverlap = layout.get('icon-allow-overlap');
|
|
403
|
+
// If allow-overlap is true, we can show symbols before placement runs on them
|
|
404
|
+
// But we have to wait for placement if we potentially depend on a paired icon/text
|
|
405
|
+
// with allow-overlap: false.
|
|
406
|
+
// See https://github.com/mapbox/mapbox-gl-js/issues/7032
|
|
401
407
|
const defaultOpacityState = new JointOpacityState(
|
|
402
408
|
null,
|
|
403
409
|
0,
|
|
404
|
-
layout.get('
|
|
405
|
-
layout.get('
|
|
410
|
+
textAllowOverlap && (iconAllowOverlap || !bucket.hasIconData() || layout.get('icon-optional')),
|
|
411
|
+
iconAllowOverlap && (textAllowOverlap || !bucket.hasTextData() || layout.get('text-optional')),
|
|
406
412
|
true
|
|
407
413
|
);
|
|
408
414
|
|
package/src/symbol/quads.js
CHANGED
|
@@ -105,7 +105,8 @@ function getGlyphQuads(anchor, shaping, layer, alongLine, feature, positions) {
|
|
|
105
105
|
|
|
106
106
|
for (let k = 0; k < positionedGlyphs.length; k++) {
|
|
107
107
|
const positionedGlyph = positionedGlyphs[k];
|
|
108
|
-
const
|
|
108
|
+
const glyphPositions = positions[positionedGlyph.fontStack];
|
|
109
|
+
const glyph = glyphPositions?.[positionedGlyph.glyph];
|
|
109
110
|
if (!glyph) continue;
|
|
110
111
|
|
|
111
112
|
const rect = glyph.rect;
|
|
@@ -115,7 +116,7 @@ function getGlyphQuads(anchor, shaping, layer, alongLine, feature, positions) {
|
|
|
115
116
|
const glyphPadding = 1.0;
|
|
116
117
|
const rectBuffer = GLYPH_PBF_BORDER + glyphPadding;
|
|
117
118
|
|
|
118
|
-
const halfAdvance = glyph.metrics.advance / 2;
|
|
119
|
+
const halfAdvance = (glyph.metrics.advance * positionedGlyph.scale) / 2;
|
|
119
120
|
|
|
120
121
|
const glyphOffset = alongLine ? [positionedGlyph.x + halfAdvance, positionedGlyph.y] : [0, 0];
|
|
121
122
|
|
|
@@ -123,10 +124,10 @@ function getGlyphQuads(anchor, shaping, layer, alongLine, feature, positions) {
|
|
|
123
124
|
? [0, 0]
|
|
124
125
|
: [positionedGlyph.x + halfAdvance + textOffset[0], positionedGlyph.y + textOffset[1]];
|
|
125
126
|
|
|
126
|
-
const x1 = glyph.metrics.left - rectBuffer - halfAdvance + builtInOffset[0];
|
|
127
|
-
const y1 = -glyph.metrics.top - rectBuffer + builtInOffset[1];
|
|
128
|
-
const x2 = x1 + rect.w;
|
|
129
|
-
const y2 = y1 + rect.h;
|
|
127
|
+
const x1 = (glyph.metrics.left - rectBuffer) * positionedGlyph.scale - halfAdvance + builtInOffset[0];
|
|
128
|
+
const y1 = (-glyph.metrics.top - rectBuffer) * positionedGlyph.scale + builtInOffset[1];
|
|
129
|
+
const x2 = x1 + rect.w * positionedGlyph.scale;
|
|
130
|
+
const y2 = y1 + rect.h * positionedGlyph.scale;
|
|
130
131
|
|
|
131
132
|
const tl = new Point(x1, y1);
|
|
132
133
|
const tr = new Point(x2, y1);
|
package/src/symbol/shaping.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { charHasUprightVerticalOrientation, charAllowsIdeographicBreaking } = require('../util/script_detection');
|
|
2
2
|
const verticalizePunctuation = require('../util/verticalize_punctuation');
|
|
3
3
|
const { plugin: rtlTextPlugin } = require('../source/rtl_text_plugin');
|
|
4
|
+
const { Formatted } = require('../style-spec/expression/definitions/formatted');
|
|
4
5
|
|
|
5
6
|
const WritingMode = {
|
|
6
7
|
horizontal: 1,
|
|
@@ -14,20 +15,94 @@ module.exports = {
|
|
|
14
15
|
WritingMode
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
class TaggedString {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.text = '';
|
|
21
|
+
this.sectionIndex = []; // maps each character in 'text' to its corresponding entry in 'sections'
|
|
22
|
+
this.sections = [];
|
|
23
|
+
}
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
static fromFeature(text, defaultFontStack) {
|
|
26
|
+
const result = new TaggedString();
|
|
27
|
+
if (text instanceof Formatted) {
|
|
28
|
+
for (let i = 0; i < text.sections.length; i++) {
|
|
29
|
+
const section = text.sections[i];
|
|
30
|
+
result.sections.push({
|
|
31
|
+
scale: section.scale || 1,
|
|
32
|
+
fontStack: section.fontStack || defaultFontStack
|
|
33
|
+
});
|
|
34
|
+
result.text += section.text;
|
|
35
|
+
for (let j = 0; j < section.text.length; j++) {
|
|
36
|
+
result.sectionIndex.push(i);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
result.text = text;
|
|
41
|
+
result.sections.push({ scale: 1, fontStack: defaultFontStack });
|
|
42
|
+
for (let i = 0; i < text.length; i++) {
|
|
43
|
+
result.sectionIndex.push(0);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
length() {
|
|
50
|
+
return this.text.length;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getSection(index) {
|
|
54
|
+
return this.sections[this.sectionIndex[index]];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getCharCode(index) {
|
|
58
|
+
return this.text.charCodeAt(index);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
verticalizePunctuation() {
|
|
62
|
+
this.text = verticalizePunctuation(this.text);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
trim() {
|
|
66
|
+
let beginningWhitespace = 0;
|
|
67
|
+
for (let i = 0; i < this.text.length && whitespace[this.text.charCodeAt(i)]; i++) {
|
|
68
|
+
beginningWhitespace++;
|
|
69
|
+
}
|
|
70
|
+
let trailingWhitespace = this.text.length;
|
|
71
|
+
for (let i = this.text.length - 1; i >= 0 && i >= beginningWhitespace && whitespace[this.text.charCodeAt(i)]; i--) {
|
|
72
|
+
trailingWhitespace--;
|
|
73
|
+
}
|
|
74
|
+
this.text = this.text.substring(beginningWhitespace, trailingWhitespace);
|
|
75
|
+
this.sectionIndex = this.sectionIndex.slice(beginningWhitespace, trailingWhitespace);
|
|
76
|
+
}
|
|
20
77
|
|
|
21
|
-
|
|
78
|
+
substring(start, end) {
|
|
79
|
+
const substring = new TaggedString();
|
|
80
|
+
substring.text = this.text.substring(start, end);
|
|
81
|
+
substring.sectionIndex = this.sectionIndex.slice(start, end);
|
|
82
|
+
substring.sections = this.sections;
|
|
83
|
+
return substring;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
toString() {
|
|
87
|
+
return this.text;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getMaxScale() {
|
|
91
|
+
return this.sectionIndex.reduce((max, index) => Math.max(max, this.sections[index].scale), 0);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function breakLines(input, lineBreakPoints) {
|
|
22
96
|
const lines = [];
|
|
97
|
+
const text = input.text;
|
|
23
98
|
let start = 0;
|
|
24
99
|
for (const lineBreak of lineBreakPoints) {
|
|
25
|
-
lines.push(
|
|
100
|
+
lines.push(input.substring(start, lineBreak));
|
|
26
101
|
start = lineBreak;
|
|
27
102
|
}
|
|
28
103
|
|
|
29
104
|
if (start < text.length) {
|
|
30
|
-
lines.push(
|
|
105
|
+
lines.push(input.substring(start, text.length));
|
|
31
106
|
}
|
|
32
107
|
return lines;
|
|
33
108
|
}
|
|
@@ -35,6 +110,7 @@ function breakLines(text, lineBreakPoints) {
|
|
|
35
110
|
function shapeText(
|
|
36
111
|
text,
|
|
37
112
|
glyphs,
|
|
113
|
+
defaultFontStack,
|
|
38
114
|
maxWidth,
|
|
39
115
|
lineHeight,
|
|
40
116
|
textAnchor,
|
|
@@ -44,9 +120,9 @@ function shapeText(
|
|
|
44
120
|
verticalHeight,
|
|
45
121
|
writingMode
|
|
46
122
|
) {
|
|
47
|
-
|
|
123
|
+
const logicalInput = TaggedString.fromFeature(text, defaultFontStack);
|
|
48
124
|
if (writingMode === WritingMode.vertical) {
|
|
49
|
-
logicalInput
|
|
125
|
+
logicalInput.verticalizePunctuation();
|
|
50
126
|
}
|
|
51
127
|
|
|
52
128
|
const positionedGlyphs = [];
|
|
@@ -62,9 +138,39 @@ function shapeText(
|
|
|
62
138
|
|
|
63
139
|
let lines;
|
|
64
140
|
|
|
65
|
-
const { processBidirectionalText } = rtlTextPlugin;
|
|
66
|
-
if (processBidirectionalText) {
|
|
67
|
-
|
|
141
|
+
const { processBidirectionalText, processStyledBidirectionalText } = rtlTextPlugin;
|
|
142
|
+
if (processBidirectionalText && logicalInput.sections.length === 1) {
|
|
143
|
+
// Bidi doesn't have to be style-aware
|
|
144
|
+
lines = [];
|
|
145
|
+
const untaggedLines = processBidirectionalText(
|
|
146
|
+
logicalInput.toString(),
|
|
147
|
+
determineLineBreaks(logicalInput, spacing, maxWidth, glyphs)
|
|
148
|
+
);
|
|
149
|
+
for (const line of untaggedLines) {
|
|
150
|
+
const taggedLine = new TaggedString();
|
|
151
|
+
taggedLine.text = line;
|
|
152
|
+
taggedLine.sections = logicalInput.sections;
|
|
153
|
+
for (let i = 0; i < line.length; i++) {
|
|
154
|
+
taggedLine.sectionIndex.push(0);
|
|
155
|
+
}
|
|
156
|
+
lines.push(taggedLine);
|
|
157
|
+
}
|
|
158
|
+
} else if (processStyledBidirectionalText) {
|
|
159
|
+
// Need version of mapbox-gl-rtl-text with style support for combining RTL text
|
|
160
|
+
// with formatting
|
|
161
|
+
lines = [];
|
|
162
|
+
const processedLines = processStyledBidirectionalText(
|
|
163
|
+
logicalInput.text,
|
|
164
|
+
logicalInput.sectionIndex,
|
|
165
|
+
determineLineBreaks(logicalInput, spacing, maxWidth, glyphs)
|
|
166
|
+
);
|
|
167
|
+
for (const line of processedLines) {
|
|
168
|
+
const taggedLine = new TaggedString();
|
|
169
|
+
taggedLine.text = line[0];
|
|
170
|
+
taggedLine.sectionIndex = line[1];
|
|
171
|
+
taggedLine.sections = logicalInput.sections;
|
|
172
|
+
lines.push(taggedLine);
|
|
173
|
+
}
|
|
68
174
|
} else {
|
|
69
175
|
lines = breakLines(logicalInput, determineLineBreaks(logicalInput, spacing, maxWidth, glyphs));
|
|
70
176
|
}
|
|
@@ -73,6 +179,7 @@ function shapeText(
|
|
|
73
179
|
|
|
74
180
|
if (!positionedGlyphs.length) return false;
|
|
75
181
|
|
|
182
|
+
shaping.text = shaping.text.toString();
|
|
76
183
|
return shaping;
|
|
77
184
|
}
|
|
78
185
|
|
|
@@ -105,13 +212,15 @@ const breakable = {
|
|
|
105
212
|
// See https://github.com/mapbox/mapbox-gl-js/issues/3658
|
|
106
213
|
};
|
|
107
214
|
|
|
108
|
-
function determineAverageLineWidth(logicalInput, spacing, maxWidth,
|
|
215
|
+
function determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap) {
|
|
109
216
|
let totalWidth = 0;
|
|
110
217
|
|
|
111
|
-
for (let index = 0; index < logicalInput.length; index++) {
|
|
112
|
-
const
|
|
218
|
+
for (let index = 0; index < logicalInput.length(); index++) {
|
|
219
|
+
const section = logicalInput.getSection(index);
|
|
220
|
+
const positions = glyphMap[section.fontStack];
|
|
221
|
+
const glyph = positions?.[logicalInput.getCharCode(index)];
|
|
113
222
|
if (!glyph) continue;
|
|
114
|
-
totalWidth += glyph.metrics.advance + spacing;
|
|
223
|
+
totalWidth += glyph.metrics.advance * section.scale + spacing;
|
|
115
224
|
}
|
|
116
225
|
|
|
117
226
|
const lineCount = Math.max(1, Math.ceil(totalWidth / maxWidth));
|
|
@@ -182,39 +291,41 @@ function leastBadBreaks(lastLineBreak) {
|
|
|
182
291
|
return leastBadBreaks(lastLineBreak.priorBreak).concat(lastLineBreak.index);
|
|
183
292
|
}
|
|
184
293
|
|
|
185
|
-
function determineLineBreaks(logicalInput, spacing, maxWidth,
|
|
294
|
+
function determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap) {
|
|
186
295
|
if (!maxWidth) return [];
|
|
187
296
|
|
|
188
297
|
if (!logicalInput) return [];
|
|
189
298
|
|
|
190
299
|
const potentialLineBreaks = [];
|
|
191
|
-
const targetWidth = determineAverageLineWidth(logicalInput, spacing, maxWidth,
|
|
300
|
+
const targetWidth = determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap);
|
|
192
301
|
|
|
193
302
|
let currentX = 0;
|
|
194
303
|
|
|
195
|
-
for (let i = 0; i < logicalInput.length; i++) {
|
|
196
|
-
const
|
|
197
|
-
const
|
|
304
|
+
for (let i = 0; i < logicalInput.length(); i++) {
|
|
305
|
+
const section = logicalInput.getSection(i);
|
|
306
|
+
const codePoint = logicalInput.getCharCode(i);
|
|
307
|
+
const positions = glyphMap[section.fontStack];
|
|
308
|
+
const glyph = positions?.[codePoint];
|
|
198
309
|
|
|
199
|
-
if (glyph && !whitespace[codePoint]) currentX += glyph.metrics.advance + spacing;
|
|
310
|
+
if (glyph && !whitespace[codePoint]) currentX += glyph.metrics.advance * section.scale + spacing;
|
|
200
311
|
|
|
201
312
|
// Ideographic characters, spaces, and word-breaking punctuation that often appear without
|
|
202
313
|
// surrounding spaces.
|
|
203
|
-
if (i < logicalInput.length - 1 && (breakable[codePoint] || charAllowsIdeographicBreaking(codePoint))) {
|
|
314
|
+
if (i < logicalInput.length() - 1 && (breakable[codePoint] || charAllowsIdeographicBreaking(codePoint))) {
|
|
204
315
|
potentialLineBreaks.push(
|
|
205
316
|
evaluateBreak(
|
|
206
317
|
i + 1,
|
|
207
318
|
currentX,
|
|
208
319
|
targetWidth,
|
|
209
320
|
potentialLineBreaks,
|
|
210
|
-
calculatePenalty(codePoint, logicalInput.
|
|
321
|
+
calculatePenalty(codePoint, logicalInput.getCharCode(i + 1)),
|
|
211
322
|
false
|
|
212
323
|
)
|
|
213
324
|
);
|
|
214
325
|
}
|
|
215
326
|
}
|
|
216
327
|
|
|
217
|
-
return leastBadBreaks(evaluateBreak(logicalInput.length, currentX, targetWidth, potentialLineBreaks, 0, true));
|
|
328
|
+
return leastBadBreaks(evaluateBreak(logicalInput.length(), currentX, targetWidth, potentialLineBreaks, 0, true));
|
|
218
329
|
}
|
|
219
330
|
|
|
220
331
|
function getAnchorAlignment(anchor) {
|
|
@@ -250,7 +361,17 @@ function getAnchorAlignment(anchor) {
|
|
|
250
361
|
return { horizontalAlign, verticalAlign };
|
|
251
362
|
}
|
|
252
363
|
|
|
253
|
-
function shapeLines(
|
|
364
|
+
function shapeLines(
|
|
365
|
+
shaping,
|
|
366
|
+
glyphMap,
|
|
367
|
+
lines,
|
|
368
|
+
lineHeight,
|
|
369
|
+
textAnchor,
|
|
370
|
+
textJustify,
|
|
371
|
+
writingMode,
|
|
372
|
+
spacing,
|
|
373
|
+
verticalHeight
|
|
374
|
+
) {
|
|
254
375
|
// the y offset *should* be part of the font metadata
|
|
255
376
|
const yOffset = -17;
|
|
256
377
|
|
|
@@ -262,27 +383,49 @@ function shapeLines(shaping, glyphs, lines, lineHeight, textAnchor, textJustify,
|
|
|
262
383
|
|
|
263
384
|
const justify = textJustify === 'right' ? 1 : textJustify === 'left' ? 0 : 0.5;
|
|
264
385
|
|
|
265
|
-
for (
|
|
266
|
-
line
|
|
386
|
+
for (const line of lines) {
|
|
387
|
+
line.trim();
|
|
388
|
+
|
|
389
|
+
const lineMaxScale = line.getMaxScale();
|
|
267
390
|
|
|
268
|
-
if (!line.length) {
|
|
391
|
+
if (!line.length()) {
|
|
269
392
|
y += lineHeight; // Still need a line feed after empty line
|
|
270
393
|
continue;
|
|
271
394
|
}
|
|
272
395
|
|
|
273
396
|
const lineStartIndex = positionedGlyphs.length;
|
|
274
|
-
for (let i = 0; i < line.length; i++) {
|
|
275
|
-
const
|
|
276
|
-
const
|
|
397
|
+
for (let i = 0; i < line.length(); i++) {
|
|
398
|
+
const section = line.getSection(i);
|
|
399
|
+
const codePoint = line.getCharCode(i);
|
|
400
|
+
// We don't know the baseline, but since we're laying out
|
|
401
|
+
// at 24 points, we can calculate how much it will move when
|
|
402
|
+
// we scale up or down.
|
|
403
|
+
const baselineOffset = (lineMaxScale - section.scale) * 24;
|
|
404
|
+
const positions = glyphMap[section.fontStack];
|
|
405
|
+
const glyph = positions?.[codePoint];
|
|
277
406
|
|
|
278
407
|
if (!glyph) continue;
|
|
279
408
|
|
|
280
409
|
if (!charHasUprightVerticalOrientation(codePoint) || writingMode === WritingMode.horizontal) {
|
|
281
|
-
positionedGlyphs.push({
|
|
282
|
-
|
|
410
|
+
positionedGlyphs.push({
|
|
411
|
+
glyph: codePoint,
|
|
412
|
+
x,
|
|
413
|
+
y: y + baselineOffset,
|
|
414
|
+
vertical: false,
|
|
415
|
+
scale: section.scale,
|
|
416
|
+
fontStack: section.fontStack
|
|
417
|
+
});
|
|
418
|
+
x += glyph.metrics.advance * section.scale + spacing;
|
|
283
419
|
} else {
|
|
284
|
-
positionedGlyphs.push({
|
|
285
|
-
|
|
420
|
+
positionedGlyphs.push({
|
|
421
|
+
glyph: codePoint,
|
|
422
|
+
x,
|
|
423
|
+
y: baselineOffset,
|
|
424
|
+
vertical: true,
|
|
425
|
+
scale: section.scale,
|
|
426
|
+
fontStack: section.fontStack
|
|
427
|
+
});
|
|
428
|
+
x += verticalHeight * section.scale + spacing;
|
|
286
429
|
}
|
|
287
430
|
}
|
|
288
431
|
|
|
@@ -291,18 +434,18 @@ function shapeLines(shaping, glyphs, lines, lineHeight, textAnchor, textJustify,
|
|
|
291
434
|
const lineLength = x - spacing;
|
|
292
435
|
maxLineLength = Math.max(lineLength, maxLineLength);
|
|
293
436
|
|
|
294
|
-
justifyLine(positionedGlyphs,
|
|
437
|
+
justifyLine(positionedGlyphs, glyphMap, lineStartIndex, positionedGlyphs.length - 1, justify);
|
|
295
438
|
}
|
|
296
439
|
|
|
297
440
|
x = 0;
|
|
298
|
-
y += lineHeight;
|
|
441
|
+
y += lineHeight * lineMaxScale;
|
|
299
442
|
}
|
|
300
443
|
|
|
301
444
|
const { horizontalAlign, verticalAlign } = getAnchorAlignment(textAnchor);
|
|
302
445
|
align(positionedGlyphs, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, lines.length);
|
|
303
446
|
|
|
304
447
|
// Calculate the bounding box
|
|
305
|
-
const height =
|
|
448
|
+
const height = y - yOffset;
|
|
306
449
|
|
|
307
450
|
shaping.top += -verticalAlign * height;
|
|
308
451
|
shaping.bottom = shaping.top + height;
|
|
@@ -311,12 +454,14 @@ function shapeLines(shaping, glyphs, lines, lineHeight, textAnchor, textJustify,
|
|
|
311
454
|
}
|
|
312
455
|
|
|
313
456
|
// justify right = 1, left = 0, center = 0.5
|
|
314
|
-
function justifyLine(positionedGlyphs,
|
|
457
|
+
function justifyLine(positionedGlyphs, glyphMap, start, end, justify) {
|
|
315
458
|
if (!justify) return;
|
|
316
459
|
|
|
317
|
-
const
|
|
460
|
+
const lastPositionedGlyph = positionedGlyphs[end];
|
|
461
|
+
const positions = glyphMap[lastPositionedGlyph.fontStack];
|
|
462
|
+
const glyph = positions?.[lastPositionedGlyph.glyph];
|
|
318
463
|
if (glyph) {
|
|
319
|
-
const lastAdvance = glyph.metrics.advance;
|
|
464
|
+
const lastAdvance = glyph.metrics.advance * lastPositionedGlyph.scale;
|
|
320
465
|
const lineIndent = (positionedGlyphs[end].x + lastAdvance) * justify;
|
|
321
466
|
|
|
322
467
|
for (let j = start; j <= end; j++) {
|
|
@@ -12,6 +12,7 @@ const classifyRings = require('../util/classify_rings');
|
|
|
12
12
|
const EXTENT = require('../data/extent');
|
|
13
13
|
const SymbolBucket = require('../data/bucket/symbol_bucket');
|
|
14
14
|
const EvaluationParameters = require('../style/evaluation_parameters');
|
|
15
|
+
const { Formatted } = require('../style-spec/expression/definitions/formatted');
|
|
15
16
|
|
|
16
17
|
// The symbol layout process needs `text-size` evaluated at up to five different zoom levels, and
|
|
17
18
|
// `icon-size` at up to three:
|
|
@@ -73,18 +74,18 @@ function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePo
|
|
|
73
74
|
|
|
74
75
|
for (const feature of bucket.features) {
|
|
75
76
|
const fontstack = layout.get('text-font').evaluate(feature, {}).join(',');
|
|
76
|
-
const
|
|
77
|
-
const glyphPositionMap = glyphPositions[fontstack] || {};
|
|
77
|
+
const glyphPositionMap = glyphPositions;
|
|
78
78
|
|
|
79
79
|
const shapedTextOrientations = {};
|
|
80
80
|
const text = feature.text;
|
|
81
81
|
if (text) {
|
|
82
|
+
const unformattedText = text instanceof Formatted ? text.toString() : text;
|
|
82
83
|
const textOffset = layout
|
|
83
84
|
.get('text-offset')
|
|
84
85
|
.evaluate(feature, {})
|
|
85
86
|
.map(t => t * oneEm);
|
|
86
87
|
const spacing = layout.get('text-letter-spacing').evaluate(feature, {}) * oneEm;
|
|
87
|
-
const spacingIfAllowed = allowsLetterSpacing(
|
|
88
|
+
const spacingIfAllowed = allowsLetterSpacing(unformattedText) ? spacing : 0;
|
|
88
89
|
const textAnchor = layout.get('text-anchor').evaluate(feature, {});
|
|
89
90
|
const textJustify = layout.get('text-justify').evaluate(feature, {});
|
|
90
91
|
const maxWidth =
|
|
@@ -92,7 +93,8 @@ function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePo
|
|
|
92
93
|
|
|
93
94
|
shapedTextOrientations.horizontal = shapeText(
|
|
94
95
|
text,
|
|
95
|
-
|
|
96
|
+
glyphMap,
|
|
97
|
+
fontstack,
|
|
96
98
|
maxWidth,
|
|
97
99
|
lineHeight,
|
|
98
100
|
textAnchor,
|
|
@@ -102,10 +104,11 @@ function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePo
|
|
|
102
104
|
oneEm,
|
|
103
105
|
WritingMode.horizontal
|
|
104
106
|
);
|
|
105
|
-
if (allowsVerticalWritingMode(
|
|
107
|
+
if (allowsVerticalWritingMode(unformattedText) && textAlongLine && keepUpright) {
|
|
106
108
|
shapedTextOrientations.vertical = shapeText(
|
|
107
109
|
text,
|
|
108
|
-
|
|
110
|
+
glyphMap,
|
|
111
|
+
fontstack,
|
|
109
112
|
maxWidth,
|
|
110
113
|
lineHeight,
|
|
111
114
|
textAnchor,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { plugin: rtlTextPlugin } = require('../source/rtl_text_plugin');
|
|
2
|
+
const { Formatted } = require('../style-spec/expression/definitions/formatted');
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
function transformText(text, layer, feature) {
|
|
4
5
|
const transform = layer.layout.get('text-transform').evaluate(feature, {});
|
|
5
6
|
if (transform === 'uppercase') {
|
|
6
7
|
text = text.toLocaleUpperCase();
|
|
@@ -13,4 +14,14 @@ module.exports = function (text, layer, feature) {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
return text;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = function (text, layer, feature) {
|
|
20
|
+
if (text instanceof Formatted) {
|
|
21
|
+
text.sections.forEach(section => {
|
|
22
|
+
section.text = transformText(section.text, layer, feature);
|
|
23
|
+
});
|
|
24
|
+
return text;
|
|
25
|
+
}
|
|
26
|
+
return transformText(text, layer, feature);
|
|
16
27
|
};
|