Skip to content

Commit 5c863f7

Browse files
author
Fabrice Di Meglio
committed
Fix bug #5371117 Regression : The Hebrew / Arabic text behavior in ICS latest build is wrong
- welcome back start / count - goodbye log clusters - clean Paint code - make private some functions as they should be - improve memory allocation (create only one Shaper and reuse it for for shaping the runs in the same input text) Change-Id: I89a320c7f041319851308c8c9a919fbeafa82cdd
1 parent e921572 commit 5c863f7

File tree

6 files changed

+187
-247
lines changed

6 files changed

+187
-247
lines changed

core/jni/android/graphics/Canvas.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -767,20 +767,17 @@ class SkCanvasGlue {
767767

768768
sp<TextLayoutCacheValue> value;
769769
#if USE_TEXT_LAYOUT_CACHE
770-
value = TextLayoutCache::getInstance().getValue(paint, textArray, contextCount, flags);
770+
value = TextLayoutCache::getInstance().getValue(paint, textArray, start, count,
771+
contextCount, flags);
771772
if (value == NULL) {
772773
LOGE("Cannot get TextLayoutCache value");
773774
return ;
774775
}
775776
#else
776777
value = new TextLayoutCacheValue();
777-
value->computeValues(paint, textArray, contextCount, flags);
778+
value->computeValues(paint, textArray, start, count, contextCount, flags);
778779
#endif
779-
size_t startIndex = 0;
780-
size_t glyphsCount = 0;
781-
value->getGlyphsIndexAndCount(start, count, &startIndex, &glyphsCount);
782-
const jchar* glyphs = value->getGlyphs(startIndex, glyphsCount);
783-
doDrawGlyphs(canvas, glyphs, 0, glyphsCount, x, y, flags, paint);
780+
doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(), x, y, flags, paint);
784781
}
785782

786783
static void doDrawGlyphs(SkCanvas* canvas, const jchar* glyphArray, int index, int count,

core/jni/android/graphics/Paint.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,18 +483,15 @@ class SkPaintGlue {
483483
}
484484

485485
jchar* glyphsArray = env->GetCharArrayElements(glyphs, NULL);
486-
HB_ShaperItem shaperItem;
487-
HB_FontRec font;
488-
FontData fontData;
489-
TextLayoutCacheValue::shapeWithHarfbuzz(&shaperItem, &font, &fontData, paint, text,
490-
start, count, contextCount, flags);
491486

492-
int glyphCount = shaperItem.num_glyphs;
493-
for (int i = 0; i < glyphCount; i++) {
494-
glyphsArray[i] = (jchar) shaperItem.glyphs[i];
495-
}
487+
TextLayoutCacheValue value;
488+
value.computeValues(paint, text, start, count, contextCount, flags);
489+
const jchar* shapedGlyphs = value.getGlyphs();
490+
size_t glyphsCount = value.getGlyphsCount();
491+
memcpy(glyphsArray, shapedGlyphs, sizeof(jchar) * glyphsCount);
492+
496493
env->ReleaseCharArrayElements(glyphs, glyphsArray, JNI_ABORT);
497-
return glyphCount;
494+
return glyphsCount;
498495
}
499496

500497
static int getTextGlyphs__StringIIIII_C(JNIEnv* env, jobject clazz, SkPaint* paint,

core/jni/android/graphics/TextLayout.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,18 @@ void TextLayout::getTextRunAdvances(SkPaint* paint, const jchar* chars, jint sta
257257
sp<TextLayoutCacheValue> value;
258258
#if USE_TEXT_LAYOUT_CACHE
259259
// Return advances from the cache. Compute them if needed
260-
value = TextLayoutCache::getInstance().getValue(paint, chars, contextCount, dirFlags);
260+
value = TextLayoutCache::getInstance().getValue(paint, chars, start, count,
261+
contextCount, dirFlags);
261262
#else
262263
value = new TextLayoutCacheValue();
263-
value->computeValues(paint, chars, contextCount, dirFlags);
264+
value->computeValues(paint, chars, start, count, contextCount, dirFlags);
264265
#endif
265266
if (value != NULL) {
266-
if (resultAdvances != NULL) {
267-
value->getAdvances(start, count, resultAdvances);
267+
if (resultAdvances) {
268+
memcpy(resultAdvances, value->getAdvances(), value->getAdvancesCount() * sizeof(jfloat));
268269
}
269270
if (resultTotalAdvance) {
270-
*resultTotalAdvance = value->getTotalAdvance(start, count);
271+
*resultTotalAdvance = value->getTotalAdvance();
271272
}
272273
}
273274
}

0 commit comments

Comments
 (0)