diff options
| author | 2017-06-06 01:05:38 +0000 | |
|---|---|---|
| committer | 2017-06-06 01:05:43 +0000 | |
| commit | 310a1d6ec6aaf625eb1594e41d9f7a11f874bc51 (patch) | |
| tree | 2f78df5af2dcc458186ef1a088f37258df07208b | |
| parent | f0daf925b0237562c83ae2eaf5587bb0022c6a92 (diff) | |
| parent | fd8c22d513d92d547f883efc45a3dbcd9558f90a (diff) | |
Merge "Move underline thickness and position computation to Paint"
| -rw-r--r-- | core/java/android/text/TextLine.java | 11 | ||||
| -rw-r--r-- | core/java/android/text/TextPaint.java | 12 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Paint.java | 21 |
3 files changed, 37 insertions, 7 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java index 97e281894395..e4ed62a1ead9 100644 --- a/core/java/android/text/TextLine.java +++ b/core/java/android/text/TextLine.java @@ -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); } } diff --git a/core/java/android/text/TextPaint.java b/core/java/android/text/TextPaint.java index 1b062cf8adcf..5234fa9a594b 100644 --- a/core/java/android/text/TextPaint.java +++ b/core/java/android/text/TextPaint.java @@ -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(); + } + } } diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index eb33ca857095..adc4369ba2ec 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -816,6 +816,27 @@ public class Paint { } /** + * 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 * * @param underlineText true to set the underlineText bit in the paint's |