This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Build display lists from SkParagraph output using the ParagraphPainter interface #37087
Merged
auto-submit
merged 1 commit into
flutter:main
from
jason-simmons:skpara_display_list_roundtrip
Nov 11, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,68 @@ SkFontStyle MakeSkFontStyle(txt::FontWeight font_weight, | |
: SkFontStyle::Slant::kItalic_Slant); | ||
} | ||
|
||
skt::ParagraphStyle TxtToSkia(const ParagraphStyle& txt) { | ||
} // anonymous namespace | ||
|
||
ParagraphBuilderSkia::ParagraphBuilderSkia( | ||
const ParagraphStyle& style, | ||
std::shared_ptr<FontCollection> font_collection) | ||
: base_style_(style.GetTextStyle()) { | ||
builder_ = skt::ParagraphBuilder::make( | ||
TxtToSkia(style), font_collection->CreateSktFontCollection()); | ||
} | ||
|
||
ParagraphBuilderSkia::~ParagraphBuilderSkia() = default; | ||
|
||
void ParagraphBuilderSkia::PushStyle(const TextStyle& style) { | ||
builder_->pushStyle(TxtToSkia(style)); | ||
txt_style_stack_.push(style); | ||
} | ||
|
||
void ParagraphBuilderSkia::Pop() { | ||
builder_->pop(); | ||
txt_style_stack_.pop(); | ||
} | ||
|
||
const TextStyle& ParagraphBuilderSkia::PeekStyle() { | ||
return txt_style_stack_.empty() ? base_style_ : txt_style_stack_.top(); | ||
} | ||
|
||
void ParagraphBuilderSkia::AddText(const std::u16string& text) { | ||
builder_->addText(text); | ||
} | ||
|
||
void ParagraphBuilderSkia::AddPlaceholder(PlaceholderRun& span) { | ||
skt::PlaceholderStyle placeholder_style; | ||
placeholder_style.fHeight = span.height; | ||
placeholder_style.fWidth = span.width; | ||
placeholder_style.fBaseline = static_cast<skt::TextBaseline>(span.baseline); | ||
placeholder_style.fBaselineOffset = span.baseline_offset; | ||
placeholder_style.fAlignment = | ||
static_cast<skt::PlaceholderAlignment>(span.alignment); | ||
|
||
builder_->addPlaceholder(placeholder_style); | ||
} | ||
|
||
std::unique_ptr<Paragraph> ParagraphBuilderSkia::Build() { | ||
return std::make_unique<ParagraphSkia>(builder_->Build(), | ||
std::move(dl_paints_)); | ||
} | ||
|
||
skt::ParagraphPainter::PaintID ParagraphBuilderSkia::CreatePaintID( | ||
const flutter::DlPaint& dl_paint) { | ||
dl_paints_.push_back(dl_paint); | ||
return dl_paints_.size() - 1; | ||
} | ||
|
||
skt::ParagraphStyle ParagraphBuilderSkia::TxtToSkia(const ParagraphStyle& txt) { | ||
skt::ParagraphStyle skia; | ||
skt::TextStyle text_style; | ||
|
||
// Convert the default color of an SkParagraph text style into a DlPaint. | ||
flutter::DlPaint dl_paint; | ||
dl_paint.setColor(text_style.getColor()); | ||
flar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
text_style.setForegroundPaintID(CreatePaintID(dl_paint)); | ||
|
||
text_style.setFontStyle(MakeSkFontStyle(txt.font_weight, txt.font_style)); | ||
text_style.setFontSize(SkDoubleToScalar(txt.font_size)); | ||
text_style.setHeight(SkDoubleToScalar(txt.height)); | ||
|
@@ -84,7 +142,7 @@ skt::ParagraphStyle TxtToSkia(const ParagraphStyle& txt) { | |
return skia; | ||
} | ||
|
||
skt::TextStyle TxtToSkia(const TextStyle& txt) { | ||
skt::TextStyle ParagraphBuilderSkia::TxtToSkia(const TextStyle& txt) { | ||
skt::TextStyle skia; | ||
|
||
skia.setColor(txt.color); | ||
|
@@ -112,10 +170,14 @@ skt::TextStyle TxtToSkia(const TextStyle& txt) { | |
|
||
skia.setLocale(SkString(txt.locale.c_str())); | ||
if (txt.has_background) { | ||
skia.setBackgroundColor(txt.background); | ||
skia.setBackgroundPaintID(CreatePaintID(txt.background_dl)); | ||
} | ||
if (txt.has_foreground) { | ||
skia.setForegroundColor(txt.foreground); | ||
skia.setForegroundPaintID(CreatePaintID(txt.foreground_dl)); | ||
} else { | ||
flutter::DlPaint dl_paint; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This piece is new and I'm not sure why it's needed now...? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TextStyle API has Before this PR the style's |
||
dl_paint.setColor(txt.color); | ||
skia.setForegroundPaintID(CreatePaintID(dl_paint)); | ||
} | ||
|
||
skia.resetFontFeatures(); | ||
|
@@ -153,50 +215,4 @@ skt::TextStyle TxtToSkia(const TextStyle& txt) { | |
return skia; | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
ParagraphBuilderSkia::ParagraphBuilderSkia( | ||
const ParagraphStyle& style, | ||
std::shared_ptr<FontCollection> font_collection) | ||
: builder_(skt::ParagraphBuilder::make( | ||
TxtToSkia(style), | ||
font_collection->CreateSktFontCollection())), | ||
base_style_(style.GetTextStyle()) {} | ||
|
||
ParagraphBuilderSkia::~ParagraphBuilderSkia() = default; | ||
|
||
void ParagraphBuilderSkia::PushStyle(const TextStyle& style) { | ||
builder_->pushStyle(TxtToSkia(style)); | ||
txt_style_stack_.push(style); | ||
} | ||
|
||
void ParagraphBuilderSkia::Pop() { | ||
builder_->pop(); | ||
txt_style_stack_.pop(); | ||
} | ||
|
||
const TextStyle& ParagraphBuilderSkia::PeekStyle() { | ||
return txt_style_stack_.empty() ? base_style_ : txt_style_stack_.top(); | ||
} | ||
|
||
void ParagraphBuilderSkia::AddText(const std::u16string& text) { | ||
builder_->addText(text); | ||
} | ||
|
||
void ParagraphBuilderSkia::AddPlaceholder(PlaceholderRun& span) { | ||
skt::PlaceholderStyle placeholder_style; | ||
placeholder_style.fHeight = span.height; | ||
placeholder_style.fWidth = span.width; | ||
placeholder_style.fBaseline = static_cast<skt::TextBaseline>(span.baseline); | ||
placeholder_style.fBaselineOffset = span.baseline_offset; | ||
placeholder_style.fAlignment = | ||
static_cast<skt::PlaceholderAlignment>(span.alignment); | ||
|
||
builder_->addPlaceholder(placeholder_style); | ||
} | ||
|
||
std::unique_ptr<Paragraph> ParagraphBuilderSkia::Build() { | ||
return std::make_unique<ParagraphSkia>(builder_->Build()); | ||
} | ||
|
||
} // namespace txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.