SkStrikeSpec.h 4.5 KB

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