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
26 #include "wine/test.h"
28 #define EXPECT_HR(hr,hr_exp) \
29 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
31 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
32 static void _expect_ref(IUnknown
* obj
, ULONG ref
, int line
)
34 ULONG rc
= IUnknown_AddRef(obj
);
35 IUnknown_Release(obj
);
36 ok_(__FILE__
,line
)(rc
-1 == ref
, "expected refcount %d, got %d\n", ref
, rc
-1);
39 static IDWriteFactory
*factory
;
41 static const WCHAR tahomaW
[] = {'T','a','h','o','m','a',0};
42 static const WCHAR blahW
[] = {'B','l','a','h','!',0};
44 static void test_CreateFontFromLOGFONT(void)
46 static const WCHAR tahomaspW
[] = {'T','a','h','o','m','a',' ',0};
47 IDWriteGdiInterop
*interop
;
48 DWRITE_FONT_WEIGHT weight
;
49 DWRITE_FONT_STYLE style
;
53 {FW_NORMAL
, DWRITE_FONT_WEIGHT_NORMAL
},
54 {FW_BOLD
, DWRITE_FONT_WEIGHT_BOLD
},
55 { 0, DWRITE_FONT_WEIGHT_NORMAL
},
56 { 50, DWRITE_FONT_WEIGHT_NORMAL
},
57 {150, DWRITE_FONT_WEIGHT_NORMAL
},
58 {250, DWRITE_FONT_WEIGHT_NORMAL
},
59 {350, DWRITE_FONT_WEIGHT_NORMAL
},
60 {450, DWRITE_FONT_WEIGHT_NORMAL
},
61 {650, DWRITE_FONT_WEIGHT_BOLD
},
62 {750, DWRITE_FONT_WEIGHT_BOLD
},
63 {850, DWRITE_FONT_WEIGHT_BOLD
},
64 {950, DWRITE_FONT_WEIGHT_BOLD
},
65 {960, DWRITE_FONT_WEIGHT_BOLD
},
67 OUTLINETEXTMETRICW otm
;
75 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
79 /* null out parameter crashes this call */
80 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, NULL
, NULL
);
82 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, NULL
, &font
);
83 EXPECT_HR(hr
, E_INVALIDARG
);
85 memset(&logfont
, 0, sizeof(logfont
));
86 logfont
.lfHeight
= 12;
88 logfont
.lfWeight
= FW_NORMAL
;
90 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
92 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
95 hfont
= CreateFontIndirectW(&logfont
);
96 hdc
= CreateCompatibleDC(0);
97 SelectObject(hdc
, hfont
);
99 otm
.otmSize
= sizeof(otm
);
100 r
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
101 ok(r
, "got %d\n", r
);
105 /* now check properties */
106 weight
= IDWriteFont_GetWeight(font
);
107 ok(weight
== DWRITE_FONT_WEIGHT_NORMAL
, "got %d\n", weight
);
109 style
= IDWriteFont_GetStyle(font
);
111 ok(style
== DWRITE_FONT_STYLE_OBLIQUE
, "got %d\n", style
);
112 ok(otm
.otmfsSelection
== 1, "got 0x%08x\n", otm
.otmfsSelection
);
114 ret
= IDWriteFont_IsSymbolFont(font
);
115 ok(!ret
, "got %d\n", ret
);
117 IDWriteFont_Release(font
);
120 for (i
= 0; i
< sizeof(weights
)/(2*sizeof(LONG
)); i
++)
122 memset(&logfont
, 0, sizeof(logfont
));
123 logfont
.lfHeight
= 12;
124 logfont
.lfWidth
= 12;
125 logfont
.lfWeight
= weights
[i
][0];
126 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
128 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
131 weight
= IDWriteFont_GetWeight(font
);
132 ok(weight
== weights
[i
][1],
133 "%d: got %d, expected %d\n", i
, weight
, weights
[i
][1]);
134 IDWriteFont_Release(font
);
137 /* weight not from enum */
138 memset(&logfont
, 0, sizeof(logfont
));
139 logfont
.lfHeight
= 12;
140 logfont
.lfWidth
= 12;
141 logfont
.lfWeight
= 550;
142 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
144 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
147 weight
= IDWriteFont_GetWeight(font
);
148 ok(weight
== DWRITE_FONT_WEIGHT_NORMAL
|| broken(weight
== DWRITE_FONT_WEIGHT_BOLD
) /* win7 w/o SP */,
150 IDWriteFont_Release(font
);
152 /* empty or nonexistent face name */
153 memset(&logfont
, 0, sizeof(logfont
));
154 logfont
.lfHeight
= 12;
155 logfont
.lfWidth
= 12;
156 logfont
.lfWeight
= FW_NORMAL
;
157 lstrcpyW(logfont
.lfFaceName
, blahW
);
159 font
= (void*)0xdeadbeef;
160 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
162 EXPECT_HR(hr
, DWRITE_E_NOFONT
);
163 ok(font
== NULL
, "got %p\n", font
);
164 if(font
) IDWriteFont_Release(font
);
167 memset(&logfont
, 0, sizeof(logfont
));
168 logfont
.lfHeight
= 12;
169 logfont
.lfWidth
= 12;
170 logfont
.lfWeight
= FW_NORMAL
;
171 lstrcpyW(logfont
.lfFaceName
, tahomaspW
);
173 font
= (void*)0xdeadbeef;
174 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
176 EXPECT_HR(hr
, DWRITE_E_NOFONT
);
177 ok(font
== NULL
, "got %p\n", font
);
178 if(font
) IDWriteFont_Release(font
);
181 memset(&logfont
, 0, sizeof(logfont
));
182 logfont
.lfHeight
= 12;
183 logfont
.lfWidth
= 12;
184 logfont
.lfWeight
= FW_NORMAL
;
186 font
= (void*)0xdeadbeef;
187 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
189 EXPECT_HR(hr
, DWRITE_E_NOFONT
);
190 ok(font
== NULL
, "got %p\n", font
);
191 if(font
) IDWriteFont_Release(font
);
194 IDWriteGdiInterop_Release(interop
);
197 static void test_CreateBitmapRenderTarget(void)
199 IDWriteBitmapRenderTarget
*target
, *target2
;
200 IDWriteGdiInterop
*interop
;
209 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
213 hr
= IDWriteGdiInterop_CreateBitmapRenderTarget(interop
, NULL
, 0, 0, &target
);
216 if (0) /* crashes on native */
217 hr
= IDWriteBitmapRenderTarget_GetSize(target
, NULL
);
219 size
.cx
= size
.cy
= -1;
220 hr
= IDWriteBitmapRenderTarget_GetSize(target
, &size
);
222 ok(size
.cx
== 0, "got %d\n", size
.cx
);
223 ok(size
.cy
== 0, "got %d\n", size
.cy
);
226 hr
= IDWriteGdiInterop_CreateBitmapRenderTarget(interop
, NULL
, 0, 0, &target2
);
228 ok(target
!= target2
, "got %p, %p\n", target2
, target
);
229 IDWriteBitmapRenderTarget_Release(target2
);
231 hdc
= IDWriteBitmapRenderTarget_GetMemoryDC(target
);
232 ok(hdc
!= NULL
, "got %p\n", hdc
);
234 hbm
= GetCurrentObject(hdc
, OBJ_BITMAP
);
235 ok(hbm
!= NULL
, "got %p\n", hbm
);
237 /* check DIB properties */
238 ret
= GetObjectW(hbm
, sizeof(ds
), &ds
);
239 ok(ret
== sizeof(BITMAP
), "got %d\n", ret
);
240 ok(ds
.dsBm
.bmWidth
== 1, "got %d\n", ds
.dsBm
.bmWidth
);
241 ok(ds
.dsBm
.bmHeight
== 1, "got %d\n", ds
.dsBm
.bmHeight
);
242 ok(ds
.dsBm
.bmPlanes
== 1, "got %d\n", ds
.dsBm
.bmPlanes
);
243 ok(ds
.dsBm
.bmBitsPixel
== 1, "got %d\n", ds
.dsBm
.bmBitsPixel
);
244 ok(!ds
.dsBm
.bmBits
, "got %p\n", ds
.dsBm
.bmBits
);
246 IDWriteBitmapRenderTarget_Release(target
);
248 hbm
= GetCurrentObject(hdc
, OBJ_BITMAP
);
249 ok(!hbm
, "got %p\n", hbm
);
252 hr
= IDWriteGdiInterop_CreateBitmapRenderTarget(interop
, NULL
, 10, 5, &target
);
255 hdc
= IDWriteBitmapRenderTarget_GetMemoryDC(target
);
256 ok(hdc
!= NULL
, "got %p\n", hdc
);
258 hbm
= GetCurrentObject(hdc
, OBJ_BITMAP
);
259 ok(hbm
!= NULL
, "got %p\n", hbm
);
261 /* check DIB properties */
262 ret
= GetObjectW(hbm
, sizeof(ds
), &ds
);
263 ok(ret
== sizeof(ds
), "got %d\n", ret
);
264 ok(ds
.dsBm
.bmWidth
== 10, "got %d\n", ds
.dsBm
.bmWidth
);
265 ok(ds
.dsBm
.bmHeight
== 5, "got %d\n", ds
.dsBm
.bmHeight
);
266 ok(ds
.dsBm
.bmPlanes
== 1, "got %d\n", ds
.dsBm
.bmPlanes
);
267 ok(ds
.dsBm
.bmBitsPixel
== 32, "got %d\n", ds
.dsBm
.bmBitsPixel
);
268 ok(ds
.dsBm
.bmBits
!= NULL
, "got %p\n", ds
.dsBm
.bmBits
);
270 size
.cx
= size
.cy
= -1;
271 hr
= IDWriteBitmapRenderTarget_GetSize(target
, &size
);
273 ok(size
.cx
== 10, "got %d\n", size
.cx
);
274 ok(size
.cy
== 5, "got %d\n", size
.cy
);
276 /* resize to same size */
277 hr
= IDWriteBitmapRenderTarget_Resize(target
, 10, 5);
278 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
280 hbm2
= GetCurrentObject(hdc
, OBJ_BITMAP
);
281 ok(hbm2
== hbm
, "got %p, %p\n", hbm2
, hbm
);
284 hr
= IDWriteBitmapRenderTarget_Resize(target
, 5, 5);
285 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
287 hbm2
= GetCurrentObject(hdc
, OBJ_BITMAP
);
288 ok(hbm2
!= hbm
, "got %p, %p\n", hbm2
, hbm
);
290 hr
= IDWriteBitmapRenderTarget_Resize(target
, 20, 5);
291 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
293 hbm2
= GetCurrentObject(hdc
, OBJ_BITMAP
);
294 ok(hbm2
!= hbm
, "got %p, %p\n", hbm2
, hbm
);
296 hr
= IDWriteBitmapRenderTarget_Resize(target
, 1, 5);
297 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
299 hbm2
= GetCurrentObject(hdc
, OBJ_BITMAP
);
300 ok(hbm2
!= hbm
, "got %p, %p\n", hbm2
, hbm
);
302 ret
= GetObjectW(hbm2
, sizeof(ds
), &ds
);
303 ok(ret
== sizeof(ds
), "got %d\n", ret
);
304 ok(ds
.dsBm
.bmWidth
== 1, "got %d\n", ds
.dsBm
.bmWidth
);
305 ok(ds
.dsBm
.bmHeight
== 5, "got %d\n", ds
.dsBm
.bmHeight
);
306 ok(ds
.dsBm
.bmPlanes
== 1, "got %d\n", ds
.dsBm
.bmPlanes
);
307 ok(ds
.dsBm
.bmBitsPixel
== 32, "got %d\n", ds
.dsBm
.bmBitsPixel
);
308 ok(ds
.dsBm
.bmBits
!= NULL
, "got %p\n", ds
.dsBm
.bmBits
);
310 /* empty rectangle */
311 hr
= IDWriteBitmapRenderTarget_Resize(target
, 0, 5);
312 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
314 hbm2
= GetCurrentObject(hdc
, OBJ_BITMAP
);
315 ok(hbm2
!= hbm
, "got %p, %p\n", hbm2
, hbm
);
317 ret
= GetObjectW(hbm2
, sizeof(ds
), &ds
);
318 ok(ret
== sizeof(BITMAP
), "got %d\n", ret
);
319 ok(ds
.dsBm
.bmWidth
== 1, "got %d\n", ds
.dsBm
.bmWidth
);
320 ok(ds
.dsBm
.bmHeight
== 1, "got %d\n", ds
.dsBm
.bmHeight
);
321 ok(ds
.dsBm
.bmPlanes
== 1, "got %d\n", ds
.dsBm
.bmPlanes
);
322 ok(ds
.dsBm
.bmBitsPixel
== 1, "got %d\n", ds
.dsBm
.bmBitsPixel
);
323 ok(!ds
.dsBm
.bmBits
, "got %p\n", ds
.dsBm
.bmBits
);
325 /* transform tests */
326 if (0) /* crashes on native */
327 hr
= IDWriteBitmapRenderTarget_GetCurrentTransform(target
, NULL
);
329 memset(&m
, 0xcc, sizeof(m
));
330 hr
= IDWriteBitmapRenderTarget_GetCurrentTransform(target
, &m
);
331 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
332 ok(m
.m11
== 1.0 && m
.m22
== 1.0 && m
.m12
== 0.0 && m
.m21
== 0.0, "got %.1f,%.1f,%.1f,%.1f\n", m
.m11
, m
.m22
, m
.m12
, m
.m21
);
333 ok(m
.dx
== 0.0 && m
.dy
== 0.0, "got %.1f,%.1f\n", m
.dx
, m
.dy
);
335 IDWriteBitmapRenderTarget_Release(target
);
336 IDWriteGdiInterop_Release(interop
);
339 static void test_GetFontFamily(void)
341 IDWriteFontFamily
*family
, *family2
;
342 IDWriteGdiInterop
*interop
;
347 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
350 memset(&logfont
, 0, sizeof(logfont
));
351 logfont
.lfHeight
= 12;
352 logfont
.lfWidth
= 12;
353 logfont
.lfWeight
= FW_NORMAL
;
354 logfont
.lfItalic
= 1;
355 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
357 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
360 if (0) /* crashes on native */
361 hr
= IDWriteFont_GetFontFamily(font
, NULL
);
364 hr
= IDWriteFont_GetFontFamily(font
, &family
);
367 EXPECT_REF(family
, 2);
369 hr
= IDWriteFont_GetFontFamily(font
, &family2
);
371 ok(family2
== family
, "got %p, previous %p\n", family2
, family
);
373 EXPECT_REF(family
, 3);
374 IDWriteFontFamily_Release(family2
);
376 hr
= IDWriteFont_QueryInterface(font
, &IID_IDWriteFontFamily
, (void**)&family2
);
377 EXPECT_HR(hr
, E_NOINTERFACE
);
378 ok(family2
== NULL
, "got %p\n", family2
);
380 IDWriteFontFamily_Release(family
);
381 IDWriteFont_Release(font
);
382 IDWriteGdiInterop_Release(interop
);
385 static void test_GetFamilyNames(void)
387 IDWriteFontFamily
*family
;
388 IDWriteLocalizedStrings
*names
, *names2
;
389 IDWriteGdiInterop
*interop
;
396 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
399 memset(&logfont
, 0, sizeof(logfont
));
400 logfont
.lfHeight
= 12;
401 logfont
.lfWidth
= 12;
402 logfont
.lfWeight
= FW_NORMAL
;
403 logfont
.lfItalic
= 1;
404 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
406 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
409 hr
= IDWriteFont_GetFontFamily(font
, &family
);
412 if (0) /* crashes on native */
413 hr
= IDWriteFontFamily_GetFamilyNames(family
, NULL
);
415 hr
= IDWriteFontFamily_GetFamilyNames(family
, &names
);
416 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
417 EXPECT_REF(names
, 1);
419 hr
= IDWriteFontFamily_GetFamilyNames(family
, &names2
);
420 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
421 EXPECT_REF(names2
, 1);
422 ok(names
!= names2
, "got %p, was %p\n", names2
, names
);
424 IDWriteLocalizedStrings_Release(names2
);
426 /* GetStringLength */
427 if (0) /* crashes on native */
428 hr
= IDWriteLocalizedStrings_GetStringLength(names
, 0, NULL
);
431 hr
= IDWriteLocalizedStrings_GetStringLength(names
, 10, &len
);
432 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
433 ok(len
== (UINT32
)-1, "got %u\n", len
);
436 hr
= IDWriteLocalizedStrings_GetStringLength(names
, 0, &len
);
437 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
438 ok(len
> 0, "got %u\n", len
);
441 hr
= IDWriteLocalizedStrings_GetString(names
, 0, NULL
, 0);
442 ok(hr
== E_NOT_SUFFICIENT_BUFFER
, "got 0x%08x\n", hr
);
444 hr
= IDWriteLocalizedStrings_GetString(names
, 10, NULL
, 0);
445 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
448 hr
= IDWriteLocalizedStrings_GetString(names
, 0, NULL
, 100);
451 hr
= IDWriteLocalizedStrings_GetString(names
, 10, buffer
, 100);
452 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
453 ok(buffer
[0] == 0, "got %x\n", buffer
[0]);
456 hr
= IDWriteLocalizedStrings_GetString(names
, 0, buffer
, len
-1);
457 ok(hr
== E_NOT_SUFFICIENT_BUFFER
, "got 0x%08x\n", hr
);
458 ok(buffer
[0] == 0, "got %x\n", buffer
[0]);
461 hr
= IDWriteLocalizedStrings_GetString(names
, 0, buffer
, len
);
462 ok(hr
== E_NOT_SUFFICIENT_BUFFER
, "got 0x%08x\n", hr
);
463 ok(buffer
[0] == 0, "got %x\n", buffer
[0]);
466 hr
= IDWriteLocalizedStrings_GetString(names
, 0, buffer
, len
+1);
467 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
468 ok(buffer
[0] != 0, "got %x\n", buffer
[0]);
470 IDWriteLocalizedStrings_Release(names
);
472 IDWriteFontFamily_Release(family
);
473 IDWriteFont_Release(font
);
474 IDWriteGdiInterop_Release(interop
);
477 static void test_CreateFontFace(void)
479 IDWriteFontFace
*fontface
, *fontface2
;
480 IDWriteGdiInterop
*interop
;
485 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
488 memset(&logfont
, 0, sizeof(logfont
));
489 logfont
.lfHeight
= 12;
490 logfont
.lfWidth
= 12;
491 logfont
.lfWeight
= FW_NORMAL
;
492 logfont
.lfItalic
= 1;
493 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
495 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
496 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
498 hr
= IDWriteFont_QueryInterface(font
, &IID_IDWriteFontFace
, (void**)&fontface
);
499 ok(hr
== E_NOINTERFACE
, "got 0x%08x\n", hr
);
501 if (0) /* crashes on native */
502 hr
= IDWriteFont_CreateFontFace(font
, NULL
);
504 hr
= IDWriteFont_CreateFontFace(font
, &fontface
);
505 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
507 hr
= IDWriteFont_CreateFontFace(font
, &fontface2
);
508 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
509 ok(fontface
== fontface2
, "got %p, was %p\n", fontface2
, fontface
);
510 /* the fontface refcount is increased here */
512 IDWriteFontFace_Release(fontface
);
514 IDWriteFontFace_Release(fontface
);
515 IDWriteFont_Release(font
);
516 IDWriteGdiInterop_Release(interop
);
519 static void test_GetMetrics(void)
521 IDWriteGdiInterop
*interop
;
522 DWRITE_FONT_METRICS metrics
;
523 OUTLINETEXTMETRICW otm
;
531 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
534 memset(&logfont
, 0, sizeof(logfont
));
535 logfont
.lfHeight
= 12;
536 logfont
.lfWidth
= 12;
537 logfont
.lfWeight
= FW_NORMAL
;
538 logfont
.lfItalic
= 1;
539 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
541 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
542 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
544 hfont
= CreateFontIndirectW(&logfont
);
545 hdc
= CreateCompatibleDC(0);
546 SelectObject(hdc
, hfont
);
548 otm
.otmSize
= sizeof(otm
);
549 ret
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
550 ok(ret
, "got %d\n", ret
);
554 if (0) /* crashes on native */
555 IDWriteFont_GetMetrics(font
, NULL
);
557 memset(&metrics
, 0, sizeof(metrics
));
558 IDWriteFont_GetMetrics(font
, &metrics
);
560 ok(metrics
.designUnitsPerEm
!= 0, "designUnitsPerEm %u\n", metrics
.designUnitsPerEm
);
561 ok(metrics
.ascent
!= 0, "ascent %u\n", metrics
.ascent
);
562 ok(metrics
.descent
!= 0, "descent %u\n", metrics
.descent
);
564 ok(metrics
.lineGap
== 0, "lineGap %d\n", metrics
.lineGap
);
565 ok(metrics
.capHeight
, "capHeight %u\n", metrics
.capHeight
);
566 ok(metrics
.xHeight
!= 0, "xHeight %u\n", metrics
.xHeight
);
567 ok(metrics
.underlinePosition
< 0, "underlinePosition %d\n", metrics
.underlinePosition
);
568 ok(metrics
.underlineThickness
!= 0, "underlineThickness %u\n", metrics
.underlineThickness
);
569 ok(metrics
.strikethroughPosition
> 0, "strikethroughPosition %d\n", metrics
.strikethroughPosition
);
570 ok(metrics
.strikethroughThickness
!= 0, "strikethroughThickness %u\n", metrics
.strikethroughThickness
);
572 IDWriteFont_Release(font
);
573 IDWriteGdiInterop_Release(interop
);
576 static void test_system_fontcollection(void)
578 IDWriteFontCollection
*collection
, *coll2
;
579 IDWriteFontFamily
*family
;
584 hr
= IDWriteFactory_GetSystemFontCollection(factory
, &collection
, FALSE
);
585 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
587 hr
= IDWriteFactory_GetSystemFontCollection(factory
, &coll2
, FALSE
);
588 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
589 ok(coll2
== collection
, "got %p, was %p\n", coll2
, collection
);
590 IDWriteFontCollection_Release(coll2
);
592 hr
= IDWriteFactory_GetSystemFontCollection(factory
, &coll2
, TRUE
);
593 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
594 ok(coll2
== collection
, "got %p, was %p\n", coll2
, collection
);
595 IDWriteFontCollection_Release(coll2
);
597 i
= IDWriteFontCollection_GetFontFamilyCount(collection
);
598 ok(i
, "got %u\n", i
);
601 family
= (void*)0xdeadbeef;
602 hr
= IDWriteFontCollection_GetFontFamily(collection
, i
, &family
);
603 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
604 ok(family
== NULL
, "got %p\n", family
);
608 hr
= IDWriteFontCollection_FindFamilyName(collection
, tahomaW
, &i
, &ret
);
609 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
610 ok(ret
, "got %d\n", ret
);
611 ok(i
!= (UINT32
)-1, "got %u\n", i
);
615 hr
= IDWriteFontCollection_FindFamilyName(collection
, blahW
, &i
, &ret
);
616 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
617 ok(!ret
, "got %d\n", ret
);
618 ok(i
== (UINT32
)-1, "got %u\n", i
);
620 IDWriteFontCollection_Release(collection
);
623 static void test_ConvertFontFaceToLOGFONT(void)
625 IDWriteGdiInterop
*interop
;
626 IDWriteFontFace
*fontface
;
631 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
632 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
634 memset(&logfont
, 0, sizeof(logfont
));
635 logfont
.lfHeight
= 12;
636 logfont
.lfWidth
= 12;
637 logfont
.lfEscapement
= 100;
638 logfont
.lfWeight
= FW_NORMAL
;
639 logfont
.lfItalic
= 1;
640 logfont
.lfUnderline
= 1;
641 logfont
.lfStrikeOut
= 1;
643 lstrcpyW(logfont
.lfFaceName
, tahomaW
);
645 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
646 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
648 hr
= IDWriteFont_CreateFontFace(font
, &fontface
);
649 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
650 IDWriteFont_Release(font
);
652 if (0) /* crashes on native */
654 hr
= IDWriteGdiInterop_ConvertFontFaceToLOGFONT(interop
, NULL
, NULL
);
655 hr
= IDWriteGdiInterop_ConvertFontFaceToLOGFONT(interop
, fontface
, NULL
);
658 memset(&logfont
, 0xa, sizeof(logfont
));
659 logfont
.lfFaceName
[0] = 0;
661 hr
= IDWriteGdiInterop_ConvertFontFaceToLOGFONT(interop
, fontface
, &logfont
);
662 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
663 ok(logfont
.lfHeight
== 0, "got %d\n", logfont
.lfHeight
);
664 ok(logfont
.lfWidth
== 0, "got %d\n", logfont
.lfWidth
);
665 ok(logfont
.lfWeight
== FW_NORMAL
, "got %d\n", logfont
.lfWeight
);
666 ok(logfont
.lfEscapement
== 0, "got %d\n", logfont
.lfEscapement
);
667 ok(logfont
.lfItalic
== 1, "got %d\n", logfont
.lfItalic
);
668 ok(logfont
.lfUnderline
== 0, "got %d\n", logfont
.lfUnderline
);
669 ok(logfont
.lfStrikeOut
== 0, "got %d\n", logfont
.lfStrikeOut
);
670 ok(!lstrcmpW(logfont
.lfFaceName
, tahomaW
), "got %s\n", wine_dbgstr_w(logfont
.lfFaceName
));
672 IDWriteGdiInterop_Release(interop
);
673 IDWriteFontFace_Release(fontface
);
676 static HRESULT WINAPI
fontcollectionloader_QueryInterface(IDWriteFontCollectionLoader
*iface
, REFIID riid
, void **obj
)
682 static ULONG WINAPI
fontcollectionloader_AddRef(IDWriteFontCollectionLoader
*iface
)
687 static ULONG WINAPI
fontcollectionloader_Release(IDWriteFontCollectionLoader
*iface
)
692 static HRESULT WINAPI
fontcollectionloader_CreateEnumeratorFromKey(IDWriteFontCollectionLoader
*iface
, IDWriteFactory
* factory
, const void * collectionKey
, UINT32 collectionKeySize
, IDWriteFontFileEnumerator
** fontFileEnumerator
)
697 static const struct IDWriteFontCollectionLoaderVtbl dwritefontcollectionloadervtbl
= {
698 fontcollectionloader_QueryInterface
,
699 fontcollectionloader_AddRef
,
700 fontcollectionloader_Release
,
701 fontcollectionloader_CreateEnumeratorFromKey
704 static void test_CustomFontCollection(void)
706 IDWriteFontCollectionLoader collection
= { &dwritefontcollectionloadervtbl
};
707 IDWriteFontCollectionLoader collection2
= { &dwritefontcollectionloadervtbl
};
710 hr
= IDWriteFactory_RegisterFontCollectionLoader(factory
, &collection
);
711 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
712 hr
= IDWriteFactory_RegisterFontCollectionLoader(factory
, &collection2
);
713 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
714 hr
= IDWriteFactory_RegisterFontCollectionLoader(factory
, &collection
);
715 ok(hr
== DWRITE_E_ALREADYREGISTERED
, "got 0x%08x\n", hr
);
717 hr
= IDWriteFactory_UnregisterFontCollectionLoader(factory
, &collection
);
718 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
719 hr
= IDWriteFactory_UnregisterFontCollectionLoader(factory
, &collection
);
720 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
721 hr
= IDWriteFactory_UnregisterFontCollectionLoader(factory
, &collection2
);
722 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
725 static HRESULT WINAPI
fontfileloader_QueryInterface(IDWriteFontFileLoader
*iface
, REFIID riid
, void **obj
)
727 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteFontFileLoader
))
730 IDWriteFontFileLoader_AddRef(iface
);
735 return E_NOINTERFACE
;
738 static ULONG WINAPI
fontfileloader_AddRef(IDWriteFontFileLoader
*iface
)
743 static ULONG WINAPI
fontfileloader_Release(IDWriteFontFileLoader
*iface
)
748 static HRESULT WINAPI
fontfileloader_CreateStreamFromKey(IDWriteFontFileLoader
*iface
, const void *fontFileReferenceKey
, UINT32 fontFileReferenceKeySize
, IDWriteFontFileStream
**fontFileStream
)
753 static const struct IDWriteFontFileLoaderVtbl dwritefontfileloadervtbl
= {
754 fontfileloader_QueryInterface
,
755 fontfileloader_AddRef
,
756 fontfileloader_Release
,
757 fontfileloader_CreateStreamFromKey
760 static void test_FontLoader(void)
762 IDWriteFontFileLoader floader
= { &dwritefontfileloadervtbl
};
763 IDWriteFontFileLoader floader2
= { &dwritefontfileloadervtbl
};
766 hr
= IDWriteFactory_RegisterFontFileLoader(factory
, NULL
);
767 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
768 hr
= IDWriteFactory_RegisterFontFileLoader(factory
, &floader
);
769 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
770 hr
= IDWriteFactory_RegisterFontFileLoader(factory
, &floader2
);
771 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
772 hr
= IDWriteFactory_RegisterFontFileLoader(factory
, &floader
);
773 ok(hr
== DWRITE_E_ALREADYREGISTERED
, "got 0x%08x\n", hr
);
775 hr
= IDWriteFactory_UnregisterFontFileLoader(factory
, &floader
);
776 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
777 hr
= IDWriteFactory_UnregisterFontFileLoader(factory
, &floader
);
778 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
779 hr
= IDWriteFactory_UnregisterFontFileLoader(factory
, &floader2
);
780 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
787 hr
= DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED
, &IID_IDWriteFactory
, (IUnknown
**)&factory
);
788 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
791 win_skip("failed to create factory\n");
795 test_CreateFontFromLOGFONT();
796 test_CreateBitmapRenderTarget();
797 test_GetFontFamily();
798 test_GetFamilyNames();
799 test_CreateFontFace();
801 test_system_fontcollection();
802 test_ConvertFontFaceToLOGFONT();
803 test_CustomFontCollection();
806 IDWriteFactory_Release(factory
);