diff options
| author | Gilles Debunne <debunne@google.com> | 2011-08-10 18:25:49 -0700 |
|---|---|---|
| committer | Gilles Debunne <debunne@google.com> | 2011-08-11 13:31:00 -0700 |
| commit | dd8f5ed79c7baed35b3f04e4778aff7867653255 (patch) | |
| tree | 013329e7cf2c0cd9b1359d048deba5b84dba34af /core/java/android/text/TextLine.java | |
| parent | 27dca78ec1bd7b789226524dcda4fa5a5a2a8544 (diff) | |
Added support for colored / thick underlined text.
Change-Id: Ib0e259dd20546855899bf091f694e41e7051fecb
Diffstat (limited to 'core/java/android/text/TextLine.java')
| -rw-r--r-- | core/java/android/text/TextLine.java | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java index 3e5f32e7d5e1..376e4f56edde 100644 --- a/core/java/android/text/TextLine.java +++ b/core/java/android/text/TextLine.java @@ -16,8 +16,6 @@ package android.text; -import com.android.internal.util.ArrayUtils; - import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; @@ -30,6 +28,8 @@ import android.text.style.MetricAffectingSpan; import android.text.style.ReplacementSpan; import android.util.Log; +import com.android.internal.util.ArrayUtils; + /** * Represents a line of styled text, for measuring in visual order and * for rendering. @@ -720,7 +720,7 @@ class TextLine { float ret = 0; int contextLen = contextEnd - contextStart; - if (needWidth || (c != null && (wp.bgColor != 0 || runIsRtl))) { + if (needWidth || (c != null && (wp.bgColor != 0 || wp.underlineColor !=0 || runIsRtl))) { int flags = runIsRtl ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR; if (mCharsValid) { ret = wp.getTextRunAdvances(mChars, start, runLen, @@ -739,15 +739,32 @@ class TextLine { } if (wp.bgColor != 0) { - int color = wp.getColor(); - Paint.Style s = wp.getStyle(); + int previousColor = wp.getColor(); + Paint.Style previousStyle = wp.getStyle(); + wp.setColor(wp.bgColor); wp.setStyle(Paint.Style.FILL); - c.drawRect(x, top, x + ret, bottom, wp); - wp.setStyle(s); - wp.setColor(color); + wp.setStyle(previousStyle); + wp.setColor(previousColor); + } + + if (wp.underlineColor != 0) { + // kStdUnderline_Offset = 1/9, defined in SkTextFormatParams.h + float middle = y + wp.baselineShift + (1.0f / 9.0f) * wp.getTextSize(); + // kStdUnderline_Thickness = 1/18, defined in SkTextFormatParams.h + float halfHeight = wp.underlineThickness * (1.0f / 18.0f / 2.0f) * wp.getTextSize(); + + int previousColor = wp.getColor(); + Paint.Style previousStyle = wp.getStyle(); + + wp.setColor(wp.underlineColor); + wp.setStyle(Paint.Style.FILL); + c.drawRect(x, middle - halfHeight, x + ret, middle + halfHeight, wp); + + wp.setStyle(previousStyle); + wp.setColor(previousColor); } drawTextRun(c, wp, start, end, contextStart, contextEnd, runIsRtl, |
