Correct cluster index
Change-Id: Ic657b3fff318e1e76efa4ab7533bc2a833d17802
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/253957
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
diff --git a/modules/skparagraph/src/OneLineShaper.cpp b/modules/skparagraph/src/OneLineShaper.cpp
index aeaa0a6..35297e4 100644
--- a/modules/skparagraph/src/OneLineShaper.cpp
+++ b/modules/skparagraph/src/OneLineShaper.cpp
@@ -235,8 +235,7 @@
// Make it [left:right) regardless of a text direction
TextRange OneLineShaper::normalizeTextRange(GlyphRange glyphRange) {
- TextRange textRange(fCurrentText.start + fCurrentRun->fClusterIndexes[glyphRange.start],
- fCurrentText.start + fCurrentRun->fClusterIndexes[glyphRange.end]);
+ TextRange textRange(clusterIndex(glyphRange.start), clusterIndex(glyphRange.end));
if (!fCurrentRun->leftToRight()) {
std::swap(textRange.start, textRange.end);
}
@@ -289,8 +288,6 @@
GlyphRange block = EMPTY_RANGE;
for (size_t i = 0; i < fCurrentRun->size(); ++i) {
- auto clusterIndex = fCurrentRun->fClusterIndexes[i];
-
// Inspect the glyph
auto glyph = fCurrentRun->fGlyphs[i];
if (glyph != 0) {
@@ -301,7 +298,7 @@
// This is the end of unresolved block
block.end = i;
} else {
- const char* cluster = text.begin() + clusterIndex;
+ const char* cluster = text.begin() + clusterIndex(i);
SkUnichar codepoint = utf8_next(&cluster, text.end());
if (u_iscntrl(codepoint)) {
// This codepoint does not have to be resolved; let's pretend it's resolved
diff --git a/modules/skparagraph/src/OneLineShaper.h b/modules/skparagraph/src/OneLineShaper.h
index 2dba20c..6bffb95 100644
--- a/modules/skparagraph/src/OneLineShaper.h
+++ b/modules/skparagraph/src/OneLineShaper.h
@@ -89,6 +89,9 @@
void commitRunBuffer(const RunInfo&) override;
TextRange clusteredText(GlyphRange glyphs);
+ ClusterIndex clusterIndex(GlyphIndex glyph) {
+ return fCurrentText.start + fCurrentRun->fClusterIndexes[glyph];
+ }
void addFullyResolved();
void addUnresolvedWithRun(GlyphRange glyphRange);
void sortOutGlyphs(std::function<void(GlyphRange)>&& sortOutUnresolvedBLock);