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