1 /* 2 * Copyright 2019 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkottieTextAdapter_DEFINED 9 #define SkottieTextAdapter_DEFINED 10 11 #include "modules/skottie/src/SkottieAdapter.h" 12 #include "modules/skottie/src/text/SkottieShaper.h" 13 #include "modules/skottie/src/text/TextAnimator.h" 14 #include "modules/skottie/src/text/TextValue.h" 15 16 #include <vector> 17 18 class SkFontMgr; 19 20 namespace skottie { 21 namespace internal { 22 23 class TextAdapter final : public SkNVRefCnt<TextAdapter> { 24 public: 25 TextAdapter(sk_sp<sksg::Group> root, sk_sp<SkFontMgr>, sk_sp<Logger>, bool hasAnimators); 26 ~TextAdapter(); 27 ADAPTER_PROPERTY(Text,TextValue,TextValue ())28 ADAPTER_PROPERTY(Text, TextValue, TextValue()) 29 30 const sk_sp<sksg::Group>& root() const { return fRoot; } 31 32 void applyAnimators(const std::vector<sk_sp<TextAnimator>>&); 33 34 private: 35 struct FragmentRec { 36 SkPoint fOrigin; // fragment position 37 38 sk_sp<sksg::Matrix<SkMatrix>> fMatrixNode; 39 sk_sp<sksg::Color> fFillColorNode, 40 fStrokeColorNode; 41 }; 42 43 void addFragment(const Shaper::Fragment&); 44 void buildDomainMaps(const Shaper::Result&); 45 46 void apply(); 47 48 void pushPropsToFragment(const TextAnimator::AnimatedProps&, const FragmentRec&) const; 49 50 void adjustLineTracking(const TextAnimator::ModulatorBuffer&, 51 const TextAnimator::DomainSpan&, 52 float line_tracking) const; 53 54 const sk_sp<sksg::Group> fRoot; 55 const sk_sp<SkFontMgr> fFontMgr; 56 sk_sp<Logger> fLogger; 57 const bool fHasAnimators; 58 59 std::vector<FragmentRec> fFragments; 60 TextAnimator::DomainMaps fMaps; 61 }; 62 63 } // namespace internal 64 } // namespace skottie 65 66 #endif // SkottieTextAdapter_DEFINED 67