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
This commit is contained in:
Raph Levien
2015-06-30 10:15:43 -07:00
parent 8726aff8cf
commit 1b3bfb2624

View File

@@ -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