SkTypeface_remote.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2018 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. #ifndef SkRemoteTypeface_DEFINED
  8. #define SkRemoteTypeface_DEFINED
  9. #include "include/core/SkFontStyle.h"
  10. #include "include/core/SkPaint.h"
  11. #include "include/core/SkTypeface.h"
  12. #include "src/core/SkAdvancedTypefaceMetrics.h"
  13. #include "src/core/SkDescriptor.h"
  14. #include "src/core/SkFontDescriptor.h"
  15. #include "src/core/SkRemoteGlyphCache.h"
  16. #include "src/core/SkScalerContext.h"
  17. class SkTypefaceProxy;
  18. class SkStrikeCache;
  19. class SkScalerContextProxy : public SkScalerContext {
  20. public:
  21. SkScalerContextProxy(sk_sp<SkTypeface> tf,
  22. const SkScalerContextEffects& effects,
  23. const SkDescriptor* desc,
  24. sk_sp<SkStrikeClient::DiscardableHandleManager> manager);
  25. void initCache(SkStrike*, SkStrikeCache*);
  26. protected:
  27. unsigned generateGlyphCount() override;
  28. bool generateAdvance(SkGlyph* glyph) override;
  29. void generateMetrics(SkGlyph* glyph) override;
  30. void generateImage(const SkGlyph& glyph) override;
  31. bool generatePath(SkGlyphID glyphID, SkPath* path) override;
  32. void generateFontMetrics(SkFontMetrics* metrics) override;
  33. SkTypefaceProxy* getProxyTypeface() const;
  34. private:
  35. sk_sp<SkStrikeClient::DiscardableHandleManager> fDiscardableManager;
  36. SkStrike* fCache = nullptr;
  37. SkStrikeCache* fStrikeCache = nullptr;
  38. typedef SkScalerContext INHERITED;
  39. };
  40. class SkTypefaceProxy : public SkTypeface {
  41. public:
  42. SkTypefaceProxy(SkFontID fontId,
  43. int glyphCount,
  44. const SkFontStyle& style,
  45. bool isFixed,
  46. sk_sp<SkStrikeClient::DiscardableHandleManager> manager,
  47. bool isLogging = true)
  48. : INHERITED{style, false}
  49. , fFontId{fontId}
  50. , fGlyphCount{glyphCount}
  51. , fIsLogging{isLogging}
  52. , fDiscardableManager{std::move(manager)} {}
  53. SkFontID remoteTypefaceID() const {return fFontId;}
  54. int glyphCount() const {return fGlyphCount;}
  55. bool isLogging() const {return fIsLogging;}
  56. protected:
  57. int onGetUPEM() const override { SK_ABORT("Should never be called."); return 0; }
  58. std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override {
  59. SK_ABORT("Should never be called.");
  60. return nullptr;
  61. }
  62. std::unique_ptr<SkFontData> onMakeFontData() const override {
  63. SK_ABORT("Should never be called.");
  64. return nullptr;
  65. }
  66. sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
  67. SK_ABORT("Should never be called.");
  68. return nullptr;
  69. }
  70. int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
  71. int coordinateCount) const override {
  72. SK_ABORT("Should never be called.");
  73. return 0;
  74. }
  75. int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
  76. int parameterCount) const override {
  77. SK_ABORT("Should never be called.");
  78. return 0;
  79. }
  80. void onGetFamilyName(SkString* familyName) const override {
  81. // Used by SkStrikeCache::DumpMemoryStatistics.
  82. *familyName = "";
  83. }
  84. SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
  85. SK_ABORT("Should never be called.");
  86. return nullptr;
  87. }
  88. int onGetTableTags(SkFontTableTag tags[]) const override {
  89. SK_ABORT("Should never be called.");
  90. return 0;
  91. }
  92. size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override {
  93. SK_ABORT("Should never be called.");
  94. return 0;
  95. }
  96. SkScalerContext* onCreateScalerContext(const SkScalerContextEffects& effects,
  97. const SkDescriptor* desc) const override {
  98. return new SkScalerContextProxy(sk_ref_sp(const_cast<SkTypefaceProxy*>(this)), effects,
  99. desc, fDiscardableManager);
  100. }
  101. void onFilterRec(SkScalerContextRec* rec) const override {
  102. // The rec filtering is already applied by the server when generating
  103. // the glyphs.
  104. }
  105. void onGetFontDescriptor(SkFontDescriptor*, bool*) const override {
  106. SK_ABORT("Should never be called.");
  107. }
  108. void getGlyphToUnicodeMap(SkUnichar*) const override {
  109. SK_ABORT("Should never be called.");
  110. }
  111. void getPostScriptGlyphNames(SkString*) const override {
  112. SK_ABORT("Should never be called.");
  113. }
  114. std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
  115. SK_ABORT("Should never be called.");
  116. return nullptr;
  117. }
  118. void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override {
  119. SK_ABORT("Should never be called.");
  120. }
  121. int onCountGlyphs() const override {
  122. return this->glyphCount();
  123. }
  124. void* onGetCTFontRef() const override {
  125. SK_ABORT("Should never be called.");
  126. return nullptr;
  127. }
  128. private:
  129. const SkFontID fFontId;
  130. const int fGlyphCount;
  131. const bool fIsLogging;
  132. sk_sp<SkStrikeClient::DiscardableHandleManager> fDiscardableManager;
  133. typedef SkTypeface INHERITED;
  134. };
  135. #endif // SkRemoteTypeface_DEFINED