Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a4f5264

Browse files
author
Jonah Williams
authored
[Impeller] Use new SkParagraph APIs for stroked text. (#41735)
~~Requires https://skia-review.googlesource.com/c/skia/+/692196~~ Landed Fixes flutter/flutter#126010 Looks correct on iOS, renders incorrectly on Android � . Might be related to all of our text bounds looking off. ### iOS ![flutter_03](https://github.com/flutter/engine/assets/8975114/50897fd0-47fd-4cad-b158-1662aa650092) ### Android ![flutter_04](https://github.com/flutter/engine/assets/8975114/bcefe843-71a0-4b98-956f-039918e9a4cc)
1 parent 16e2ab7 commit a4f5264

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

impeller/display_list/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impeller_component("skia_conversions") {
1515
"../geometry",
1616
"//flutter/fml",
1717
"//third_party/skia",
18+
"//third_party/skia/modules/skparagraph",
1819
]
1920
}
2021

impeller/display_list/dl_dispatcher.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,23 @@ void DlDispatcher::drawDisplayList(
11041104
void DlDispatcher::drawTextBlob(const sk_sp<SkTextBlob> blob,
11051105
SkScalar x,
11061106
SkScalar y) {
1107-
canvas_.DrawTextFrame(TextFrameFromTextBlob(blob), //
1108-
impeller::Point{x, y}, //
1109-
paint_ //
1107+
const auto text_frame = TextFrameFromTextBlob(blob);
1108+
if (paint_.style == Paint::Style::kStroke) {
1109+
auto path = skia_conversions::PathDataFromTextBlob(blob);
1110+
auto bounds = text_frame.GetBounds();
1111+
if (!bounds.has_value()) {
1112+
return;
1113+
}
1114+
canvas_.Save();
1115+
canvas_.Translate({x + bounds->origin.x, y + bounds->origin.y, 0.0});
1116+
canvas_.DrawPath(path, paint_);
1117+
canvas_.Restore();
1118+
return;
1119+
}
1120+
1121+
canvas_.DrawTextFrame(text_frame, //
1122+
impeller::Point{x, y}, //
1123+
paint_ //
11101124
);
11111125
}
11121126

impeller/display_list/dl_unittests.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,19 @@ TEST_P(DisplayListTest, CanDrawWithMaskBlur) {
447447
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
448448
}
449449

450+
TEST_P(DisplayListTest, CanDrawStrokedText) {
451+
flutter::DisplayListBuilder builder;
452+
flutter::DlPaint paint;
453+
454+
paint.setDrawStyle(flutter::DlDrawStyle::kStroke);
455+
paint.setColor(flutter::DlColor::kRed());
456+
builder.DrawTextBlob(
457+
SkTextBlob::MakeFromString("stoked about stroked text", CreateTestFont()),
458+
250, 250, paint);
459+
460+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
461+
}
462+
450463
TEST_P(DisplayListTest, IgnoreMaskFilterWhenSavingLayer) {
451464
auto texture = CreateTextureForFixture("embarcadero.jpg");
452465
flutter::DisplayListBuilder builder;

impeller/display_list/skia_conversions.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "impeller/display_list/skia_conversions.h"
6+
#include "third_party/skia/modules/skparagraph/include/Paragraph.h"
67

78
namespace impeller {
89
namespace skia_conversions {
@@ -159,6 +160,14 @@ std::vector<Matrix> ToRSXForms(const SkRSXform xform[], int count) {
159160
return result;
160161
}
161162

163+
Path PathDataFromTextBlob(const sk_sp<SkTextBlob>& blob) {
164+
if (!blob) {
165+
return {};
166+
}
167+
168+
return ToPath(skia::textlayout::Paragraph::GetPath(blob.get()));
169+
}
170+
162171
std::optional<impeller::PixelFormat> ToPixelFormat(SkColorType type) {
163172
switch (type) {
164173
case kRGBA_8888_SkColorType:

impeller/display_list/skia_conversions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "third_party/skia/include/core/SkPoint.h"
1717
#include "third_party/skia/include/core/SkRRect.h"
1818
#include "third_party/skia/include/core/SkRSXform.h"
19+
#include "third_party/skia/include/core/SkTextBlob.h"
1920

2021
namespace impeller {
2122
namespace skia_conversions {
@@ -40,6 +41,8 @@ Path ToPath(const SkPath& path);
4041

4142
Path ToPath(const SkRRect& rrect);
4243

44+
Path PathDataFromTextBlob(const sk_sp<SkTextBlob>& blob);
45+
4346
std::optional<impeller::PixelFormat> ToPixelFormat(SkColorType type);
4447

4548
} // namespace skia_conversions

0 commit comments

Comments
 (0)