From b216c21acdbcb0e8a2b970d6ff9f72e9bf185623 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Wed, 22 Feb 2017 10:02:40 -0500 Subject: [PATCH] underline is now only tracked by android Change-Id: I189c57dd47ad413b8964d7e5805dfd6d4af11982 --- core/jni/android/graphics/Paint.cpp | 36 ++++++++++++++++++++--------- libs/hwui/hwui/Canvas.cpp | 6 ++--- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index dfe809dd7d58b..bdf79d30aa099 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -84,15 +84,15 @@ namespace PaintGlue { } static jlong init(JNIEnv* env, jobject) { - static_assert(1 << 0 == SkPaint::kAntiAlias_Flag, "paint_flags_mismatch"); - static_assert(1 << 2 == SkPaint::kDither_Flag, "paint_flags_mismatch"); - static_assert(1 << 3 == SkPaint::kUnderlineText_Flag, "paint_flags_mismatch"); - static_assert(1 << 4 == SkPaint::kStrikeThruText_Flag, "paint_flags_mismatch"); - static_assert(1 << 5 == SkPaint::kFakeBoldText_Flag, "paint_flags_mismatch"); - static_assert(1 << 6 == SkPaint::kLinearText_Flag, "paint_flags_mismatch"); - static_assert(1 << 7 == SkPaint::kSubpixelText_Flag, "paint_flags_mismatch"); - static_assert(1 << 8 == SkPaint::kDevKernText_Flag, "paint_flags_mismatch"); - static_assert(1 << 10 == SkPaint::kEmbeddedBitmapText_Flag, "paint_flags_mismatch"); + static_assert(1 << 0 == SkPaint::kAntiAlias_Flag, "paint_flags_mismatch"); + static_assert(1 << 2 == SkPaint::kDither_Flag, "paint_flags_mismatch"); + static_assert(1 << 3 == SkPaint::kUnderlineText_ReserveFlag, "paint_flags_mismatch"); + static_assert(1 << 4 == SkPaint::kStrikeThruText_ReserveFlag, "paint_flags_mismatch"); + static_assert(1 << 5 == SkPaint::kFakeBoldText_Flag, "paint_flags_mismatch"); + static_assert(1 << 6 == SkPaint::kLinearText_Flag, "paint_flags_mismatch"); + static_assert(1 << 7 == SkPaint::kSubpixelText_Flag, "paint_flags_mismatch"); + static_assert(1 << 8 == SkPaint::kDevKernText_Flag, "paint_flags_mismatch"); + static_assert(1 << 10 == SkPaint::kEmbeddedBitmapText_Flag, "paint_flags_mismatch"); Paint* obj = new Paint(); defaultSettingsForAndroid(obj); @@ -692,11 +692,25 @@ namespace PaintGlue { } static void setUnderlineText(jlong paintHandle, jboolean underlineText) { - reinterpret_cast(paintHandle)->setUnderlineText(underlineText); + Paint* paint = reinterpret_cast(paintHandle); + uint32_t flags = paint->getFlags(); + if (underlineText) { + flags |= Paint::kUnderlineText_ReserveFlag; + } else { + flags &= ~Paint::kUnderlineText_ReserveFlag; + } + paint->setFlags(flags); } static void setStrikeThruText(jlong paintHandle, jboolean strikeThruText) { - reinterpret_cast(paintHandle)->setStrikeThruText(strikeThruText); + Paint* paint = reinterpret_cast(paintHandle); + uint32_t flags = paint->getFlags(); + if (strikeThruText) { + flags |= Paint::kStrikeThruText_ReserveFlag; + } else { + flags &= ~Paint::kStrikeThruText_ReserveFlag; + } + paint->setFlags(flags); } static void setFakeBoldText(jlong paintHandle, jboolean fakeBoldText) { diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp index 2dc8ce8fe774b..c365b5d8e6043 100644 --- a/libs/hwui/hwui/Canvas.cpp +++ b/libs/hwui/hwui/Canvas.cpp @@ -45,7 +45,7 @@ void Canvas::drawTextDecorations(float x, float y, float length, const SkPaint& } else { flags = paint.getFlags(); } - if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) { + if (flags & (SkPaint::kUnderlineText_ReserveFlag | SkPaint::kStrikeThruText_ReserveFlag)) { // Same values used by Skia const float kStdStrikeThru_Offset = (-6.0f / 21.0f); const float kStdUnderline_Offset = (1.0f / 9.0f); @@ -55,12 +55,12 @@ void Canvas::drawTextDecorations(float x, float y, float length, const SkPaint& SkScalar right = x + length; float textSize = paint.getTextSize(); float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f); - if (flags & SkPaint::kUnderlineText_Flag) { + if (flags & SkPaint::kUnderlineText_ReserveFlag) { SkScalar top = y + textSize * kStdUnderline_Offset - 0.5f * strokeWidth; SkScalar bottom = y + textSize * kStdUnderline_Offset + 0.5f * strokeWidth; drawRect(left, top, right, bottom, paint); } - if (flags & SkPaint::kStrikeThruText_Flag) { + if (flags & SkPaint::kStrikeThruText_ReserveFlag) { SkScalar top = y + textSize * kStdStrikeThru_Offset - 0.5f * strokeWidth; SkScalar bottom = y + textSize * kStdStrikeThru_Offset + 0.5f * strokeWidth; drawRect(left, top, right, bottom, paint);