summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-10-12 13:43:06 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-10-13 09:54:36 -0700
commit59799947c7254b39a9940fead15aed11f87d94c6 (patch)
tree508608d66b13f554553804e7f846d977aceca4aa
parent67f0108389cdd51f3c59ae7638ea2ecd1c4fa899 (diff)
downloadqtlocation-mapboxgl-59799947c7254b39a9940fead15aed11f87d94c6.tar.gz
Break lines on com­mon­ly un­spaced punc­tu­a­tion
Par­ti­cu­lar­ly hy­phens and soft hy­phens. Fixes #2595.
-rw-r--r--CHANGELOG.md1
-rw-r--r--platform/node/CHANGELOG.md1
-rw-r--r--src/mbgl/text/font_stack.cpp22
3 files changed, 22 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa6548db93..dbc795ada0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/platform/node/CHANGELOG.md b/platform/node/CHANGELOG.md
index 55012622ca..358024e774 100644
--- a/platform/node/CHANGELOG.md
+++ b/platform/node/CHANGELOG.md
@@ -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
diff --git a/src/mbgl/text/font_stack.cpp b/src/mbgl/text/font_stack.cpp
index 6d06796e84..122a55d9da 100644
--- a/src/mbgl/text/font_stack.cpp
+++ b/src/mbgl/text/font_stack.cpp
@@ -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;
@@ -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;
}
}