Skip to content

Commit

Permalink
Remove obsolete SkPaint foreground/background attributes from TextSty…
Browse files Browse the repository at this point in the history
…le (flutter#40059)

Remove obsolete SkPaint foreground/background attributes from TextStyle
  • Loading branch information
jason-simmons authored Mar 3, 2023
1 parent b0edd18 commit f9da7b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
10 changes: 2 additions & 8 deletions lib/ui/text/paragraph_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,24 +454,18 @@ void ParagraphBuilder::pushStyle(const tonic::Int32List& encoded,
if (mask & kTSBackgroundMask) {
Paint background(background_objects, background_data);
if (background.isNotNull()) {
SkPaint sk_paint;
style.has_background = true;
style.background = *background.paint(sk_paint);
DlPaint dl_paint;
background.toDlPaint(dl_paint);
style.background_dl = dl_paint;
style.background = dl_paint;
}
}

if (mask & kTSForegroundMask) {
Paint foreground(foreground_objects, foreground_data);
if (foreground.isNotNull()) {
SkPaint sk_paint;
style.has_foreground = true;
style.foreground = *foreground.paint(sk_paint);
DlPaint dl_paint;
foreground.toDlPaint(dl_paint);
style.foreground_dl = dl_paint;
style.foreground = dl_paint;
}
}

Expand Down
8 changes: 4 additions & 4 deletions third_party/txt/src/skia/paragraph_builder_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ skt::TextStyle ParagraphBuilderSkia::TxtToSkia(const TextStyle& txt) {
skia.setHalfLeading(txt.half_leading);

skia.setLocale(SkString(txt.locale.c_str()));
if (txt.has_background) {
skia.setBackgroundPaintID(CreatePaintID(txt.background_dl));
if (txt.background.has_value()) {
skia.setBackgroundPaintID(CreatePaintID(txt.background.value()));
}
if (txt.has_foreground) {
skia.setForegroundPaintID(CreatePaintID(txt.foreground_dl));
if (txt.foreground.has_value()) {
skia.setForegroundPaintID(CreatePaintID(txt.foreground.value()));
} else {
flutter::DlPaint dl_paint;
dl_paint.setColor(txt.color);
Expand Down
18 changes: 4 additions & 14 deletions third_party/txt/src/skia/paragraph_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,22 +300,12 @@ TextStyle ParagraphSkia::SkiaToTxt(const skt::TextStyle& skia) {

txt.locale = skia.getLocale().c_str();
if (skia.hasBackground()) {
skt::ParagraphPainter::SkPaintOrID background =
skia.getBackgroundPaintOrID();
if (std::holds_alternative<SkPaint>(background)) {
txt.background = std::get<SkPaint>(background);
} else if (std::holds_alternative<PaintID>(background)) {
txt.background_dl = dl_paints_[std::get<PaintID>(background)];
}
PaintID background_id = std::get<PaintID>(skia.getBackgroundPaintOrID());
txt.background = dl_paints_[background_id];
}
if (skia.hasForeground()) {
skt::ParagraphPainter::SkPaintOrID foreground =
skia.getForegroundPaintOrID();
if (std::holds_alternative<SkPaint>(foreground)) {
txt.foreground = std::get<SkPaint>(foreground);
} else if (std::holds_alternative<PaintID>(foreground)) {
txt.foreground_dl = dl_paints_[std::get<PaintID>(foreground)];
}
PaintID foreground_id = std::get<PaintID>(skia.getForegroundPaintOrID());
txt.foreground = dl_paints_[foreground_id];
}

txt.text_shadows.clear();
Expand Down
9 changes: 3 additions & 6 deletions third_party/txt/src/txt/text_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef LIB_TXT_SRC_TEXT_STYLE_H_
#define LIB_TXT_SRC_TEXT_STYLE_H_

#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -55,12 +56,8 @@ class TextStyle {
double height = 1.0;
bool has_height_override = false;
std::string locale;
bool has_background = false;
SkPaint background;
flutter::DlPaint background_dl;
bool has_foreground = false;
SkPaint foreground;
flutter::DlPaint foreground_dl;
std::optional<flutter::DlPaint> background;
std::optional<flutter::DlPaint> foreground;
// An ordered list of shadows where the first shadow will be drawn first (at
// the bottom).
std::vector<TextShadow> text_shadows;
Expand Down

0 comments on commit f9da7b0

Please sign in to comment.