1 /* 2 * Copyright 2014 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 SkScalarContext_win_dw_DEFINED 9 #define SkScalarContext_win_dw_DEFINED 10 11 #include "include/core/SkScalar.h" 12 #include "include/core/SkTypes.h" 13 #include "include/private/base/SkTDArray.h" 14 #include "src/core/SkScalerContext.h" 15 #include "src/ports/SkTypeface_win_dw.h" 16 17 #include <dwrite.h> 18 #include <dwrite_2.h> 19 20 class SkGlyph; 21 class SkDescriptor; 22 23 class SkScalerContext_DW : public SkScalerContext { 24 public: 25 SkScalerContext_DW(sk_sp<DWriteFontTypeface>, 26 const SkScalerContextEffects&, 27 const SkDescriptor*); 28 ~SkScalerContext_DW() override; 29 30 protected: 31 bool generateAdvance(SkGlyph* glyph) override; 32 void generateMetrics(SkGlyph* glyph, SkArenaAlloc*) override; 33 void generateImage(const SkGlyph& glyph) override; 34 bool generatePath(const SkGlyph&, SkPath*) override; 35 sk_sp<SkDrawable> generateDrawable(const SkGlyph&) override; 36 void generateFontMetrics(SkFontMetrics*) override; 37 38 private: 39 struct ScalerContextBits { 40 using value_type = decltype(SkGlyph::fScalerContextBits); 41 static const constexpr value_type ForceBW = 1 << 0; 42 43 static const constexpr value_type DW = 0 << 1; 44 static const constexpr value_type PNG = 1 << 1; 45 static const constexpr value_type SVG = 2 << 1; 46 static const constexpr value_type COLR = 3 << 1; 47 static const constexpr value_type PATH = 4 << 1; 48 static const constexpr value_type FormatMask = 0x7 << 1; 49 }; 50 51 static void BilevelToBW(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph); 52 53 template<bool APPLY_PREBLEND> 54 static void GrayscaleToA8(const uint8_t* SK_RESTRICT src, 55 const SkGlyph& glyph, 56 const uint8_t* table8); 57 58 template<bool APPLY_PREBLEND> 59 static void RGBToA8(const uint8_t* SK_RESTRICT src, 60 const SkGlyph& glyph, 61 const uint8_t* table8); 62 63 template<bool APPLY_PREBLEND, bool RGB> 64 static void RGBToLcd16(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph, 65 const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB); 66 67 const void* drawDWMask(const SkGlyph& glyph, 68 DWRITE_RENDERING_MODE renderingMode, 69 DWRITE_TEXTURE_TYPE textureType); 70 71 HRESULT getBoundingBox(SkGlyph* glyph, 72 DWRITE_RENDERING_MODE renderingMode, 73 DWRITE_TEXTURE_TYPE textureType, 74 RECT* bbox); 75 getDWriteTypeface()76 DWriteFontTypeface* getDWriteTypeface() { 77 return static_cast<DWriteFontTypeface*>(this->getTypeface()); 78 } 79 80 bool isColorGlyph(const SkGlyph&); 81 bool getColorGlyphRun(const SkGlyph&, IDWriteColorGlyphRunEnumerator**); 82 bool generateColorMetrics(SkGlyph*); 83 bool generateColorGlyphImage(const SkGlyph&); 84 bool drawColorGlyphImage(const SkGlyph&, SkCanvas&); 85 86 bool isSVGGlyph(const SkGlyph&); 87 bool generateSVGMetrics(SkGlyph*); 88 bool generateSVGGlyphImage(const SkGlyph&); 89 bool drawSVGGlyphImage(const SkGlyph&, SkCanvas&); 90 91 bool isPngGlyph(const SkGlyph&); 92 bool generatePngMetrics(SkGlyph*); 93 bool generatePngGlyphImage(const SkGlyph&); 94 bool drawPngGlyphImage(const SkGlyph&, SkCanvas&); 95 96 static void SetGlyphBounds(SkGlyph* glyph, const SkRect& bounds); 97 98 SkTDArray<uint8_t> fBits; 99 /** The total matrix without the text height scale. */ 100 SkMatrix fSkXform; 101 /** The total matrix without the text height scale. */ 102 DWRITE_MATRIX fXform; 103 /** The text size to render with. */ 104 SkScalar fTextSizeRender; 105 /** The text size to measure with. */ 106 SkScalar fTextSizeMeasure; 107 int fGlyphCount; 108 DWRITE_RENDERING_MODE fRenderingMode; 109 DWRITE_TEXTURE_TYPE fTextureType; 110 DWRITE_MEASURING_MODE fMeasuringMode; 111 DWRITE_TEXT_ANTIALIAS_MODE fAntiAliasMode; 112 DWRITE_GRID_FIT_MODE fGridFitMode; 113 }; 114 115 #endif 116