Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Break lines on com­mon­ly un­spaced punc­tu­a­tion #2598

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- A new `MGLAnnotationImage.enabled` property allows you to disable touch events on individual annotations. ([#2501](https://github.com/mapbox/mapbox-gl-native/pull/2501))
- Fixed a rendering issue that caused one-way arrows along tile boundaries to point due east instead of in the direction of travel. ([#2530](https://github.com/mapbox/mapbox-gl-native/pull/2530))
- Fixed a rendering issue with styles that use the `background-pattern` property. ([#2531](https://github.com/mapbox/mapbox-gl-native/pull/2531))
- Labels can now line wrap on hyphens and other punctuation. ([#2598](https://github.com/mapbox/mapbox-gl-native/pull/2598))
- A new delegate callback was added for observing taps to annotation callout views. ([#2596](https://github.com/mapbox/mapbox-gl-native/pull/2596))

## iOS 2.1.2
Expand Down
1 change: 1 addition & 0 deletions platform/node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# master
- Labels can now line wrap on hyphens and other punctuation. ([#2598](https://github.com/mapbox/mapbox-gl-native/pull/2598))

# 2.0.0

Expand Down
22 changes: 20 additions & 2 deletions src/mbgl/text/font_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float m
}

if (justify) {
justifyLine(positionedGlyphs, metrics, lineStartIndex, lastSafeBreak - 1, justify);
// Collapse invisible characters.
uint32_t breakGlyph = positionedGlyphs[lastSafeBreak].glyph;
uint32_t lineEnd = lastSafeBreak;
if (breakGlyph == 0x20 /* space */
|| breakGlyph == 0x200b /* zero-width space */) {
lineEnd--;
}

justifyLine(positionedGlyphs, metrics, lineStartIndex, lineEnd, justify);
}

lineStartIndex = lastSafeBreak + 1;
Expand All @@ -113,7 +121,17 @@ void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float m
line++;
}

if (shape.glyph == 32) {
// Spaces, plus word-breaking punctuation that often appears without surrounding spaces.
if (shape.glyph == 0x20 /* space */
|| shape.glyph == 0x26 /* ampersand */
|| shape.glyph == 0x2b /* plus sign */
|| shape.glyph == 0x2d /* hyphen-minus */
|| shape.glyph == 0x2f /* solidus */
|| shape.glyph == 0xad /* soft hyphen */
|| shape.glyph == 0xb7 /* middle dot */
|| shape.glyph == 0x200b /* zero-width space */
|| shape.glyph == 0x2010 /* hyphen */
|| shape.glyph == 0x2013 /* en dash */) {
lastSafeBreak = i;
}
}
Expand Down