annotate src/gui_dwrite.cpp @ 7270:33e8080d7863

Added tag v7.4.942 for changeset 5fb84b6f61a54d7b79a160dff52724e12889f1fb
author Christian Brabandt <cb@256bit.org>
date Thu, 26 Nov 2015 07:54:03 +0100
parents f62b2e76dd80
children 567e027a3ea1
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 extern "C" HINSTANCE vimLoadLib(char *name);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 typedef int (WINAPI *PGETUSERDEFAULTLOCALENAME)(LPWSTR, int);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 typedef HRESULT (WINAPI *PD2D1CREATEFACTORY)(D2D1_FACTORY_TYPE,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 REFIID, const D2D1_FACTORY_OPTIONS *, void **);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 typedef HRESULT (WINAPI *PDWRITECREATEFACTORY)(DWRITE_FACTORY_TYPE,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 REFIID, IUnknown **);
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 static HINSTANCE hD2D1DLL = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 static HINSTANCE hDWriteDLL = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 static PGETUSERDEFAULTLOCALENAME pGetUserDefaultLocaleName = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 static PD2D1CREATEFACTORY pD2D1CreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 static PDWRITECREATEFACTORY pDWriteCreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 #define GetUserDefaultLocaleName (*pGetUserDefaultLocaleName)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 #define D2D1CreateFactory (*pD2D1CreateFactory)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 #define DWriteCreateFactory (*pDWriteCreateFactory)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 static void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 unload(HINSTANCE &hinst)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 if (hinst != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 FreeLibrary(hinst);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 hinst = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 }
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 #endif // DYNAMIC_DIRECTX
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 template <class T> inline void SafeRelease(T **ppT)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 if (*ppT)
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 (*ppT)->Release();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 *ppT = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 }
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 struct GdiTextRendererContext
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 // const fields.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 COLORREF color;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 FLOAT cellWidth;
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 // working fields.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 FLOAT offsetX;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 static DWRITE_PIXEL_GEOMETRY
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 ToPixelGeometry(int value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 switch (value)
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 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 case 0:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 return DWRITE_PIXEL_GEOMETRY_FLAT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 case 1:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 return DWRITE_PIXEL_GEOMETRY_RGB;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 case 2:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 return DWRITE_PIXEL_GEOMETRY_BGR;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 static int
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 ToInt(DWRITE_PIXEL_GEOMETRY value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 switch (value)
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 case DWRITE_PIXEL_GEOMETRY_FLAT:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 return 0;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 case DWRITE_PIXEL_GEOMETRY_RGB:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 return 1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 case DWRITE_PIXEL_GEOMETRY_BGR:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 return 2;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 return -1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 static DWRITE_RENDERING_MODE
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 ToRenderingMode(int value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 switch (value)
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 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 case 0:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 return DWRITE_RENDERING_MODE_DEFAULT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 case 1:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 return DWRITE_RENDERING_MODE_ALIASED;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 case 2:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 case 3:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 case 4:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 case 5:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 case 6:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 return DWRITE_RENDERING_MODE_OUTLINE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 static D2D1_TEXT_ANTIALIAS_MODE
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141 ToTextAntialiasMode(int value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 switch (value)
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 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 case 0:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 return D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 case 1:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 return D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 case 2:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 return D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 case 3:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 return D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 static int
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 ToInt(DWRITE_RENDERING_MODE value)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 switch (value)
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 case DWRITE_RENDERING_MODE_DEFAULT:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 return 0;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 case DWRITE_RENDERING_MODE_ALIASED:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 return 1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 return 2;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 return 3;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 return 4;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 return 5;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 case DWRITE_RENDERING_MODE_OUTLINE:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 return 6;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 default:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 return -1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 class AdjustedGlyphRun : public DWRITE_GLYPH_RUN
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 private:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 FLOAT mDelta;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 FLOAT *mAdjustedAdvances;
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 public:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 AdjustedGlyphRun(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 const DWRITE_GLYPH_RUN *glyphRun,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 FLOAT cellWidth) :
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 DWRITE_GLYPH_RUN(*glyphRun),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 mDelta(0.0f),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 mAdjustedAdvances(new FLOAT[glyphRun->glyphCount])
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 assert(cellWidth != 0.0f);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 for (UINT32 i = 0; i < glyphRun->glyphCount; ++i)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 FLOAT orig = glyphRun->glyphAdvances[i];
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 FLOAT adjusted = adjustToCell(orig, cellWidth);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 mAdjustedAdvances[i] = adjusted;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201 mDelta += adjusted - orig;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 glyphAdvances = mAdjustedAdvances;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 ~AdjustedGlyphRun(void)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 delete[] mAdjustedAdvances;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 }
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 FLOAT getDelta(void) const
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 return mDelta;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 }
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 static FLOAT adjustToCell(FLOAT value, FLOAT cellWidth)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 int cellCount = (int)floor(value / cellWidth + 0.5f);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 if (cellCount < 1)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 cellCount = 1;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 return cellCount * cellWidth;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 }
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 class GdiTextRenderer : public IDWriteTextRenderer
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 public:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 GdiTextRenderer(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 IDWriteBitmapRenderTarget* bitmapRenderTarget,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 IDWriteRenderingParams* renderingParams) :
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 cRefCount_(0),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 pRenderTarget_(bitmapRenderTarget),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233 pRenderingParams_(renderingParams)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235 pRenderTarget_->AddRef();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236 pRenderingParams_->AddRef();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
237 AddRef();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
238 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240 ~GdiTextRenderer()
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 SafeRelease(&pRenderTarget_);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 SafeRelease(&pRenderingParams_);
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
246 IFACEMETHOD(IsPixelSnappingDisabled)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
247 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
248 __out BOOL* isDisabled)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 *isDisabled = FALSE;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 return S_OK;
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 IFACEMETHOD(GetCurrentTransform)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
256 __out DWRITE_MATRIX* transform)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258 //forward the render target's transform
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 pRenderTarget_->GetCurrentTransform(transform);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
260 return S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263 IFACEMETHOD(GetPixelsPerDip)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
265 __out FLOAT* pixelsPerDip)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
266 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 *pixelsPerDip = pRenderTarget_->GetPixelsPerDip();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
268 return S_OK;
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 IFACEMETHOD(DrawGlyphRun)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 FLOAT baselineOriginX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 FLOAT baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 DWRITE_MEASURING_MODE measuringMode,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276 __in DWRITE_GLYPH_RUN const* glyphRun,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 IUnknown* clientDrawingEffect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 HRESULT hr = S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 GdiTextRendererContext *context =
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 reinterpret_cast<GdiTextRendererContext*>(clientDrawingContext);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 AdjustedGlyphRun adjustedGlyphRun(glyphRun, context->cellWidth);
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 // 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
288 RECT dirtyRect = {0};
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 hr = pRenderTarget_->DrawGlyphRun(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291 baselineOriginX + context->offsetX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
292 baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293 measuringMode,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 &adjustedGlyphRun,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 pRenderingParams_,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296 context->color,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297 &dirtyRect);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
298
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299 context->offsetX += adjustedGlyphRun.getDelta();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
301 return hr;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
302 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304 IFACEMETHOD(DrawUnderline)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 FLOAT baselineOriginX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
307 FLOAT baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
308 __in DWRITE_UNDERLINE const* underline,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
309 IUnknown* clientDrawingEffect)
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 return E_NOTIMPL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
312 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
313
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 IFACEMETHOD(DrawStrikethrough)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 FLOAT baselineOriginX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317 FLOAT baselineOriginY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 __in DWRITE_STRIKETHROUGH const* strikethrough,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 IUnknown* clientDrawingEffect)
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 return E_NOTIMPL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 IFACEMETHOD(DrawInlineObject)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 __maybenull void* clientDrawingContext,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 FLOAT originX,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 FLOAT originY,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328 IDWriteInlineObject* inlineObject,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 BOOL isSideways,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 BOOL isRightToLeft,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
331 IUnknown* clientDrawingEffect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
332 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
333 return E_NOTIMPL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
334 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
336 public:
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337 IFACEMETHOD_(unsigned long, AddRef) ()
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 return InterlockedIncrement(&cRefCount_);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
340 }
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 IFACEMETHOD_(unsigned long, Release) ()
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 long newCount = InterlockedDecrement(&cRefCount_);
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 if (newCount == 0)
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 delete this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 return 0;
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 return newCount;
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 IFACEMETHOD(QueryInterface)(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 IID const& riid,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 void** ppvObject)
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 if (__uuidof(IDWriteTextRenderer) == riid)
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 *ppvObject = this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
361 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
362 else if (__uuidof(IDWritePixelSnapping) == riid)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
363 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
364 *ppvObject = this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
365 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
366 else if (__uuidof(IUnknown) == riid)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
367 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
368 *ppvObject = this;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
369 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372 *ppvObject = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
373 return E_FAIL;
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 return S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
377 }
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 private:
6120
f62b2e76dd80 updated for version 7.4.398
Bram Moolenaar <bram@vim.org>
parents: 6110
diff changeset
380 long cRefCount_;
6110
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 IDWriteBitmapRenderTarget* pRenderTarget_;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382 IDWriteRenderingParams* pRenderingParams_;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
383 };
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 struct DWriteContext {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 FLOAT mDpiScaleX;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
387 FLOAT mDpiScaleY;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
388 bool mDrawing;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
389
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390 ID2D1Factory *mD2D1Factory;
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 ID2D1DCRenderTarget *mRT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 ID2D1SolidColorBrush *mBrush;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
394
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395 IDWriteFactory *mDWriteFactory;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396 IDWriteGdiInterop *mGdiInterop;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 IDWriteRenderingParams *mRenderingParams;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398 IDWriteTextFormat *mTextFormat;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 HFONT mLastHFont;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401 DWRITE_FONT_WEIGHT mFontWeight;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
402 DWRITE_FONT_STYLE mFontStyle;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404 D2D1_TEXT_ANTIALIAS_MODE mTextAntialiasMode;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
405
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
406 // METHODS
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
407
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
408 DWriteContext();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
409
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
410 virtual ~DWriteContext();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412 HRESULT SetLOGFONT(const LOGFONTW &logFont, float fontSize);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414 void SetFont(HFONT hFont);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416 void SetFont(const LOGFONTW &logFont);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
418 void DrawText(HDC hdc, const WCHAR* text, int len,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 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
420
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421 float PixelsToDipsX(int x);
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 float PixelsToDipsY(int y);
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 SetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 const DWriteRenderingParams *params);
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 DWriteRenderingParams *GetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
429 DWriteRenderingParams *params);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 };
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 DWriteContext::DWriteContext() :
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433 mDpiScaleX(1.f),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
434 mDpiScaleY(1.f),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
435 mDrawing(false),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
436 mD2D1Factory(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 mRT(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438 mBrush(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
439 mDWriteFactory(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
440 mGdiInterop(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
441 mRenderingParams(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
442 mTextFormat(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
443 mLastHFont(NULL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
444 mFontWeight(DWRITE_FONT_WEIGHT_NORMAL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
445 mFontStyle(DWRITE_FONT_STYLE_NORMAL),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
446 mTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
447 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
448 HRESULT hr;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
449
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
450 HDC screen = ::GetDC(0);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
451 mDpiScaleX = ::GetDeviceCaps(screen, LOGPIXELSX) / 96.0f;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
452 mDpiScaleY = ::GetDeviceCaps(screen, LOGPIXELSY) / 96.0f;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
453 ::ReleaseDC(0, screen);
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 hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456 __uuidof(ID2D1Factory), NULL,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 reinterpret_cast<void**>(&mD2D1Factory));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458 _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
459
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460 if (SUCCEEDED(hr))
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 D2D1_RENDER_TARGET_PROPERTIES props = {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
463 D2D1_RENDER_TARGET_TYPE_DEFAULT,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
464 { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE },
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
465 0, 0,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
466 D2D1_RENDER_TARGET_USAGE_NONE,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
467 D2D1_FEATURE_LEVEL_DEFAULT
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 hr = mD2D1Factory->CreateDCRenderTarget(&props, &mRT);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
470 _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
471 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
472
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
473 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
474 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
475 hr = mRT->CreateSolidColorBrush(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
476 D2D1::ColorF(D2D1::ColorF::Black),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
477 &mBrush);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
478 _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
479 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
480
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
481 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
482 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
483 hr = DWriteCreateFactory(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
484 DWRITE_FACTORY_TYPE_SHARED,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
485 __uuidof(IDWriteFactory),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
486 reinterpret_cast<IUnknown**>(&mDWriteFactory));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
487 _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
488 mDWriteFactory);
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
491 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
492 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
493 hr = mDWriteFactory->GetGdiInterop(&mGdiInterop);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
494 _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
495 }
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 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
498 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
499 hr = mDWriteFactory->CreateRenderingParams(&mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
500 _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
501 mRenderingParams);
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
505 DWriteContext::~DWriteContext()
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
506 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
507 SafeRelease(&mTextFormat);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
508 SafeRelease(&mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
509 SafeRelease(&mGdiInterop);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
510 SafeRelease(&mDWriteFactory);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
511 SafeRelease(&mBrush);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
512 SafeRelease(&mRT);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
513 SafeRelease(&mD2D1Factory);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
514 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
515
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
516 HRESULT
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
517 DWriteContext::SetLOGFONT(const LOGFONTW &logFont, float fontSize)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
518 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
519 // 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
520 HRESULT hr = S_OK;
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 IDWriteFont *font = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
523 IDWriteFontFamily *fontFamily = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
524 IDWriteLocalizedStrings *localizedFamilyNames = NULL;
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 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
527 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528 hr = mGdiInterop->CreateFontFromLOGFONT(&logFont, &font);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 // Get the font family to which this font belongs.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
532 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
533 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
534 hr = font->GetFontFamily(&fontFamily);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
535 }
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 // 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
538 // 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
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 = fontFamily->GetFamilyNames(&localizedFamilyNames);
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 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
545 // 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
546 // 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
547
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
548 wchar_t familyName[100];
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
549 if (SUCCEEDED(hr))
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 hr = localizedFamilyNames->GetString(0, familyName,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
552 ARRAYSIZE(familyName));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
553 }
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 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
556 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
557 // 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
558 if (fontSize == 0)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
559 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
560 // Convert from pixels to DIPs.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
561 fontSize = PixelsToDipsY(logFont.lfHeight);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
562 if (fontSize < 0)
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 // Negative lfHeight represents the size of the em unit.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
565 fontSize = -fontSize;
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 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
568 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
569 // Positive lfHeight represents the cell height (ascent +
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
570 // descent).
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
571 DWRITE_FONT_METRICS fontMetrics;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
572 font->GetMetrics(&fontMetrics);
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 // Convert the cell height (ascent + descent) from design units
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
575 // to ems.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
576 float cellHeight = static_cast<float>(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
577 fontMetrics.ascent + fontMetrics.descent)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
578 / fontMetrics.designUnitsPerEm;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
579
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
580 // 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
581 // size.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
582 fontSize /= cellHeight;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
583 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
584 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
585 }
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 // 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
588 // 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
589 // 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
590 wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
591 if (SUCCEEDED(hr))
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 if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
594 hr = HRESULT_FROM_WIN32(GetLastError());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
595 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
596
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
597 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
598 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
599 // Create the text format object.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
600 hr = mDWriteFactory->CreateTextFormat(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
601 familyName,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
602 NULL, // no custom font collection
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
603 font->GetWeight(),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
604 font->GetStyle(),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
605 font->GetStretch(),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606 fontSize,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 localeName,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 &mTextFormat);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
609 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
610
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
611 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
612 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
613 mFontWeight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
614 mFontStyle = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615 : DWRITE_FONT_STYLE_NORMAL;
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 SafeRelease(&localizedFamilyNames);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
619 SafeRelease(&fontFamily);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 SafeRelease(&font);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
621
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
622 return hr;
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 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
626 DWriteContext::SetFont(HFONT hFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
628 if (mLastHFont != hFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
630 LOGFONTW lf;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
631 if (GetObjectW(hFont, sizeof(lf), &lf))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
632 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
633 SetFont(lf);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
634 mLastHFont = hFont;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
635 }
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 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
638
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
639 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
640 DWriteContext::SetFont(const LOGFONTW &logFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
641 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
642 SafeRelease(&mTextFormat);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
643 mLastHFont = NULL;
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 HRESULT hr = SetLOGFONT(logFont, 0.f);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
646
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
647 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
648 hr = mTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
649
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651 hr = mTextFormat->SetParagraphAlignment(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
652 DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
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->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
658 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
659 DWriteContext::DrawText(HDC hdc, const WCHAR* text, int len,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
660 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
661 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
662 HRESULT hr = S_OK;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
663 IDWriteBitmapRenderTarget *bmpRT = NULL;
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 // Skip when any fonts are not set.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 if (mTextFormat == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 return;
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 // Check possibility of zero divided error.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
670 if (cellWidth == 0 || mDpiScaleX == 0.0f || mDpiScaleY == 0.0f)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
671 return;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
672
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
673 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 hr = mGdiInterop->CreateBitmapRenderTarget(hdc, w, h, &bmpRT);
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 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 IDWriteTextLayout *textLayout = NULL;
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 HDC memdc = bmpRT->GetMemoryDC();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 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
682
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
683 hr = mDWriteFactory->CreateGdiCompatibleTextLayout(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
684 text, len, mTextFormat, PixelsToDipsX(w),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
685 PixelsToDipsY(h), mDpiScaleX, NULL, TRUE, &textLayout);
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 if (SUCCEEDED(hr))
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
688 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
689 DWRITE_TEXT_RANGE textRange = { 0, len };
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
690 textLayout->SetFontWeight(mFontWeight, textRange);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 textLayout->SetFontStyle(mFontStyle, textRange);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
692 }
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 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
696 GdiTextRenderer *renderer = new GdiTextRenderer(bmpRT,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
697 mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
698 GdiTextRendererContext data = {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
699 color,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
700 PixelsToDipsX(cellWidth),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
701 0.0f
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 textLayout->Draw(&data, renderer, 0, 0);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
704 SafeRelease(&renderer);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
705 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
706
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
707 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
708
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
709 SafeRelease(&textLayout);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
710 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
711
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
712 SafeRelease(&bmpRT);
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
715 float
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
716 DWriteContext::PixelsToDipsX(int x)
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 return x / mDpiScaleX;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
719 }
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 float
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
722 DWriteContext::PixelsToDipsY(int y)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
723 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
724 return y / mDpiScaleY;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
725 }
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 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
728 DWriteContext::SetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729 const DWriteRenderingParams *params)
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 if (mDWriteFactory == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732 return;
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 IDWriteRenderingParams *renderingParams = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
735 D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode =
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
736 D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
737 HRESULT hr;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
738 if (params != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
739 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740 hr = mDWriteFactory->CreateCustomRenderingParams(params->gamma,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
741 params->enhancedContrast, params->clearTypeLevel,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
742 ToPixelGeometry(params->pixelGeometry),
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
743 ToRenderingMode(params->renderingMode), &renderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
744 textAntialiasMode = ToTextAntialiasMode(params->textAntialiasMode);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
745 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
746 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
747 hr = mDWriteFactory->CreateRenderingParams(&renderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
748 if (SUCCEEDED(hr) && renderingParams != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
749 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750 SafeRelease(&mRenderingParams);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
751 mRenderingParams = renderingParams;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
752 mTextAntialiasMode = textAntialiasMode;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
753 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
756 DWriteRenderingParams *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
757 DWriteContext::GetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
758 DWriteRenderingParams *params)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
759 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
760 if (params != NULL && mRenderingParams != NULL)
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 params->gamma = mRenderingParams->GetGamma();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
763 params->enhancedContrast = mRenderingParams->GetEnhancedContrast();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
764 params->clearTypeLevel = mRenderingParams->GetClearTypeLevel();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
765 params->pixelGeometry = ToInt(mRenderingParams->GetPixelGeometry());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
766 params->renderingMode = ToInt(mRenderingParams->GetRenderingMode());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
767 params->textAntialiasMode = mTextAntialiasMode;
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 return params;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
770 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
771
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
772 ////////////////////////////////////////////////////////////////////////////
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
773 // PUBLIC C INTERFACES
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
774
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
775 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
776 DWrite_Init(void)
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 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779 // Load libraries.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780 hD2D1DLL = vimLoadLib(const_cast<char*>("d2d1.dll"));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
781 hDWriteDLL = vimLoadLib(const_cast<char*>("dwrite.dll"));
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
782 if (hD2D1DLL == NULL || hDWriteDLL == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
784 DWrite_Final();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
785 return;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
786 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
787 // Get address of procedures.
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
788 pGetUserDefaultLocaleName = (PGETUSERDEFAULTLOCALENAME)GetProcAddress(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
789 GetModuleHandle("kernel32.dll"), "GetUserDefaultLocaleName");
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
790 pD2D1CreateFactory = (PD2D1CREATEFACTORY)GetProcAddress(hD2D1DLL,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
791 "D2D1CreateFactory");
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
792 pDWriteCreateFactory = (PDWRITECREATEFACTORY)GetProcAddress(hDWriteDLL,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
793 "DWriteCreateFactory");
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
796
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
797 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
798 DWrite_Final(void)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
799 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
800 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
801 pGetUserDefaultLocaleName = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
802 pD2D1CreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
803 pDWriteCreateFactory = NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
804 unload(hDWriteDLL);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
805 unload(hD2D1DLL);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
806 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
807 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
808
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
809 DWriteContext *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
810 DWriteContext_Open(void)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
811 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
812 #ifdef DYNAMIC_DIRECTX
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
813 if (pGetUserDefaultLocaleName == NULL || pD2D1CreateFactory == NULL
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
814 || pDWriteCreateFactory == NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
815 return NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
816 #endif
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
817 return new DWriteContext();
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
820 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
821 DWriteContext_BeginDraw(DWriteContext *ctx)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
822 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
823 if (ctx != NULL && ctx->mRT != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
824 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
825 ctx->mRT->BeginDraw();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
826 ctx->mRT->SetTransform(D2D1::IdentityMatrix());
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
827 ctx->mDrawing = true;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
828 }
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
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
831 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
832 DWriteContext_BindDC(DWriteContext *ctx, HDC hdc, RECT *rect)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
833 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
834 if (ctx != NULL && ctx->mRT != NULL)
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 ctx->mRT->BindDC(hdc, rect);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
837 ctx->mRT->SetTextAntialiasMode(ctx->mTextAntialiasMode);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
838 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
839 }
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 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
842 DWriteContext_SetFont(DWriteContext *ctx, HFONT hFont)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
843 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
844 if (ctx != NULL)
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 ctx->SetFont(hFont);
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 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
849
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
850 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
851 DWriteContext_DrawText(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
852 DWriteContext *ctx,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
853 HDC hdc,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
854 const WCHAR* text,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
855 int len,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
856 int x,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
857 int y,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
858 int w,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
859 int h,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
860 int cellWidth,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
861 COLORREF color)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
862 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
863 if (ctx != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
864 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
865 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
866
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
867 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
868 DWriteContext_EndDraw(DWriteContext *ctx)
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 && ctx->mRT != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
871 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
872 ctx->mRT->EndDraw();
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
873 ctx->mDrawing = false;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
874 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
875 }
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 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
878 DWriteContext_Close(DWriteContext *ctx)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
879 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
880 delete ctx;
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 void
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
884 DWriteContext_SetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
885 DWriteContext *ctx,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
886 const DWriteRenderingParams *params)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
887 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
888 if (ctx != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
889 ctx->SetRenderingParams(params);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
890 }
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
891
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
892 DWriteRenderingParams *
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
893 DWriteContext_GetRenderingParams(
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
894 DWriteContext *ctx,
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
895 DWriteRenderingParams *params)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
896 {
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
897 if (ctx != NULL)
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
898 return ctx->GetRenderingParams(params);
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
899 else
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
900 return NULL;
1bff71d20262 updated for version 7.4.393
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
901 }