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

Commit 325a0f96 authored by Romain Guy's avatar Romain Guy
Browse files

The font cache should respect the fake bold flag.

Change-Id: Ie4edc9ba46610edde831b55e769944e9a19bdcb5
parent b03ba34b
Loading
Loading
Loading
Loading
+30 −26
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ namespace uirenderer {
// Font
///////////////////////////////////////////////////////////////////////////////

Font::Font(FontRenderer* state, uint32_t fontId, float fontSize) :
    mState(state), mFontId(fontId), mFontSize(fontSize) {
Font::Font(FontRenderer* state, uint32_t fontId, float fontSize, int flags) :
    mState(state), mFontId(fontId), mFontSize(fontSize), mFlags(flags) {
}


@@ -275,17 +275,17 @@ Font::CachedGlyphInfo* Font::cacheGlyph(SkPaint* paint, int32_t glyph) {
    return newGlyph;
}

Font* Font::create(FontRenderer* state, uint32_t fontId, float fontSize) {
Font* Font::create(FontRenderer* state, uint32_t fontId, float fontSize, int flags) {
    Vector<Font*> &activeFonts = state->mActiveFonts;

    for (uint32_t i = 0; i < activeFonts.size(); i++) {
        Font* font = activeFonts[i];
        if (font->mFontId == fontId && font->mFontSize == fontSize) {
        if (font->mFontId == fontId && font->mFontSize == fontSize && font->mFlags == flags) {
            return font;
        }
    }

    Font* newFont = new Font(state, fontId, fontSize);
    Font* newFont = new Font(state, fontId, fontSize, flags);
    activeFonts.push(newFont);
    return newFont;
}
@@ -634,7 +634,11 @@ void FontRenderer::precacheLatin(SkPaint* paint) {

void FontRenderer::setFont(SkPaint* paint, uint32_t fontId, float fontSize) {
    uint32_t currentNumFonts = mActiveFonts.size();
    mCurrentFont = Font::create(this, fontId, fontSize);
    int flags = 0;
    if (paint->isFakeBoldText()) {
        flags |= Font::kFakeBold;
    }
    mCurrentFont = Font::create(this, fontId, fontSize, flags);

    const float maxPrecacheFontSize = 40.0f;
    bool isNewFont = currentNumFonts != mActiveFonts.size();
@@ -757,7 +761,7 @@ void FontRenderer::horizontalBlur(float* weights, int32_t radius,
            blurredPixel = 0.0f;
            const float* gPtr = weights;
            // Optimization for non-border pixels
            if ((x > radius) && (x < (width - radius))) {
            if (x > radius && x < (width - radius)) {
                const uint8_t *i = input + (x - radius);
                for (int r = -radius; r <= radius; r ++) {
                    currentPixel = (float) (*i);
@@ -776,7 +780,7 @@ void FontRenderer::horizontalBlur(float* weights, int32_t radius,
                        validW = width - 1;
                    }

                    currentPixel = (float)(input[validW]);
                    currentPixel = (float) input[validW];
                    blurredPixel += currentPixel * gPtr[0];
                    gPtr++;
                }
@@ -801,7 +805,7 @@ void FontRenderer::verticalBlur(float* weights, int32_t radius,
            const float* gPtr = weights;
            const uint8_t* input = source + x;
            // Optimization for non-border pixels
            if ((y > radius) && (y < (height - radius))) {
            if (y > radius && y < (height - radius)) {
                const uint8_t *i = input + ((y - radius) * width);
                for (int32_t r = -radius; r <= radius; r ++) {
                    currentPixel = (float)(*i);
+7 −2
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@ class FontRenderer;
 */
class Font {
public:
    enum Style {
        kFakeBold
    };

    ~Font();

    /**
@@ -53,7 +57,7 @@ public:
    /**
     * Creates a new font associated with the specified font state.
     */
    static Font* create(FontRenderer* state, uint32_t fontId, float fontSize);
    static Font* create(FontRenderer* state, uint32_t fontId, float fontSize, int flags);

protected:
    friend class FontRenderer;
@@ -99,7 +103,7 @@ protected:
        SkFixed mRsbDelta;
    };

    Font(FontRenderer* state, uint32_t fontId, float fontSize);
    Font(FontRenderer* state, uint32_t fontId, float fontSize, int flags);

    DefaultKeyedVector<int32_t, CachedGlyphInfo*> mCachedGlyphs;

@@ -117,6 +121,7 @@ protected:
    FontRenderer* mState;
    uint32_t mFontId;
    float mFontSize;
    int mFlags;
};

class FontRenderer {