summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roozbeh Pournader <roozbeh@google.com> 2017-06-05 15:57:14 -0700
committer Roozbeh Pournader <roozbeh@google.com> 2017-06-05 15:57:14 -0700
commitfd8c22d513d92d547f883efc45a3dbcd9558f90a (patch)
treed631419d14c2172612ab147c0306a5fe00e8f713
parenta3112ceedc146005779dba2825af5484d55c8827 (diff)
Move underline thickness and position computation to Paint
Also, in TextLine, fix underline color and thickness to come from the underline info rather than the TextPaint object. Bug: 32907446 Bug: 62353930 Test: Manual Test: cts-tradefed run cts-dev --module CtsTextTestCases Test: cts-tradefed run cts-dev --module CtsWidgetTestCases Change-Id: I259e9cf635a7056ccd367baa77c03100c69e3b98
-rw-r--r--core/java/android/text/TextLine.java11
-rw-r--r--core/java/android/text/TextPaint.java12
-rw-r--r--graphics/java/android/graphics/Paint.java21
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