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> realScalerContext, 25 SkTypeface_proxy& proxyTypeface, 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> fRealScalerContext; 38 }; 39 40 class SkTypeface_proxy : public SkTypeface { 41 public: 42 SkTypeface_proxy(sk_sp<SkTypeface> realTypeface, 43 const SkFontStyle& style, bool isFixedPitch = false) SkTypeface(style,isFixedPitch)44 : SkTypeface(style, isFixedPitch) 45 , fRealTypeface(std::move(realTypeface)) { SkASSERT_RELEASE(fRealTypeface); } 46 47 protected: 48 int onGetUPEM() const override; 49 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override; 50 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override; 51 bool onGlyphMaskNeedsCurrentColor() const override; 52 int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], 53 int coordinateCount) const override; 54 int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], 55 int parameterCount) const override; 56 SkFontStyle onGetFontStyle() const override; 57 bool onGetFixedPitch() const override; 58 void onGetFamilyName(SkString* familyName) const override; 59 bool onGetPostScriptName(SkString* postScriptName) const override; 60 int onGetResourceName(SkString* resourceName) const override; 61 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; 62 int onGetTableTags(SkFontTableTag tags[]) const override; 63 size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override; 64 std::unique_ptr<SkScalerContext> onCreateScalerContext( 65 const SkScalerContextEffects& effects, const SkDescriptor* desc) const override; 66 void onFilterRec(SkScalerContextRec* rec) const override; 67 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override; 68 void getGlyphToUnicodeMap(SkUnichar* unichar) const override; 69 void getPostScriptGlyphNames(SkString* glyphNames) const override; 70 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; 71 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override; 72 int onCountGlyphs() const override; 73 void* onGetCTFontRef() const override; 74 bool onGetKerningPairAdjustments(const SkGlyphID glyphs[], 75 int count, 76 int32_t adjustments[]) const override; 77 private: 78 sk_sp<SkTypeface> fRealTypeface; 79 }; 80 81 #endif // SkTypeface_proxy_DEFINED 82