1 /* 2 * Copyright 2024 Google LLC 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 SkTypeface_proxy_DEFINED 9 #define SkTypeface_proxy_DEFINED 10 #include "include/core/SkStream.h" 11 #include "include/core/SkString.h" 12 #include "src/core/SkScalerContext.h" 13 14 #include <string.h> 15 #include <array> 16 #include <cstddef> 17 #include <cstdint> 18 #include <memory> 19 #include <utility> 20 21 class SkTypeface_proxy; 22 class SkScalerContext_proxy : public SkScalerContext { 23 public: 24 SkScalerContext_proxy(std::unique_ptr<SkScalerContext> proxy, 25 sk_sp<SkTypeface_proxy> typeface, 26 const SkScalerContextEffects& effects, 27 const SkDescriptor* desc); 28 29 ~SkScalerContext_proxy() override = default; 30 protected: 31 SkScalerContext::GlyphMetrics generateMetrics(const SkGlyph&, SkArenaAlloc* alloc) override; 32 void generateImage(const SkGlyph& glyph, void* imageBuffer) override; 33 bool generatePath(const SkGlyph& glyph, SkPath* path, bool* modified) override ; 34 sk_sp<SkDrawable> generateDrawable(const SkGlyph& glyph) override; 35 void generateFontMetrics(SkFontMetrics* metrics) override ; 36 private: 37 std::unique_ptr<SkScalerContext> fProxy; 38 }; 39 40 class SkTypeface_proxy : public SkTypeface { 41 public: 42 SkTypeface_proxy(const SkFontStyle& style, bool isFixedPitch = false) SkTypeface(style,isFixedPitch)43 : SkTypeface(style, isFixedPitch) 44 , fProxy(nullptr) { } 45 setProxy(sk_sp<SkTypeface> proxy)46 void setProxy(sk_sp<SkTypeface> proxy) { fProxy = std::move(proxy); } 47 48 protected: 49 int onGetUPEM() const override; 50 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override; 51 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override; 52 bool onGlyphMaskNeedsCurrentColor() const override; 53 int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], 54 int coordinateCount) const override; 55 int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], 56 int parameterCount) const override; 57 SkFontStyle onGetFontStyle() const override; 58 bool onGetFixedPitch() const override; 59 void onGetFamilyName(SkString* familyName) const override; 60 bool onGetPostScriptName(SkString* postScriptName) const override; 61 int onGetResourceName(SkString* resourceName) const override; 62 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; 63 int onGetTableTags(SkFontTableTag tags[]) const override; 64 size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override; 65 std::unique_ptr<SkScalerContext> onCreateScalerContext( 66 const SkScalerContextEffects& effects, const SkDescriptor* desc) const override; 67 void onFilterRec(SkScalerContextRec* rec) const override; 68 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override; 69 void getGlyphToUnicodeMap(SkUnichar* unichar) const override; 70 void getPostScriptGlyphNames(SkString* glyphNames) const override; 71 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; 72 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override; 73 int onCountGlyphs() const override; 74 void* onGetCTFontRef() const override; 75 bool onGetKerningPairAdjustments(const uint16_t glyphs[], 76 int count, 77 int32_t adjustments[]) const override; 78 private: 79 sk_sp<SkTypeface> fProxy; 80 }; 81 82 #endif // SkTypeface_proxy_DEFINED 83