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

Commit c437f6ee authored by Behdad Esfahbod's avatar Behdad Esfahbod Committed by Android (Google) Code Review
Browse files

Merge "Further centralize Minikin interaction" into lmp-dev

parents b9333b59 63c5c78a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -40,8 +40,8 @@ static int snprintfcat(char* buf, int off, int size, const char* format, ...) {
    return off + n;
}

std::string MinikinUtils::setLayoutProperties(Layout* layout, const Paint* paint, int bidiFlags,
        TypefaceImpl* typeface) {
void MinikinUtils::doLayout(Layout* layout, const Paint* paint, int bidiFlags, TypefaceImpl* typeface,
        const uint16_t* buf, size_t start, size_t count, size_t bufSize) {
    TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface);
    layout->setFontCollection(resolvedFace->fFontCollection);
    FontStyle style = resolvedFace->fStyle;
@@ -62,7 +62,7 @@ std::string MinikinUtils::setLayoutProperties(Layout* layout, const Paint* paint
    SkPaintOptionsAndroid::FontVariant var = paint->getPaintOptionsAndroid().getFontVariant();
    const char* varstr = var == SkPaintOptionsAndroid::kElegant_Variant ? "elegant" : "compact";
    off = snprintfcat(css, off, sizeof(css), " -minikin-variant: %s;", varstr);
    return std::string(css);
    layout->doLayout(buf, start, count, bufSize, std::string(css));
}

float MinikinUtils::xOffsetForTextAlign(Paint* paint, const Layout& layout) {
+2 −2
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ class TypefaceImpl;

class MinikinUtils {
public:
    static std::string setLayoutProperties(Layout* layout, const Paint* paint, int bidiFlags,
            TypefaceImpl* typeface);
    static void doLayout(Layout* layout, const Paint* paint, int bidiFlags, TypefaceImpl* typeface,
            const uint16_t* buf, size_t start, size_t count, size_t bufSize);

    static float xOffsetForTextAlign(Paint* paint, const Layout& layout);

+8 −16
Original line number Diff line number Diff line
@@ -535,8 +535,7 @@ public:

        Layout layout;
        TypefaceImpl* typeface = GraphicsJNI::getNativeTypeface(env, jpaint);
        std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
        layout.doLayout(textArray, index, count, textLength, css);
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray, index, count, textLength);
        result = layout.getAdvance();
        env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT);
        return result;
@@ -563,8 +562,7 @@ public:

        Layout layout;
        TypefaceImpl* typeface = GraphicsJNI::getNativeTypeface(env, jpaint);
        std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
        layout.doLayout(textArray, start, count, textLength, css);
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray, start, count, textLength);
        width = layout.getAdvance();

        env->ReleaseStringChars(text, textArray);
@@ -586,8 +584,7 @@ public:

        Layout layout;
        TypefaceImpl* typeface = GraphicsJNI::getNativeTypeface(env, jpaint);
        std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
        layout.doLayout(textArray, 0, textLength, textLength, css);
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray, 0, textLength, textLength);
        width = layout.getAdvance();

        env->ReleaseStringChars(text, textArray);
@@ -616,8 +613,7 @@ public:
        jfloat* widthsArray = autoWidths.ptr();

        Layout layout;
        std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
        layout.doLayout(text, 0, count, count, css);
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
        layout.getAdvances(widthsArray);

        return count;
@@ -670,8 +666,7 @@ public:
        int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR;

        Layout layout;
        std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
        layout.doLayout(text, start, count, contextCount, css);
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, start, count, contextCount);
        layout.getAdvances(advancesArray);
        totalAdvance = layout.getAdvance();

@@ -770,8 +765,7 @@ public:
    static void getTextPath(JNIEnv* env, Paint* paint, TypefaceImpl* typeface, const jchar* text,
            jint count, jint bidiFlags, jfloat x, jfloat y, SkPath* path) {
        Layout layout;
        std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
        layout.doLayout(text, 0, count, count, css);
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
        size_t nGlyphs = layout.nGlyphs();
        uint16_t* glyphs = new uint16_t[nGlyphs];
        SkPoint* pos = new SkPoint[nGlyphs];
@@ -833,8 +827,7 @@ public:
        float measured = 0;

        Layout layout;
        std::string css = MinikinUtils::setLayoutProperties(&layout, &paint, bidiFlags, typeface);
        layout.doLayout(text, 0, count, count, css);
        MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, 0, count, count);
        float* advances = new float[count];
        layout.getAdvances(advances);
        const bool forwardScan = (textBufferDirection == Paint::kForward_TextBufferDirection);
@@ -914,8 +907,7 @@ public:
        SkIRect ir;

        Layout layout;
        std::string css = MinikinUtils::setLayoutProperties(&layout, &paint, bidiFlags, typeface);
        layout.doLayout(text, 0, count, count, css);
        MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, 0, count, count);
        MinikinRect rect;
        layout.getBounds(&rect);
        r.fLeft = rect.mLeft;
+2 −4
Original line number Diff line number Diff line
@@ -486,8 +486,7 @@ void drawText(Canvas* canvas, const uint16_t* text, int start, int count, int co
    Paint paint(origPaint);

    Layout layout;
    std::string css = MinikinUtils::setLayoutProperties(&layout, &paint, bidiFlags, typeface);
    layout.doLayout(text, start, count, contextCount, css);
    MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, start, count, contextCount);

    size_t nGlyphs = layout.nGlyphs();
    uint16_t* glyphs = new uint16_t[nGlyphs];
@@ -625,8 +624,7 @@ static void drawTextOnPath(Canvas* canvas, const uint16_t* text, int count, int
                           const Paint& paint, TypefaceImpl* typeface) {
    Paint paintCopy(paint);
    Layout layout;
    std::string css = MinikinUtils::setLayoutProperties(&layout, &paintCopy, bidiFlags, typeface);
    layout.doLayout(text, 0, count, count, css);
    MinikinUtils::doLayout(&layout, &paintCopy, bidiFlags, typeface, text, 0, count, count);
    hOffset += MinikinUtils::hOffsetForTextAlign(&paintCopy, layout, path);

    // Set align to left for drawing, as we don't want individual
+3 −6
Original line number Diff line number Diff line
@@ -620,8 +620,7 @@ static void renderTextLayout(DisplayListRenderer* renderer, Layout* layout,
static void renderText(DisplayListRenderer* renderer, const jchar* text, int count,
        jfloat x, jfloat y, int bidiFlags, Paint* paint, TypefaceImpl* typeface) {
    Layout layout;
    std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
    layout.doLayout(text, 0, count, count, css);
    MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
    x += MinikinUtils::xOffsetForTextAlign(paint, layout);
    renderTextLayout(renderer, &layout, x, y, paint);
}
@@ -655,8 +654,7 @@ static void renderTextOnPath(DisplayListRenderer* renderer, const jchar* text, i
        SkPath* path, jfloat hOffset, jfloat vOffset, int bidiFlags, Paint* paint,
        TypefaceImpl* typeface) {
    Layout layout;
    std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
    layout.doLayout(text, 0, count, count, css);
    MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
    hOffset += MinikinUtils::hOffsetForTextAlign(paint, layout, *path);
    Paint::Align align = paint->getTextAlign();
    paint->setTextAlign(Paint::kLeft_Align);
@@ -670,8 +668,7 @@ static void renderTextRun(DisplayListRenderer* renderer, const jchar* text,
        jint start, jint count, jint contextCount, jfloat x, jfloat y,
        int bidiFlags, Paint* paint, TypefaceImpl* typeface) {
    Layout layout;
    std::string css = MinikinUtils::setLayoutProperties(&layout, paint, bidiFlags, typeface);
    layout.doLayout(text, start, count, contextCount, css);
    MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, start, count, contextCount);
    x += MinikinUtils::xOffsetForTextAlign(paint, layout);
    renderTextLayout(renderer, &layout, x, y, paint);
}