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 "SkScalar.h"
12 #include "SkScalerContext.h"
13 #include "SkTypeface_win_dw.h"
14 #include "SkTypes.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     virtual ~SkScalerContext_DW();
28 
29 protected:
30     unsigned generateGlyphCount() override;
31     uint16_t generateCharToGlyph(SkUnichar uni) override;
32     void generateAdvance(SkGlyph* glyph) override;
33     void generateMetrics(SkGlyph* glyph) override;
34     void generateImage(const SkGlyph& glyph) override;
35     void generatePath(SkGlyphID glyph, SkPath* path) override;
36     void generateFontMetrics(SkPaint::FontMetrics*) override;
37 
38 private:
39     const void* drawDWMask(const SkGlyph& glyph,
40                            DWRITE_RENDERING_MODE renderingMode,
41                            DWRITE_TEXTURE_TYPE textureType);
42 
43     HRESULT getBoundingBox(SkGlyph* glyph,
44                            DWRITE_RENDERING_MODE renderingMode,
45                            DWRITE_TEXTURE_TYPE textureType,
46                            RECT* bbox);
47 
48     bool isColorGlyph(const SkGlyph& glyph);
49 
getDWriteTypeface()50     DWriteFontTypeface* getDWriteTypeface() {
51         return static_cast<DWriteFontTypeface*>(this->getTypeface());
52     }
53 
54     bool getColorGlyphRun(const SkGlyph& glyph, IDWriteColorGlyphRunEnumerator** colorGlyph);
55 
56     void generateColorGlyphImage(const SkGlyph& glyph);
57 
58     SkTDArray<uint8_t> fBits;
59     /** The total matrix without the text height scale. */
60     SkMatrix fSkXform;
61     /** The total matrix without the text height scale. */
62     DWRITE_MATRIX fXform;
63     /** The non-rotational part of total matrix without the text height scale.
64      *  This is used to find the magnitude of gdi compatible advances.
65      */
66     DWRITE_MATRIX fGsA;
67     /** The inverse of the rotational part of the total matrix.
68      *  This is used to find the direction of gdi compatible advances.
69      */
70     SkMatrix fG_inv;
71     /** The text size to render with. */
72     SkScalar fTextSizeRender;
73     /** The text size to measure with. */
74     SkScalar fTextSizeMeasure;
75     int fGlyphCount;
76     DWRITE_RENDERING_MODE fRenderingMode;
77     DWRITE_TEXTURE_TYPE fTextureType;
78     DWRITE_MEASURING_MODE fMeasuringMode;
79     DWRITE_TEXT_ANTIALIAS_MODE fAntiAliasMode;
80     DWRITE_GRID_FIT_MODE fGridFitMode;
81     bool fIsColorFont;
82 };
83 
84 #endif
85