-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathDirect2DRenderer.h
131 lines (116 loc) · 3.99 KB
/
Direct2DRenderer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/************************************************************************
*
* File: CustomTextRenderer.h
*
* Description:
*
*
* This file is part of the Microsoft Windows SDK Code Samples.
*
* Copyright (C) Microsoft Corporation. All rights reserved.
*
* This source code is intended only as a supplement to Microsoft
* Development Tools and/or on-line documentation. See these other
* materials for detailed information regarding Microsoft code samples.
*
* THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
************************************************************************/
#pragma once
template <class T> void SafeRelease(T **ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}
/******************************************************************
* *
* CustomTextRenderer *
* *
* The IDWriteTextRenderer interface is an input parameter to *
* IDWriteTextLayout::Draw. This interfaces defines a number of *
* callback functions that the client application implements for *
* custom text rendering. This sample renderer implementation *
* renders text using text outlines and Direct2D. *
* A more sophisticated client would also support bitmap *
* renderings. *
* *
******************************************************************/
class CustomTextRenderer : public IDWriteTextRenderer
{
public:
CustomTextRenderer(
ID2D1Factory* pD2DFactory,
ID2D1RenderTarget* pRT,
ID2D1SolidColorBrush* pOutlineBrush
);
~CustomTextRenderer();
IFACEMETHOD(IsPixelSnappingDisabled)(
__maybenull void* clientDrawingContext,
__out BOOL* isDisabled
);
IFACEMETHOD(GetCurrentTransform)(
__maybenull void* clientDrawingContext,
__out DWRITE_MATRIX* transform
);
IFACEMETHOD(GetPixelsPerDip)(
__maybenull void* clientDrawingContext,
__out FLOAT* pixelsPerDip
);
IFACEMETHOD(DrawGlyphRun)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
DWRITE_MEASURING_MODE measuringMode,
__in DWRITE_GLYPH_RUN const* glyphRun,
__in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
IUnknown* clientDrawingEffect
);
IFACEMETHOD(DrawUnderline)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
__in DWRITE_UNDERLINE const* underline,
IUnknown* clientDrawingEffect
);
IFACEMETHOD(DrawStrikethrough)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
__in DWRITE_STRIKETHROUGH const* strikethrough,
IUnknown* clientDrawingEffect
);
IFACEMETHOD(DrawInlineObject)(
__maybenull void* clientDrawingContext,
FLOAT originX,
FLOAT originY,
IDWriteInlineObject* inlineObject,
BOOL isSideways,
BOOL isRightToLeft,
IUnknown* clientDrawingEffect
);
public:
IFACEMETHOD_(unsigned long, AddRef) ();
IFACEMETHOD_(unsigned long, Release) ();
IFACEMETHOD(QueryInterface) (
IID const& riid,
void** ppvObject
);
public:
void SetColorBrush(ID2D1SolidColorBrush* pBrush) {
SafeRelease(&pFillBrush_);
pFillBrush_ = pBrush;
pFillBrush_->AddRef();
}
private:
unsigned long cRefCount_;
ID2D1Factory* pD2DFactory_;
ID2D1RenderTarget* pRT_;
ID2D1SolidColorBrush* pOutlineBrush_;
ID2D1SolidColorBrush* pFillBrush_;
};