Skip to content

Commit

Permalink
Break lines on com­mon­ly un­spaced punc­tu­a­tion
Browse files Browse the repository at this point in the history
Par­ti­cu­lar­ly hy­phens and soft hy­phens.

Fixes mapbox#2595.
  • Loading branch information
1ec5 committed Oct 13, 2015
1 parent dd68bd3 commit 74f22bd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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

0 comments on commit 74f22bd

Please sign in to comment.