From 3e0fc64da064b8c4156daf53242b8eeb47830f64 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 30 Jun 2015 10:15:43 -0700 Subject: [PATCH] Allow clusters to start with zero-width characters The logic in getRunAdvance() assumed that any zero-width character was part of the preceding cluster, which is valid most of the time. However, characters such as ZWNBSP (U+FEFF) renders as a zero width glyph and is also a grapheme cluster boundary. This patch adds a clause to handle that case. Bug: 22121742 Change-Id: Iad79a7d988bded1ef05f0fd7905d20669ea22051 --- libs/minikin/Measurement.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/minikin/Measurement.cpp b/libs/minikin/Measurement.cpp index 0b68ac5f6..a7bc64bea 100644 --- a/libs/minikin/Measurement.cpp +++ b/libs/minikin/Measurement.cpp @@ -41,7 +41,8 @@ static float getRunAdvance(Layout& layout, const uint16_t* buf, size_t layoutSta clusterWidth = charAdvance; } } - if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f) { + if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f && + !GraphemeBreak::isGraphemeBreak(buf, start, count, offset)) { // In the middle of a cluster, distribute width of cluster so that each grapheme cluster // gets an equal share. // TODO: get caret information out of font when that's available -- GitLab