[skottie] Text line height support
Change-Id: Id5b52e7586aa42400162fd227add28d6ebf3ac11 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212728 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
e897c1bd16
commit
a50484a570
@ -256,6 +256,7 @@ DEF_TEST(Skottie_Shaper_HAlign, reporter) {
|
||||
const skottie::Shaper::TextDesc desc = {
|
||||
typeface,
|
||||
tsize.text_size,
|
||||
tsize.text_size,
|
||||
talign.align,
|
||||
skottie::Shaper::VAlign::kTopBaseline,
|
||||
};
|
||||
@ -316,6 +317,7 @@ DEF_TEST(Skottie_Shaper_VAlign, reporter) {
|
||||
const skottie::Shaper::TextDesc desc = {
|
||||
typeface,
|
||||
tsize.text_size,
|
||||
tsize.text_size,
|
||||
SkTextUtils::Align::kCenter_Align,
|
||||
talign.align,
|
||||
};
|
||||
|
@ -102,7 +102,11 @@ public:
|
||||
}
|
||||
|
||||
void commitLine() override {
|
||||
fOffset += { 0, fMaxRunDescent + fMaxRunLeading - fMaxRunAscent };
|
||||
// Observe explicit line height, if specified; otherwise use line metrics.
|
||||
const auto lh = fDesc.fLineHeight > 0
|
||||
? fDesc.fLineHeight
|
||||
: fMaxRunDescent + fMaxRunLeading - fMaxRunAscent;
|
||||
fOffset.fY += lh;
|
||||
}
|
||||
|
||||
Shaper::Result makeBlob() {
|
||||
|
@ -40,7 +40,8 @@ public:
|
||||
|
||||
struct TextDesc {
|
||||
const sk_sp<SkTypeface>& fTypeface;
|
||||
SkScalar fTextSize;
|
||||
SkScalar fTextSize,
|
||||
fLineHeight; // when 0, use natural/computed line height.
|
||||
SkTextUtils::Align fHAlign;
|
||||
VAlign fVAlign;
|
||||
};
|
||||
|
@ -45,6 +45,7 @@ void TextAdapter::apply() {
|
||||
const Shaper::TextDesc text_desc = {
|
||||
fText.fTypeface,
|
||||
fText.fTextSize,
|
||||
fText.fLineHeight,
|
||||
fText.fHAlign,
|
||||
fText.fVAlign,
|
||||
};
|
||||
|
@ -17,6 +17,7 @@ bool TextValue::operator==(const TextValue &other) const {
|
||||
&& fText == other.fText
|
||||
&& fTextSize == other.fTextSize
|
||||
&& fStrokeWidth == other.fStrokeWidth
|
||||
&& fLineHeight == other.fLineHeight
|
||||
&& fHAlign == other.fHAlign
|
||||
&& fVAlign == other.fVAlign
|
||||
&& fBox == other.fBox
|
||||
@ -48,6 +49,7 @@ bool ValueTraits<TextValue>::FromJSON(const skjson::Value& jv,
|
||||
}
|
||||
v->fText.set(text->begin(), text->size());
|
||||
v->fTextSize = **text_size;
|
||||
v->fLineHeight = ParseDefault<float>((*jtxt)["lh"], 0);
|
||||
|
||||
static constexpr SkTextUtils::Align gAlignMap[] = {
|
||||
SkTextUtils::kLeft_Align, // 'j': 0
|
||||
|
@ -19,7 +19,8 @@ struct TextValue {
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
SkString fText;
|
||||
float fTextSize = 0,
|
||||
fStrokeWidth = 0;
|
||||
fStrokeWidth = 0,
|
||||
fLineHeight = 0;
|
||||
SkTextUtils::Align fHAlign = SkTextUtils::kLeft_Align;
|
||||
Shaper::VAlign fVAlign = Shaper::VAlign::kTop;
|
||||
SkRect fBox = SkRect::MakeEmpty();
|
||||
|
6331
resources/skottie/skottie-line-height.json
Normal file
6331
resources/skottie/skottie-line-height.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user