4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 #define EXPECT_HR(hr,hr_exp) \
31 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
33 static IDWriteFactory *factory;
35 static void test_CreateFontFromLOGFONT(void)
37 static const WCHAR arialW[] = {'A','r','i','a','l',0};
38 static const WCHAR blahW[] = {'B','l','a','h','!',0};
39 IDWriteGdiInterop *interop;
40 DWRITE_FONT_WEIGHT weight;
41 DWRITE_FONT_STYLE style;
45 {FW_NORMAL, DWRITE_FONT_WEIGHT_NORMAL},
46 {FW_BOLD, DWRITE_FONT_WEIGHT_BOLD},
47 { 0, DWRITE_FONT_WEIGHT_NORMAL},
48 { 50, DWRITE_FONT_WEIGHT_NORMAL},
49 {150, DWRITE_FONT_WEIGHT_NORMAL},
50 {250, DWRITE_FONT_WEIGHT_NORMAL},
51 {350, DWRITE_FONT_WEIGHT_NORMAL},
52 {450, DWRITE_FONT_WEIGHT_NORMAL},
53 {650, DWRITE_FONT_WEIGHT_BOLD},
54 {750, DWRITE_FONT_WEIGHT_BOLD},
55 {850, DWRITE_FONT_WEIGHT_BOLD},
56 {950, DWRITE_FONT_WEIGHT_BOLD},
57 {960, DWRITE_FONT_WEIGHT_BOLD},
63 hr = IDWriteFactory_GetGdiInterop(factory, &interop);
67 /* null out parameter crashes this call */
68 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, NULL);
70 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, &font);
71 EXPECT_HR(hr, E_INVALIDARG);
73 memset(&logfont, 0, sizeof(logfont));
74 logfont.lfHeight = 12;
76 logfont.lfWeight = FW_NORMAL;
78 lstrcpyW(logfont.lfFaceName, arialW);
80 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
83 /* now check properties */
84 weight = IDWriteFont_GetWeight(font);
86 ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
88 style = IDWriteFont_GetStyle(font);
89 ok(style == DWRITE_FONT_STYLE_ITALIC, "got %d\n", style);
91 ret = IDWriteFont_IsSymbolFont(font);
92 ok(!ret, "got %d\n", ret);
94 IDWriteFont_Release(font);
97 for (i = 0; i < sizeof(weights)/(2*sizeof(LONG)); i++)
99 memset(&logfont, 0, sizeof(logfont));
100 logfont.lfHeight = 12;
101 logfont.lfWidth = 12;
102 logfont.lfWeight = weights[i][0];
103 lstrcpyW(logfont.lfFaceName, arialW);
105 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
108 weight = IDWriteFont_GetWeight(font);
110 ok(weight == weights[i][1],
111 "%d: got %d, expected %d\n", i, weight, weights[i][1]);
112 IDWriteFont_Release(font);
115 /* weight not from enum */
116 memset(&logfont, 0, sizeof(logfont));
117 logfont.lfHeight = 12;
118 logfont.lfWidth = 12;
119 logfont.lfWeight = 550;
120 lstrcpyW(logfont.lfFaceName, arialW);
122 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
125 weight = IDWriteFont_GetWeight(font);
127 ok(weight == DWRITE_FONT_WEIGHT_NORMAL || broken(weight == DWRITE_FONT_WEIGHT_BOLD) /* win7 w/o SP */,
129 IDWriteFont_Release(font);
131 /* empty or nonexistent face name */
132 memset(&logfont, 0, sizeof(logfont));
133 logfont.lfHeight = 12;
134 logfont.lfWidth = 12;
135 logfont.lfWeight = FW_NORMAL;
136 lstrcpyW(logfont.lfFaceName, blahW);
138 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
140 EXPECT_HR(hr, DWRITE_E_NOFONT);
142 memset(&logfont, 0, sizeof(logfont));
143 logfont.lfHeight = 12;
144 logfont.lfWidth = 12;
145 logfont.lfWeight = FW_NORMAL;
147 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
149 EXPECT_HR(hr, DWRITE_E_NOFONT);
151 IDWriteGdiInterop_Release(interop);
154 static void test_CreateBitmapRenderTarget(void)
156 IDWriteBitmapRenderTarget *target, *target2;
157 IDWriteGdiInterop *interop;
165 hr = IDWriteFactory_GetGdiInterop(factory, &interop);
169 hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target);
172 if (0) /* crashes on native */
173 hr = IDWriteBitmapRenderTarget_GetSize(target, NULL);
175 size.cx = size.cy = -1;
176 hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
178 ok(size.cx == 0, "got %d\n", size.cx);
179 ok(size.cy == 0, "got %d\n", size.cy);
182 hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target2);
184 ok(target != target2, "got %p, %p\n", target2, target);
185 IDWriteBitmapRenderTarget_Release(target2);
187 hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target);
188 ok(hdc != NULL, "got %p\n", hdc);
190 hbm = GetCurrentObject(hdc, OBJ_BITMAP);
191 ok(hbm != NULL, "got %p\n", hbm);
193 /* check DIB properties */
194 ret = GetObjectW(hbm, sizeof(ds), &ds);
195 ok(ret == sizeof(BITMAP), "got %d\n", ret);
196 ok(ds.dsBm.bmWidth == 1, "got %d\n", ds.dsBm.bmWidth);
197 ok(ds.dsBm.bmHeight == 1, "got %d\n", ds.dsBm.bmHeight);
198 ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes);
199 ok(ds.dsBm.bmBitsPixel == 1, "got %d\n", ds.dsBm.bmBitsPixel);
200 ok(!ds.dsBm.bmBits, "got %p\n", ds.dsBm.bmBits);
202 IDWriteBitmapRenderTarget_Release(target);
204 hbm = GetCurrentObject(hdc, OBJ_BITMAP);
205 ok(!hbm, "got %p\n", hbm);
208 hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 10, 5, &target);
211 hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target);
212 ok(hdc != NULL, "got %p\n", hdc);
214 hbm = GetCurrentObject(hdc, OBJ_BITMAP);
215 ok(hbm != NULL, "got %p\n", hbm);
217 /* check DIB properties */
218 ret = GetObjectW(hbm, sizeof(ds), &ds);
219 ok(ret == sizeof(ds), "got %d\n", ret);
220 ok(ds.dsBm.bmWidth == 10, "got %d\n", ds.dsBm.bmWidth);
221 ok(ds.dsBm.bmHeight == 5, "got %d\n", ds.dsBm.bmHeight);
222 ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes);
223 ok(ds.dsBm.bmBitsPixel == 32, "got %d\n", ds.dsBm.bmBitsPixel);
224 ok(ds.dsBm.bmBits != NULL, "got %p\n", ds.dsBm.bmBits);
226 size.cx = size.cy = -1;
227 hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
229 ok(size.cx == 10, "got %d\n", size.cx);
230 ok(size.cy == 5, "got %d\n", size.cy);
232 IDWriteBitmapRenderTarget_Release(target);
234 IDWriteGdiInterop_Release(interop);
241 hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
242 ok(hr == S_OK, "got 0x%08x\n", hr);
245 win_skip("failed to create factory\n");
249 test_CreateFontFromLOGFONT();
250 test_CreateBitmapRenderTarget();
252 IDWriteFactory_Release(factory);