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 SkStrikeSpec_DEFINED 9 #define SkStrikeSpec_DEFINED 10 11 #include "src/core/SkDescriptor.h" 12 #include "src/core/SkStrikeCache.h" 13 #include "src/core/SkStrikeInterface.h" 14 15 #if SK_SUPPORT_GPU 16 #include "src/gpu/text/GrStrikeCache.h" 17 #include "src/gpu/text/GrTextContext.h" 18 #endif 19 20 class SkFont; 21 class SkPaint; 22 class SkStrikeCache; 23 class SkSurfaceProps; 24 25 class SkStrikeSpec { 26 public: 27 // Create a strike spec for mask style cache entries. 28 static SkStrikeSpec MakeMask( 29 const SkFont& font, 30 const SkPaint& paint, 31 const SkSurfaceProps& surfaceProps, 32 SkScalerContextFlags scalerContextFlags, 33 const SkMatrix& deviceMatrix); 34 35 // Create a strike spec for path style cache entries. 36 static SkStrikeSpec MakePath( 37 const SkFont& font, 38 const SkPaint& paint, 39 const SkSurfaceProps& surfaceProps, 40 SkScalerContextFlags scalerContextFlags); 41 42 static SkStrikeSpec MakeSourceFallback(const SkFont& font, 43 const SkPaint& paint, 44 const SkSurfaceProps& surfaceProps, 45 SkScalerContextFlags scalerContextFlags, 46 SkScalar maxSourceGlyphDimension); 47 48 // Create a canonical strike spec for device-less measurements. 49 static SkStrikeSpec MakeCanonicalized( 50 const SkFont& font, const SkPaint* paint = nullptr); 51 52 // Create a strike spec without a device, and does not switch over to path for large sizes. 53 // This means that strikeToSourceRatio() is always 1. 54 static SkStrikeSpec MakeWithNoDevice(const SkFont& font, const SkPaint* paint = nullptr); 55 56 // Make a canonical strike spec for device-less measurements using default typeface and size. 57 static SkStrikeSpec MakeDefault(); 58 59 // Make a strike spec for PDF Vector strikes 60 static SkStrikeSpec MakePDFVector(const SkTypeface& typeface, int* size); 61 62 #if SK_SUPPORT_GPU 63 // Create a strike spec for scaled distance field text. 64 static std::tuple<SkStrikeSpec, SkScalar, SkScalar> MakeSDFT( 65 const SkFont& font, 66 const SkPaint& paint, 67 const SkSurfaceProps& surfaceProps, 68 const SkMatrix& deviceMatrix, 69 const GrTextContext::Options& options); 70 71 sk_sp<GrTextStrike> findOrCreateGrStrike(GrStrikeCache* cache) const; 72 #endif 73 74 SkScopedStrike findOrCreateScopedStrike(SkStrikeCacheInterface* cache) const; 75 76 SkExclusiveStrikePtr findOrCreateExclusiveStrike( 77 SkStrikeCache* cache = SkStrikeCache::GlobalStrikeCache()) const; 78 strikeToSourceRatio()79 SkScalar strikeToSourceRatio() const { return fStrikeToSourceRatio; } descriptor()80 const SkDescriptor& descriptor() const { return *fAutoDescriptor.getDesc(); } 81 static bool ShouldDrawAsPath(const SkPaint& paint, const SkFont& font, const SkMatrix& matrix); 82 83 private: 84 void commonSetup( 85 const SkFont& font, 86 const SkPaint& paint, 87 const SkSurfaceProps& surfaceProps, 88 SkScalerContextFlags scalerContextFlags, 89 const SkMatrix& deviceMatrix); 90 91 SkAutoDescriptor fAutoDescriptor; 92 sk_sp<SkMaskFilter> fMaskFilter; 93 sk_sp<SkPathEffect> fPathEffect; 94 sk_sp<SkTypeface> fTypeface; 95 SkScalar fStrikeToSourceRatio{1.0f}; 96 }; 97 98 class SkBulkGlyphMetrics { 99 public: 100 explicit SkBulkGlyphMetrics(const SkStrikeSpec& spec); 101 SkSpan<const SkGlyph*> glyphs(SkSpan<const SkGlyphID> glyphIDs); 102 103 private: 104 static constexpr int kTypicalGlyphCount = 20; 105 SkAutoSTArray<kTypicalGlyphCount, const SkGlyph*> fGlyphs; 106 SkExclusiveStrikePtr fStrike; 107 }; 108 109 class SkBulkGlyphMetricsAndPaths { 110 public: 111 explicit SkBulkGlyphMetricsAndPaths(const SkStrikeSpec& spec); 112 SkSpan<const SkGlyph*> glyphs(SkSpan<const SkGlyphID> glyphIDs); 113 114 private: 115 static constexpr int kTypicalGlyphCount = 20; 116 SkAutoSTArray<kTypicalGlyphCount, const SkGlyph*> fGlyphs; 117 SkExclusiveStrikePtr fStrike; 118 }; 119 120 class SkBulkGlyphMetricsAndImages { 121 public: 122 explicit SkBulkGlyphMetricsAndImages(const SkStrikeSpec& spec); 123 SkSpan<const SkGlyph*> glyphs(SkSpan<const SkPackedGlyphID> glyphIDs); 124 125 private: 126 static constexpr int kTypicalGlyphCount = 20; 127 SkAutoSTArray<kTypicalGlyphCount, const SkGlyph*> fGlyphs; 128 SkExclusiveStrikePtr fStrike; 129 }; 130 131 #endif // SkStrikeSpec_DEFINED 132