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

Commit b39d8973 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Use Harfbuzz for Canvas drawText APIs

Change-Id: I661d5e9e0bbe9a859e7a000cb161994d29add099
parent 4af51a14
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -743,7 +743,11 @@ public:
                                      jcharArray text, int index, int count,
                                      jfloat x, jfloat y, int flags, SkPaint* paint) {
        jchar* textArray = env->GetCharArrayElements(text, NULL);
#if RTL_USE_HARFBUZZ
        drawTextWithGlyphs(canvas, textArray + index, 0, count, x, y, flags, paint);
#else
        TextLayout::drawText(paint, textArray + index, count, flags, x, y, canvas);
#endif
        env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
    }

@@ -752,7 +756,11 @@ public:
                                          int start, int end,
                                          jfloat x, jfloat y, int flags, SkPaint* paint) {
        const jchar* textArray = env->GetStringChars(text, NULL);
#if RTL_USE_HARFBUZZ
        drawTextWithGlyphs(canvas, textArray, start, end, x, y, flags, paint);
#else
        TextLayout::drawText(paint, textArray + start, end - start, flags, x, y, canvas);
#endif
        env->ReleaseStringChars(text, textArray);
    }

@@ -781,6 +789,23 @@ public:
                x, y, flags, paint);
    }

    static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray,
            int start, int count, int contextCount,
            jfloat x, jfloat y, int flags, SkPaint* paint) {

        sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
                paint, textArray, start, count, contextCount, flags);
        if (value == NULL) {
            LOGE("drawTextWithGlyphs -- cannot get Cache value");
            return ;
        }
#if DEBUG_GLYPHS
        logGlyphs(value);
#endif
        doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(),
                x, y, flags, paint);
    }

    static void drawTextWithGlyphs___CIIFFIPaint(JNIEnv* env, jobject, SkCanvas* canvas,
                                      jcharArray text, int index, int count,
                                      jfloat x, jfloat y, int flags, SkPaint* paint) {
@@ -831,8 +856,13 @@ public:
        jfloat x, jfloat y, int dirFlags, SkPaint* paint) {

        jchar* chars = env->GetCharArrayElements(text, NULL);
#if RTL_USE_HARFBUZZ
        drawTextWithGlyphs(canvas, chars + contextIndex, index - contextIndex,
                count, contextCount, x, y, dirFlags, paint);
#else
        TextLayout::drawTextRun(paint, chars + contextIndex, index - contextIndex,
                count, contextCount, dirFlags, x, y, canvas);
#endif
        env->ReleaseCharArrayElements(text, chars, JNI_ABORT);
    }

@@ -844,8 +874,13 @@ public:
        jint count = end - start;
        jint contextCount = contextEnd - contextStart;
        const jchar* chars = env->GetStringChars(text, NULL);
#if RTL_USE_HARFBUZZ
        drawTextWithGlyphs(canvas, chars + contextStart, start - contextStart,
                count, contextCount, x, y, dirFlags, paint);
#else
        TextLayout::drawTextRun(paint, chars + contextStart, start - contextStart,
                count, contextCount, dirFlags, x, y, canvas);
#endif
        env->ReleaseStringChars(text, chars);
    }