33 explicit MockPropertyObserver(
bool override_props =
false) : fOverrideProps(override_props) {}
37 std::unique_ptr<skottie::ColorPropertyHandle> handle;
42 std::unique_ptr<skottie::OpacityPropertyHandle> handle;
47 std::unique_ptr<skottie::TextPropertyHandle> handle;
50 struct TransformInfo {
52 std::unique_ptr<skottie::TransformPropertyHandle> handle;
57 auto prop_handle = lh();
60 prop_handle->set(kOverrideColor);
62 fColors.push_back({
SkString(node_name), std::move(prop_handle)});
63 fColorsWithFullKeypath.push_back({
SkString(fCurrentNode.c_str()), lh()});
68 auto prop_handle = lh();
71 prop_handle->set(kOverrideOpacity);
73 fOpacities.push_back({
SkString(node_name), std::move(prop_handle)});
78 auto prop_handle = lh();
81 prop_handle->set(kOverrideText);
83 fTexts.push_back({
SkString(node_name), std::move(prop_handle)});
88 auto prop_handle = lh();
98 prop_handle->set(kOverrideTransform);
100 fTransforms.push_back({
SkString(node_name), std::move(prop_handle)});
104 if (node_name ==
nullptr) {
107 fCurrentNode = fCurrentNode.empty() ? node_name : fCurrentNode +
"." + node_name;
111 if (node_name ==
nullptr) {
114 auto length = strlen(node_name);
116 fCurrentNode.length() >
length
117 ? fCurrentNode.substr(0, fCurrentNode.length() - strlen(node_name) - 1)
121 const std::vector<ColorInfo>&
colors()
const {
return fColors; }
122 const std::vector<OpacityInfo>& opacities()
const {
return fOpacities; }
123 const std::vector<TextInfo>& texts()
const {
return fTexts; }
124 const std::vector<TransformInfo>& transforms()
const {
return fTransforms; }
125 const std::vector<ColorInfo>& colorsWithFullKeypath()
const {
126 return fColorsWithFullKeypath;
130 const bool fOverrideProps;
131 std::vector<ColorInfo> fColors;
132 std::vector<OpacityInfo> fOpacities;
133 std::vector<TextInfo> fTexts;
134 std::vector<TransformInfo> fTransforms;
135 std::string fCurrentNode;
136 std::vector<ColorInfo> fColorsWithFullKeypath;
155 const char* bcp47[],
int bcp47Count,
163 int ttcIndex)
const override {
180static const char gTestJson[] = R
"({
190 "fName": "test_font",
191 "fFamily": "test-family",
192 "fStyle": "TestFontStyle"
204 "o": { "a": 0, "k": 50 }
210 { "v": { "a": 0, "k": [ 0, 1, 0 ] }},
214 { "v": { "a": 0, "k": 1 }}
216 "nm": "fill_effect_0",
224 "p": { "a": 0, "k": [ 50, 50 ] },
225 "s": { "a": 0, "k": [ 50, 50 ] }
230 "c": { "a": 0, "k": [ 1, 0, 0] }
234 "nm": "shape_transform_0",
235 "o": { "a": 0, "k": 100 },
236 "s": { "a": 0, "k": [ 50, 50 ] }
246 "p": { "a": 0, "k": [25, 25] }
273 auto test_font_manager = sk_make_sp<MockFontMgr>(
test_typeface);
276 auto observer = sk_make_sp<MockPropertyObserver>();
279 .setPropertyObserver(observer)
280 .setFontManager(test_font_manager)
285 const auto&
colors = observer->colors();
292 const auto& colorsWithFullKeypath = observer->colorsWithFullKeypath();
299 const auto& opacities = observer->opacities();
306 const auto& transforms = observer->transforms();
312 SkVector::Make(100, 100),
320 SkPoint::Make(25, 25),
321 SkVector::Make(100, 100),
330 SkVector::Make(50, 50),
336 const auto& texts = observer->texts();
350 Shaper::VAlign::kTopBaseline,
352 Shaper::LinebreakPolicy::kExplicit,
353 Shaper::Direction::kLTR,
358 TextPaintOrder::kFillStroke,
359 SkPaint::Join::kDefault_Join,
367 text_prop.fLocale =
"custom_lc";
368 texts[0].handle->set(text_prop);
375 auto test_font_manager = sk_make_sp<MockFontMgr>(
test_typeface);
378 auto observer = sk_make_sp<MockPropertyObserver>(
true);
381 .setPropertyObserver(observer)
382 .setFontManager(test_font_manager)
392 for (
const auto& c : observer->colors()) {
395 for (
const auto& o : observer->opacities()) {
396 o.handle->set(0.25f);
398 for (
const auto& t : observer->texts()) {
399 t.handle->set(make_text_prop(
"bar"));
401 for (
const auto& t : observer->transforms()) {
static void test_typeface(skiatest::Reporter *reporter)
DEF_TEST(Skottie_Props, reporter)
constexpr SkColor SK_ColorTRANSPARENT
constexpr SkColor SK_ColorGRAY
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
#define REPORTER_ASSERT(r, cond,...)
virtual void onGetFamilyName(int index, SkString *familyName) const =0
virtual sk_sp< SkTypeface > onMakeFromData(sk_sp< SkData >, int ttcIndex) const =0
virtual sk_sp< SkFontStyleSet > onCreateStyleSet(int index) const =0
virtual sk_sp< SkTypeface > onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const =0
virtual sk_sp< SkFontStyleSet > onMatchFamily(const char familyName[]) const =0
virtual sk_sp< SkTypeface > onMakeFromStreamIndex(std::unique_ptr< SkStreamAsset >, int ttcIndex) const =0
virtual sk_sp< SkTypeface > onMakeFromStreamArgs(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const =0
virtual sk_sp< SkTypeface > onMatchFamilyStyle(const char familyName[], const SkFontStyle &) const =0
virtual sk_sp< SkTypeface > onLegacyMakeTypeface(const char familyName[], SkFontStyle) const =0
virtual sk_sp< SkTypeface > onMakeFromFile(const char path[], int ttcIndex) const =0
virtual int onCountFamilies() const =0
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
virtual void onTransformProperty(const char node_name[], const LazyHandle< TransformPropertyHandle > &)
virtual void onLeavingNode(const char node_name[], NodeType node_type)
virtual void onOpacityProperty(const char node_name[], const LazyHandle< OpacityPropertyHandle > &)
virtual void onTextProperty(const char node_name[], const LazyHandle< TextPropertyHandle > &)
virtual void onEnterNode(const char node_name[], NodeType node_type)
std::function< std::unique_ptr< T >()> LazyHandle
virtual void onColorProperty(const char node_name[], const LazyHandle< ColorPropertyHandle > &)
PODArray< SkColor > colors
DlVertices::Builder Builder
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
float OpacityPropertyValue
SkColor ColorPropertyValue
static SkScalar prop(SkScalar radius, SkScalar newSize, SkScalar oldSize)
static constexpr SkRect MakeEmpty()