xref: /aosp_15_r20/external/skia/src/ports/SkScalerContext_win_dw.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #include <dwrite_3.h>
20 
21 class SkGlyph;
22 class SkDescriptor;
23 
24 interface IDWritePaintReader;
25 struct DWRITE_PAINT_ELEMENT;
26 
27 class SkScalerContext_DW : public SkScalerContext {
28 public:
29     SkScalerContext_DW(sk_sp<DWriteFontTypeface>,
30                        const SkScalerContextEffects&,
31                        const SkDescriptor*);
32     ~SkScalerContext_DW() override;
33 
34 protected:
35     GlyphMetrics generateMetrics(const SkGlyph&, SkArenaAlloc*) override;
36     void generateImage(const SkGlyph&, void* imageBuffer) override;
37     bool generatePath(const SkGlyph&, SkPath*, bool*) override;
38     sk_sp<SkDrawable> generateDrawable(const SkGlyph&) override;
39     void generateFontMetrics(SkFontMetrics*) override;
40 
41 private:
42     bool setAdvance(const SkGlyph&, SkVector*);
43 
44     struct ScalerContextBits {
45         using value_type = uint16_t;
46         static const constexpr value_type NONE   = 0;
47         static const constexpr value_type DW     = 1;
48         static const constexpr value_type DW_1   = 2;
49         static const constexpr value_type PNG    = 3;
50         static const constexpr value_type SVG    = 4;
51         static const constexpr value_type COLR   = 5;
52         static const constexpr value_type COLRv1 = 6;
53         static const constexpr value_type PATH   = 7;
54     };
55 
56     static void BilevelToBW(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph, void* dst);
57 
58     template<bool APPLY_PREBLEND>
59     static void GrayscaleToA8(const uint8_t* SK_RESTRICT src,
60                               const SkGlyph& glyph, void* dst,
61                               const uint8_t* table8);
62 
63     template<bool APPLY_PREBLEND>
64     static void RGBToA8(const uint8_t* SK_RESTRICT src,
65                         const SkGlyph& glyph, void* dst,
66                         const uint8_t* table8);
67 
68     template<bool APPLY_PREBLEND, bool RGB>
69     static void RGBToLcd16(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph, void* dst,
70                            const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB);
71 
getDWriteTypeface()72     DWriteFontTypeface* getDWriteTypeface() {
73         return static_cast<DWriteFontTypeface*>(this->getTypeface());
74     }
75 
76     bool generateColorV1PaintBounds(SkMatrix*, SkRect*, IDWritePaintReader&, DWRITE_PAINT_ELEMENT const &);
77     bool generateColorV1Metrics(const SkGlyph&, SkRect*);
78     bool generateColorV1Image(const SkGlyph&, void* dst);
79     bool drawColorV1Paint(SkCanvas&, IDWritePaintReader&, DWRITE_PAINT_ELEMENT const &);
80     bool drawColorV1Image(const SkGlyph&, SkCanvas&);
81 
82     bool getColorGlyphRun(const SkGlyph&, IDWriteColorGlyphRunEnumerator**);
83     bool generateColorMetrics(const SkGlyph&, SkRect*);
84     bool generateColorImage(const SkGlyph&, void* dst);
85     bool drawColorImage(const SkGlyph&, SkCanvas&);
86 
87     bool generateSVGMetrics(const SkGlyph&, SkRect*);
88     bool generateSVGImage(const SkGlyph&, void* dst);
89     bool drawSVGImage(const SkGlyph&, SkCanvas&);
90 
91     bool generatePngMetrics(const SkGlyph&, SkRect*);
92     bool generatePngImage(const SkGlyph&, void* dst);
93     bool drawPngImage(const SkGlyph&, SkCanvas&);
94 
95     bool generateDWMetrics(const SkGlyph&, DWRITE_RENDERING_MODE, DWRITE_TEXTURE_TYPE, SkRect*);
96     const void* getDWMaskBits(const SkGlyph&, DWRITE_RENDERING_MODE, DWRITE_TEXTURE_TYPE);
97     bool generateDWImage(const SkGlyph&, void* dst);
98 
99     SkTDArray<uint8_t> fBits;
100     /** The total matrix without the text height scale. */
101     SkMatrix fSkXform;
102     /** The total matrix without the text height scale. */
103     DWRITE_MATRIX fXform;
104     /** The text size to render with. */
105     SkScalar fTextSizeRender;
106     /** The text size to measure with. */
107     SkScalar fTextSizeMeasure;
108     int fGlyphCount;
109     DWRITE_RENDERING_MODE fRenderingMode;
110     DWRITE_TEXTURE_TYPE fTextureType;
111     DWRITE_MEASURING_MODE fMeasuringMode;
112     DWRITE_TEXT_ANTIALIAS_MODE fAntiAliasMode;
113     DWRITE_GRID_FIT_MODE fGridFitMode;
114 };
115 
116 #endif
117