[skottie] Fill-over-stroke support for text

AE allows selecting the paint order when both fill & stroke are present.

The CL also fixes some text stroke issues: stroke width not parsed
correctly and not actually used on the paint.

Change-Id: Iec27bb65d09f689365e43b801d3844106780572b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301857
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2020-07-10 09:58:48 -04:00 committed by Skia Commit-Bot
parent c1f3f8cda4
commit 082323b57d
5 changed files with 35 additions and 11 deletions

View File

@ -31,6 +31,11 @@ namespace skottie {
using ColorPropertyValue = SkColor;
using OpacityPropertyValue = float;
enum class TextPaintOrder : uint8_t {
kFillStroke,
kStrokeFill,
};
struct TextPropertyValue {
sk_sp<SkTypeface> fTypeface;
SkString fText;
@ -44,6 +49,7 @@ struct TextPropertyValue {
SkRect fBox = SkRect::MakeEmpty();
SkColor fFillColor = SK_ColorTRANSPARENT,
fStrokeColor = SK_ColorTRANSPARENT;
TextPaintOrder fPaintOrder = TextPaintOrder::kFillStroke;
bool fHasFill = false,
fHasStroke = false;

View File

@ -324,6 +324,7 @@ DEF_TEST(Skottie_Properties, reporter) {
SkRect::MakeEmpty(),
SK_ColorTRANSPARENT,
SK_ColorTRANSPARENT,
TextPaintOrder::kFillStroke,
false,
false
}));

View File

@ -138,16 +138,29 @@ void TextAdapter::addFragment(const Shaper::Fragment& frag) {
SkASSERT(fText->fHasFill || fText->fHasStroke);
if (fText->fHasFill) {
rec.fFillColorNode = sksg::Color::Make(fText->fFillColor);
rec.fFillColorNode->setAntiAlias(true);
draws.push_back(sksg::Draw::Make(blob_node, rec.fFillColorNode));
}
if (fText->fHasStroke) {
rec.fStrokeColorNode = sksg::Color::Make(fText->fStrokeColor);
rec.fStrokeColorNode->setAntiAlias(true);
rec.fStrokeColorNode->setStyle(SkPaint::kStroke_Style);
draws.push_back(sksg::Draw::Make(blob_node, rec.fStrokeColorNode));
auto add_fill = [&]() {
if (fText->fHasFill) {
rec.fFillColorNode = sksg::Color::Make(fText->fFillColor);
rec.fFillColorNode->setAntiAlias(true);
draws.push_back(sksg::Draw::Make(blob_node, rec.fFillColorNode));
}
};
auto add_stroke = [&] {
if (fText->fHasStroke) {
rec.fStrokeColorNode = sksg::Color::Make(fText->fStrokeColor);
rec.fStrokeColorNode->setAntiAlias(true);
rec.fStrokeColorNode->setStyle(SkPaint::kStroke_Style);
rec.fStrokeColorNode->setStrokeWidth(fText->fStrokeWidth);
draws.push_back(sksg::Draw::Make(blob_node, rec.fStrokeColorNode));
}
};
if (fText->fPaintOrder == TextPaintOrder::kFillStroke) {
add_fill();
add_stroke();
} else {
add_stroke();
add_fill();
}
SkASSERT(!draws.empty());

View File

@ -133,7 +133,10 @@ bool Parse(const skjson::Value& jv, const internal::AnimationBuilder& abuilder,
v->fHasStroke = parse_color((*jtxt)["sc"], &v->fStrokeColor);
if (v->fHasStroke) {
v->fStrokeWidth = ParseDefault((*jtxt)["s"], 0.0f);
v->fStrokeWidth = ParseDefault((*jtxt)["sw"], 1.0f);
v->fPaintOrder = ParseDefault((*jtxt)["of"], true)
? TextPaintOrder::kFillStroke
: TextPaintOrder::kStrokeFill;
}
return true;

File diff suppressed because one or more lines are too long