Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15cc68ce authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

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
parent 776627b8
Loading
Loading
Loading
Loading
+28 −10
Original line number Diff line number Diff line
@@ -332,15 +332,7 @@ uint32_t TextLayoutValue::getElapsedTime() {
}

TextLayoutShaper::TextLayoutShaper() : mShaperItemGlyphArraySize(0) {
    mDefaultTypeface = SkFontHost::CreateTypeface(NULL, NULL, NULL, 0, SkTypeface::kNormal);
    mArabicTypeface = NULL;
    mHebrewRegularTypeface = NULL;
    mHebrewBoldTypeface = NULL;
    mBengaliTypeface = NULL;
    mThaiTypeface = NULL;
    mDevanagariRegularTypeface = NULL;
    mTamilRegularTypeface = NULL;
    mTamilBoldTypeface = NULL;
    init();

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

TextLayoutShaper::~TextLayoutShaper() {
void TextLayoutShaper::init() {
    mDefaultTypeface = SkFontHost::CreateTypeface(NULL, NULL, NULL, 0, SkTypeface::kNormal);
    mArabicTypeface = NULL;
    mHebrewRegularTypeface = NULL;
    mHebrewBoldTypeface = NULL;
    mBengaliTypeface = NULL;
    mThaiTypeface = NULL;
    mDevanagariRegularTypeface = NULL;
    mTamilRegularTypeface = NULL;
    mTamilBoldTypeface = NULL;
}

void TextLayoutShaper::unrefTypefaces() {
    SkSafeUnref(mDefaultTypeface);
    SkSafeUnref(mArabicTypeface);
    SkSafeUnref(mHebrewRegularTypeface);
@@ -369,6 +373,10 @@ TextLayoutShaper::~TextLayoutShaper() {
    SkSafeUnref(mDevanagariRegularTypeface);
    SkSafeUnref(mTamilRegularTypeface);
    SkSafeUnref(mTamilBoldTypeface);
}

TextLayoutShaper::~TextLayoutShaper() {
    unrefTypefaces();
    deleteShaperItemGlyphArrays();
}

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

void TextLayoutShaper::purgeCaches() {
    mCachedHBFaces.clear();
    unrefTypefaces();
    init();
}

TextLayoutEngine::TextLayoutEngine() {
    mShaper = new TextLayoutShaper();
#if USE_TEXT_LAYOUT_CACHE
@@ -1018,6 +1032,10 @@ sp<TextLayoutValue> TextLayoutEngine::getValue(const SkPaint* paint, const jchar
void TextLayoutEngine::purgeCaches() {
#if USE_TEXT_LAYOUT_CACHE
    mTextLayoutCache->clear();
    mShaper->purgeCaches();
#if DEBUG_GLYPHS
    ALOGD("Purged TextLayoutEngine caches");
#endif
#endif
}

+5 −0
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ public:
    void computeValues(TextLayoutValue* value, const SkPaint* paint, const UChar* chars,
            size_t start, size_t count, size_t contextCount, int dirFlags);

    void purgeCaches();

private:
    /**
     * Harfbuzz shaper item
@@ -218,6 +220,9 @@ private:
     */
    UnicodeString mBuffer;

    void init();
    void unrefTypefaces();

    SkTypeface* typefaceForUnichar(const SkPaint* paint, SkTypeface* typeface,
        SkUnichar unichar, HB_Script script);