summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2016-12-29 10:32:45 -0800
committerChris Loer <chris.loer@gmail.com>2016-12-29 10:32:45 -0800
commit7778913153bc7358e50f2809236b9bbb84d92bef (patch)
treebefd37a9677f430f7674c9de3c1530b224f1567f
parenta88357d0e4013ec62d7d20e7a11ecd7d2b1e812f (diff)
downloadqtlocation-mapboxgl-7778913153bc7358e50f2809236b9bbb84d92bef.tar.gz
Disallow line breaking within parentheses.
-rw-r--r--src/mbgl/text/glyph_set.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/mbgl/text/glyph_set.cpp b/src/mbgl/text/glyph_set.cpp
index 0040926103..6f4ccdcf0a 100644
--- a/src/mbgl/text/glyph_set.cpp
+++ b/src/mbgl/text/glyph_set.cpp
@@ -205,6 +205,8 @@ std::set<std::size_t> GlyphSet::determineLineBreaks(const std::u16string& logica
std::list<PotentialBreak> potentialBreaks;
float currentX = 0;
+
+ float insideParenthesesPenalty = 0;
for (std::size_t i = 0; i < logicalInput.size(); i++) {
const char16_t codePoint = logicalInput[i];
@@ -220,9 +222,16 @@ std::set<std::size_t> GlyphSet::determineLineBreaks(const std::u16string& logica
const char16_t previousCodePoint = i > 0 ? logicalInput[i-1] : 0;
potentialBreaks.push_back(evaluateBreak(i, currentX, targetWidth, potentialBreaks,
- calculatePenalty(codePoint, previousCodePoint),
+ calculatePenalty(codePoint, previousCodePoint) + insideParenthesesPenalty,
false));
}
+
+ // Make breaking within a parentheses essentially impossible
+ if (codePoint == 0x28 || codePoint == 0xff08 ) {
+ insideParenthesesPenalty += 10000000;
+ } else if (codePoint == 0x29 || codePoint == 0xff09 ) {
+ insideParenthesesPenalty -= 10000000;
+ }
currentX += it->second.metrics.advance + spacing;
}