Skip to content

Commit 1b10241

Browse files
committed
Fix for bug 6936752 Tamil text gets truncated on right-hand side
The getTextRunAdvances() method wasn't accounting for the true width of the text. On closer examination, in Tamil the clusters consist of a number of glyphs each of which has a nonzero advance (in some other scripts, the first glyph in the cluster has an advance, and others are effectively zero). Previously, we were just using the advance of the first glyph in the cluster. This patch changes the behavior to sum the advances of all the glyphs within the cluster. Change-Id: I77a51235f4bb0dfaa72cbb920a8c3b217ad25404
1 parent 4249be4 commit 1b10241

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -686,23 +686,24 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
686686
i, HBFixedToFloat(mShaperItem.advances[i]));
687687
}
688688
#endif
689-
// Get Advances and their total
690-
jfloat currentAdvance = HBFixedToFloat(mShaperItem.advances[mShaperItem.log_clusters[0]]);
691-
jfloat totalFontRunAdvance = currentAdvance;
692-
outAdvances->replaceAt(currentAdvance, startScriptRun);
693-
for (size_t i = 1; i < countScriptRun; i++) {
694-
size_t clusterPrevious = mShaperItem.log_clusters[i - 1];
689+
jfloat totalFontRunAdvance = 0;
690+
size_t clusterStart = 0;
691+
for (size_t i = 0; i < countScriptRun; i++) {
695692
size_t cluster = mShaperItem.log_clusters[i];
696-
if (cluster != clusterPrevious) {
697-
currentAdvance = HBFixedToFloat(mShaperItem.advances[mShaperItem.log_clusters[i]]);
698-
outAdvances->replaceAt(currentAdvance, startScriptRun + i);
693+
size_t clusterNext = i == countScriptRun - 1 ? mShaperItem.num_glyphs :
694+
mShaperItem.log_clusters[i + 1];
695+
if (cluster != clusterNext) {
696+
jfloat advance = 0;
697+
// The advance for the cluster is the sum of the advances of all glyphs within
698+
// the cluster.
699+
for (size_t j = cluster; j < clusterNext; j++) {
700+
advance += HBFixedToFloat(mShaperItem.advances[j]);
701+
}
702+
totalFontRunAdvance += advance;
703+
outAdvances->replaceAt(advance, startScriptRun + clusterStart);
704+
clusterStart = i + 1;
699705
}
700706
}
701-
// TODO: can be removed and go back in the previous loop when Harfbuzz log clusters are fixed
702-
for (size_t i = 1; i < mShaperItem.num_glyphs; i++) {
703-
currentAdvance = HBFixedToFloat(mShaperItem.advances[i]);
704-
totalFontRunAdvance += currentAdvance;
705-
}
706707

707708
#if DEBUG_ADVANCES
708709
ALOGD("Returned advances");

0 commit comments

Comments
 (0)