From d8d3d6ac4b43dd1e83fa79bf13ff2c562b929277 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 8 Oct 2024 15:07:19 -0700 Subject: [PATCH] [Impeller] Do not scale the miter limit applied to stroked text (flutter/engine#55745) Fixes https://github.com/flutter/flutter/issues/156224 --- .../display_list/aiks_dl_text_unittests.cc | 19 ++++++++++++++++++- engine/src/flutter/impeller/fixtures/BUILD.gn | 1 + .../backends/skia/typographer_context_skia.cc | 4 ++-- .../testing/impeller_golden_tests_output.txt | 3 +++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/impeller/display_list/aiks_dl_text_unittests.cc b/engine/src/flutter/impeller/display_list/aiks_dl_text_unittests.cc index 03c79971b2b..921ccf64532 100644 --- a/engine/src/flutter/impeller/display_list/aiks_dl_text_unittests.cc +++ b/engine/src/flutter/impeller/display_list/aiks_dl_text_unittests.cc @@ -32,6 +32,7 @@ namespace testing { struct TextRenderOptions { bool stroke = false; Scalar font_size = 50; + Scalar stroke_width = 1; DlColor color = DlColor::kYellow(); SkPoint position = SkPoint::Make(100, 200); std::shared_ptr filter; @@ -72,7 +73,7 @@ bool RenderTextInCanvasSkia(const std::shared_ptr& context, DlPaint text_paint; text_paint.setColor(options.color); text_paint.setMaskFilter(options.filter); - text_paint.setStrokeWidth(1); + text_paint.setStrokeWidth(options.stroke_width); text_paint.setDrawStyle(options.stroke ? DlDrawStyle::kStroke : DlDrawStyle::kFill); canvas.DrawTextFrame(frame, options.position.x(), options.position.y(), @@ -159,6 +160,22 @@ TEST_P(AiksTest, CanRenderStrokedTextFrame) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } +TEST_P(AiksTest, CanRenderTextStrokeWidth) { + DisplayListBuilder builder; + + DlPaint paint; + paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1)); + builder.DrawPaint(paint); + + ASSERT_TRUE(RenderTextInCanvasSkia(GetContext(), builder, "LMNOP VWXYZ", + "Roboto-Medium.ttf", + { + .stroke = true, + .stroke_width = 4, + })); + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + TEST_P(AiksTest, CanRenderTextFrameWithHalfScaling) { DisplayListBuilder builder; diff --git a/engine/src/flutter/impeller/fixtures/BUILD.gn b/engine/src/flutter/impeller/fixtures/BUILD.gn index a51b5a72214..dfeaae94b17 100644 --- a/engine/src/flutter/impeller/fixtures/BUILD.gn +++ b/engine/src/flutter/impeller/fixtures/BUILD.gn @@ -103,6 +103,7 @@ test_fixtures("file_fixtures") { fixtures = [ "//flutter/third_party/txt/third_party/fonts/HomemadeApple.ttf", "//flutter/third_party/txt/third_party/fonts/NotoColorEmoji.ttf", + "//flutter/third_party/txt/third_party/fonts/Roboto-Medium.ttf", "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf", "airplane.jpg", "bay_bridge.jpg", diff --git a/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc b/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc index a86e2ee6b8b..9a448ce0cf3 100644 --- a/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc +++ b/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc @@ -232,7 +232,7 @@ static void DrawGlyph(SkCanvas* canvas, glyph_paint.setStrokeWidth(prop->stroke_width * scaled_font.scale); glyph_paint.setStrokeCap(ToSkiaCap(prop->stroke_cap)); glyph_paint.setStrokeJoin(ToSkiaJoin(prop->stroke_join)); - glyph_paint.setStrokeMiter(prop->stroke_miter * scaled_font.scale); + glyph_paint.setStrokeMiter(prop->stroke_miter); } canvas->save(); canvas->translate(glyph.subpixel_offset.x, glyph.subpixel_offset.y); @@ -388,7 +388,7 @@ static Rect ComputeGlyphSize(const SkFont& font, glyph_paint.setStrokeWidth(glyph.properties->stroke_width * scale); glyph_paint.setStrokeCap(ToSkiaCap(glyph.properties->stroke_cap)); glyph_paint.setStrokeJoin(ToSkiaJoin(glyph.properties->stroke_join)); - glyph_paint.setStrokeMiter(glyph.properties->stroke_miter * scale); + glyph_paint.setStrokeMiter(glyph.properties->stroke_miter); } font.getBounds(&glyph.glyph.index, 1, &scaled_bounds, &glyph_paint); diff --git a/engine/src/flutter/testing/impeller_golden_tests_output.txt b/engine/src/flutter/testing/impeller_golden_tests_output.txt index 7d56e0f10a3..b1d74255a47 100644 --- a/engine/src/flutter/testing/impeller_golden_tests_output.txt +++ b/engine/src/flutter/testing/impeller_golden_tests_output.txt @@ -466,6 +466,9 @@ impeller_Play_AiksTest_CanRenderTextInSaveLayer_Vulkan.png impeller_Play_AiksTest_CanRenderTextOutsideBoundaries_Metal.png impeller_Play_AiksTest_CanRenderTextOutsideBoundaries_OpenGLES.png impeller_Play_AiksTest_CanRenderTextOutsideBoundaries_Vulkan.png +impeller_Play_AiksTest_CanRenderTextStrokeWidth_Metal.png +impeller_Play_AiksTest_CanRenderTextStrokeWidth_OpenGLES.png +impeller_Play_AiksTest_CanRenderTextStrokeWidth_Vulkan.png impeller_Play_AiksTest_CanRenderTextWithLargePerspectiveTransform_Metal.png impeller_Play_AiksTest_CanRenderTextWithLargePerspectiveTransform_OpenGLES.png impeller_Play_AiksTest_CanRenderTextWithLargePerspectiveTransform_Vulkan.png