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