• 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, SkArenaAlloc*) override;
32     void generateImage(const SkGlyph& glyph) override;
33     bool generatePath(const SkGlyph&, SkPath*) override;
34     sk_sp<SkDrawable> generateDrawable(const SkGlyph&) 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 
getDWriteTypeface()63     DWriteFontTypeface* getDWriteTypeface() {
64         return static_cast<DWriteFontTypeface*>(this->getTypeface());
65     }
66 
67     bool isColorGlyph(const SkGlyph&);
68     bool getColorGlyphRun(const SkGlyph&, IDWriteColorGlyphRunEnumerator**);
69     bool generateColorMetrics(SkGlyph*);
70     void generateColorGlyphImage(const SkGlyph&);
71     void drawColorGlyphImage(const SkGlyph&, SkCanvas&);
72 
73     bool isPngGlyph(const SkGlyph&);
74     bool generatePngMetrics(SkGlyph*);
75     void generatePngGlyphImage(const SkGlyph&);
76     void drawPngGlyphImage(const SkGlyph&, SkCanvas&);
77 
78 
79     SkTDArray<uint8_t> fBits;
80     /** The total matrix without the text height scale. */
81     SkMatrix fSkXform;
82     /** The total matrix without the text height scale. */
83     DWRITE_MATRIX fXform;
84     /** The text size to render with. */
85     SkScalar fTextSizeRender;
86     /** The text size to measure with. */
87     SkScalar fTextSizeMeasure;
88     int fGlyphCount;
89     DWRITE_RENDERING_MODE fRenderingMode;
90     DWRITE_TEXTURE_TYPE fTextureType;
91     DWRITE_MEASURING_MODE fMeasuringMode;
92     DWRITE_TEXT_ANTIALIAS_MODE fAntiAliasMode;
93     DWRITE_GRID_FIT_MODE fGridFitMode;
94 };
95 
96 #endif
97