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

Commit 310a1d6e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move underline thickness and position computation to Paint"

parents f0daf925 fd8c22d5
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -705,9 +705,8 @@ class TextLine {
    }

    private static void drawUnderline(TextPaint wp, Canvas c, int color, float thickness,
            float xleft, float xright, int baseline) {
        // kStdUnderline_Offset = 1/9, defined in SkTextFormatParams.h
        final float underlineTop = baseline + wp.baselineShift + (1.0f / 9.0f) * wp.getTextSize();
            float xleft, float xright, float baseline) {
        final float underlineTop = baseline + wp.baselineShift + wp.getUnderlinePosition();

        final int previousColor = wp.getColor();
        final Paint.Style previousStyle = wp.getStyle();
@@ -802,8 +801,6 @@ class TextLine {
            }

            if (numUnderlines != 0) {
                // kStdUnderline_Thickness = 1/18, defined in SkTextFormatParams.h
                final float defaultThickness = (1.0f / 18.0f) * wp.getTextSize();
                for (int i = 0; i < numUnderlines; i++) {
                    final UnderlineInfo info = underlines.get(i);

@@ -826,11 +823,11 @@ class TextLine {
                    // setUnderLineText() are called. For backward compatibility, we need to draw
                    // both underlines, the one with custom color first.
                    if (info.underlineColor != 0) {
                        drawUnderline(wp, c, wp.underlineColor, wp.underlineThickness,
                        drawUnderline(wp, c, info.underlineColor, info.underlineThickness,
                                underlineXLeft, underlineXRight, y);
                    }
                    if (info.isUnderlineText) {
                        drawUnderline(wp, c, wp.getColor(), defaultThickness,
                        drawUnderline(wp, c, wp.getColor(), ((Paint) wp).getUnderlineThickness(),
                                underlineXLeft, underlineXRight, y);
                    }
                }
+12 −0
Original line number Diff line number Diff line
@@ -102,4 +102,16 @@ public class TextPaint extends Paint {
        underlineColor = color;
        underlineThickness = thickness;
    }

    /**
     * @hide
     */
    @Override
    public float getUnderlineThickness() {
        if (underlineColor != 0) { // Return custom thickness only if underline color is set.
            return underlineThickness;
        } else {
            return super.getUnderlineThickness();
        }
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -815,6 +815,27 @@ public class Paint {
        return (getFlags() & UNDERLINE_TEXT_FLAG) != 0;
    }

    /**
     * Distance from top of the underline to the baseline. Positive values mean below the baseline.
     * This method returns where the underline should be drawn independent of if the underlineText
     * bit is set at the moment.
     * @hide
     */
    public float getUnderlinePosition() {
        // kStdUnderline_Offset = 1/9, defined in SkTextFormatParams.h
        // TODO: replace with position from post and MVAR tables (b/62353930).
        return (1.0f / 9.0f) * getTextSize();
    }

    /**
     * @hide
     */
    public float getUnderlineThickness() {
        // kStdUnderline_Thickness = 1/18, defined in SkTextFormatParams.h
        // TODO: replace with thickness from post and MVAR tables (b/62353930).
        return (1.0f / 18.0f) * getTextSize();
    }

    /**
     * Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit
     *