/* * Copyright 2022 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SkottieFont_DEFINED #define SkottieFont_DEFINED #include "include/core/SkTypeface.h" #include "include/private/base/SkNoncopyable.h" #include "include/utils/SkCustomTypeface.h" #include "modules/sksg/include/SkSGRenderNode.h" #include "src/core/SkTHash.h" #include #include class SkPath; namespace skjson { class ObjectValue; } namespace skottie::internal { class AnimationBuilder; // Font backed by Lottie character data (glyph paths and glyph compositions). class CustomFont final : SkNoncopyable { public: ~CustomFont(); using GlyphCompMap = SkTHashMap>; class Builder final : SkNoncopyable { public: bool parseGlyph(const AnimationBuilder*, const skjson::ObjectValue&); std::unique_ptr detach(); private: static bool ParseGlyphPath(const AnimationBuilder*, const skjson::ObjectValue&, SkPath*); static sk_sp ParseGlyphComp(const AnimationBuilder*, const skjson::ObjectValue&); GlyphCompMap fGlyphComps; SkCustomTypefaceBuilder fCustomBuilder; }; // Helper for resolving (SkTypeface, SkGlyphID) tuples to a composition root. // Used post-shaping, to substitute composition glyphs in the rendering tree. class GlyphCompMapper final : public SkRefCnt { public: explicit GlyphCompMapper(std::vector>&& fonts) : fFonts(std::move(fonts)) {} ~GlyphCompMapper() override = default; sk_sp getGlyphComp(const SkTypeface*, SkGlyphID) const; private: const std::vector> fFonts; }; const sk_sp& typeface() const { return fTypeface; } int glyphCompCount() const { return fGlyphComps.count(); } private: CustomFont(GlyphCompMap&&, sk_sp tf); const GlyphCompMap fGlyphComps; const sk_sp fTypeface; }; } // namespace skottie::internal #endif // SkottieFont_DEFINED