Use SkTextBlob::bounds instead of TextFrame::getBounds(). (flutter/engine#45148)

Closes https://github.com/flutter/flutter/issues/133157.
This commit is contained in:
Matan Lurey
2023-08-26 17:50:18 -07:00
committed by GitHub
parent 5672127793
commit fa81dcec02
2 changed files with 29 additions and 6 deletions

View File

@@ -1111,20 +1111,17 @@ void DlDispatcher::drawDisplayList(
void DlDispatcher::drawTextBlob(const sk_sp<SkTextBlob>& blob,
SkScalar x,
SkScalar y) {
const auto text_frame = MakeTextFrameFromTextBlobSkia(blob);
if (paint_.style == Paint::Style::kStroke) {
auto path = skia_conversions::PathDataFromTextBlob(blob);
auto bounds = text_frame.GetBounds();
if (!bounds.has_value()) {
return;
}
auto bounds = blob->bounds();
canvas_.Save();
canvas_.Translate({x + bounds->origin.x, y + bounds->origin.y, 0.0});
canvas_.Translate({x + bounds.left(), y + bounds.top(), 0.0});
canvas_.DrawPath(path, paint_);
canvas_.Restore();
return;
}
const auto text_frame = MakeTextFrameFromTextBlobSkia(blob);
canvas_.DrawTextFrame(text_frame, //
impeller::Point{x, y}, //
paint_ //

View File

@@ -460,6 +460,32 @@ TEST_P(DisplayListTest, CanDrawStrokedText) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
// Regression test for https://github.com/flutter/flutter/issues/133157.
TEST_P(DisplayListTest, StrokedTextNotOffsetFromNormalText) {
flutter::DisplayListBuilder builder;
flutter::DlPaint paint;
auto const& text_blob = SkTextBlob::MakeFromString("00000", CreateTestFont());
// https://api.flutter.dev/flutter/material/Colors/blue-constant.html.
auto const& mat_blue = flutter::DlColor(0xFF2196f3);
// Draw a blue filled rectangle so the text is easier to see.
paint.setDrawStyle(flutter::DlDrawStyle::kFill);
paint.setColor(mat_blue);
builder.DrawRect(SkRect::MakeXYWH(0, 0, 500, 500), paint);
// Draw stacked text, with stroked text on top.
paint.setDrawStyle(flutter::DlDrawStyle::kFill);
paint.setColor(flutter::DlColor::kWhite());
builder.DrawTextBlob(text_blob, 250, 250, paint);
paint.setDrawStyle(flutter::DlDrawStyle::kStroke);
paint.setColor(flutter::DlColor::kBlack());
builder.DrawTextBlob(text_blob, 250, 250, paint);
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(DisplayListTest, IgnoreMaskFilterWhenSavingLayer) {
auto texture = CreateTextureForFixture("embarcadero.jpg");
flutter::DisplayListBuilder builder;