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