Mercurial > vim
annotate src/gui_dwrite.cpp @ 12952:7fd105bfe992 v8.0.1352
patch 8.0.1352: dead URLs in the help go unnoticed
commit https://github.com/vim/vim/commit/f38c86eb6b665d9fcd3d232820a48198eccac376
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 28 14:19:07 2017 +0100
patch 8.0.1352: dead URLs in the help go unnoticed
Problem: Dead URLs in the help go unnoticed.
Solution: Add a script to check URLs in the help files. (Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 28 Nov 2017 14:30:05 +0100 |
parents | 2ebc3df65ca2 |
children | 18e6f4addce9 |
rev | line source |
---|---|
6110 | 1 /* vi:set ts=8 sts=4 sw=4 noet: */ |
2 /* | |
3 * Author: MURAOKA Taro <koron.kaoriya@gmail.com> | |
4 * | |
5 * Contributors: | |
6 * - Ken Takata | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
7 * - Yasuhiro Matsumoto |
6110 | 8 * |
9 * Copyright (C) 2013 MURAOKA Taro <koron.kaoriya@gmail.com> | |
10 * THIS FILE IS DISTRIBUTED UNDER THE VIM LICENSE. | |
11 */ | |
12 | |
13 #define WIN32_LEAN_AND_MEAN | |
14 | |
15 #ifndef DYNAMIC_DIRECTX | |
16 # if WINVER < 0x0600 | |
17 # error WINVER must be 0x0600 or above to use DirectWrite(DirectX) | |
18 # endif | |
19 #endif | |
20 | |
21 #include <windows.h> | |
22 #include <crtdbg.h> | |
23 #include <assert.h> | |
24 #include <math.h> | |
25 #include <d2d1.h> | |
26 #include <d2d1helper.h> | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
27 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
28 // Disable these macros to compile with old VC and newer SDK (V8.1 or later). |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
29 #if defined(_MSC_VER) && (_MSC_VER < 1700) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
30 # define _COM_Outptr_ __out |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
31 # define _In_reads_(s) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
32 # define _In_reads_opt_(s) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
33 # define _Maybenull_ |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
34 # define _Out_writes_(s) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
35 # define _Out_writes_opt_(s) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
36 # define _Out_writes_to_(x, y) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
37 # define _Out_writes_to_opt_(x, y) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
38 # define _Outptr_ |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
39 #endif |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
40 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
41 #include <dwrite_2.h> |
6110 | 42 |
43 #include "gui_dwrite.h" | |
44 | |
45 #ifdef __MINGW32__ | |
46 # define __maybenull SAL__maybenull | |
47 # define __in SAL__in | |
48 # define __out SAL__out | |
49 #endif | |
50 | |
8641
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
51 #if (defined(_MSC_VER) && (_MSC_VER >= 1700)) || (__cplusplus >= 201103L) |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
52 # define FINAL final |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
53 #else |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
54 # define FINAL |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
55 #endif |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
56 |
6110 | 57 #ifdef DYNAMIC_DIRECTX |
58 extern "C" HINSTANCE vimLoadLib(char *name); | |
59 | |
60 typedef int (WINAPI *PGETUSERDEFAULTLOCALENAME)(LPWSTR, int); | |
61 typedef HRESULT (WINAPI *PD2D1CREATEFACTORY)(D2D1_FACTORY_TYPE, | |
62 REFIID, const D2D1_FACTORY_OPTIONS *, void **); | |
63 typedef HRESULT (WINAPI *PDWRITECREATEFACTORY)(DWRITE_FACTORY_TYPE, | |
64 REFIID, IUnknown **); | |
65 | |
66 static HINSTANCE hD2D1DLL = NULL; | |
67 static HINSTANCE hDWriteDLL = NULL; | |
68 | |
69 static PGETUSERDEFAULTLOCALENAME pGetUserDefaultLocaleName = NULL; | |
70 static PD2D1CREATEFACTORY pD2D1CreateFactory = NULL; | |
71 static PDWRITECREATEFACTORY pDWriteCreateFactory = NULL; | |
72 | |
73 #define GetUserDefaultLocaleName (*pGetUserDefaultLocaleName) | |
74 #define D2D1CreateFactory (*pD2D1CreateFactory) | |
75 #define DWriteCreateFactory (*pDWriteCreateFactory) | |
76 | |
77 static void | |
78 unload(HINSTANCE &hinst) | |
79 { | |
80 if (hinst != NULL) | |
81 { | |
82 FreeLibrary(hinst); | |
83 hinst = NULL; | |
84 } | |
85 } | |
86 #endif // DYNAMIC_DIRECTX | |
87 | |
88 template <class T> inline void SafeRelease(T **ppT) | |
89 { | |
90 if (*ppT) | |
91 { | |
92 (*ppT)->Release(); | |
93 *ppT = NULL; | |
94 } | |
95 } | |
96 | |
97 static DWRITE_PIXEL_GEOMETRY | |
98 ToPixelGeometry(int value) | |
99 { | |
100 switch (value) | |
101 { | |
102 default: | |
103 case 0: | |
104 return DWRITE_PIXEL_GEOMETRY_FLAT; | |
105 case 1: | |
106 return DWRITE_PIXEL_GEOMETRY_RGB; | |
107 case 2: | |
108 return DWRITE_PIXEL_GEOMETRY_BGR; | |
109 } | |
110 } | |
111 | |
112 static int | |
113 ToInt(DWRITE_PIXEL_GEOMETRY value) | |
114 { | |
115 switch (value) | |
116 { | |
117 case DWRITE_PIXEL_GEOMETRY_FLAT: | |
118 return 0; | |
119 case DWRITE_PIXEL_GEOMETRY_RGB: | |
120 return 1; | |
121 case DWRITE_PIXEL_GEOMETRY_BGR: | |
122 return 2; | |
123 default: | |
124 return -1; | |
125 } | |
126 } | |
127 | |
128 static DWRITE_RENDERING_MODE | |
129 ToRenderingMode(int value) | |
130 { | |
131 switch (value) | |
132 { | |
133 default: | |
134 case 0: | |
135 return DWRITE_RENDERING_MODE_DEFAULT; | |
136 case 1: | |
137 return DWRITE_RENDERING_MODE_ALIASED; | |
138 case 2: | |
139 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC; | |
140 case 3: | |
141 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL; | |
142 case 4: | |
143 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL; | |
144 case 5: | |
145 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; | |
146 case 6: | |
147 return DWRITE_RENDERING_MODE_OUTLINE; | |
148 } | |
149 } | |
150 | |
151 static D2D1_TEXT_ANTIALIAS_MODE | |
152 ToTextAntialiasMode(int value) | |
153 { | |
154 switch (value) | |
155 { | |
156 default: | |
157 case 0: | |
158 return D2D1_TEXT_ANTIALIAS_MODE_DEFAULT; | |
159 case 1: | |
160 return D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE; | |
161 case 2: | |
162 return D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE; | |
163 case 3: | |
164 return D2D1_TEXT_ANTIALIAS_MODE_ALIASED; | |
165 } | |
166 } | |
167 | |
168 static int | |
169 ToInt(DWRITE_RENDERING_MODE value) | |
170 { | |
171 switch (value) | |
172 { | |
173 case DWRITE_RENDERING_MODE_DEFAULT: | |
174 return 0; | |
175 case DWRITE_RENDERING_MODE_ALIASED: | |
176 return 1; | |
177 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC: | |
178 return 2; | |
179 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL: | |
180 return 3; | |
181 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL: | |
182 return 4; | |
183 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC: | |
184 return 5; | |
185 case DWRITE_RENDERING_MODE_OUTLINE: | |
186 return 6; | |
187 default: | |
188 return -1; | |
189 } | |
190 } | |
191 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
192 class FontCache { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
193 public: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
194 struct Item { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
195 HFONT hFont; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
196 IDWriteTextFormat* pTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
197 DWRITE_FONT_WEIGHT fontWeight; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
198 DWRITE_FONT_STYLE fontStyle; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
199 Item() : hFont(NULL), pTextFormat(NULL) {} |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
200 }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
201 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
202 private: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
203 int mSize; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
204 Item *mItems; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
205 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
206 public: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
207 FontCache(int size = 2) : |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
208 mSize(size), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
209 mItems(new Item[size]) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
210 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
211 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
212 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
213 ~FontCache() |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
214 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
215 for (int i = 0; i < mSize; ++i) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
216 SafeRelease(&mItems[i].pTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
217 delete[] mItems; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
218 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
219 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
220 bool get(HFONT hFont, Item &item) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
221 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
222 int n = find(hFont); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
223 if (n < 0) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
224 return false; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
225 item = mItems[n]; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
226 slide(n); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
227 return true; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
228 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
229 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
230 void put(const Item& item) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
231 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
232 int n = find(item.hFont); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
233 if (n < 0) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
234 n = mSize - 1; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
235 if (mItems[n].pTextFormat != item.pTextFormat) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
236 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
237 SafeRelease(&mItems[n].pTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
238 item.pTextFormat->AddRef(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
239 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
240 mItems[n] = item; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
241 slide(n); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
242 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
243 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
244 private: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
245 int find(HFONT hFont) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
246 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
247 for (int i = 0; i < mSize; ++i) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
248 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
249 if (mItems[i].hFont == hFont) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
250 return i; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
251 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
252 return -1; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
253 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
254 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
255 void slide(int nextTop) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
256 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
257 if (nextTop == 0) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
258 return; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
259 Item tmp = mItems[nextTop]; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
260 for (int i = nextTop - 1; i >= 0; --i) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
261 mItems[i + 1] = mItems[i]; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
262 mItems[0] = tmp; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
263 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
264 }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
265 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
266 struct DWriteContext { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
267 HDC mHDC; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
268 bool mDrawing; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
269 bool mFallbackDC; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
270 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
271 ID2D1Factory *mD2D1Factory; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
272 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
273 ID2D1DCRenderTarget *mRT; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
274 ID2D1SolidColorBrush *mBrush; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
275 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
276 IDWriteFactory *mDWriteFactory; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
277 IDWriteFactory2 *mDWriteFactory2; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
278 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
279 IDWriteGdiInterop *mGdiInterop; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
280 IDWriteRenderingParams *mRenderingParams; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
281 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
282 FontCache mFontCache; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
283 IDWriteTextFormat *mTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
284 DWRITE_FONT_WEIGHT mFontWeight; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
285 DWRITE_FONT_STYLE mFontStyle; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
286 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
287 D2D1_TEXT_ANTIALIAS_MODE mTextAntialiasMode; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
288 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
289 // METHODS |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
290 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
291 DWriteContext(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
292 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
293 virtual ~DWriteContext(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
294 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
295 HRESULT CreateTextFormatFromLOGFONT(const LOGFONTW &logFont, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
296 IDWriteTextFormat **ppTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
297 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
298 HRESULT SetFontByLOGFONT(const LOGFONTW &logFont); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
299 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
300 void SetFont(HFONT hFont); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
301 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
302 void BindDC(HDC hdc, RECT *rect); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
303 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
304 void AssureDrawing(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
305 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
306 ID2D1Brush* SolidBrush(COLORREF color); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
307 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
308 void DrawText(const WCHAR* text, int len, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
309 int x, int y, int w, int h, int cellWidth, COLORREF color, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
310 UINT fuOptions, CONST RECT *lprc, CONST INT * lpDx); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
311 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
312 void FillRect(RECT *rc, COLORREF color); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
313 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
314 void Flush(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
315 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
316 void SetRenderingParams( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
317 const DWriteRenderingParams *params); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
318 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
319 DWriteRenderingParams *GetRenderingParams( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
320 DWriteRenderingParams *params); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
321 }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
322 |
6110 | 323 class AdjustedGlyphRun : public DWRITE_GLYPH_RUN |
324 { | |
325 private: | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
326 FLOAT &mAccum; |
6110 | 327 FLOAT mDelta; |
328 FLOAT *mAdjustedAdvances; | |
329 | |
330 public: | |
331 AdjustedGlyphRun( | |
332 const DWRITE_GLYPH_RUN *glyphRun, | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
333 FLOAT cellWidth, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
334 FLOAT &accum) : |
6110 | 335 DWRITE_GLYPH_RUN(*glyphRun), |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
336 mAccum(accum), |
6110 | 337 mDelta(0.0f), |
338 mAdjustedAdvances(new FLOAT[glyphRun->glyphCount]) | |
339 { | |
340 assert(cellWidth != 0.0f); | |
341 for (UINT32 i = 0; i < glyphRun->glyphCount; ++i) | |
342 { | |
343 FLOAT orig = glyphRun->glyphAdvances[i]; | |
344 FLOAT adjusted = adjustToCell(orig, cellWidth); | |
345 mAdjustedAdvances[i] = adjusted; | |
346 mDelta += adjusted - orig; | |
347 } | |
348 glyphAdvances = mAdjustedAdvances; | |
349 } | |
350 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
351 ~AdjustedGlyphRun() |
6110 | 352 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
353 mAccum += mDelta; |
6110 | 354 delete[] mAdjustedAdvances; |
355 } | |
356 | |
357 static FLOAT adjustToCell(FLOAT value, FLOAT cellWidth) | |
358 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
359 int cellCount = int(floor(value / cellWidth + 0.5f)); |
6110 | 360 if (cellCount < 1) |
361 cellCount = 1; | |
362 return cellCount * cellWidth; | |
363 } | |
364 }; | |
365 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
366 struct TextRendererContext { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
367 // const fields. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
368 COLORREF color; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
369 FLOAT cellWidth; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
370 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
371 // working fields. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
372 FLOAT offsetX; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
373 }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
374 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
375 class TextRenderer FINAL : public IDWriteTextRenderer |
6110 | 376 { |
377 public: | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
378 TextRenderer( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
379 DWriteContext* pDWC) : |
6110 | 380 cRefCount_(0), |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
381 pDWC_(pDWC) |
6110 | 382 { |
383 AddRef(); | |
384 } | |
385 | |
8271
770774e66011
commit https://github.com/vim/vim/commit/edb4f2b3601b0abd47091606269c0ac3244a805b
Christian Brabandt <cb@256bit.org>
parents:
7547
diff
changeset
|
386 // add "virtual" to avoid a compiler warning |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
387 virtual ~TextRenderer() |
6110 | 388 { |
389 } | |
390 | |
391 IFACEMETHOD(IsPixelSnappingDisabled)( | |
392 __maybenull void* clientDrawingContext, | |
393 __out BOOL* isDisabled) | |
394 { | |
395 *isDisabled = FALSE; | |
396 return S_OK; | |
397 } | |
398 | |
399 IFACEMETHOD(GetCurrentTransform)( | |
400 __maybenull void* clientDrawingContext, | |
401 __out DWRITE_MATRIX* transform) | |
402 { | |
8271
770774e66011
commit https://github.com/vim/vim/commit/edb4f2b3601b0abd47091606269c0ac3244a805b
Christian Brabandt <cb@256bit.org>
parents:
7547
diff
changeset
|
403 // forward the render target's transform |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
404 pDWC_->mRT->GetTransform( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
405 reinterpret_cast<D2D1_MATRIX_3X2_F*>(transform)); |
6110 | 406 return S_OK; |
407 } | |
408 | |
409 IFACEMETHOD(GetPixelsPerDip)( | |
410 __maybenull void* clientDrawingContext, | |
411 __out FLOAT* pixelsPerDip) | |
412 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
413 float dpiX, unused; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
414 pDWC_->mRT->GetDpi(&dpiX, &unused); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
415 *pixelsPerDip = dpiX / 96.0f; |
6110 | 416 return S_OK; |
417 } | |
418 | |
419 IFACEMETHOD(DrawUnderline)( | |
420 __maybenull void* clientDrawingContext, | |
421 FLOAT baselineOriginX, | |
422 FLOAT baselineOriginY, | |
423 __in DWRITE_UNDERLINE const* underline, | |
424 IUnknown* clientDrawingEffect) | |
425 { | |
426 return E_NOTIMPL; | |
427 } | |
428 | |
429 IFACEMETHOD(DrawStrikethrough)( | |
430 __maybenull void* clientDrawingContext, | |
431 FLOAT baselineOriginX, | |
432 FLOAT baselineOriginY, | |
433 __in DWRITE_STRIKETHROUGH const* strikethrough, | |
434 IUnknown* clientDrawingEffect) | |
435 { | |
436 return E_NOTIMPL; | |
437 } | |
438 | |
439 IFACEMETHOD(DrawInlineObject)( | |
440 __maybenull void* clientDrawingContext, | |
441 FLOAT originX, | |
442 FLOAT originY, | |
443 IDWriteInlineObject* inlineObject, | |
444 BOOL isSideways, | |
445 BOOL isRightToLeft, | |
446 IUnknown* clientDrawingEffect) | |
447 { | |
448 return E_NOTIMPL; | |
449 } | |
450 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
451 IFACEMETHOD(DrawGlyphRun)( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
452 __maybenull void* clientDrawingContext, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
453 FLOAT baselineOriginX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
454 FLOAT baselineOriginY, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
455 DWRITE_MEASURING_MODE measuringMode, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
456 __in DWRITE_GLYPH_RUN const* glyphRun, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
457 __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
458 IUnknown* clientDrawingEffect) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
459 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
460 TextRendererContext *context = |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
461 reinterpret_cast<TextRendererContext*>(clientDrawingContext); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
462 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
463 AdjustedGlyphRun adjustedGlyphRun(glyphRun, context->cellWidth, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
464 context->offsetX); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
465 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
466 if (pDWC_->mDWriteFactory2 != NULL) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
467 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
468 IDWriteColorGlyphRunEnumerator *enumerator = NULL; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
469 HRESULT hr = pDWC_->mDWriteFactory2->TranslateColorGlyphRun( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
470 baselineOriginX + context->offsetX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
471 baselineOriginY, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
472 &adjustedGlyphRun, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
473 NULL, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
474 DWRITE_MEASURING_MODE_GDI_NATURAL, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
475 NULL, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
476 0, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
477 &enumerator); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
478 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
479 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
480 // Draw by IDWriteFactory2 for color emoji |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
481 BOOL hasRun = TRUE; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
482 enumerator->MoveNext(&hasRun); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
483 while (hasRun) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
484 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
485 const DWRITE_COLOR_GLYPH_RUN* colorGlyphRun; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
486 enumerator->GetCurrentRun(&colorGlyphRun); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
487 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
488 pDWC_->mBrush->SetColor(colorGlyphRun->runColor); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
489 pDWC_->mRT->DrawGlyphRun( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
490 D2D1::Point2F( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
491 colorGlyphRun->baselineOriginX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
492 colorGlyphRun->baselineOriginY), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
493 &colorGlyphRun->glyphRun, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
494 pDWC_->mBrush, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
495 DWRITE_MEASURING_MODE_NATURAL); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
496 enumerator->MoveNext(&hasRun); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
497 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
498 SafeRelease(&enumerator); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
499 return S_OK; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
500 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
501 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
502 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
503 // Draw by IDWriteFactory (without color emoji) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
504 pDWC_->mRT->DrawGlyphRun( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
505 D2D1::Point2F( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
506 baselineOriginX + context->offsetX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
507 baselineOriginY), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
508 &adjustedGlyphRun, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
509 pDWC_->SolidBrush(context->color), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
510 DWRITE_MEASURING_MODE_NATURAL); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
511 return S_OK; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
512 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
513 |
6110 | 514 public: |
515 IFACEMETHOD_(unsigned long, AddRef) () | |
516 { | |
517 return InterlockedIncrement(&cRefCount_); | |
518 } | |
519 | |
520 IFACEMETHOD_(unsigned long, Release) () | |
521 { | |
522 long newCount = InterlockedDecrement(&cRefCount_); | |
523 | |
524 if (newCount == 0) | |
525 { | |
526 delete this; | |
527 return 0; | |
528 } | |
529 return newCount; | |
530 } | |
531 | |
532 IFACEMETHOD(QueryInterface)( | |
533 IID const& riid, | |
534 void** ppvObject) | |
535 { | |
536 if (__uuidof(IDWriteTextRenderer) == riid) | |
537 { | |
538 *ppvObject = this; | |
539 } | |
540 else if (__uuidof(IDWritePixelSnapping) == riid) | |
541 { | |
542 *ppvObject = this; | |
543 } | |
544 else if (__uuidof(IUnknown) == riid) | |
545 { | |
546 *ppvObject = this; | |
547 } | |
548 else | |
549 { | |
550 *ppvObject = NULL; | |
551 return E_FAIL; | |
552 } | |
553 | |
554 return S_OK; | |
555 } | |
556 | |
557 private: | |
6120 | 558 long cRefCount_; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
559 DWriteContext* pDWC_; |
6110 | 560 }; |
561 | |
562 DWriteContext::DWriteContext() : | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
563 mHDC(NULL), |
6110 | 564 mDrawing(false), |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
565 mFallbackDC(false), |
6110 | 566 mD2D1Factory(NULL), |
567 mRT(NULL), | |
568 mBrush(NULL), | |
569 mDWriteFactory(NULL), | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
570 mDWriteFactory2(NULL), |
6110 | 571 mGdiInterop(NULL), |
572 mRenderingParams(NULL), | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
573 mFontCache(8), |
6110 | 574 mTextFormat(NULL), |
575 mFontWeight(DWRITE_FONT_WEIGHT_NORMAL), | |
576 mFontStyle(DWRITE_FONT_STYLE_NORMAL), | |
577 mTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT) | |
578 { | |
579 HRESULT hr; | |
580 | |
581 hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, | |
582 __uuidof(ID2D1Factory), NULL, | |
583 reinterpret_cast<void**>(&mD2D1Factory)); | |
584 _RPT2(_CRT_WARN, "D2D1CreateFactory: hr=%p p=%p\n", hr, mD2D1Factory); | |
585 | |
586 if (SUCCEEDED(hr)) | |
587 { | |
588 D2D1_RENDER_TARGET_PROPERTIES props = { | |
589 D2D1_RENDER_TARGET_TYPE_DEFAULT, | |
590 { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE }, | |
591 0, 0, | |
592 D2D1_RENDER_TARGET_USAGE_NONE, | |
593 D2D1_FEATURE_LEVEL_DEFAULT | |
594 }; | |
595 hr = mD2D1Factory->CreateDCRenderTarget(&props, &mRT); | |
596 _RPT2(_CRT_WARN, "CreateDCRenderTarget: hr=%p p=%p\n", hr, mRT); | |
597 } | |
598 | |
599 if (SUCCEEDED(hr)) | |
600 { | |
601 hr = mRT->CreateSolidColorBrush( | |
602 D2D1::ColorF(D2D1::ColorF::Black), | |
603 &mBrush); | |
604 _RPT2(_CRT_WARN, "CreateSolidColorBrush: hr=%p p=%p\n", hr, mBrush); | |
605 } | |
606 | |
607 if (SUCCEEDED(hr)) | |
608 { | |
609 hr = DWriteCreateFactory( | |
610 DWRITE_FACTORY_TYPE_SHARED, | |
611 __uuidof(IDWriteFactory), | |
612 reinterpret_cast<IUnknown**>(&mDWriteFactory)); | |
613 _RPT2(_CRT_WARN, "DWriteCreateFactory: hr=%p p=%p\n", hr, | |
614 mDWriteFactory); | |
615 } | |
616 | |
617 if (SUCCEEDED(hr)) | |
618 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
619 DWriteCreateFactory( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
620 DWRITE_FACTORY_TYPE_SHARED, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
621 __uuidof(IDWriteFactory2), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
622 reinterpret_cast<IUnknown**>(&mDWriteFactory2)); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
623 _RPT1(_CRT_WARN, "IDWriteFactory2: %s\n", SUCCEEDED(hr) ? "available" : "not available"); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
624 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
625 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
626 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
627 { |
6110 | 628 hr = mDWriteFactory->GetGdiInterop(&mGdiInterop); |
629 _RPT2(_CRT_WARN, "GetGdiInterop: hr=%p p=%p\n", hr, mGdiInterop); | |
630 } | |
631 | |
632 if (SUCCEEDED(hr)) | |
633 { | |
634 hr = mDWriteFactory->CreateRenderingParams(&mRenderingParams); | |
635 _RPT2(_CRT_WARN, "CreateRenderingParams: hr=%p p=%p\n", hr, | |
636 mRenderingParams); | |
637 } | |
638 } | |
639 | |
640 DWriteContext::~DWriteContext() | |
641 { | |
642 SafeRelease(&mTextFormat); | |
643 SafeRelease(&mRenderingParams); | |
644 SafeRelease(&mGdiInterop); | |
645 SafeRelease(&mDWriteFactory); | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
646 SafeRelease(&mDWriteFactory2); |
6110 | 647 SafeRelease(&mBrush); |
648 SafeRelease(&mRT); | |
649 SafeRelease(&mD2D1Factory); | |
650 } | |
651 | |
652 HRESULT | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
653 DWriteContext::CreateTextFormatFromLOGFONT(const LOGFONTW &logFont, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
654 IDWriteTextFormat **ppTextFormat) |
6110 | 655 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
656 // Most of this function is copied from: https://github.com/Microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/multimedia/DirectWrite/RenderTest/TextHelpers.cpp |
6110 | 657 HRESULT hr = S_OK; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
658 IDWriteTextFormat *pTextFormat = NULL; |
6110 | 659 |
660 IDWriteFont *font = NULL; | |
661 IDWriteFontFamily *fontFamily = NULL; | |
662 IDWriteLocalizedStrings *localizedFamilyNames = NULL; | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
663 float fontSize = 0; |
6110 | 664 |
665 if (SUCCEEDED(hr)) | |
666 { | |
667 hr = mGdiInterop->CreateFontFromLOGFONT(&logFont, &font); | |
668 } | |
669 | |
670 // Get the font family to which this font belongs. | |
671 if (SUCCEEDED(hr)) | |
672 { | |
673 hr = font->GetFontFamily(&fontFamily); | |
674 } | |
675 | |
676 // Get the family names. This returns an object that encapsulates one or | |
677 // more names with the same meaning but in different languages. | |
678 if (SUCCEEDED(hr)) | |
679 { | |
680 hr = fontFamily->GetFamilyNames(&localizedFamilyNames); | |
681 } | |
682 | |
683 // Get the family name at index zero. If we were going to display the name | |
684 // we'd want to try to find one that matched the use locale, but for | |
685 // purposes of creating a text format object any language will do. | |
686 | |
687 wchar_t familyName[100]; | |
688 if (SUCCEEDED(hr)) | |
689 { | |
690 hr = localizedFamilyNames->GetString(0, familyName, | |
691 ARRAYSIZE(familyName)); | |
692 } | |
693 | |
694 if (SUCCEEDED(hr)) | |
695 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
696 // Use lfHeight of the LOGFONT as font size. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
697 fontSize = float(logFont.lfHeight); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
698 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
699 if (fontSize < 0) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
700 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
701 // Negative lfHeight represents the size of the em unit. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
702 fontSize = -fontSize; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
703 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
704 else |
6110 | 705 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
706 // Positive lfHeight represents the cell height (ascent + |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
707 // descent). |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
708 DWRITE_FONT_METRICS fontMetrics; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
709 font->GetMetrics(&fontMetrics); |
6110 | 710 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
711 // Convert the cell height (ascent + descent) from design units |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
712 // to ems. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
713 float cellHeight = static_cast<float>( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
714 fontMetrics.ascent + fontMetrics.descent) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
715 / fontMetrics.designUnitsPerEm; |
6110 | 716 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
717 // Divide the font size by the cell height to get the font em |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
718 // size. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
719 fontSize /= cellHeight; |
6110 | 720 } |
721 } | |
722 | |
723 // The text format includes a locale name. Ideally, this would be the | |
724 // language of the text, which may or may not be the same as the primary | |
725 // language of the user. However, for our purposes the user locale will do. | |
726 wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; | |
727 if (SUCCEEDED(hr)) | |
728 { | |
729 if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0) | |
730 hr = HRESULT_FROM_WIN32(GetLastError()); | |
731 } | |
732 | |
733 if (SUCCEEDED(hr)) | |
734 { | |
735 // Create the text format object. | |
736 hr = mDWriteFactory->CreateTextFormat( | |
737 familyName, | |
738 NULL, // no custom font collection | |
739 font->GetWeight(), | |
740 font->GetStyle(), | |
741 font->GetStretch(), | |
742 fontSize, | |
743 localeName, | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
744 &pTextFormat); |
6110 | 745 } |
746 | |
747 if (SUCCEEDED(hr)) | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
748 hr = pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
749 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
750 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
751 hr = pTextFormat->SetParagraphAlignment( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
752 DWRITE_PARAGRAPH_ALIGNMENT_CENTER); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
753 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
754 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
755 hr = pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
756 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
757 SafeRelease(&localizedFamilyNames); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
758 SafeRelease(&fontFamily); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
759 SafeRelease(&font); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
760 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
761 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
762 *ppTextFormat = pTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
763 else |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
764 SafeRelease(&pTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
765 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
766 return hr; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
767 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
768 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
769 HRESULT |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
770 DWriteContext::SetFontByLOGFONT(const LOGFONTW &logFont) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
771 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
772 HRESULT hr = S_OK; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
773 IDWriteTextFormat *pTextFormat = NULL; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
774 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
775 hr = CreateTextFormatFromLOGFONT(logFont, &pTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
776 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
777 if (SUCCEEDED(hr)) |
6110 | 778 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
779 SafeRelease(&mTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
780 mTextFormat = pTextFormat; |
6110 | 781 mFontWeight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight); |
782 mFontStyle = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC | |
783 : DWRITE_FONT_STYLE_NORMAL; | |
784 } | |
785 | |
786 return hr; | |
787 } | |
788 | |
789 void | |
790 DWriteContext::SetFont(HFONT hFont) | |
791 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
792 FontCache::Item item; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
793 if (mFontCache.get(hFont, item)) |
6110 | 794 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
795 if (item.pTextFormat != NULL) |
6110 | 796 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
797 item.pTextFormat->AddRef(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
798 SafeRelease(&mTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
799 mTextFormat = item.pTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
800 mFontWeight = item.fontWeight; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
801 mFontStyle = item.fontStyle; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
802 mFallbackDC = false; |
6110 | 803 } |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
804 else |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
805 mFallbackDC = true; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
806 return; |
6110 | 807 } |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
808 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
809 HRESULT hr = E_FAIL; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
810 LOGFONTW lf; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
811 if (GetObjectW(hFont, sizeof(lf), &lf)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
812 hr = SetFontByLOGFONT(lf); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
813 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
814 item.hFont = hFont; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
815 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
816 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
817 item.pTextFormat = mTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
818 item.fontWeight = mFontWeight; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
819 item.fontStyle = mFontStyle; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
820 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
821 mFontCache.put(item); |
6110 | 822 } |
823 | |
824 void | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
825 DWriteContext::BindDC(HDC hdc, RECT *rect) |
6110 | 826 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
827 Flush(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
828 mRT->BindDC(hdc, rect); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
829 mRT->SetTransform(D2D1::IdentityMatrix()); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
830 mHDC = hdc; |
6110 | 831 } |
832 | |
833 void | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
834 DWriteContext::AssureDrawing() |
6110 | 835 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
836 if (mDrawing == false) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
837 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
838 mRT->BeginDraw(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
839 mDrawing = true; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
840 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
841 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
842 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
843 ID2D1Brush* |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
844 DWriteContext::SolidBrush(COLORREF color) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
845 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
846 mBrush->SetColor(D2D1::ColorF(UINT32(GetRValue(color)) << 16 | |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
847 UINT32(GetGValue(color)) << 8 | UINT32(GetBValue(color)))); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
848 return mBrush; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
849 } |
6110 | 850 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
851 void |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
852 DWriteContext::DrawText(const WCHAR* text, int len, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
853 int x, int y, int w, int h, int cellWidth, COLORREF color, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
854 UINT fuOptions, CONST RECT *lprc, CONST INT * lpDx) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
855 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
856 if (mFallbackDC) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
857 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
858 Flush(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
859 ExtTextOutW(mHDC, x, y, fuOptions, lprc, text, len, lpDx); |
6110 | 860 return; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
861 } |
6110 | 862 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
863 AssureDrawing(); |
6110 | 864 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
865 HRESULT hr; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
866 IDWriteTextLayout *textLayout = NULL; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
867 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
868 hr = mDWriteFactory->CreateTextLayout(text, len, mTextFormat, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
869 FLOAT(w), FLOAT(h), &textLayout); |
6110 | 870 |
871 if (SUCCEEDED(hr)) | |
872 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
873 DWRITE_TEXT_RANGE textRange = { 0, UINT32(len) }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
874 textLayout->SetFontWeight(mFontWeight, textRange); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
875 textLayout->SetFontStyle(mFontStyle, textRange); |
6110 | 876 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
877 TextRenderer renderer(this); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
878 TextRendererContext context = { color, FLOAT(cellWidth), 0.0f }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
879 textLayout->Draw(&context, &renderer, FLOAT(x), FLOAT(y)); |
6110 | 880 } |
881 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
882 SafeRelease(&textLayout); |
6110 | 883 } |
884 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
885 void |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
886 DWriteContext::FillRect(RECT *rc, COLORREF color) |
6110 | 887 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
888 AssureDrawing(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
889 mRT->FillRectangle( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
890 D2D1::RectF(FLOAT(rc->left), FLOAT(rc->top), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
891 FLOAT(rc->right), FLOAT(rc->bottom)), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
892 SolidBrush(color)); |
6110 | 893 } |
894 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
895 void |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
896 DWriteContext::Flush() |
6110 | 897 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
898 if (mDrawing) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
899 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
900 mRT->EndDraw(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
901 mDrawing = false; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
902 } |
6110 | 903 } |
904 | |
905 void | |
906 DWriteContext::SetRenderingParams( | |
907 const DWriteRenderingParams *params) | |
908 { | |
909 if (mDWriteFactory == NULL) | |
910 return; | |
911 | |
912 IDWriteRenderingParams *renderingParams = NULL; | |
913 D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode = | |
914 D2D1_TEXT_ANTIALIAS_MODE_DEFAULT; | |
915 HRESULT hr; | |
916 if (params != NULL) | |
917 { | |
918 hr = mDWriteFactory->CreateCustomRenderingParams(params->gamma, | |
919 params->enhancedContrast, params->clearTypeLevel, | |
920 ToPixelGeometry(params->pixelGeometry), | |
921 ToRenderingMode(params->renderingMode), &renderingParams); | |
922 textAntialiasMode = ToTextAntialiasMode(params->textAntialiasMode); | |
923 } | |
924 else | |
925 hr = mDWriteFactory->CreateRenderingParams(&renderingParams); | |
926 if (SUCCEEDED(hr) && renderingParams != NULL) | |
927 { | |
928 SafeRelease(&mRenderingParams); | |
929 mRenderingParams = renderingParams; | |
930 mTextAntialiasMode = textAntialiasMode; | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
931 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
932 Flush(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
933 mRT->SetTextRenderingParams(mRenderingParams); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
934 mRT->SetTextAntialiasMode(mTextAntialiasMode); |
6110 | 935 } |
936 } | |
937 | |
938 DWriteRenderingParams * | |
939 DWriteContext::GetRenderingParams( | |
940 DWriteRenderingParams *params) | |
941 { | |
942 if (params != NULL && mRenderingParams != NULL) | |
943 { | |
944 params->gamma = mRenderingParams->GetGamma(); | |
945 params->enhancedContrast = mRenderingParams->GetEnhancedContrast(); | |
946 params->clearTypeLevel = mRenderingParams->GetClearTypeLevel(); | |
947 params->pixelGeometry = ToInt(mRenderingParams->GetPixelGeometry()); | |
948 params->renderingMode = ToInt(mRenderingParams->GetRenderingMode()); | |
949 params->textAntialiasMode = mTextAntialiasMode; | |
950 } | |
951 return params; | |
952 } | |
953 | |
954 //////////////////////////////////////////////////////////////////////////// | |
955 // PUBLIC C INTERFACES | |
956 | |
957 void | |
958 DWrite_Init(void) | |
959 { | |
960 #ifdef DYNAMIC_DIRECTX | |
961 // Load libraries. | |
962 hD2D1DLL = vimLoadLib(const_cast<char*>("d2d1.dll")); | |
963 hDWriteDLL = vimLoadLib(const_cast<char*>("dwrite.dll")); | |
964 if (hD2D1DLL == NULL || hDWriteDLL == NULL) | |
965 { | |
966 DWrite_Final(); | |
967 return; | |
968 } | |
969 // Get address of procedures. | |
970 pGetUserDefaultLocaleName = (PGETUSERDEFAULTLOCALENAME)GetProcAddress( | |
971 GetModuleHandle("kernel32.dll"), "GetUserDefaultLocaleName"); | |
972 pD2D1CreateFactory = (PD2D1CREATEFACTORY)GetProcAddress(hD2D1DLL, | |
973 "D2D1CreateFactory"); | |
974 pDWriteCreateFactory = (PDWRITECREATEFACTORY)GetProcAddress(hDWriteDLL, | |
975 "DWriteCreateFactory"); | |
976 #endif | |
977 } | |
978 | |
979 void | |
980 DWrite_Final(void) | |
981 { | |
982 #ifdef DYNAMIC_DIRECTX | |
983 pGetUserDefaultLocaleName = NULL; | |
984 pD2D1CreateFactory = NULL; | |
985 pDWriteCreateFactory = NULL; | |
986 unload(hDWriteDLL); | |
987 unload(hD2D1DLL); | |
988 #endif | |
989 } | |
990 | |
991 DWriteContext * | |
992 DWriteContext_Open(void) | |
993 { | |
994 #ifdef DYNAMIC_DIRECTX | |
995 if (pGetUserDefaultLocaleName == NULL || pD2D1CreateFactory == NULL | |
996 || pDWriteCreateFactory == NULL) | |
997 return NULL; | |
998 #endif | |
999 return new DWriteContext(); | |
1000 } | |
1001 | |
1002 void | |
1003 DWriteContext_BindDC(DWriteContext *ctx, HDC hdc, RECT *rect) | |
1004 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1005 if (ctx != NULL) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1006 ctx->BindDC(hdc, rect); |
6110 | 1007 } |
1008 | |
1009 void | |
1010 DWriteContext_SetFont(DWriteContext *ctx, HFONT hFont) | |
1011 { | |
1012 if (ctx != NULL) | |
1013 ctx->SetFont(hFont); | |
1014 } | |
1015 | |
1016 void | |
1017 DWriteContext_DrawText( | |
1018 DWriteContext *ctx, | |
1019 const WCHAR* text, | |
1020 int len, | |
1021 int x, | |
1022 int y, | |
1023 int w, | |
1024 int h, | |
1025 int cellWidth, | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1026 COLORREF color, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1027 UINT fuOptions, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1028 CONST RECT *lprc, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1029 CONST INT * lpDx) |
6110 | 1030 { |
1031 if (ctx != NULL) | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1032 ctx->DrawText(text, len, x, y, w, h, cellWidth, color, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1033 fuOptions, lprc, lpDx); |
6110 | 1034 } |
1035 | |
1036 void | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1037 DWriteContext_FillRect(DWriteContext *ctx, RECT *rc, COLORREF color) |
6110 | 1038 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1039 if (ctx != NULL) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1040 ctx->FillRect(rc, color); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1041 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1042 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1043 void |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1044 DWriteContext_Flush(DWriteContext *ctx) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1045 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1046 if (ctx != NULL) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1047 ctx->Flush(); |
6110 | 1048 } |
1049 | |
1050 void | |
1051 DWriteContext_Close(DWriteContext *ctx) | |
1052 { | |
1053 delete ctx; | |
1054 } | |
1055 | |
1056 void | |
1057 DWriteContext_SetRenderingParams( | |
1058 DWriteContext *ctx, | |
1059 const DWriteRenderingParams *params) | |
1060 { | |
1061 if (ctx != NULL) | |
1062 ctx->SetRenderingParams(params); | |
1063 } | |
1064 | |
1065 DWriteRenderingParams * | |
1066 DWriteContext_GetRenderingParams( | |
1067 DWriteContext *ctx, | |
1068 DWriteRenderingParams *params) | |
1069 { | |
1070 if (ctx != NULL) | |
1071 return ctx->GetRenderingParams(params); | |
1072 else | |
1073 return NULL; | |
1074 } |