diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/hwui/hwui/DrawTextFunctor.h | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/libs/hwui/hwui/DrawTextFunctor.h b/libs/hwui/hwui/DrawTextFunctor.h index 1fcb6920db14..cfca48084d97 100644 --- a/libs/hwui/hwui/DrawTextFunctor.h +++ b/libs/hwui/hwui/DrawTextFunctor.h @@ -34,7 +34,9 @@ namespace flags = com::android::graphics::hwui::flags; namespace android { -inline constexpr int kHighContrastTextBorderWidth = 4; +// These should match the constants in framework/base/core/java/android/text/Layout.java +inline constexpr float kHighContrastTextBorderWidth = 4.0f; +inline constexpr float kHighContrastTextBorderWidthFactor = 0.2f; static inline void drawStroke(SkScalar left, SkScalar right, SkScalar top, SkScalar thickness, const Paint& paint, Canvas* canvas) { @@ -48,7 +50,16 @@ static void simplifyPaint(int color, Paint* paint) { paint->setShader(nullptr); paint->setColorFilter(nullptr); paint->setLooper(nullptr); - paint->setStrokeWidth(kHighContrastTextBorderWidth + 0.04 * paint->getSkFont().getSize()); + + if (flags::high_contrast_text_small_text_rect()) { + paint->setStrokeWidth( + std::max(kHighContrastTextBorderWidth, + kHighContrastTextBorderWidthFactor * paint->getSkFont().getSize())); + } else { + auto borderWidthFactor = 0.04f; + paint->setStrokeWidth(kHighContrastTextBorderWidth + + borderWidthFactor * paint->getSkFont().getSize()); + } paint->setStrokeJoin(SkPaint::kRound_Join); paint->setLooper(nullptr); } @@ -106,36 +117,7 @@ public: Paint outlinePaint(paint); simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, &outlinePaint); outlinePaint.setStyle(SkPaint::kStrokeAndFill_Style); - if (flags::high_contrast_text_small_text_rect()) { - const SkFont& font = paint.getSkFont(); - auto padding = kHighContrastTextBorderWidth + 0.1f * font.getSize(); - - // Draw the background only behind each glyph's bounds. We do this instead of using - // the bounds of the entire layout, because the layout includes alignment whitespace - // etc which can obscure other text from separate passes (e.g. emojis). - // Merge all the glyph bounds into one rect for this line, since drawing a rect for - // each glyph is expensive. - SkRect glyphBounds; - SkRect bgBounds; - for (size_t i = start; i < end; i++) { - auto glyph = layout.getGlyphId(i); - - font.getBounds(reinterpret_cast<const SkGlyphID*>(&glyph), 1, &glyphBounds, - &paint); - glyphBounds.offset(layout.getX(i), layout.getY(i)); - - bgBounds.join(glyphBounds); - } - - if (!bgBounds.isEmpty()) { - bgBounds.offset(x, y); - bgBounds.outset(padding, padding); - canvas->drawRect(bgBounds.fLeft, bgBounds.fTop, bgBounds.fRight, - bgBounds.fBottom, outlinePaint); - } - } else { - canvas->drawGlyphs(glyphFunc, glyphCount, outlinePaint, x, y, totalAdvance); - } + canvas->drawGlyphs(glyphFunc, glyphCount, outlinePaint, x, y, totalAdvance); // inner gDrawTextBlobMode = DrawTextBlobMode::HctInner; |