Mercurial > vim
annotate src/gui_dwrite.cpp @ 13134:c4b5ad2b3596 v8.0.1441
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
commit https://github.com/vim/vim/commit/ce46d934af35d0f774be7f996001db03cf0b894a
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 30 22:46:06 2018 +0100
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Problem: Using ":undo 0" leaves undo in wrong state.
Solution: Instead of searching for state 1 and go above, just use the start.
(Ozaki Kiichi, closes #2595)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 30 Jan 2018 23:00:06 +0100 |
parents | cfce9ac1d1e8 |
children | 808625d4b71b |
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 |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
41 #ifdef FEAT_DIRECTX_COLOR_EMOJI |
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
42 # include <dwrite_2.h> |
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
43 #else |
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
44 # include <dwrite.h> |
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
45 #endif |
6110 | 46 |
47 #include "gui_dwrite.h" | |
48 | |
49 #ifdef __MINGW32__ | |
50 # define __maybenull SAL__maybenull | |
51 # define __in SAL__in | |
52 # define __out SAL__out | |
53 #endif | |
54 | |
8641
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
55 #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
|
56 # define FINAL final |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
57 #else |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
58 # define FINAL |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
59 #endif |
0af716a4f5d2
commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents:
8271
diff
changeset
|
60 |
6110 | 61 #ifdef DYNAMIC_DIRECTX |
62 extern "C" HINSTANCE vimLoadLib(char *name); | |
63 | |
64 typedef int (WINAPI *PGETUSERDEFAULTLOCALENAME)(LPWSTR, int); | |
65 typedef HRESULT (WINAPI *PD2D1CREATEFACTORY)(D2D1_FACTORY_TYPE, | |
66 REFIID, const D2D1_FACTORY_OPTIONS *, void **); | |
67 typedef HRESULT (WINAPI *PDWRITECREATEFACTORY)(DWRITE_FACTORY_TYPE, | |
68 REFIID, IUnknown **); | |
69 | |
70 static HINSTANCE hD2D1DLL = NULL; | |
71 static HINSTANCE hDWriteDLL = NULL; | |
72 | |
73 static PGETUSERDEFAULTLOCALENAME pGetUserDefaultLocaleName = NULL; | |
74 static PD2D1CREATEFACTORY pD2D1CreateFactory = NULL; | |
75 static PDWRITECREATEFACTORY pDWriteCreateFactory = NULL; | |
76 | |
77 #define GetUserDefaultLocaleName (*pGetUserDefaultLocaleName) | |
78 #define D2D1CreateFactory (*pD2D1CreateFactory) | |
79 #define DWriteCreateFactory (*pDWriteCreateFactory) | |
80 | |
81 static void | |
82 unload(HINSTANCE &hinst) | |
83 { | |
84 if (hinst != NULL) | |
85 { | |
86 FreeLibrary(hinst); | |
87 hinst = NULL; | |
88 } | |
89 } | |
90 #endif // DYNAMIC_DIRECTX | |
91 | |
92 template <class T> inline void SafeRelease(T **ppT) | |
93 { | |
94 if (*ppT) | |
95 { | |
96 (*ppT)->Release(); | |
97 *ppT = NULL; | |
98 } | |
99 } | |
100 | |
101 static DWRITE_PIXEL_GEOMETRY | |
102 ToPixelGeometry(int value) | |
103 { | |
104 switch (value) | |
105 { | |
106 default: | |
107 case 0: | |
108 return DWRITE_PIXEL_GEOMETRY_FLAT; | |
109 case 1: | |
110 return DWRITE_PIXEL_GEOMETRY_RGB; | |
111 case 2: | |
112 return DWRITE_PIXEL_GEOMETRY_BGR; | |
113 } | |
114 } | |
115 | |
116 static int | |
117 ToInt(DWRITE_PIXEL_GEOMETRY value) | |
118 { | |
119 switch (value) | |
120 { | |
121 case DWRITE_PIXEL_GEOMETRY_FLAT: | |
122 return 0; | |
123 case DWRITE_PIXEL_GEOMETRY_RGB: | |
124 return 1; | |
125 case DWRITE_PIXEL_GEOMETRY_BGR: | |
126 return 2; | |
127 default: | |
128 return -1; | |
129 } | |
130 } | |
131 | |
132 static DWRITE_RENDERING_MODE | |
133 ToRenderingMode(int value) | |
134 { | |
135 switch (value) | |
136 { | |
137 default: | |
138 case 0: | |
139 return DWRITE_RENDERING_MODE_DEFAULT; | |
140 case 1: | |
141 return DWRITE_RENDERING_MODE_ALIASED; | |
142 case 2: | |
143 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC; | |
144 case 3: | |
145 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL; | |
146 case 4: | |
147 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL; | |
148 case 5: | |
149 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; | |
150 case 6: | |
151 return DWRITE_RENDERING_MODE_OUTLINE; | |
152 } | |
153 } | |
154 | |
155 static D2D1_TEXT_ANTIALIAS_MODE | |
156 ToTextAntialiasMode(int value) | |
157 { | |
158 switch (value) | |
159 { | |
160 default: | |
161 case 0: | |
162 return D2D1_TEXT_ANTIALIAS_MODE_DEFAULT; | |
163 case 1: | |
164 return D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE; | |
165 case 2: | |
166 return D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE; | |
167 case 3: | |
168 return D2D1_TEXT_ANTIALIAS_MODE_ALIASED; | |
169 } | |
170 } | |
171 | |
172 static int | |
173 ToInt(DWRITE_RENDERING_MODE value) | |
174 { | |
175 switch (value) | |
176 { | |
177 case DWRITE_RENDERING_MODE_DEFAULT: | |
178 return 0; | |
179 case DWRITE_RENDERING_MODE_ALIASED: | |
180 return 1; | |
181 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC: | |
182 return 2; | |
183 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL: | |
184 return 3; | |
185 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL: | |
186 return 4; | |
187 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC: | |
188 return 5; | |
189 case DWRITE_RENDERING_MODE_OUTLINE: | |
190 return 6; | |
191 default: | |
192 return -1; | |
193 } | |
194 } | |
195 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
196 class FontCache { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
197 public: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
198 struct Item { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
199 HFONT hFont; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
200 IDWriteTextFormat* pTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 }; |
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 private: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
207 int mSize; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
208 Item *mItems; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
209 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
210 public: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
211 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
|
212 mSize(size), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
213 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
|
214 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
215 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
216 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
217 ~FontCache() |
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 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
|
220 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
|
221 delete[] mItems; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
222 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
223 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
224 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
|
225 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
226 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
|
227 if (n < 0) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
228 return false; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
229 item = mItems[n]; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
230 slide(n); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
231 return true; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
232 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
233 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
234 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
|
235 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
236 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
|
237 if (n < 0) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
238 n = mSize - 1; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
239 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
|
240 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
241 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
|
242 item.pTextFormat->AddRef(); |
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 mItems[n] = item; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
245 slide(n); |
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 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
248 private: |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
249 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
|
250 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
251 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
|
252 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
253 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
|
254 return i; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
255 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
256 return -1; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
257 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
258 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
259 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
|
260 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
261 if (nextTop == 0) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
262 return; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 mItems[0] = tmp; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
267 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
268 }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
269 |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
270 enum DrawingMode { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
271 DM_GDI = 0, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
272 DM_DIRECTX = 1, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
273 DM_INTEROP = 2, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
274 }; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
275 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
276 struct DWriteContext { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
277 HDC mHDC; |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
278 RECT mBindRect; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
279 DrawingMode mDMode; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
280 HDC mInteropHDC; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
281 bool mDrawing; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
282 bool mFallbackDC; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
283 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
284 ID2D1Factory *mD2D1Factory; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
285 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
286 ID2D1DCRenderTarget *mRT; |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
287 ID2D1GdiInteropRenderTarget *mGDIRT; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
288 ID2D1SolidColorBrush *mBrush; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
289 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
290 IDWriteFactory *mDWriteFactory; |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
291 #ifdef FEAT_DIRECTX_COLOR_EMOJI |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
292 IDWriteFactory2 *mDWriteFactory2; |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
293 #endif |
12934
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 IDWriteGdiInterop *mGdiInterop; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
296 IDWriteRenderingParams *mRenderingParams; |
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 FontCache mFontCache; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
299 IDWriteTextFormat *mTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
300 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
|
301 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
|
302 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
303 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
|
304 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
305 // METHODS |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
306 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
307 DWriteContext(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
308 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
309 virtual ~DWriteContext(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
310 |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
311 HRESULT CreateDeviceResources(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
312 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
313 void DiscardDeviceResources(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
314 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
315 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
|
316 IDWriteTextFormat **ppTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
317 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
318 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
|
319 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
320 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
|
321 |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
322 void BindDC(HDC hdc, const RECT *rect); |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
323 |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
324 HRESULT SetDrawingMode(DrawingMode mode); |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
325 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
326 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
|
327 |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
328 void DrawText(const WCHAR *text, int len, |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
329 int x, int y, int w, int h, int cellWidth, COLORREF color, |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
330 UINT fuOptions, const RECT *lprc, const INT *lpDx); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
331 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
332 void FillRect(const RECT *rc, COLORREF color); |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
333 |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
334 void DrawLine(int x1, int y1, int x2, int y2, COLORREF color); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
335 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
336 void SetPixel(int x, int y, COLORREF color); |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
337 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
338 void Flush(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
339 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
340 void SetRenderingParams( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
341 const DWriteRenderingParams *params); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
342 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
343 DWriteRenderingParams *GetRenderingParams( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
344 DWriteRenderingParams *params); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
345 }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
346 |
6110 | 347 class AdjustedGlyphRun : public DWRITE_GLYPH_RUN |
348 { | |
349 private: | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
350 FLOAT &mAccum; |
6110 | 351 FLOAT mDelta; |
352 FLOAT *mAdjustedAdvances; | |
353 | |
354 public: | |
355 AdjustedGlyphRun( | |
356 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
|
357 FLOAT cellWidth, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
358 FLOAT &accum) : |
6110 | 359 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
|
360 mAccum(accum), |
6110 | 361 mDelta(0.0f), |
362 mAdjustedAdvances(new FLOAT[glyphRun->glyphCount]) | |
363 { | |
364 assert(cellWidth != 0.0f); | |
365 for (UINT32 i = 0; i < glyphRun->glyphCount; ++i) | |
366 { | |
367 FLOAT orig = glyphRun->glyphAdvances[i]; | |
368 FLOAT adjusted = adjustToCell(orig, cellWidth); | |
369 mAdjustedAdvances[i] = adjusted; | |
370 mDelta += adjusted - orig; | |
371 } | |
372 glyphAdvances = mAdjustedAdvances; | |
373 } | |
374 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
375 ~AdjustedGlyphRun() |
6110 | 376 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
377 mAccum += mDelta; |
6110 | 378 delete[] mAdjustedAdvances; |
379 } | |
380 | |
381 static FLOAT adjustToCell(FLOAT value, FLOAT cellWidth) | |
382 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
383 int cellCount = int(floor(value / cellWidth + 0.5f)); |
6110 | 384 if (cellCount < 1) |
385 cellCount = 1; | |
386 return cellCount * cellWidth; | |
387 } | |
388 }; | |
389 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
390 struct TextRendererContext { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
391 // const fields. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
392 COLORREF color; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
393 FLOAT cellWidth; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
394 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
395 // working fields. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
396 FLOAT offsetX; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
397 }; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
398 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
399 class TextRenderer FINAL : public IDWriteTextRenderer |
6110 | 400 { |
401 public: | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
402 TextRenderer( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
403 DWriteContext* pDWC) : |
6110 | 404 cRefCount_(0), |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
405 pDWC_(pDWC) |
6110 | 406 { |
407 AddRef(); | |
408 } | |
409 | |
8271
770774e66011
commit https://github.com/vim/vim/commit/edb4f2b3601b0abd47091606269c0ac3244a805b
Christian Brabandt <cb@256bit.org>
parents:
7547
diff
changeset
|
410 // 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
|
411 virtual ~TextRenderer() |
6110 | 412 { |
413 } | |
414 | |
415 IFACEMETHOD(IsPixelSnappingDisabled)( | |
416 __maybenull void* clientDrawingContext, | |
417 __out BOOL* isDisabled) | |
418 { | |
419 *isDisabled = FALSE; | |
420 return S_OK; | |
421 } | |
422 | |
423 IFACEMETHOD(GetCurrentTransform)( | |
424 __maybenull void* clientDrawingContext, | |
425 __out DWRITE_MATRIX* transform) | |
426 { | |
8271
770774e66011
commit https://github.com/vim/vim/commit/edb4f2b3601b0abd47091606269c0ac3244a805b
Christian Brabandt <cb@256bit.org>
parents:
7547
diff
changeset
|
427 // 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
|
428 pDWC_->mRT->GetTransform( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
429 reinterpret_cast<D2D1_MATRIX_3X2_F*>(transform)); |
6110 | 430 return S_OK; |
431 } | |
432 | |
433 IFACEMETHOD(GetPixelsPerDip)( | |
434 __maybenull void* clientDrawingContext, | |
435 __out FLOAT* pixelsPerDip) | |
436 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
437 float dpiX, unused; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
438 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
|
439 *pixelsPerDip = dpiX / 96.0f; |
6110 | 440 return S_OK; |
441 } | |
442 | |
443 IFACEMETHOD(DrawUnderline)( | |
444 __maybenull void* clientDrawingContext, | |
445 FLOAT baselineOriginX, | |
446 FLOAT baselineOriginY, | |
447 __in DWRITE_UNDERLINE const* underline, | |
448 IUnknown* clientDrawingEffect) | |
449 { | |
450 return E_NOTIMPL; | |
451 } | |
452 | |
453 IFACEMETHOD(DrawStrikethrough)( | |
454 __maybenull void* clientDrawingContext, | |
455 FLOAT baselineOriginX, | |
456 FLOAT baselineOriginY, | |
457 __in DWRITE_STRIKETHROUGH const* strikethrough, | |
458 IUnknown* clientDrawingEffect) | |
459 { | |
460 return E_NOTIMPL; | |
461 } | |
462 | |
463 IFACEMETHOD(DrawInlineObject)( | |
464 __maybenull void* clientDrawingContext, | |
465 FLOAT originX, | |
466 FLOAT originY, | |
467 IDWriteInlineObject* inlineObject, | |
468 BOOL isSideways, | |
469 BOOL isRightToLeft, | |
470 IUnknown* clientDrawingEffect) | |
471 { | |
472 return E_NOTIMPL; | |
473 } | |
474 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
475 IFACEMETHOD(DrawGlyphRun)( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
476 __maybenull void* clientDrawingContext, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
477 FLOAT baselineOriginX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
478 FLOAT baselineOriginY, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
479 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
|
480 __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
|
481 __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
|
482 IUnknown* clientDrawingEffect) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
483 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
484 TextRendererContext *context = |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
485 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
|
486 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
487 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
|
488 context->offsetX); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
489 |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
490 #ifdef FEAT_DIRECTX_COLOR_EMOJI |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
491 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
|
492 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
493 IDWriteColorGlyphRunEnumerator *enumerator = NULL; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
494 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
|
495 baselineOriginX + context->offsetX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
496 baselineOriginY, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
497 &adjustedGlyphRun, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
498 NULL, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
499 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
|
500 NULL, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
501 0, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
502 &enumerator); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
503 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
504 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
505 // 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
|
506 BOOL hasRun = TRUE; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
507 enumerator->MoveNext(&hasRun); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
508 while (hasRun) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
509 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
510 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
|
511 enumerator->GetCurrentRun(&colorGlyphRun); |
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 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
|
514 pDWC_->mRT->DrawGlyphRun( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
515 D2D1::Point2F( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
516 colorGlyphRun->baselineOriginX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
517 colorGlyphRun->baselineOriginY), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
518 &colorGlyphRun->glyphRun, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
519 pDWC_->mBrush, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
520 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
|
521 enumerator->MoveNext(&hasRun); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
522 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
523 SafeRelease(&enumerator); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
524 return S_OK; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
525 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
526 } |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
527 #endif |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
528 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
529 // 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
|
530 pDWC_->mRT->DrawGlyphRun( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
531 D2D1::Point2F( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
532 baselineOriginX + context->offsetX, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
533 baselineOriginY), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
534 &adjustedGlyphRun, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
535 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
|
536 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
|
537 return S_OK; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
538 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
539 |
6110 | 540 public: |
541 IFACEMETHOD_(unsigned long, AddRef) () | |
542 { | |
543 return InterlockedIncrement(&cRefCount_); | |
544 } | |
545 | |
546 IFACEMETHOD_(unsigned long, Release) () | |
547 { | |
548 long newCount = InterlockedDecrement(&cRefCount_); | |
549 | |
550 if (newCount == 0) | |
551 { | |
552 delete this; | |
553 return 0; | |
554 } | |
555 return newCount; | |
556 } | |
557 | |
558 IFACEMETHOD(QueryInterface)( | |
559 IID const& riid, | |
560 void** ppvObject) | |
561 { | |
562 if (__uuidof(IDWriteTextRenderer) == riid) | |
563 { | |
564 *ppvObject = this; | |
565 } | |
566 else if (__uuidof(IDWritePixelSnapping) == riid) | |
567 { | |
568 *ppvObject = this; | |
569 } | |
570 else if (__uuidof(IUnknown) == riid) | |
571 { | |
572 *ppvObject = this; | |
573 } | |
574 else | |
575 { | |
576 *ppvObject = NULL; | |
577 return E_FAIL; | |
578 } | |
579 | |
580 return S_OK; | |
581 } | |
582 | |
583 private: | |
6120 | 584 long cRefCount_; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
585 DWriteContext* pDWC_; |
6110 | 586 }; |
587 | |
588 DWriteContext::DWriteContext() : | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
589 mHDC(NULL), |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
590 mBindRect(), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
591 mDMode(DM_GDI), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
592 mInteropHDC(NULL), |
6110 | 593 mDrawing(false), |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
594 mFallbackDC(false), |
6110 | 595 mD2D1Factory(NULL), |
596 mRT(NULL), | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
597 mGDIRT(NULL), |
6110 | 598 mBrush(NULL), |
599 mDWriteFactory(NULL), | |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
600 #ifdef FEAT_DIRECTX_COLOR_EMOJI |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
601 mDWriteFactory2(NULL), |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
602 #endif |
6110 | 603 mGdiInterop(NULL), |
604 mRenderingParams(NULL), | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
605 mFontCache(8), |
6110 | 606 mTextFormat(NULL), |
607 mFontWeight(DWRITE_FONT_WEIGHT_NORMAL), | |
608 mFontStyle(DWRITE_FONT_STYLE_NORMAL), | |
609 mTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT) | |
610 { | |
611 HRESULT hr; | |
612 | |
613 hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, | |
614 __uuidof(ID2D1Factory), NULL, | |
615 reinterpret_cast<void**>(&mD2D1Factory)); | |
616 _RPT2(_CRT_WARN, "D2D1CreateFactory: hr=%p p=%p\n", hr, mD2D1Factory); | |
617 | |
618 if (SUCCEEDED(hr)) | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
619 hr = CreateDeviceResources(); |
6110 | 620 |
621 if (SUCCEEDED(hr)) | |
622 { | |
623 hr = DWriteCreateFactory( | |
624 DWRITE_FACTORY_TYPE_SHARED, | |
625 __uuidof(IDWriteFactory), | |
626 reinterpret_cast<IUnknown**>(&mDWriteFactory)); | |
627 _RPT2(_CRT_WARN, "DWriteCreateFactory: hr=%p p=%p\n", hr, | |
628 mDWriteFactory); | |
629 } | |
630 | |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
631 #ifdef FEAT_DIRECTX_COLOR_EMOJI |
6110 | 632 if (SUCCEEDED(hr)) |
633 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
634 DWriteCreateFactory( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
635 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
|
636 __uuidof(IDWriteFactory2), |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
637 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
|
638 _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
|
639 } |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
640 #endif |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
641 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
642 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
643 { |
6110 | 644 hr = mDWriteFactory->GetGdiInterop(&mGdiInterop); |
645 _RPT2(_CRT_WARN, "GetGdiInterop: hr=%p p=%p\n", hr, mGdiInterop); | |
646 } | |
647 | |
648 if (SUCCEEDED(hr)) | |
649 { | |
650 hr = mDWriteFactory->CreateRenderingParams(&mRenderingParams); | |
651 _RPT2(_CRT_WARN, "CreateRenderingParams: hr=%p p=%p\n", hr, | |
652 mRenderingParams); | |
653 } | |
654 } | |
655 | |
656 DWriteContext::~DWriteContext() | |
657 { | |
658 SafeRelease(&mTextFormat); | |
659 SafeRelease(&mRenderingParams); | |
660 SafeRelease(&mGdiInterop); | |
661 SafeRelease(&mDWriteFactory); | |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
662 #ifdef FEAT_DIRECTX_COLOR_EMOJI |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
663 SafeRelease(&mDWriteFactory2); |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
664 #endif |
6110 | 665 SafeRelease(&mBrush); |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
666 SafeRelease(&mGDIRT); |
6110 | 667 SafeRelease(&mRT); |
668 SafeRelease(&mD2D1Factory); | |
669 } | |
670 | |
671 HRESULT | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
672 DWriteContext::CreateDeviceResources() |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
673 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
674 HRESULT hr; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
675 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
676 if (mRT != NULL) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
677 return S_OK; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
678 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
679 D2D1_RENDER_TARGET_PROPERTIES props = { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
680 D2D1_RENDER_TARGET_TYPE_DEFAULT, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
681 { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE }, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
682 0, 0, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
683 D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
684 D2D1_FEATURE_LEVEL_DEFAULT |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
685 }; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
686 hr = mD2D1Factory->CreateDCRenderTarget(&props, &mRT); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
687 _RPT2(_CRT_WARN, "CreateDCRenderTarget: hr=%p p=%p\n", hr, mRT); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
688 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
689 if (SUCCEEDED(hr)) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
690 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
691 // This always succeeds. |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
692 mRT->QueryInterface( |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
693 __uuidof(ID2D1GdiInteropRenderTarget), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
694 reinterpret_cast<void**>(&mGDIRT)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
695 _RPT1(_CRT_WARN, "GdiInteropRenderTarget: p=%p\n", mGDIRT); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
696 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
697 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
698 if (SUCCEEDED(hr)) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
699 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
700 hr = mRT->CreateSolidColorBrush( |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
701 D2D1::ColorF(D2D1::ColorF::Black), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
702 &mBrush); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
703 _RPT2(_CRT_WARN, "CreateSolidColorBrush: hr=%p p=%p\n", hr, mBrush); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
704 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
705 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
706 if (SUCCEEDED(hr)) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
707 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
708 if (mHDC != NULL) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
709 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
710 mRT->BindDC(mHDC, &mBindRect); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
711 mRT->SetTransform(D2D1::IdentityMatrix()); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
712 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
713 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
714 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
715 return hr; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
716 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
717 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
718 void |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
719 DWriteContext::DiscardDeviceResources() |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
720 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
721 SafeRelease(&mBrush); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
722 SafeRelease(&mGDIRT); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
723 SafeRelease(&mRT); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
724 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
725 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
726 HRESULT |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
727 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
|
728 IDWriteTextFormat **ppTextFormat) |
6110 | 729 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
730 // Most of this function is copied from: https://github.com/Microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/multimedia/DirectWrite/RenderTest/TextHelpers.cpp |
6110 | 731 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
|
732 IDWriteTextFormat *pTextFormat = NULL; |
6110 | 733 |
734 IDWriteFont *font = NULL; | |
735 IDWriteFontFamily *fontFamily = NULL; | |
736 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
|
737 float fontSize = 0; |
6110 | 738 |
739 if (SUCCEEDED(hr)) | |
740 { | |
741 hr = mGdiInterop->CreateFontFromLOGFONT(&logFont, &font); | |
742 } | |
743 | |
744 // Get the font family to which this font belongs. | |
745 if (SUCCEEDED(hr)) | |
746 { | |
747 hr = font->GetFontFamily(&fontFamily); | |
748 } | |
749 | |
750 // Get the family names. This returns an object that encapsulates one or | |
751 // more names with the same meaning but in different languages. | |
752 if (SUCCEEDED(hr)) | |
753 { | |
754 hr = fontFamily->GetFamilyNames(&localizedFamilyNames); | |
755 } | |
756 | |
757 // Get the family name at index zero. If we were going to display the name | |
758 // we'd want to try to find one that matched the use locale, but for | |
759 // purposes of creating a text format object any language will do. | |
760 | |
761 wchar_t familyName[100]; | |
762 if (SUCCEEDED(hr)) | |
763 { | |
764 hr = localizedFamilyNames->GetString(0, familyName, | |
765 ARRAYSIZE(familyName)); | |
766 } | |
767 | |
768 if (SUCCEEDED(hr)) | |
769 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
770 // 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
|
771 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
|
772 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
773 if (fontSize < 0) |
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 // 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
|
776 fontSize = -fontSize; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
777 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
778 else |
6110 | 779 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
780 // 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
|
781 // descent). |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
782 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
|
783 font->GetMetrics(&fontMetrics); |
6110 | 784 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
785 // 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
|
786 // to ems. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
787 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
|
788 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
|
789 / fontMetrics.designUnitsPerEm; |
6110 | 790 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
791 // 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
|
792 // size. |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
793 fontSize /= cellHeight; |
6110 | 794 } |
795 } | |
796 | |
797 // The text format includes a locale name. Ideally, this would be the | |
798 // language of the text, which may or may not be the same as the primary | |
799 // language of the user. However, for our purposes the user locale will do. | |
800 wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; | |
801 if (SUCCEEDED(hr)) | |
802 { | |
803 if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0) | |
804 hr = HRESULT_FROM_WIN32(GetLastError()); | |
805 } | |
806 | |
807 if (SUCCEEDED(hr)) | |
808 { | |
809 // Create the text format object. | |
810 hr = mDWriteFactory->CreateTextFormat( | |
811 familyName, | |
812 NULL, // no custom font collection | |
813 font->GetWeight(), | |
814 font->GetStyle(), | |
815 font->GetStretch(), | |
816 fontSize, | |
817 localeName, | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
818 &pTextFormat); |
6110 | 819 } |
820 | |
821 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
|
822 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
|
823 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
824 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
825 hr = pTextFormat->SetParagraphAlignment( |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
826 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
|
827 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
828 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
829 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
|
830 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
831 SafeRelease(&localizedFamilyNames); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
832 SafeRelease(&fontFamily); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
833 SafeRelease(&font); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
834 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
835 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
836 *ppTextFormat = pTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
837 else |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
838 SafeRelease(&pTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
839 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
840 return hr; |
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 HRESULT |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
844 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
|
845 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
846 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
|
847 IDWriteTextFormat *pTextFormat = NULL; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
848 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
849 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
|
850 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
851 if (SUCCEEDED(hr)) |
6110 | 852 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
853 SafeRelease(&mTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
854 mTextFormat = pTextFormat; |
6110 | 855 mFontWeight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight); |
856 mFontStyle = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC | |
857 : DWRITE_FONT_STYLE_NORMAL; | |
858 } | |
859 | |
860 return hr; | |
861 } | |
862 | |
863 void | |
864 DWriteContext::SetFont(HFONT hFont) | |
865 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
866 FontCache::Item item; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
867 if (mFontCache.get(hFont, item)) |
6110 | 868 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
869 if (item.pTextFormat != NULL) |
6110 | 870 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
871 item.pTextFormat->AddRef(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
872 SafeRelease(&mTextFormat); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
873 mTextFormat = item.pTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
874 mFontWeight = item.fontWeight; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
875 mFontStyle = item.fontStyle; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
876 mFallbackDC = false; |
6110 | 877 } |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
878 else |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
879 mFallbackDC = true; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
880 return; |
6110 | 881 } |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
882 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
883 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
|
884 LOGFONTW lf; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
885 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
|
886 hr = SetFontByLOGFONT(lf); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
887 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
888 item.hFont = hFont; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
889 if (SUCCEEDED(hr)) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
890 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
891 item.pTextFormat = mTextFormat; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
892 item.fontWeight = mFontWeight; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
893 item.fontStyle = mFontStyle; |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
894 mFallbackDC = false; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
895 } |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
896 else |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
897 mFallbackDC = true; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
898 mFontCache.put(item); |
6110 | 899 } |
900 | |
901 void | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
902 DWriteContext::BindDC(HDC hdc, const RECT *rect) |
6110 | 903 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
904 Flush(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
905 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
|
906 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
|
907 mHDC = hdc; |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
908 mBindRect = *rect; |
6110 | 909 } |
910 | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
911 HRESULT |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
912 DWriteContext::SetDrawingMode(DrawingMode mode) |
6110 | 913 { |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
914 HRESULT hr = S_OK; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
915 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
916 switch (mode) |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
917 { |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
918 default: |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
919 case DM_GDI: |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
920 if (mInteropHDC != NULL) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
921 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
922 mGDIRT->ReleaseDC(NULL); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
923 mInteropHDC = NULL; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
924 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
925 if (mDrawing) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
926 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
927 hr = mRT->EndDraw(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
928 if (hr == D2DERR_RECREATE_TARGET) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
929 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
930 hr = S_OK; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
931 DiscardDeviceResources(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
932 CreateDeviceResources(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
933 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
934 mDrawing = false; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
935 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
936 break; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
937 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
938 case DM_DIRECTX: |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
939 if (mInteropHDC != NULL) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
940 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
941 mGDIRT->ReleaseDC(NULL); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
942 mInteropHDC = NULL; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
943 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
944 else if (mDrawing == false) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
945 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
946 CreateDeviceResources(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
947 mRT->BeginDraw(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
948 mDrawing = true; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
949 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
950 break; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
951 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
952 case DM_INTEROP: |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
953 if (mDrawing == false) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
954 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
955 CreateDeviceResources(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
956 mRT->BeginDraw(); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
957 mDrawing = true; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
958 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
959 if (mInteropHDC == NULL) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
960 hr = mGDIRT->GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &mInteropHDC); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
961 break; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
962 } |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
963 mDMode = mode; |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
964 return hr; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
965 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
966 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
967 ID2D1Brush* |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
968 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
|
969 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
970 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
|
971 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
|
972 return mBrush; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
973 } |
6110 | 974 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
975 void |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
976 DWriteContext::DrawText(const WCHAR *text, int len, |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
977 int x, int y, int w, int h, int cellWidth, COLORREF color, |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
978 UINT fuOptions, const RECT *lprc, const INT *lpDx) |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
979 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
980 if (mFallbackDC) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
981 { |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
982 // Fall back to GDI rendering. |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
983 HRESULT hr = SetDrawingMode(DM_INTEROP); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
984 if (SUCCEEDED(hr)) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
985 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
986 HGDIOBJ hFont = ::GetCurrentObject(mHDC, OBJ_FONT); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
987 HGDIOBJ hOldFont = ::SelectObject(mInteropHDC, hFont); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
988 ::SetTextColor(mInteropHDC, color); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
989 ::SetBkMode(mInteropHDC, ::GetBkMode(mHDC)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
990 ::ExtTextOutW(mInteropHDC, x, y, fuOptions, lprc, text, len, lpDx); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
991 ::SelectObject(mInteropHDC, hOldFont); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
992 } |
6110 | 993 return; |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
994 } |
6110 | 995 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
996 HRESULT hr; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
997 IDWriteTextLayout *textLayout = NULL; |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
998 |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
999 SetDrawingMode(DM_DIRECTX); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1000 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1001 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
|
1002 FLOAT(w), FLOAT(h), &textLayout); |
6110 | 1003 |
1004 if (SUCCEEDED(hr)) | |
1005 { | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1006 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
|
1007 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
|
1008 textLayout->SetFontStyle(mFontStyle, textRange); |
6110 | 1009 |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1010 TextRenderer renderer(this); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1011 TextRendererContext context = { color, FLOAT(cellWidth), 0.0f }; |
13028
cfce9ac1d1e8
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Christian Brabandt <cb@256bit.org>
parents:
12986
diff
changeset
|
1012 textLayout->Draw(&context, &renderer, FLOAT(x), FLOAT(y) - 0.5f); |
6110 | 1013 } |
1014 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1015 SafeRelease(&textLayout); |
6110 | 1016 } |
1017 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1018 void |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1019 DWriteContext::FillRect(const RECT *rc, COLORREF color) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1020 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1021 if (mDMode == DM_INTEROP) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1022 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1023 // GDI functions are used before this call. Keep using GDI. |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1024 // (Switching to Direct2D causes terrible slowdown.) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1025 HBRUSH hbr = ::CreateSolidBrush(color); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1026 ::FillRect(mInteropHDC, rc, hbr); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1027 ::DeleteObject(HGDIOBJ(hbr)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1028 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1029 else |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1030 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1031 SetDrawingMode(DM_DIRECTX); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1032 mRT->FillRectangle( |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1033 D2D1::RectF(FLOAT(rc->left), FLOAT(rc->top), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1034 FLOAT(rc->right), FLOAT(rc->bottom)), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1035 SolidBrush(color)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1036 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1037 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1038 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1039 void |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1040 DWriteContext::DrawLine(int x1, int y1, int x2, int y2, COLORREF color) |
6110 | 1041 { |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1042 if (mDMode == DM_INTEROP) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1043 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1044 // GDI functions are used before this call. Keep using GDI. |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1045 // (Switching to Direct2D causes terrible slowdown.) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1046 HPEN hpen = ::CreatePen(PS_SOLID, 1, color); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1047 HGDIOBJ old_pen = ::SelectObject(mInteropHDC, HGDIOBJ(hpen)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1048 ::MoveToEx(mInteropHDC, x1, y1, NULL); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1049 ::LineTo(mInteropHDC, x2, y2); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1050 ::SelectObject(mInteropHDC, old_pen); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1051 ::DeleteObject(HGDIOBJ(hpen)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1052 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1053 else |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1054 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1055 SetDrawingMode(DM_DIRECTX); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1056 mRT->DrawLine( |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1057 D2D1::Point2F(FLOAT(x1), FLOAT(y1) + 0.5f), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1058 D2D1::Point2F(FLOAT(x2), FLOAT(y2) + 0.5f), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1059 SolidBrush(color)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1060 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1061 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1062 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1063 void |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1064 DWriteContext::SetPixel(int x, int y, COLORREF color) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1065 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1066 if (mDMode == DM_INTEROP) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1067 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1068 // GDI functions are used before this call. Keep using GDI. |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1069 // (Switching to Direct2D causes terrible slowdown.) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1070 ::SetPixel(mInteropHDC, x, y, color); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1071 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1072 else |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1073 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1074 SetDrawingMode(DM_DIRECTX); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1075 // Direct2D doesn't have SetPixel API. Use DrawLine instead. |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1076 mRT->DrawLine( |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1077 D2D1::Point2F(FLOAT(x), FLOAT(y) + 0.5f), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1078 D2D1::Point2F(FLOAT(x+1), FLOAT(y) + 0.5f), |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1079 SolidBrush(color)); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1080 } |
6110 | 1081 } |
1082 | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1083 void |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1084 DWriteContext::Flush() |
6110 | 1085 { |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1086 SetDrawingMode(DM_GDI); |
6110 | 1087 } |
1088 | |
1089 void | |
1090 DWriteContext::SetRenderingParams( | |
1091 const DWriteRenderingParams *params) | |
1092 { | |
1093 if (mDWriteFactory == NULL) | |
1094 return; | |
1095 | |
1096 IDWriteRenderingParams *renderingParams = NULL; | |
1097 D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode = | |
1098 D2D1_TEXT_ANTIALIAS_MODE_DEFAULT; | |
1099 HRESULT hr; | |
1100 if (params != NULL) | |
1101 { | |
1102 hr = mDWriteFactory->CreateCustomRenderingParams(params->gamma, | |
1103 params->enhancedContrast, params->clearTypeLevel, | |
1104 ToPixelGeometry(params->pixelGeometry), | |
1105 ToRenderingMode(params->renderingMode), &renderingParams); | |
1106 textAntialiasMode = ToTextAntialiasMode(params->textAntialiasMode); | |
1107 } | |
1108 else | |
1109 hr = mDWriteFactory->CreateRenderingParams(&renderingParams); | |
1110 if (SUCCEEDED(hr) && renderingParams != NULL) | |
1111 { | |
1112 SafeRelease(&mRenderingParams); | |
1113 mRenderingParams = renderingParams; | |
1114 mTextAntialiasMode = textAntialiasMode; | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1115 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1116 Flush(); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1117 mRT->SetTextRenderingParams(mRenderingParams); |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1118 mRT->SetTextAntialiasMode(mTextAntialiasMode); |
6110 | 1119 } |
1120 } | |
1121 | |
1122 DWriteRenderingParams * | |
1123 DWriteContext::GetRenderingParams( | |
1124 DWriteRenderingParams *params) | |
1125 { | |
1126 if (params != NULL && mRenderingParams != NULL) | |
1127 { | |
1128 params->gamma = mRenderingParams->GetGamma(); | |
1129 params->enhancedContrast = mRenderingParams->GetEnhancedContrast(); | |
1130 params->clearTypeLevel = mRenderingParams->GetClearTypeLevel(); | |
1131 params->pixelGeometry = ToInt(mRenderingParams->GetPixelGeometry()); | |
1132 params->renderingMode = ToInt(mRenderingParams->GetRenderingMode()); | |
1133 params->textAntialiasMode = mTextAntialiasMode; | |
1134 } | |
1135 return params; | |
1136 } | |
1137 | |
1138 //////////////////////////////////////////////////////////////////////////// | |
1139 // PUBLIC C INTERFACES | |
1140 | |
1141 void | |
1142 DWrite_Init(void) | |
1143 { | |
1144 #ifdef DYNAMIC_DIRECTX | |
1145 // Load libraries. | |
1146 hD2D1DLL = vimLoadLib(const_cast<char*>("d2d1.dll")); | |
1147 hDWriteDLL = vimLoadLib(const_cast<char*>("dwrite.dll")); | |
1148 if (hD2D1DLL == NULL || hDWriteDLL == NULL) | |
1149 { | |
1150 DWrite_Final(); | |
1151 return; | |
1152 } | |
1153 // Get address of procedures. | |
1154 pGetUserDefaultLocaleName = (PGETUSERDEFAULTLOCALENAME)GetProcAddress( | |
1155 GetModuleHandle("kernel32.dll"), "GetUserDefaultLocaleName"); | |
1156 pD2D1CreateFactory = (PD2D1CREATEFACTORY)GetProcAddress(hD2D1DLL, | |
1157 "D2D1CreateFactory"); | |
1158 pDWriteCreateFactory = (PDWRITECREATEFACTORY)GetProcAddress(hDWriteDLL, | |
1159 "DWriteCreateFactory"); | |
1160 #endif | |
1161 } | |
1162 | |
1163 void | |
1164 DWrite_Final(void) | |
1165 { | |
1166 #ifdef DYNAMIC_DIRECTX | |
1167 pGetUserDefaultLocaleName = NULL; | |
1168 pD2D1CreateFactory = NULL; | |
1169 pDWriteCreateFactory = NULL; | |
1170 unload(hDWriteDLL); | |
1171 unload(hD2D1DLL); | |
1172 #endif | |
1173 } | |
1174 | |
1175 DWriteContext * | |
1176 DWriteContext_Open(void) | |
1177 { | |
1178 #ifdef DYNAMIC_DIRECTX | |
1179 if (pGetUserDefaultLocaleName == NULL || pD2D1CreateFactory == NULL | |
1180 || pDWriteCreateFactory == NULL) | |
1181 return NULL; | |
1182 #endif | |
1183 return new DWriteContext(); | |
1184 } | |
1185 | |
1186 void | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1187 DWriteContext_BindDC(DWriteContext *ctx, HDC hdc, const RECT *rect) |
6110 | 1188 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1189 if (ctx != NULL) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1190 ctx->BindDC(hdc, rect); |
6110 | 1191 } |
1192 | |
1193 void | |
1194 DWriteContext_SetFont(DWriteContext *ctx, HFONT hFont) | |
1195 { | |
1196 if (ctx != NULL) | |
1197 ctx->SetFont(hFont); | |
1198 } | |
1199 | |
1200 void | |
1201 DWriteContext_DrawText( | |
1202 DWriteContext *ctx, | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1203 const WCHAR *text, |
6110 | 1204 int len, |
1205 int x, | |
1206 int y, | |
1207 int w, | |
1208 int h, | |
1209 int cellWidth, | |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1210 COLORREF color, |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1211 UINT fuOptions, |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1212 const RECT *lprc, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1213 const INT *lpDx) |
6110 | 1214 { |
1215 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
|
1216 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
|
1217 fuOptions, lprc, lpDx); |
6110 | 1218 } |
1219 | |
1220 void | |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1221 DWriteContext_FillRect(DWriteContext *ctx, const RECT *rc, COLORREF color) |
6110 | 1222 { |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1223 if (ctx != NULL) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1224 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
|
1225 } |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1226 |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1227 void |
12986
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1228 DWriteContext_DrawLine(DWriteContext *ctx, int x1, int y1, int x2, int y2, |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1229 COLORREF color) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1230 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1231 if (ctx != NULL) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1232 ctx->DrawLine(x1, y1, x2, y2, color); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1233 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1234 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1235 void |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1236 DWriteContext_SetPixel(DWriteContext *ctx, int x, int y, COLORREF color) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1237 { |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1238 if (ctx != NULL) |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1239 ctx->SetPixel(x, y, color); |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1240 } |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1241 |
18e6f4addce9
patch 8.0.1369: MS-Windows: drawing underline slow, mFallbackDC not updated
Christian Brabandt <cb@256bit.org>
parents:
12934
diff
changeset
|
1242 void |
12934
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1243 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
|
1244 { |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1245 if (ctx != NULL) |
2ebc3df65ca2
patch 8.0.1343: MS-Windows: does not show colored emojis
Christian Brabandt <cb@256bit.org>
parents:
8641
diff
changeset
|
1246 ctx->Flush(); |
6110 | 1247 } |
1248 | |
1249 void | |
1250 DWriteContext_Close(DWriteContext *ctx) | |
1251 { | |
1252 delete ctx; | |
1253 } | |
1254 | |
1255 void | |
1256 DWriteContext_SetRenderingParams( | |
1257 DWriteContext *ctx, | |
1258 const DWriteRenderingParams *params) | |
1259 { | |
1260 if (ctx != NULL) | |
1261 ctx->SetRenderingParams(params); | |
1262 } | |
1263 | |
1264 DWriteRenderingParams * | |
1265 DWriteContext_GetRenderingParams( | |
1266 DWriteContext *ctx, | |
1267 DWriteRenderingParams *params) | |
1268 { | |
1269 if (ctx != NULL) | |
1270 return ctx->GetRenderingParams(params); | |
1271 else | |
1272 return NULL; | |
1273 } |