Skip to content

Commit 57e9723

Browse files
committed
Partial fix for bug 6132077 (incorrect line breaking of Arabic text).
Fixed getTextRunAdvances so that advances are correctly aligned with UTF-16 code point offices, rather than runs being reversed in RTL. Change-Id: Ife59c0c26f745654c16656c86072e9102d8f6bc7
1 parent 1579a67 commit 57e9723

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
550550
return;
551551
}
552552

553+
// To be filled in later
554+
for (size_t i = 0; i < count; i++) {
555+
outAdvances->add(0);
556+
}
553557
UErrorCode error = U_ZERO_ERROR;
554558
bool useNormalizedString = false;
555559
for (ssize_t i = count - 1; i >= 0; --i) {
@@ -691,23 +695,11 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
691695

692696
logGlyphs(mShaperItem);
693697
#endif
694-
if (isRTL) {
695-
endScriptRun = startScriptRun;
696-
#if DEBUG_GLYPHS
697-
ALOGD("Updated endScriptRun = %d", int(endScriptRun));
698-
#endif
699-
} else {
700-
startScriptRun = endScriptRun;
701-
#if DEBUG_GLYPHS
702-
ALOGD("Updated startScriptRun = %d", int(startScriptRun));
703-
#endif
704-
}
705698

706699
if (mShaperItem.advances == NULL || mShaperItem.num_glyphs == 0) {
707700
#if DEBUG_GLYPHS
708701
ALOGD("Advances array is empty or num_glypth = 0");
709702
#endif
710-
outAdvances->insertAt(0, outAdvances->size(), countScriptRun);
711703
continue;
712704
}
713705

@@ -721,15 +713,13 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
721713
// Get Advances and their total
722714
jfloat currentAdvance = HBFixedToFloat(mShaperItem.advances[mShaperItem.log_clusters[0]]);
723715
jfloat totalFontRunAdvance = currentAdvance;
724-
outAdvances->add(currentAdvance);
716+
outAdvances->replaceAt(currentAdvance, startScriptRun);
725717
for (size_t i = 1; i < countScriptRun; i++) {
726718
size_t clusterPrevious = mShaperItem.log_clusters[i - 1];
727719
size_t cluster = mShaperItem.log_clusters[i];
728-
if (cluster == clusterPrevious) {
729-
outAdvances->add(0);
730-
} else {
720+
if (cluster != clusterPrevious) {
731721
currentAdvance = HBFixedToFloat(mShaperItem.advances[mShaperItem.log_clusters[i]]);
732-
outAdvances->add(currentAdvance);
722+
outAdvances->replaceAt(currentAdvance, startScriptRun + i);
733723
}
734724
}
735725
// TODO: can be removed and go back in the previous loop when Harfbuzz log clusters are fixed
@@ -746,6 +736,7 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
746736
(*outAdvances)[i], mShaperItem.log_clusters[i], totalFontRunAdvance);
747737
}
748738
#endif
739+
749740
// Get Glyphs and reverse them in place if RTL
750741
if (outGlyphs) {
751742
size_t countGlyphs = mShaperItem.num_glyphs;

0 commit comments

Comments
 (0)