• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/core/SkScalerContext.h"
14 #include "src/ports/SkTypeface_win_dw.h"
15 
16 #include <dwrite.h>
17 #include <dwrite_2.h>
18 
19 class SkGlyph;
20 class SkDescriptor;
21 
22 class SkScalerContext_DW : public SkScalerContext {
23 public:
24     SkScalerContext_DW(sk_sp<DWriteFontTypeface>,
25                        const SkScalerContextEffects&,
26                        const SkDescriptor*);
27     ~SkScalerContext_DW() override;
28 
29 protected:
30     bool generateAdvance(SkGlyph* glyph) override;
31     void generateMetrics(SkGlyph* glyph) override;
32     void generateImage(const SkGlyph& glyph) override;
33     bool generatePath(SkGlyphID glyph, SkPath* path) override;
34     void generateFontMetrics(SkFontMetrics*) override;
35 
36 private:
37     static void BilevelToBW(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph);
38 
39     template<bool APPLY_PREBLEND>
40     static void GrayscaleToA8(const uint8_t* SK_RESTRICT src,
41                               const SkGlyph& glyph,
42                               const uint8_t* table8);
43 
44     template<bool APPLY_PREBLEND>
45     static void RGBToA8(const uint8_t* SK_RESTRICT src,
46                         const SkGlyph& glyph,
47                         const uint8_t* table8);
48 
49     template<bool APPLY_PREBLEND, bool RGB>
50     static void RGBToLcd16(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph,
51                            const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB);
52 
53     const void* drawDWMask(const SkGlyph& glyph,
54                            DWRITE_RENDERING_MODE renderingMode,
55                            DWRITE_TEXTURE_TYPE textureType);
56 
57     HRESULT getBoundingBox(SkGlyph* glyph,
58                            DWRITE_RENDERING_MODE renderingMode,
59                            DWRITE_TEXTURE_TYPE textureType,
60                            RECT* bbox);
61 
62     bool isColorGlyph(const SkGlyph& glyph);
63 
64     bool isPngGlyph(const SkGlyph& glyph);
65 
getDWriteTypeface()66     DWriteFontTypeface* getDWriteTypeface() {
67         return static_cast<DWriteFontTypeface*>(this->getTypeface());
68     }
69 
70     bool getColorGlyphRun(const SkGlyph& glyph, IDWriteColorGlyphRunEnumerator** colorGlyph);
71 
72     void generateColorMetrics(SkGlyph* glyph);
73 
74     void generateColorGlyphImage(const SkGlyph& glyph);
75 
76     void generatePngMetrics(SkGlyph* glyph);
77 
78     void generatePngGlyphImage(const SkGlyph& glyph);
79 
80 
81     SkTDArray<uint8_t> fBits;
82     /** The total matrix without the text height scale. */
83     SkMatrix fSkXform;
84     /** The total matrix without the text height scale. */
85     DWRITE_MATRIX fXform;
86     /** The text size to render with. */
87     SkScalar fTextSizeRender;
88     /** The text size to measure with. */
89     SkScalar fTextSizeMeasure;
90     int fGlyphCount;
91     DWRITE_RENDERING_MODE fRenderingMode;
92     DWRITE_TEXTURE_TYPE fTextureType;
93     DWRITE_MEASURING_MODE fMeasuringMode;
94     DWRITE_TEXT_ANTIALIAS_MODE fAntiAliasMode;
95     DWRITE_GRID_FIT_MODE fGridFitMode;
96     bool fIsColorFont;
97 };
98 
99 #endif
100