diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index cdf59f42a58ad..3e67fd9916ac8 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -626,6 +626,18 @@ TEST_P(AiksTest, CanRenderTextFrame) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, CanRenderTextFrameWithInvertedTransform) { + Canvas canvas; + canvas.DrawPaint({.color = Color(0.1, 0.1, 0.1, 1.0)}); + + canvas.Translate({1000, 0, 0}); + canvas.Scale({-1, 1, 1}); + ASSERT_TRUE(RenderTextInCanvasSkia( + GetContext(), canvas, "the quick brown fox jumped over the lazy dog!.?", + "Roboto-Regular.ttf")); + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + TEST_P(AiksTest, CanRenderStrokedTextFrame) { Canvas canvas; canvas.DrawPaint({.color = Color(0.1, 0.1, 0.1, 1.0)}); diff --git a/impeller/entity/contents/text_contents.cc b/impeller/entity/contents/text_contents.cc index b4cbdbabf10c7..9090118dc7295 100644 --- a/impeller/entity/contents/text_contents.cc +++ b/impeller/entity/contents/text_contents.cc @@ -231,6 +231,7 @@ bool TextContents::Render(const ContentContext& renderer, const Rect& atlas_glyph_bounds = maybe_atlas_glyph_bounds.value().first; Rect glyph_bounds = maybe_atlas_glyph_bounds.value().second; + Rect scaled_bounds = glyph_bounds.Scale(1.0 / rounded_scale); // For each glyph, we compute two rectangles. One for the vertex // positions and one for the texture coordinates (UVs). The atlas // glyph bounds are used to compute UVs in cases where the @@ -243,19 +244,19 @@ bool TextContents::Render(const ContentContext& renderer, (atlas_glyph_bounds.GetSize() + Point(1, 1)) / atlas_size; Point unrounded_glyph_position = - (basis_transform * glyph_position.position) + - glyph_bounds.GetLeftTop(); + basis_transform * + (glyph_position.position + scaled_bounds.GetLeftTop()); + Point screen_glyph_position = (screen_offset + unrounded_glyph_position + subpixel_adjustment) .Floor(); - Size scaled_size = glyph_bounds.GetSize(); for (const Point& point : unit_points) { Point position; if (is_translation_scale) { - position = screen_glyph_position + (point * scaled_size); + position = screen_glyph_position + + (basis_transform * point * scaled_bounds.GetSize()); } else { - Rect scaled_bounds = glyph_bounds.Scale(1.0 / rounded_scale); position = entity_transform * (glyph_position.position + scaled_bounds.GetLeftTop() + point * scaled_bounds.GetSize()); diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index 90d667e024b02..9124d03713460 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -445,6 +445,9 @@ impeller_Play_AiksTest_CanRenderTextFrameWithFractionScaling_Vulkan.png impeller_Play_AiksTest_CanRenderTextFrameWithHalfScaling_Metal.png impeller_Play_AiksTest_CanRenderTextFrameWithHalfScaling_OpenGLES.png impeller_Play_AiksTest_CanRenderTextFrameWithHalfScaling_Vulkan.png +impeller_Play_AiksTest_CanRenderTextFrameWithInvertedTransform_Metal.png +impeller_Play_AiksTest_CanRenderTextFrameWithInvertedTransform_OpenGLES.png +impeller_Play_AiksTest_CanRenderTextFrameWithInvertedTransform_Vulkan.png impeller_Play_AiksTest_CanRenderTextFrame_Metal.png impeller_Play_AiksTest_CanRenderTextFrame_OpenGLES.png impeller_Play_AiksTest_CanRenderTextFrame_Vulkan.png