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
19class SkGlyph;
20class SkDescriptor;
21
22class SkScalerContext_DW : public SkScalerContext {
23public:
24    SkScalerContext_DW(sk_sp<DWriteFontTypeface>,
25                       const SkScalerContextEffects&,
26                       const SkDescriptor*);
27    ~SkScalerContext_DW() override;
28
29protected:
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
38private:
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
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 text size to render with. */
64    SkScalar fTextSizeRender;
65    /** The text size to measure with. */
66    SkScalar fTextSizeMeasure;
67    int fGlyphCount;
68    DWRITE_RENDERING_MODE fRenderingMode;
69    DWRITE_TEXTURE_TYPE fTextureType;
70    DWRITE_MEASURING_MODE fMeasuringMode;
71    DWRITE_TEXT_ANTIALIAS_MODE fAntiAliasMode;
72    DWRITE_GRID_FIT_MODE fGridFitMode;
73    bool fIsColorFont;
74};
75
76#endif
77