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 1 commit
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
Next Next commit
[Impeller][WIP] Use new SkParagraph APIs for stroked text
  • Loading branch information
jonahwilliams committed May 4, 2023
commit d90570816bd6f6f0a3f666ba8413ad2f320aa0fe
20 changes: 17 additions & 3 deletions impeller/display_list/dl_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,23 @@ void DlDispatcher::drawTextBlob(const sk_sp<SkTextBlob> blob,
SkScalar x,
SkScalar y) {
Scalar scale = canvas_.GetCurrentTransformation().GetMaxBasisLength();
canvas_.DrawTextFrame(TextFrameFromTextBlob(blob, scale), //
impeller::Point{x, y}, //
paint_ //
auto text_frame = TextFrameFromTextBlob(blob, scale);
if (paint_.style == Paint::Style::kStroke) {
auto path = PathDataFromTextBlob(blob);
auto bounds = text_frame.GetBounds();
if (!bounds.has_value()) {
return;
}
canvas_.Save();
canvas_.Translate({x + bounds->origin.x, y + bounds->origin.y, 0.0});
Copy link
Member

Choose a reason for hiding this comment

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

Is the frame bounds origin actually the right thing to be adding here? It would seem weird for Skia's API to circularly depend on the text frame bounds origin when coming up with path coords to output. Needing to add in something like the baseline offset would make sense, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest I don't really know. This is similar to the approach I used when drawing with different color sources on top of the text: https://github.com/flutter/engine/blob/main/impeller/aiks/canvas.cc#L529-L534

canvas_.DrawPath(path, paint_);
canvas_.Restore();
return;
}

canvas_.DrawTextFrame(text_frame, //
impeller::Point{x, y}, //
paint_ //
);
}

Expand Down
11 changes: 11 additions & 0 deletions impeller/typographer/backends/skia/text_frame_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#include <vector>

#include "flutter/fml/logging.h"
#include "impeller/display_list/skia_conversions.h"
#include "impeller/typographer/backends/skia/typeface_skia.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkRect.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkFontMetrics.h"
#include "third_party/skia/modules/skparagraph/include/Paragraph.h"
#include "third_party/skia/src/core/SkStrikeSpec.h" // nogncheck
#include "third_party/skia/src/core/SkTextBlobPriv.h" // nogncheck

Expand All @@ -38,6 +40,15 @@ static Rect ToRect(const SkRect& rect) {
return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
}

Path PathDataFromTextBlob(const sk_sp<SkTextBlob>& blob) {
if (!blob) {
return {};
}

return skia_conversions::ToPath(
skia::textlayout::Paragraph::getPaths(blob.get()));
}

TextFrame TextFrameFromTextBlob(const sk_sp<SkTextBlob>& blob, Scalar scale) {
if (!blob) {
return {};
Expand Down
3 changes: 3 additions & 0 deletions impeller/typographer/backends/skia/text_frame_skia.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#pragma once

#include "flutter/fml/macros.h"
#include "impeller/geometry/path.h"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Remove unused include

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

#include "impeller/typographer/text_frame.h"
#include "third_party/skia/include/core/SkTextBlob.h"

namespace impeller {

Path PathDataFromTextBlob(const sk_sp<SkTextBlob>& blob);

TextFrame TextFrameFromTextBlob(const sk_sp<SkTextBlob>& blob,
Scalar scale = 1.0f);

Expand Down