Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbols: Allow text line breaks on lines #4124

Merged
merged 6 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- _...Add new stuff here..._

### 🐞 Bug fixes

- ⚠️ Fix ignoring embedded line breaks when `symbol-placement` is `line` or `line-center` ([#4124](https://github.com/maplibre/maplibre-gl-js/pull/4124))
- _...Add new stuff here..._

## 4.3.2
Expand Down
11 changes: 3 additions & 8 deletions src/symbol/shaping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ function shapeText(
translate: [number, number],
writingMode: WritingMode.horizontal | WritingMode.vertical,
allowVerticalPlacement: boolean,
symbolPlacement: string,
layoutTextSize: number,
layoutTextSizeThisZoom: number
): Shaping | false {
Expand All @@ -275,7 +274,7 @@ function shapeText(
lines = [];
const untaggedLines =
processBidirectionalText(logicalInput.toString(),
determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize));
determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize));
for (const line of untaggedLines) {
const taggedLine = new TaggedString();
taggedLine.text = line;
Expand All @@ -292,7 +291,7 @@ function shapeText(
const processedLines =
processStyledBidirectionalText(logicalInput.text,
logicalInput.sectionIndex,
determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize));
determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize));
for (const line of processedLines) {
const taggedLine = new TaggedString();
taggedLine.text = line[0];
Expand All @@ -301,7 +300,7 @@ function shapeText(
lines.push(taggedLine);
}
} else {
lines = breakLines(logicalInput, determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize));
lines = breakLines(logicalInput, determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize));
}

const positionedLines = [];
Expand Down Expand Up @@ -503,12 +502,8 @@ function determineLineBreaks(
};
},
imagePositions: {[_: string]: ImagePosition},
symbolPlacement: string,
layoutTextSize: number
): Array<number> {
if (symbolPlacement !== 'point')
return [];

if (!logicalInput)
return [];

Expand Down
10 changes: 5 additions & 5 deletions src/symbol/symbol_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ export function performSymbolLayout(args: {
const symbolPlacement = layout.get('symbol-placement');
const maxWidth = symbolPlacement === 'point' ?
layout.get('text-max-width').evaluate(feature, {}, args.canonical) * ONE_EM :
0;
Infinity;

const addVerticalShapingForPointLabelIfNeeded = () => {
if (args.bucket.allowVerticalPlacement && allowsVerticalWritingMode(unformattedText)) {
// Vertical POI label placement is meant to be used for scripts that support vertical
// writing mode, thus, default left justification is used. If Latin
// scripts would need to be supported, this should take into account other justifications.
shapedTextOrientations.vertical = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor,
'left', spacingIfAllowed, textOffset, WritingMode.vertical, true, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
'left', spacingIfAllowed, textOffset, WritingMode.vertical, true, layoutTextSize, layoutTextSizeThisZoom);
}
};

Expand All @@ -193,7 +193,7 @@ export function performSymbolLayout(args: {
// If using text-variable-anchor for the layer, we use a center anchor for all shapings and apply
// the offsets for the anchor in the placement step.
const shaping = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, 'center',
justification, spacingIfAllowed, textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
justification, spacingIfAllowed, textOffset, WritingMode.horizontal, false, layoutTextSize, layoutTextSizeThisZoom);
if (shaping) {
shapedTextOrientations.horizontal[justification] = shaping;
singleLine = shaping.positionedLines.length === 1;
Expand All @@ -209,7 +209,7 @@ export function performSymbolLayout(args: {

// Horizontal point or line label.
const shaping = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify, spacingIfAllowed,
textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
textOffset, WritingMode.horizontal, false, layoutTextSize, layoutTextSizeThisZoom);
if (shaping) shapedTextOrientations.horizontal[textJustify] = shaping;

// Vertical point label (if allowVerticalPlacement is enabled).
Expand All @@ -218,7 +218,7 @@ export function performSymbolLayout(args: {
// Verticalized line label.
if (allowsVerticalWritingMode(unformattedText) && textAlongLine && keepUpright) {
shapedTextOrientations.vertical = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify,
spacingIfAllowed, textOffset, WritingMode.vertical, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
spacingIfAllowed, textOffset, WritingMode.vertical, false, layoutTextSize, layoutTextSizeThisZoom);
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"zoom": 4,
"sources": {
"mapbox": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-20,
0
],
[
20,
0
]
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "literal",
"type": "symbol",
"source": "mapbox",
"layout": {
"symbol-placement": "line-center",
"text-field": "abcde\nabcde",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"zoom": 4,
"sources": {
"mapbox": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-20,
0
],
[
20,
0
]
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "literal",
"type": "symbol",
"source": "mapbox",
"layout": {
"symbol-placement": "line",
"text-field": "abcde\nabcde",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"version": 8,
"metadata": {
"test": {
"height": 128,
"width": 512
}
},
"center": [
-2,
0
],
"zoom": 6,
"sources": {
"mapbox": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-20,
0
],
[
20,
0
]
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "literal",
"type": "symbol",
"source": "mapbox",
"layout": {
"symbol-placement": "line-center",
"text-field": "Lorem ipsum dolor sit amet.",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
],
"text-max-width": 0,
"text-anchor": "left"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"version": 8,
"metadata": {
"test": {
"height": 128,
"width": 512
}
},
"center": [
10,
0
],
"zoom": 4,
"sources": {
"mapbox": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-20,
0
],
[
20,
0
]
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "literal",
"type": "symbol",
"source": "mapbox",
"layout": {
"symbol-placement": "line",
"text-field": "Lorem ipsum dolor sit amet.",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
],
"text-max-width": 0,
"text-anchor": "left"
}
}
]
}
Loading