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

Commit 626a454c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't create variation instance if the Typeface is variation instance" into main

parents 7c3fc3b8 fe1c8dfd
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ Typeface* Typeface::createRelative(Typeface* src, Typeface::Style style) {
        result->fBaseWeight = resolvedFace->fBaseWeight;
        result->fAPIStyle = style;
        result->fStyle = computeRelativeStyle(result->fBaseWeight, style);
        result->fIsVariationInstance = resolvedFace->fIsVariationInstance;
    }
    return result;
}
@@ -88,6 +89,7 @@ Typeface* Typeface::createAbsolute(Typeface* base, int weight, bool italic) {
        result->fBaseWeight = resolvedFace->fBaseWeight;
        result->fAPIStyle = computeAPIStyle(weight, italic);
        result->fStyle = computeMinikinStyle(weight, italic);
        result->fIsVariationInstance = resolvedFace->fIsVariationInstance;
    }
    return result;
}
@@ -109,6 +111,7 @@ Typeface* Typeface::createFromTypefaceWithVariation(Typeface* src,
        result->fBaseWeight = resolvedFace->fBaseWeight;
        result->fAPIStyle = resolvedFace->fAPIStyle;
        result->fStyle = resolvedFace->fStyle;
        result->fIsVariationInstance = true;
    }
    return result;
}
@@ -121,6 +124,7 @@ Typeface* Typeface::createWithDifferentBaseWeight(Typeface* src, int weight) {
        result->fBaseWeight = weight;
        result->fAPIStyle = resolvedFace->fAPIStyle;
        result->fStyle = computeRelativeStyle(weight, result->fAPIStyle);
        result->fIsVariationInstance = resolvedFace->fIsVariationInstance;
    }
    return result;
}
@@ -170,6 +174,7 @@ Typeface* Typeface::createFromFamilies(std::vector<std::shared_ptr<minikin::Font
    result->fBaseWeight = weight;
    result->fAPIStyle = computeAPIStyle(weight, italic);
    result->fStyle = computeMinikinStyle(weight, italic);
    result->fIsVariationInstance = false;
    return result;
}

+3 −0
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ public:
    // base weight in CSS-style units, 1..1000
    int fBaseWeight;

    // True if the Typeface is already created for variation settings.
    bool fIsVariationInstance;

    static const Typeface* resolveDefault(const Typeface* src);

    // The following three functions create new Typeface from an existing Typeface with a different
+11 −3
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ static void releaseLayout(jlong ptr) {
static jlong shapeTextRun(const uint16_t* text, int textSize, int start, int count,
    int contextStart, int contextCount, minikin::Bidi bidiFlags,
    const Paint& paint, const Typeface* typeface) {

    const Typeface* resolvedFace = Typeface::resolveDefault(typeface);
    minikin::MinikinPaint minikinPaint = MinikinUtils::prepareMinikinPaint(&paint, typeface);

    minikin::Layout layout = MinikinUtils::doLayout(&paint, bidiFlags, typeface,
@@ -103,8 +103,16 @@ static jlong shapeTextRun(const uint16_t* text, int textSize, int start, int cou
                fontId = it->second;  // We've seen it.
            } else {
                fontId = fonts.size();  // This is new to us. Create new one.
                std::shared_ptr<minikin::Font> font = std::make_shared<minikin::Font>(
                        fakedFont.font, fakedFont.fakery.variationSettings());
                std::shared_ptr<minikin::Font> font;
                if (resolvedFace->fIsVariationInstance) {
                    // The optimization for target SDK 35 or before because the variation instance
                    // is already created and no runtime variation resolution happens on such
                    // environment.
                    font = fakedFont.font;
                } else {
                    font = std::make_shared<minikin::Font>(fakedFont.font,
                                                           fakedFont.fakery.variationSettings());
                }
                fonts.push_back(reinterpret_cast<jlong>(new FontWrapper(std::move(font))));
                fakedToFontIds.insert(std::make_pair(fakedFont, fontId));
            }