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

Commit 16c142b4 authored by Mike Reed's avatar Mike Reed
Browse files

move alignment to Paint (from SkPaint)

Test: make

Change-Id: I35633b0a43b68b4784d8f253a9c37d1d8da7dc87
parent 2daf457f
Loading
Loading
Loading
Loading
+0 −8
Original line number Original line Diff line number Diff line
@@ -732,14 +732,10 @@ void SkiaCanvas::drawGlyphs(ReadGlyphFunc glyphFunc, int count, const SkPaint& p
                            float y, float boundsLeft, float boundsTop, float boundsRight,
                            float y, float boundsLeft, float boundsTop, float boundsRight,
                            float boundsBottom, float totalAdvance) {
                            float boundsBottom, float totalAdvance) {
    if (count <= 0 || paint.nothingToDraw()) return;
    if (count <= 0 || paint.nothingToDraw()) return;
    // Set align to left for drawing, as we don't want individual
    // glyphs centered or right-aligned; the offset above takes
    // care of all alignment.
    SkPaint paintCopy(paint);
    SkPaint paintCopy(paint);
    if (mPaintFilter) {
    if (mPaintFilter) {
        mPaintFilter->filter(&paintCopy);
        mPaintFilter->filter(&paintCopy);
    }
    }
    paintCopy.setTextAlign(SkPaint::kLeft_Align);
    SkASSERT(paintCopy.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
    SkASSERT(paintCopy.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
    // Stroke with a hairline is drawn on HW with a fill style for compatibility with Android O and
    // Stroke with a hairline is drawn on HW with a fill style for compatibility with Android O and
    // older.
    // older.
@@ -763,14 +759,10 @@ void SkiaCanvas::drawGlyphs(ReadGlyphFunc glyphFunc, int count, const SkPaint& p
void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
void SkiaCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOffset, float vOffset,
                                  const SkPaint& paint, const SkPath& path, size_t start,
                                  const SkPaint& paint, const SkPath& path, size_t start,
                                  size_t end) {
                                  size_t end) {
    // Set align to left for drawing, as we don't want individual
    // glyphs centered or right-aligned; the offsets take care of
    // that portion of the alignment.
    SkPaint paintCopy(paint);
    SkPaint paintCopy(paint);
    if (mPaintFilter) {
    if (mPaintFilter) {
        mPaintFilter->filter(&paintCopy);
        mPaintFilter->filter(&paintCopy);
    }
    }
    paintCopy.setTextAlign(SkPaint::kLeft_Align);
    SkASSERT(paintCopy.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
    SkASSERT(paintCopy.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);


    const int N = end - start;
    const int N = end - start;
+9 −0
Original line number Original line Diff line number Diff line
@@ -86,6 +86,14 @@ public:


    const Typeface* getAndroidTypeface() const { return mTypeface; }
    const Typeface* getAndroidTypeface() const { return mTypeface; }


    enum Align {
        kLeft_Align,
        kCenter_Align,
        kRight_Align,
    };
    Align getTextAlign() const { return mAlign; }
    void setTextAlign(Align align) { mAlign = align; }

private:
private:
    float mLetterSpacing = 0;
    float mLetterSpacing = 0;
    float mWordSpacing = 0;
    float mWordSpacing = 0;
@@ -98,6 +106,7 @@ private:
    // object. Thus, following pointer can never be a dangling pointer. Note that
    // object. Thus, following pointer can never be a dangling pointer. Note that
    // nullptr is valid: it means the default typeface.
    // nullptr is valid: it means the default typeface.
    const Typeface* mTypeface = nullptr;
    const Typeface* mTypeface = nullptr;
    Align mAlign = kLeft_Align;
};
};


}  // namespace android
}  // namespace android
+4 −2
Original line number Original line Diff line number Diff line
@@ -34,7 +34,8 @@ Paint::Paint(const Paint& paint)
        , mMinikinLocaleListId(paint.mMinikinLocaleListId)
        , mMinikinLocaleListId(paint.mMinikinLocaleListId)
        , mFamilyVariant(paint.mFamilyVariant)
        , mFamilyVariant(paint.mFamilyVariant)
        , mHyphenEdit(paint.mHyphenEdit)
        , mHyphenEdit(paint.mHyphenEdit)
        , mTypeface(paint.mTypeface) {}
        , mTypeface(paint.mTypeface)
        , mAlign(paint.mAlign) {}


Paint::Paint(const SkPaint& paint)
Paint::Paint(const SkPaint& paint)
        : SkPaint(paint)
        : SkPaint(paint)
@@ -55,6 +56,7 @@ Paint& Paint::operator=(const Paint& other) {
    mFamilyVariant = other.mFamilyVariant;
    mFamilyVariant = other.mFamilyVariant;
    mHyphenEdit = other.mHyphenEdit;
    mHyphenEdit = other.mHyphenEdit;
    mTypeface = other.mTypeface;
    mTypeface = other.mTypeface;
    mAlign = other.mAlign;
    return *this;
    return *this;
}
}


@@ -64,6 +66,6 @@ bool operator==(const Paint& a, const Paint& b) {
           a.mFontFeatureSettings == b.mFontFeatureSettings &&
           a.mFontFeatureSettings == b.mFontFeatureSettings &&
           a.mMinikinLocaleListId == b.mMinikinLocaleListId &&
           a.mMinikinLocaleListId == b.mMinikinLocaleListId &&
           a.mFamilyVariant == b.mFamilyVariant && a.mHyphenEdit == b.mHyphenEdit &&
           a.mFamilyVariant == b.mFamilyVariant && a.mHyphenEdit == b.mHyphenEdit &&
           a.mTypeface == b.mTypeface;
           a.mTypeface == b.mTypeface && a.mAlign == b.mAlign;
}
}
}  // namespace android
}  // namespace android
+0 −1
Original line number Original line Diff line number Diff line
@@ -46,7 +46,6 @@ class ListViewAnimation : public TestListViewSceneBase {
                SkColorGetR(randomColor) + SkColorGetG(randomColor) + SkColorGetB(randomColor) <
                SkColorGetR(randomColor) + SkColorGetG(randomColor) + SkColorGetB(randomColor) <
                128 * 3;
                128 * 3;
        paint.setColor(bgDark ? Color::White : Color::Grey_700);
        paint.setColor(bgDark ? Color::White : Color::Grey_700);
        paint.setTextAlign(SkPaint::kCenter_Align);
        paint.setTextSize(size / 2);
        paint.setTextSize(size / 2);
        char charToShow = 'A' + (rand() % 26);
        char charToShow = 'A' + (rand() % 26);
        const SkPoint pos[] = {{SkIntToScalar(size / 2),
        const SkPoint pos[] = {{SkIntToScalar(size / 2),