Skip to content

Commit 15cc68c

Browse files
author
Fabrice Di Meglio
committed
Fix bug #6495019 Character gets garbled when locale is changed
- add missing cached data clearing. The Shaper was caching the HB_Face so clear them too - do minor code refactoring Change-Id: Ifa86cc63815bdb4b51ce688cf16e986415b1e8c1
1 parent 776627b commit 15cc68c

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,7 @@ uint32_t TextLayoutValue::getElapsedTime() {
332332
}
333333

334334
TextLayoutShaper::TextLayoutShaper() : mShaperItemGlyphArraySize(0) {
335-
mDefaultTypeface = SkFontHost::CreateTypeface(NULL, NULL, NULL, 0, SkTypeface::kNormal);
336-
mArabicTypeface = NULL;
337-
mHebrewRegularTypeface = NULL;
338-
mHebrewBoldTypeface = NULL;
339-
mBengaliTypeface = NULL;
340-
mThaiTypeface = NULL;
341-
mDevanagariRegularTypeface = NULL;
342-
mTamilRegularTypeface = NULL;
343-
mTamilBoldTypeface = NULL;
335+
init();
344336

345337
mFontRec.klass = &harfbuzzSkiaClass;
346338
mFontRec.userData = 0;
@@ -359,7 +351,19 @@ TextLayoutShaper::TextLayoutShaper() : mShaperItemGlyphArraySize(0) {
359351
mShaperItem.font->userData = &mShapingPaint;
360352
}
361353

362-
TextLayoutShaper::~TextLayoutShaper() {
354+
void TextLayoutShaper::init() {
355+
mDefaultTypeface = SkFontHost::CreateTypeface(NULL, NULL, NULL, 0, SkTypeface::kNormal);
356+
mArabicTypeface = NULL;
357+
mHebrewRegularTypeface = NULL;
358+
mHebrewBoldTypeface = NULL;
359+
mBengaliTypeface = NULL;
360+
mThaiTypeface = NULL;
361+
mDevanagariRegularTypeface = NULL;
362+
mTamilRegularTypeface = NULL;
363+
mTamilBoldTypeface = NULL;
364+
}
365+
366+
void TextLayoutShaper::unrefTypefaces() {
363367
SkSafeUnref(mDefaultTypeface);
364368
SkSafeUnref(mArabicTypeface);
365369
SkSafeUnref(mHebrewRegularTypeface);
@@ -369,6 +373,10 @@ TextLayoutShaper::~TextLayoutShaper() {
369373
SkSafeUnref(mDevanagariRegularTypeface);
370374
SkSafeUnref(mTamilRegularTypeface);
371375
SkSafeUnref(mTamilBoldTypeface);
376+
}
377+
378+
TextLayoutShaper::~TextLayoutShaper() {
379+
unrefTypefaces();
372380
deleteShaperItemGlyphArrays();
373381
}
374382

@@ -983,6 +991,12 @@ HB_Face TextLayoutShaper::getCachedHBFace(SkTypeface* typeface) {
983991
return face;
984992
}
985993

994+
void TextLayoutShaper::purgeCaches() {
995+
mCachedHBFaces.clear();
996+
unrefTypefaces();
997+
init();
998+
}
999+
9861000
TextLayoutEngine::TextLayoutEngine() {
9871001
mShaper = new TextLayoutShaper();
9881002
#if USE_TEXT_LAYOUT_CACHE
@@ -1018,6 +1032,10 @@ sp<TextLayoutValue> TextLayoutEngine::getValue(const SkPaint* paint, const jchar
10181032
void TextLayoutEngine::purgeCaches() {
10191033
#if USE_TEXT_LAYOUT_CACHE
10201034
mTextLayoutCache->clear();
1035+
mShaper->purgeCaches();
1036+
#if DEBUG_GLYPHS
1037+
ALOGD("Purged TextLayoutEngine caches");
1038+
#endif
10211039
#endif
10221040
}
10231041

core/jni/android/graphics/TextLayoutCache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class TextLayoutShaper {
169169
void computeValues(TextLayoutValue* value, const SkPaint* paint, const UChar* chars,
170170
size_t start, size_t count, size_t contextCount, int dirFlags);
171171

172+
void purgeCaches();
173+
172174
private:
173175
/**
174176
* Harfbuzz shaper item
@@ -218,6 +220,9 @@ class TextLayoutShaper {
218220
*/
219221
UnicodeString mBuffer;
220222

223+
void init();
224+
void unrefTypefaces();
225+
221226
SkTypeface* typefaceForUnichar(const SkPaint* paint, SkTypeface* typeface,
222227
SkUnichar unichar, HB_Script script);
223228

0 commit comments

Comments
 (0)