Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,24 @@ TEST_P(AiksTest, StrokedPathWithMoveToThenCloseDrawnCorrectly) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanRenderTextWithLargePerspectiveTransform) {
// Verifies that text scales are clamped to work around
// https://github.com/flutter/flutter/issues/136112 .

Canvas canvas;
Paint save_paint;
canvas.SaveLayer(save_paint);
canvas.Transform(Matrix(2000, 0, 0, 0, //
0, 2000, 0, 0, //
0, 0, -1, 9000, //
0, 0, -1, 7000 //
));

ASSERT_TRUE(RenderTextInCanvasSkia(GetContext(), canvas, "Hello world",
"Roboto-Regular.ttf"));
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

} // namespace testing
} // namespace impeller

Expand Down
1 change: 1 addition & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,7 @@ TEST_P(EntityTest, TextContentsCeilsGlyphScaleToDecimal) {
ASSERT_EQ(TextFrame::RoundScaledFontSize(0.5321111f, 12), 0.53f);
ASSERT_EQ(TextFrame::RoundScaledFontSize(2.1f, 12), 2.1f);
ASSERT_EQ(TextFrame::RoundScaledFontSize(0.0f, 12), 0.0f);
ASSERT_EQ(TextFrame::RoundScaledFontSize(100000000.0f, 12), 48.0f);
}

TEST_P(EntityTest, AdvancedBlendCoverageHintIsNotResetByEntityPass) {
Expand Down
7 changes: 6 additions & 1 deletion impeller/typographer/text_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ bool TextFrame::MaybeHasOverlapping() const {

// static
Scalar TextFrame::RoundScaledFontSize(Scalar scale, Scalar point_size) {
return std::round(scale * 100) / 100;
// An arbitrarily chosen maximum text scale to ensure that regardless of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

// CTM, a glyph will fit in the atlas. If we clamp significantly, this may
// reduce fidelity but is preferable to the alternative of failing to render.
constexpr Scalar kMaximumTextScale = 48;
Scalar result = std::round(scale * 100) / 100;
return std::clamp(result, 0.0f, kMaximumTextScale);
}

void TextFrame::CollectUniqueFontGlyphPairs(FontGlyphMap& glyph_map,
Expand Down
3 changes: 3 additions & 0 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,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_CanRenderTextWithLargePerspectiveTransform_Metal.png
impeller_Play_AiksTest_CanRenderTextWithLargePerspectiveTransform_OpenGLES.png
impeller_Play_AiksTest_CanRenderTextWithLargePerspectiveTransform_Vulkan.png
impeller_Play_AiksTest_CanRenderThickCurvedStrokes_Metal.png
impeller_Play_AiksTest_CanRenderThickCurvedStrokes_OpenGLES.png
impeller_Play_AiksTest_CanRenderThickCurvedStrokes_Vulkan.png
Expand Down