annotate src/gui_dwrite.cpp @ 12084:69ce6b3f0834 v8.0.0922

patch 8.0.0922: quickfix list always added after current one commit https://github.com/vim/vim/commit/55b6926450d75788dada3ff44a35e328224df758 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 13 13:42:01 2017 +0200 patch 8.0.0922: quickfix list always added after current one Problem: Quickfix list always added after current one. Solution: Make it possible to add a quickfix list after the last one. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Sun, 13 Aug 2017 13:45:04 +0200
parents 0af716a4f5d2
children 2ebc3df65ca2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet: */
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 /*
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 * Author: MURAOKA Taro <koron.kaoriya@gmail.com>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 * Contributors:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 * - Ken Takata
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 * Copyright (C) 2013 MURAOKA Taro <koron.kaoriya@gmail.com>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 * THIS FILE IS DISTRIBUTED UNDER THE VIM LICENSE.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 */
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 #define WIN32_LEAN_AND_MEAN
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 #ifndef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 # if WINVER < 0x0600
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 # error WINVER must be 0x0600 or above to use DirectWrite(DirectX)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 # endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 #include <windows.h>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 #include <crtdbg.h>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 #include <assert.h>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 #include <math.h>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 #include <d2d1.h>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 #include <d2d1helper.h>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 #include <dwrite.h>
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 #include "gui_dwrite.h"
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 #ifdef __MINGW32__
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 # define __maybenull SAL__maybenull
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 # define __in SAL__in
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 # define __out SAL__out
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35
8641
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8271
diff changeset
36 #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
37 # define FINAL final
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8271
diff changeset
38 #else
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8271
diff changeset
39 # define FINAL
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8271
diff changeset
40 #endif
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8271
diff changeset
41
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 extern "C" HINSTANCE vimLoadLib(char *name);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 typedef int (WINAPI *PGETUSERDEFAULTLOCALENAME)(LPWSTR, int);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 typedef HRESULT (WINAPI *PD2D1CREATEFACTORY)(D2D1_FACTORY_TYPE,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 REFIID, const D2D1_FACTORY_OPTIONS *, void **);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 typedef HRESULT (WINAPI *PDWRITECREATEFACTORY)(DWRITE_FACTORY_TYPE,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 REFIID, IUnknown **);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 static HINSTANCE hD2D1DLL = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 static HINSTANCE hDWriteDLL = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 static PGETUSERDEFAULTLOCALENAME pGetUserDefaultLocaleName = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 static PD2D1CREATEFACTORY pD2D1CreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 static PDWRITECREATEFACTORY pDWriteCreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 #define GetUserDefaultLocaleName (*pGetUserDefaultLocaleName)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 #define D2D1CreateFactory (*pD2D1CreateFactory)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 #define DWriteCreateFactory (*pDWriteCreateFactory)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 static void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 unload(HINSTANCE &hinst)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 if (hinst != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 FreeLibrary(hinst);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 hinst = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 #endif // DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 template <class T> inline void SafeRelease(T **ppT)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 if (*ppT)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 (*ppT)->Release();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 *ppT = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82 struct GdiTextRendererContext
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 // const fields.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 COLORREF color;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 FLOAT cellWidth;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 // working fields.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 FLOAT offsetX;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 static DWRITE_PIXEL_GEOMETRY
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 ToPixelGeometry(int value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 switch (value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 case 0:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 return DWRITE_PIXEL_GEOMETRY_FLAT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 case 1:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 return DWRITE_PIXEL_GEOMETRY_RGB;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 case 2:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 return DWRITE_PIXEL_GEOMETRY_BGR;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 static int
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 ToInt(DWRITE_PIXEL_GEOMETRY value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 switch (value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 case DWRITE_PIXEL_GEOMETRY_FLAT:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 return 0;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 case DWRITE_PIXEL_GEOMETRY_RGB:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 return 1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 case DWRITE_PIXEL_GEOMETRY_BGR:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 return 2;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 return -1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 static DWRITE_RENDERING_MODE
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 ToRenderingMode(int value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 switch (value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 case 0:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 return DWRITE_RENDERING_MODE_DEFAULT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 case 1:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 return DWRITE_RENDERING_MODE_ALIASED;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 case 2:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 case 3:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137 case 4:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 case 5:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141 case 6:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 return DWRITE_RENDERING_MODE_OUTLINE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 static D2D1_TEXT_ANTIALIAS_MODE
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 ToTextAntialiasMode(int value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 switch (value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 case 0:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 return D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 case 1:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155 return D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 case 2:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 return D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 case 3:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 return D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 static int
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 ToInt(DWRITE_RENDERING_MODE value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 switch (value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 case DWRITE_RENDERING_MODE_DEFAULT:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 return 0;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 case DWRITE_RENDERING_MODE_ALIASED:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 return 1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 return 2;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 return 3;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 return 4;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 return 5;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 case DWRITE_RENDERING_MODE_OUTLINE:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 return 6;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 return -1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187 class AdjustedGlyphRun : public DWRITE_GLYPH_RUN
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 private:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 FLOAT mDelta;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 FLOAT *mAdjustedAdvances;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 public:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 AdjustedGlyphRun(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 const DWRITE_GLYPH_RUN *glyphRun,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 FLOAT cellWidth) :
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 DWRITE_GLYPH_RUN(*glyphRun),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 mDelta(0.0f),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 mAdjustedAdvances(new FLOAT[glyphRun->glyphCount])
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201 assert(cellWidth != 0.0f);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 for (UINT32 i = 0; i < glyphRun->glyphCount; ++i)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 FLOAT orig = glyphRun->glyphAdvances[i];
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 FLOAT adjusted = adjustToCell(orig, cellWidth);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 mAdjustedAdvances[i] = adjusted;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 mDelta += adjusted - orig;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 glyphAdvances = mAdjustedAdvances;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 ~AdjustedGlyphRun(void)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 delete[] mAdjustedAdvances;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 FLOAT getDelta(void) const
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 return mDelta;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 static FLOAT adjustToCell(FLOAT value, FLOAT cellWidth)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 int cellCount = (int)floor(value / cellWidth + 0.5f);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 if (cellCount < 1)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 cellCount = 1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 return cellCount * cellWidth;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230
8641
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8271
diff changeset
231 class GdiTextRenderer FINAL : public IDWriteTextRenderer
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233 public:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 GdiTextRenderer(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235 IDWriteBitmapRenderTarget* bitmapRenderTarget,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236 IDWriteRenderingParams* renderingParams) :
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
237 cRefCount_(0),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
238 pRenderTarget_(bitmapRenderTarget),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239 pRenderingParams_(renderingParams)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 pRenderTarget_->AddRef();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 pRenderingParams_->AddRef();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 AddRef();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
244 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245
8271
770774e66011 commit https://github.com/vim/vim/commit/edb4f2b3601b0abd47091606269c0ac3244a805b
Christian Brabandt <cb@256bit.org>
parents: 7547
diff changeset
246 // add "virtual" to avoid a compiler warning
770774e66011 commit https://github.com/vim/vim/commit/edb4f2b3601b0abd47091606269c0ac3244a805b
Christian Brabandt <cb@256bit.org>
parents: 7547
diff changeset
247 virtual ~GdiTextRenderer()
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
248 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 SafeRelease(&pRenderTarget_);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 SafeRelease(&pRenderingParams_);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253 IFACEMETHOD(IsPixelSnappingDisabled)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 __out BOOL* isDisabled)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
256 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257 *isDisabled = FALSE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258 return S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
260
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 IFACEMETHOD(GetCurrentTransform)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263 __out DWRITE_MATRIX* transform)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 {
8271
770774e66011 commit https://github.com/vim/vim/commit/edb4f2b3601b0abd47091606269c0ac3244a805b
Christian Brabandt <cb@256bit.org>
parents: 7547
diff changeset
265 // forward the render target's transform
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
266 pRenderTarget_->GetCurrentTransform(transform);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 return S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
268 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
270 IFACEMETHOD(GetPixelsPerDip)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 __out FLOAT* pixelsPerDip)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 *pixelsPerDip = pRenderTarget_->GetPixelsPerDip();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 return S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 IFACEMETHOD(DrawGlyphRun)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 FLOAT baselineOriginX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281 FLOAT baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 DWRITE_MEASURING_MODE measuringMode,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 __in DWRITE_GLYPH_RUN const* glyphRun,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 IUnknown* clientDrawingEffect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 HRESULT hr = S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289 GdiTextRendererContext *context =
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 reinterpret_cast<GdiTextRendererContext*>(clientDrawingContext);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
292 AdjustedGlyphRun adjustedGlyphRun(glyphRun, context->cellWidth);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 // Pass on the drawing call to the render target to do the real work.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 RECT dirtyRect = {0};
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297 hr = pRenderTarget_->DrawGlyphRun(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
298 baselineOriginX + context->offsetX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299 baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300 measuringMode,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
301 &adjustedGlyphRun,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
302 pRenderingParams_,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 context->color,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304 &dirtyRect);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 context->offsetX += adjustedGlyphRun.getDelta();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
307
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
308 return hr;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
309 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
310
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
311 IFACEMETHOD(DrawUnderline)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
312 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
313 FLOAT baselineOriginX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 FLOAT baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 __in DWRITE_UNDERLINE const* underline,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 IUnknown* clientDrawingEffect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 return E_NOTIMPL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
321 IFACEMETHOD(DrawStrikethrough)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 FLOAT baselineOriginX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 FLOAT baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 __in DWRITE_STRIKETHROUGH const* strikethrough,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 IUnknown* clientDrawingEffect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328 return E_NOTIMPL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
331 IFACEMETHOD(DrawInlineObject)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
332 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
333 FLOAT originX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
334 FLOAT originY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 IDWriteInlineObject* inlineObject,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
336 BOOL isSideways,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337 BOOL isRightToLeft,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 IUnknown* clientDrawingEffect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
340 return E_NOTIMPL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
341 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
342
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 public:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 IFACEMETHOD_(unsigned long, AddRef) ()
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
345 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
346 return InterlockedIncrement(&cRefCount_);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
347 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
348
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 IFACEMETHOD_(unsigned long, Release) ()
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 long newCount = InterlockedDecrement(&cRefCount_);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 if (newCount == 0)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 delete this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 return 0;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
358 return newCount;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
359 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
360
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
361 IFACEMETHOD(QueryInterface)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
362 IID const& riid,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
363 void** ppvObject)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
364 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
365 if (__uuidof(IDWriteTextRenderer) == riid)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
366 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
367 *ppvObject = this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
368 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
369 else if (__uuidof(IDWritePixelSnapping) == riid)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 *ppvObject = this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
373 else if (__uuidof(IUnknown) == riid)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
374 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
375 *ppvObject = this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
377 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
378 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379 *ppvObject = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 return E_FAIL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
383 return S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
384 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
385
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 private:
6120
f62b2e76dd80 updated for version 7.4.398
Bram Moolenaar <bram@vim.org>
parents: 6110
diff changeset
387 long cRefCount_;
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
388 IDWriteBitmapRenderTarget* pRenderTarget_;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
389 IDWriteRenderingParams* pRenderingParams_;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390 };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392 struct DWriteContext {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 FLOAT mDpiScaleX;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
394 FLOAT mDpiScaleY;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395 bool mDrawing;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 ID2D1Factory *mD2D1Factory;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399 ID2D1DCRenderTarget *mRT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 ID2D1SolidColorBrush *mBrush;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
402 IDWriteFactory *mDWriteFactory;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 IDWriteGdiInterop *mGdiInterop;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404 IDWriteRenderingParams *mRenderingParams;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
405 IDWriteTextFormat *mTextFormat;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
406
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
407 HFONT mLastHFont;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
408 DWRITE_FONT_WEIGHT mFontWeight;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
409 DWRITE_FONT_STYLE mFontStyle;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
410
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411 D2D1_TEXT_ANTIALIAS_MODE mTextAntialiasMode;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413 // METHODS
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415 DWriteContext();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417 virtual ~DWriteContext();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
418
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 HRESULT SetLOGFONT(const LOGFONTW &logFont, float fontSize);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
420
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421 void SetFont(HFONT hFont);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
423 void SetFont(const LOGFONTW &logFont);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
424
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 void DrawText(HDC hdc, const WCHAR* text, int len,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 int x, int y, int w, int h, int cellWidth, COLORREF color);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
428 float PixelsToDipsX(int x);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
429
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 float PixelsToDipsY(int y);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
431
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
432 void SetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433 const DWriteRenderingParams *params);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
434
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
435 DWriteRenderingParams *GetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
436 DWriteRenderingParams *params);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
439 DWriteContext::DWriteContext() :
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
440 mDpiScaleX(1.f),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
441 mDpiScaleY(1.f),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
442 mDrawing(false),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
443 mD2D1Factory(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
444 mRT(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
445 mBrush(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
446 mDWriteFactory(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
447 mGdiInterop(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
448 mRenderingParams(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
449 mTextFormat(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
450 mLastHFont(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
451 mFontWeight(DWRITE_FONT_WEIGHT_NORMAL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
452 mFontStyle(DWRITE_FONT_STYLE_NORMAL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
453 mTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
454 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
455 HRESULT hr;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 HDC screen = ::GetDC(0);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458 mDpiScaleX = ::GetDeviceCaps(screen, LOGPIXELSX) / 96.0f;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
459 mDpiScaleY = ::GetDeviceCaps(screen, LOGPIXELSY) / 96.0f;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460 ::ReleaseDC(0, screen);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
461
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
462 hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
463 __uuidof(ID2D1Factory), NULL,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
464 reinterpret_cast<void**>(&mD2D1Factory));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
465 _RPT2(_CRT_WARN, "D2D1CreateFactory: hr=%p p=%p\n", hr, mD2D1Factory);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
466
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
467 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
468 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
469 D2D1_RENDER_TARGET_PROPERTIES props = {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
470 D2D1_RENDER_TARGET_TYPE_DEFAULT,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
471 { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE },
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
472 0, 0,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
473 D2D1_RENDER_TARGET_USAGE_NONE,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
474 D2D1_FEATURE_LEVEL_DEFAULT
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
475 };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
476 hr = mD2D1Factory->CreateDCRenderTarget(&props, &mRT);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
477 _RPT2(_CRT_WARN, "CreateDCRenderTarget: hr=%p p=%p\n", hr, mRT);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
478 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
479
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
480 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
481 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
482 hr = mRT->CreateSolidColorBrush(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
483 D2D1::ColorF(D2D1::ColorF::Black),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
484 &mBrush);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
485 _RPT2(_CRT_WARN, "CreateSolidColorBrush: hr=%p p=%p\n", hr, mBrush);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
486 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
487
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
488 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
489 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
490 hr = DWriteCreateFactory(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
491 DWRITE_FACTORY_TYPE_SHARED,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
492 __uuidof(IDWriteFactory),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
493 reinterpret_cast<IUnknown**>(&mDWriteFactory));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
494 _RPT2(_CRT_WARN, "DWriteCreateFactory: hr=%p p=%p\n", hr,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
495 mDWriteFactory);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
496 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
497
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
498 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
499 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
500 hr = mDWriteFactory->GetGdiInterop(&mGdiInterop);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
501 _RPT2(_CRT_WARN, "GetGdiInterop: hr=%p p=%p\n", hr, mGdiInterop);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
502 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
503
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
504 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
505 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
506 hr = mDWriteFactory->CreateRenderingParams(&mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
507 _RPT2(_CRT_WARN, "CreateRenderingParams: hr=%p p=%p\n", hr,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
508 mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
509 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
510 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
511
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
512 DWriteContext::~DWriteContext()
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
513 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
514 SafeRelease(&mTextFormat);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
515 SafeRelease(&mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
516 SafeRelease(&mGdiInterop);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
517 SafeRelease(&mDWriteFactory);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
518 SafeRelease(&mBrush);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
519 SafeRelease(&mRT);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
520 SafeRelease(&mD2D1Factory);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
521 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
522
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
523 HRESULT
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
524 DWriteContext::SetLOGFONT(const LOGFONTW &logFont, float fontSize)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
525 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
526 // Most of this function is copy from: http://msdn.microsoft.com/en-us/library/windows/desktop/dd941783(v=vs.85).aspx
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
527 HRESULT hr = S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529 IDWriteFont *font = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530 IDWriteFontFamily *fontFamily = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 IDWriteLocalizedStrings *localizedFamilyNames = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
532
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
533 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
534 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
535 hr = mGdiInterop->CreateFontFromLOGFONT(&logFont, &font);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
536 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
537
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
538 // Get the font family to which this font belongs.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
539 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
540 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
541 hr = font->GetFontFamily(&fontFamily);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
542 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
543
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
544 // Get the family names. This returns an object that encapsulates one or
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
545 // more names with the same meaning but in different languages.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
546 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
547 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
548 hr = fontFamily->GetFamilyNames(&localizedFamilyNames);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
549 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
550
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
551 // Get the family name at index zero. If we were going to display the name
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
552 // we'd want to try to find one that matched the use locale, but for
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
553 // purposes of creating a text format object any language will do.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
554
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
555 wchar_t familyName[100];
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
556 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
557 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
558 hr = localizedFamilyNames->GetString(0, familyName,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
559 ARRAYSIZE(familyName));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
560 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
561
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
562 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
563 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
564 // If no font size was passed in use the lfHeight of the LOGFONT.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
565 if (fontSize == 0)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
566 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
567 // Convert from pixels to DIPs.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
568 fontSize = PixelsToDipsY(logFont.lfHeight);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
569 if (fontSize < 0)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
570 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
571 // Negative lfHeight represents the size of the em unit.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
572 fontSize = -fontSize;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
573 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
574 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
575 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
576 // Positive lfHeight represents the cell height (ascent +
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
577 // descent).
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
578 DWRITE_FONT_METRICS fontMetrics;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
579 font->GetMetrics(&fontMetrics);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
580
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
581 // Convert the cell height (ascent + descent) from design units
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
582 // to ems.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
583 float cellHeight = static_cast<float>(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
584 fontMetrics.ascent + fontMetrics.descent)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
585 / fontMetrics.designUnitsPerEm;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
586
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
587 // Divide the font size by the cell height to get the font em
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
588 // size.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
589 fontSize /= cellHeight;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
590 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
591 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
592 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
593
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
594 // The text format includes a locale name. Ideally, this would be the
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
595 // language of the text, which may or may not be the same as the primary
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
596 // language of the user. However, for our purposes the user locale will do.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
597 wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
598 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
599 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
600 if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
601 hr = HRESULT_FROM_WIN32(GetLastError());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
602 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
603
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
604 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
605 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606 // Create the text format object.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 hr = mDWriteFactory->CreateTextFormat(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 familyName,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
609 NULL, // no custom font collection
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
610 font->GetWeight(),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
611 font->GetStyle(),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
612 font->GetStretch(),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
613 fontSize,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
614 localeName,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615 &mTextFormat);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
616 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
617
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
618 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
619 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 mFontWeight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
621 mFontStyle = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
622 : DWRITE_FONT_STYLE_NORMAL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
623 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
624
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
625 SafeRelease(&localizedFamilyNames);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
626 SafeRelease(&fontFamily);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 SafeRelease(&font);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
628
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629 return hr;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
630 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
631
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
632 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
633 DWriteContext::SetFont(HFONT hFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
634 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
635 if (mLastHFont != hFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
636 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
637 LOGFONTW lf;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
638 if (GetObjectW(hFont, sizeof(lf), &lf))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
639 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
640 SetFont(lf);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
641 mLastHFont = hFont;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
642 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
643 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
644 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
645
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
646 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
647 DWriteContext::SetFont(const LOGFONTW &logFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
648 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
649 SafeRelease(&mTextFormat);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 mLastHFont = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
652 HRESULT hr = SetLOGFONT(logFont, 0.f);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
653
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
654 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
655 hr = mTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
656
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
657 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
658 hr = mTextFormat->SetParagraphAlignment(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
659 DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
660
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
661 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
662 hr = mTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
663 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
664
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
665 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 DWriteContext::DrawText(HDC hdc, const WCHAR* text, int len,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 int x, int y, int w, int h, int cellWidth, COLORREF color)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
668 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
669 HRESULT hr = S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
670 IDWriteBitmapRenderTarget *bmpRT = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
671
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
672 // Skip when any fonts are not set.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
673 if (mTextFormat == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 return;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 // Check possibility of zero divided error.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677 if (cellWidth == 0 || mDpiScaleX == 0.0f || mDpiScaleY == 0.0f)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 return;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
679
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
680 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 hr = mGdiInterop->CreateBitmapRenderTarget(hdc, w, h, &bmpRT);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
682
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
683 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
684 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
685 IDWriteTextLayout *textLayout = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
686
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
687 HDC memdc = bmpRT->GetMemoryDC();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
688 BitBlt(memdc, 0, 0, w, h, hdc, x, y, SRCCOPY);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
689
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
690 hr = mDWriteFactory->CreateGdiCompatibleTextLayout(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 text, len, mTextFormat, PixelsToDipsX(w),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
692 PixelsToDipsY(h), mDpiScaleX, NULL, TRUE, &textLayout);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
693
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
694 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
695 {
7547
567e027a3ea1 commit https://github.com/vim/vim/commit/5fa4d448fb717874b6619bcda62e42190702997c
Christian Brabandt <cb@256bit.org>
parents: 6120
diff changeset
696 DWRITE_TEXT_RANGE textRange = { 0, (UINT32)len };
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
697 textLayout->SetFontWeight(mFontWeight, textRange);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
698 textLayout->SetFontStyle(mFontStyle, textRange);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
699 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
700
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
701 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
702 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
703 GdiTextRenderer *renderer = new GdiTextRenderer(bmpRT,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
704 mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
705 GdiTextRendererContext data = {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
706 color,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
707 PixelsToDipsX(cellWidth),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
708 0.0f
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
709 };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
710 textLayout->Draw(&data, renderer, 0, 0);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
711 SafeRelease(&renderer);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
712 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
713
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
714 BitBlt(hdc, x, y, w, h, memdc, 0, 0, SRCCOPY);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
715
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
716 SafeRelease(&textLayout);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
717 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
718
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
719 SafeRelease(&bmpRT);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
720 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
721
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
722 float
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
723 DWriteContext::PixelsToDipsX(int x)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
724 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
725 return x / mDpiScaleX;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
726 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
727
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
728 float
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729 DWriteContext::PixelsToDipsY(int y)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
730 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
731 return y / mDpiScaleY;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
733
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
734 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
735 DWriteContext::SetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
736 const DWriteRenderingParams *params)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
737 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
738 if (mDWriteFactory == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
739 return;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
741 IDWriteRenderingParams *renderingParams = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
742 D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode =
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
743 D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
744 HRESULT hr;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
745 if (params != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
746 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
747 hr = mDWriteFactory->CreateCustomRenderingParams(params->gamma,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
748 params->enhancedContrast, params->clearTypeLevel,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
749 ToPixelGeometry(params->pixelGeometry),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750 ToRenderingMode(params->renderingMode), &renderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
751 textAntialiasMode = ToTextAntialiasMode(params->textAntialiasMode);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
752 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
753 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 hr = mDWriteFactory->CreateRenderingParams(&renderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755 if (SUCCEEDED(hr) && renderingParams != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
756 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
757 SafeRelease(&mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
758 mRenderingParams = renderingParams;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
759 mTextAntialiasMode = textAntialiasMode;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
760 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
761 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
762
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
763 DWriteRenderingParams *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
764 DWriteContext::GetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
765 DWriteRenderingParams *params)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
766 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
767 if (params != NULL && mRenderingParams != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
768 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
769 params->gamma = mRenderingParams->GetGamma();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
770 params->enhancedContrast = mRenderingParams->GetEnhancedContrast();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
771 params->clearTypeLevel = mRenderingParams->GetClearTypeLevel();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
772 params->pixelGeometry = ToInt(mRenderingParams->GetPixelGeometry());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
773 params->renderingMode = ToInt(mRenderingParams->GetRenderingMode());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
774 params->textAntialiasMode = mTextAntialiasMode;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
775 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
776 return params;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
777 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
778
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779 ////////////////////////////////////////////////////////////////////////////
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780 // PUBLIC C INTERFACES
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
781
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
782 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783 DWrite_Init(void)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
784 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
785 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
786 // Load libraries.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
787 hD2D1DLL = vimLoadLib(const_cast<char*>("d2d1.dll"));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
788 hDWriteDLL = vimLoadLib(const_cast<char*>("dwrite.dll"));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
789 if (hD2D1DLL == NULL || hDWriteDLL == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
790 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
791 DWrite_Final();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
792 return;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
793 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794 // Get address of procedures.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795 pGetUserDefaultLocaleName = (PGETUSERDEFAULTLOCALENAME)GetProcAddress(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
796 GetModuleHandle("kernel32.dll"), "GetUserDefaultLocaleName");
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
797 pD2D1CreateFactory = (PD2D1CREATEFACTORY)GetProcAddress(hD2D1DLL,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
798 "D2D1CreateFactory");
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
799 pDWriteCreateFactory = (PDWRITECREATEFACTORY)GetProcAddress(hDWriteDLL,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
800 "DWriteCreateFactory");
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
801 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
802 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
803
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
804 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
805 DWrite_Final(void)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
806 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
807 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
808 pGetUserDefaultLocaleName = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
809 pD2D1CreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
810 pDWriteCreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
811 unload(hDWriteDLL);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
812 unload(hD2D1DLL);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
813 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
814 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
815
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
816 DWriteContext *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
817 DWriteContext_Open(void)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
818 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
819 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
820 if (pGetUserDefaultLocaleName == NULL || pD2D1CreateFactory == NULL
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
821 || pDWriteCreateFactory == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
822 return NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
823 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
824 return new DWriteContext();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
825 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
826
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
827 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
828 DWriteContext_BeginDraw(DWriteContext *ctx)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
829 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
830 if (ctx != NULL && ctx->mRT != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
831 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
832 ctx->mRT->BeginDraw();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
833 ctx->mRT->SetTransform(D2D1::IdentityMatrix());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
834 ctx->mDrawing = true;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
835 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
836 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
837
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
838 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
839 DWriteContext_BindDC(DWriteContext *ctx, HDC hdc, RECT *rect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
840 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
841 if (ctx != NULL && ctx->mRT != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
842 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
843 ctx->mRT->BindDC(hdc, rect);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
844 ctx->mRT->SetTextAntialiasMode(ctx->mTextAntialiasMode);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
845 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
846 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
847
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
848 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
849 DWriteContext_SetFont(DWriteContext *ctx, HFONT hFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
850 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
851 if (ctx != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
852 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
853 ctx->SetFont(hFont);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
854 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
855 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
856
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
857 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
858 DWriteContext_DrawText(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
859 DWriteContext *ctx,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
860 HDC hdc,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
861 const WCHAR* text,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
862 int len,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
863 int x,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
864 int y,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
865 int w,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
866 int h,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
867 int cellWidth,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
868 COLORREF color)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
869 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
870 if (ctx != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
871 ctx->DrawText(hdc, text, len, x, y, w, h, cellWidth, color);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
872 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
873
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
874 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
875 DWriteContext_EndDraw(DWriteContext *ctx)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
876 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
877 if (ctx != NULL && ctx->mRT != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
878 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
879 ctx->mRT->EndDraw();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
880 ctx->mDrawing = false;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
881 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
882 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
883
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
884 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
885 DWriteContext_Close(DWriteContext *ctx)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
886 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
887 delete ctx;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
888 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
889
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
890 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
891 DWriteContext_SetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
892 DWriteContext *ctx,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
893 const DWriteRenderingParams *params)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
894 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
895 if (ctx != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
896 ctx->SetRenderingParams(params);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
897 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
898
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
899 DWriteRenderingParams *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
900 DWriteContext_GetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
901 DWriteContext *ctx,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
902 DWriteRenderingParams *params)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
903 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
904 if (ctx != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
905 return ctx->GetRenderingParams(params);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
906 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
907 return NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
908 }