From 7778913153bc7358e50f2809236b9bbb84d92bef Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Thu, 29 Dec 2016 10:32:45 -0800 Subject: Disallow line breaking within parentheses. --- src/mbgl/text/glyph_set.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 GlyphSet::determineLineBreaks(const std::u16string& logica std::list 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 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; } -- cgit v1.2.1