2 * Unit test suite for fonts
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
29 #define expect_(expected, got, precision) ok(abs((expected) - (got)) <= (precision), "Expected %d, got %d\n", (expected), (got))
30 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
31 #define expectf(expected, got) expectf_((expected), (got), 0.001)
33 static const WCHAR nonexistent
[] = {'T','h','i','s','F','o','n','t','s','h','o','u','l','d','N','o','t','E','x','i','s','t','\0'};
34 static const WCHAR MSSansSerif
[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
35 static const WCHAR TimesNewRoman
[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
36 static const WCHAR Tahoma
[] = {'T','a','h','o','m','a',0};
38 static void set_rect_empty(RectF
*rc
)
46 static void create_testfontfile(const WCHAR
*filename
, int resource
, WCHAR pathW
[MAX_PATH
])
53 GetTempPathW(MAX_PATH
, pathW
);
54 lstrcatW(pathW
, filename
);
56 file
= CreateFileW(pathW
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
57 ok(file
!= INVALID_HANDLE_VALUE
, "file creation failed, at %s, error %d\n", wine_dbgstr_w(pathW
), GetLastError());
59 res
= FindResourceA(GetModuleHandleA(NULL
), MAKEINTRESOURCEA(resource
), (LPCSTR
)RT_RCDATA
);
60 ok(res
!= 0, "couldn't find resource\n");
61 ptr
= LockResource(LoadResource(GetModuleHandleA(NULL
), res
));
62 WriteFile(file
, ptr
, SizeofResource(GetModuleHandleA(NULL
), res
), &written
, NULL
);
63 ok(written
== SizeofResource(GetModuleHandleA(NULL
), res
), "couldn't write resource\n");
67 #define DELETE_FONTFILE(filename) _delete_testfontfile(filename, __LINE__)
68 static void _delete_testfontfile(const WCHAR
*filename
, int line
)
70 BOOL ret
= DeleteFileW(filename
);
71 ok_(__FILE__
,line
)(ret
, "failed to delete file %s, error %d\n", wine_dbgstr_w(filename
), GetLastError());
74 static void test_long_name(void)
77 static const WCHAR path_longname
[] = {'w','i','n','e','_','l','o','n','g','n','a','m','e','.','t','t','f',0};
79 GpFontCollection
*fonts
;
82 WCHAR family_name
[LF_FACESIZE
];
85 stat
= GdipNewPrivateFontCollection(&fonts
);
86 ok(stat
== Ok
, "GdipNewPrivateFontCollection failed: %d\n", stat
);
88 create_testfontfile(path_longname
, 1, path
);
90 stat
= GdipPrivateAddFontFile(fonts
, path
);
91 ok(stat
== Ok
, "GdipPrivateAddFontFile failed: %d\n", stat
);
93 stat
= GdipGetFontCollectionFamilyCount(fonts
, &num_families
);
94 ok(stat
== Ok
, "GdipGetFontCollectionFamilyCount failed: %d\n", stat
);
96 ok(num_families
== 1, "expected num_families to be 1, got %d\n", num_families
);
98 stat
= GdipGetFontCollectionFamilyList(fonts
, num_families
, &family
, &num_families
);
99 ok(stat
== Ok
, "GdipGetFontCollectionFamilyList failed: %d\n", stat
);
101 stat
= GdipGetFamilyName(family
, family_name
, LANG_NEUTRAL
);
102 ok(stat
== Ok
, "GdipGetFamilyName failed: %d\n", stat
);
104 stat
= GdipCreateFont(family
, 256.0, FontStyleRegular
, UnitPixel
, &font
);
105 ok(stat
== Ok
, "GdipCreateFont failed: %d\n", stat
);
109 stat
= GdipDeleteFont(font
);
110 ok(stat
== Ok
, "GdipDeleteFont failed: %d\n", stat
);
112 stat
= GdipDeletePrivateFontCollection(&fonts
);
113 ok(stat
== Ok
, "GdipDeletePrivateFontCollection failed: %d\n", stat
);
115 DELETE_FONTFILE(path
);
118 static void test_createfont(void)
120 GpFontFamily
* fontfamily
= NULL
, *fontfamily2
;
126 WCHAR familyname
[LF_FACESIZE
];
128 stat
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &fontfamily
);
129 expect (FontFamilyNotFound
, stat
);
130 stat
= GdipDeleteFont(font
);
131 expect (InvalidParameter
, stat
);
132 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &fontfamily
);
134 stat
= GdipCreateFont(fontfamily
, 12, FontStyleRegular
, UnitPoint
, &font
);
136 stat
= GdipGetFontUnit (font
, &unit
);
138 expect (UnitPoint
, unit
);
140 stat
= GdipGetFamily(font
, &fontfamily2
);
142 stat
= GdipGetFamilyName(fontfamily2
, familyname
, 0);
144 ok (lstrcmpiW(Tahoma
, familyname
) == 0, "Expected Tahoma, got %s\n",
145 wine_dbgstr_w(familyname
));
146 stat
= GdipDeleteFontFamily(fontfamily2
);
149 /* Test to see if returned size is based on unit (it's not) */
150 GdipGetFontSize(font
, &size
);
151 ok (size
== 12, "Expected 12, got %f\n", size
);
152 GdipDeleteFont(font
);
154 /* Make sure everything is converted correctly for all Units */
155 for (i
= UnitWorld
; i
<=UnitMillimeter
; i
++)
157 if (i
== UnitDisplay
) continue; /* Crashes WindowsXP, wtf? */
158 stat
= GdipCreateFont(fontfamily
, 24, FontStyleRegular
, i
, &font
);
160 GdipGetFontSize (font
, &size
);
161 ok (size
== 24, "Expected 24, got %f (with unit: %d)\n", size
, i
);
162 GdipGetFontUnit (font
, &unit
);
164 GdipDeleteFont(font
);
167 GdipDeleteFontFamily(fontfamily
);
170 static void test_logfont(void)
174 GpFontFamily
*family
;
176 GpGraphics
*graphics
;
180 UINT16 em_height
, line_spacing
;
183 stat
= GdipCreateFromHDC(hdc
, &graphics
);
186 memset(&lfa
, 0, sizeof(LOGFONTA
));
187 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
188 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
190 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
192 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
195 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
196 expect(0, lfa2
.lfWidth
);
197 expect(0, lfa2
.lfEscapement
);
198 expect(0, lfa2
.lfOrientation
);
199 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
200 expect(0, lfa2
.lfItalic
);
201 expect(0, lfa2
.lfUnderline
);
202 expect(0, lfa2
.lfStrikeOut
);
203 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
204 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
205 expect(0, lfa2
.lfOutPrecision
);
206 expect(0, lfa2
.lfClipPrecision
);
207 expect(0, lfa2
.lfQuality
);
208 expect(0, lfa2
.lfPitchAndFamily
);
210 GdipDeleteFont(font
);
212 memset(&lfa
, 0, sizeof(LOGFONTA
));
215 lfa
.lfEscapement
= lfa
.lfOrientation
= 50;
216 lfa
.lfItalic
= lfa
.lfUnderline
= lfa
.lfStrikeOut
= TRUE
;
218 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
219 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
221 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
223 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
226 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
227 expect(0, lfa2
.lfWidth
);
228 expect(0, lfa2
.lfEscapement
);
229 expect(0, lfa2
.lfOrientation
);
230 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
231 expect(TRUE
, lfa2
.lfItalic
);
232 expect(TRUE
, lfa2
.lfUnderline
);
233 expect(TRUE
, lfa2
.lfStrikeOut
);
234 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
235 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
236 expect(0, lfa2
.lfOutPrecision
);
237 expect(0, lfa2
.lfClipPrecision
);
238 expect(0, lfa2
.lfQuality
);
239 expect(0, lfa2
.lfPitchAndFamily
);
241 stat
= GdipGetFontStyle(font
, &style
);
243 ok (style
== (FontStyleItalic
| FontStyleUnderline
| FontStyleStrikeout
),
244 "Expected , got %d\n", style
);
246 stat
= GdipGetFontUnit(font
, &unit
);
248 expect(UnitWorld
, unit
);
250 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
252 expectf(25.347656, rval
);
253 stat
= GdipGetFontSize(font
, &rval
);
257 stat
= GdipGetFamily(font
, &family
);
259 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
261 expect(2048, em_height
);
262 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
264 expect(2472, line_spacing
);
265 GdipDeleteFontFamily(family
);
267 GdipDeleteFont(font
);
269 memset(&lfa
, 0, sizeof(lfa
));
271 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
272 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
274 memset(&lfa2
, 0xff, sizeof(lfa2
));
275 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
277 expect(lfa
.lfHeight
, lfa2
.lfHeight
);
279 stat
= GdipGetFontUnit(font
, &unit
);
281 expect(UnitWorld
, unit
);
283 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
285 expectf(30.175781, rval
);
286 stat
= GdipGetFontSize(font
, &rval
);
290 stat
= GdipGetFamily(font
, &family
);
292 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
294 expect(2048, em_height
);
295 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
297 expect(2472, line_spacing
);
298 GdipDeleteFontFamily(family
);
300 GdipDeleteFont(font
);
302 GdipDeleteGraphics(graphics
);
306 static void test_fontfamily (void)
308 GpFontFamily
*family
, *clonedFontFamily
;
309 WCHAR itsName
[LF_FACESIZE
];
312 /* FontFamily cannot be NULL */
313 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, NULL
);
314 expect (InvalidParameter
, stat
);
316 /* FontFamily must be able to actually find the family.
317 * If it can't, any subsequent calls should fail.
319 stat
= GdipCreateFontFamilyFromName (nonexistent
, NULL
, &family
);
320 expect (FontFamilyNotFound
, stat
);
322 /* Bitmap fonts are not found */
323 stat
= GdipCreateFontFamilyFromName (MSSansSerif
, NULL
, &family
);
324 expect (FontFamilyNotFound
, stat
);
325 if(stat
== Ok
) GdipDeleteFontFamily(family
);
327 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, &family
);
330 stat
= GdipGetFamilyName (family
, itsName
, LANG_NEUTRAL
);
332 expect (0, lstrcmpiW(itsName
, Tahoma
));
336 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
337 stat
= GdipGetFamilyName (family
, NULL
, LANG_NEUTRAL
);
341 /* Make sure we don't read old data */
342 ZeroMemory (itsName
, sizeof(itsName
));
343 stat
= GdipCloneFontFamily(family
, &clonedFontFamily
);
345 GdipDeleteFontFamily(family
);
346 stat
= GdipGetFamilyName(clonedFontFamily
, itsName
, LANG_NEUTRAL
);
348 expect(0, lstrcmpiW(itsName
, Tahoma
));
350 GdipDeleteFontFamily(clonedFontFamily
);
353 static void test_fontfamily_properties (void)
355 GpFontFamily
* FontFamily
= NULL
;
359 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &FontFamily
);
362 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
364 ok (result
== 2472, "Expected 2472, got %d\n", result
);
366 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
368 ok(result
== 2048, "Expected 2048, got %d\n", result
);
370 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
372 ok(result
== 2049, "Expected 2049, got %d\n", result
);
374 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
376 ok(result
== 423, "Expected 423, got %d\n", result
);
377 GdipDeleteFontFamily(FontFamily
);
379 stat
= GdipCreateFontFamilyFromName(TimesNewRoman
, NULL
, &FontFamily
);
380 if(stat
== FontFamilyNotFound
)
381 skip("Times New Roman not installed\n");
385 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
387 ok(result
== 2355, "Expected 2355, got %d\n", result
);
389 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
391 ok(result
== 2048, "Expected 2048, got %d\n", result
);
393 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
395 ok(result
== 1825, "Expected 1825, got %d\n", result
);
397 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
399 ok(result
== 443, "Expected 443 got %d\n", result
);
400 GdipDeleteFontFamily(FontFamily
);
404 static void check_family(const char* context
, GpFontFamily
*family
, WCHAR
*name
)
410 stat
= GdipGetFamilyName(family
, name
, LANG_NEUTRAL
);
411 ok(stat
== Ok
, "could not get the %s family name: %.8x\n", context
, stat
);
413 stat
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPixel
, &font
);
414 ok(stat
== Ok
, "could not create a font for the %s family: %.8x\n", context
, stat
);
417 stat
= GdipDeleteFont(font
);
418 ok(stat
== Ok
, "could not delete the %s family font: %.8x\n", context
, stat
);
421 stat
= GdipDeleteFontFamily(family
);
422 ok(stat
== Ok
, "could not delete the %s family: %.8x\n", context
, stat
);
425 static void test_getgenerics (void)
428 GpFontFamily
*family
;
429 WCHAR sansname
[LF_FACESIZE
], serifname
[LF_FACESIZE
], mononame
[LF_FACESIZE
];
430 int missingfonts
= 0;
432 stat
= GdipGetGenericFontFamilySansSerif(&family
);
434 if (stat
== FontFamilyNotFound
)
437 check_family("Sans Serif", family
, sansname
);
439 stat
= GdipGetGenericFontFamilySerif(&family
);
441 if (stat
== FontFamilyNotFound
)
444 check_family("Serif", family
, serifname
);
446 stat
= GdipGetGenericFontFamilyMonospace(&family
);
448 if (stat
== FontFamilyNotFound
)
451 check_family("Monospace", family
, mononame
);
453 if (missingfonts
&& strcmp(winetest_platform
, "wine") == 0)
454 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
456 /* Check that the family names are all different */
457 ok(lstrcmpiW(sansname
, serifname
) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname
));
458 ok(lstrcmpiW(sansname
, mononame
) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname
));
459 ok(lstrcmpiW(serifname
, mononame
) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname
));
462 static void test_installedfonts (void)
465 GpFontCollection
* collection
=NULL
;
467 stat
= GdipNewInstalledFontCollection(NULL
);
468 expect (InvalidParameter
, stat
);
470 stat
= GdipNewInstalledFontCollection(&collection
);
472 ok (collection
!= NULL
, "got NULL font collection\n");
475 static void test_heightgivendpi(void)
479 GpFontFamily
* fontfamily
= NULL
;
483 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &fontfamily
);
486 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPixel
, &font
);
489 stat
= GdipGetFontHeightGivenDPI(NULL
, 96, &height
);
490 expect(InvalidParameter
, stat
);
492 stat
= GdipGetFontHeightGivenDPI(font
, 96, NULL
);
493 expect(InvalidParameter
, stat
);
495 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
497 expectf(36.210938, height
);
498 GdipDeleteFont(font
);
501 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitWorld
, &font
);
504 stat
= GdipGetFontUnit(font
, &unit
);
506 expect(UnitWorld
, unit
);
508 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
510 expectf(36.210938, height
);
511 GdipDeleteFont(font
);
514 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPoint
, &font
);
516 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
518 expectf(48.281250, height
);
519 GdipDeleteFont(font
);
522 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitInch
, &font
);
525 stat
= GdipGetFontUnit(font
, &unit
);
527 expect(UnitInch
, unit
);
529 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
531 expectf(3476.250000, height
);
532 GdipDeleteFont(font
);
535 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitDocument
, &font
);
538 stat
= GdipGetFontUnit(font
, &unit
);
540 expect(UnitDocument
, unit
);
542 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
544 expectf(11.587500, height
);
545 GdipDeleteFont(font
);
548 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitMillimeter
, &font
);
551 stat
= GdipGetFontUnit(font
, &unit
);
553 expect(UnitMillimeter
, unit
);
555 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
557 expectf(136.860245, height
);
558 GdipDeleteFont(font
);
560 GdipDeleteFontFamily(fontfamily
);
563 static int CALLBACK
font_enum_proc(const LOGFONTW
*lfe
, const TEXTMETRICW
*ntme
,
564 DWORD type
, LPARAM lparam
)
566 NEWTEXTMETRICW
*ntm
= (NEWTEXTMETRICW
*)lparam
;
568 if (type
!= TRUETYPE_FONTTYPE
) return 1;
570 *ntm
= *(NEWTEXTMETRICW
*)ntme
;
576 UINT16 em_height
, line_spacing
, ascent
, descent
;
577 REAL font_height
, font_size
;
581 static void gdi_get_font_metrics(LOGFONTW
*lf
, struct font_metrics
*fm
)
586 OUTLINETEXTMETRICW otm
;
589 hdc
= CreateCompatibleDC(0);
591 /* it's the only way to get extended NEWTEXTMETRIC fields */
592 ret
= EnumFontFamiliesExW(hdc
, lf
, font_enum_proc
, (LPARAM
)&ntm
, 0);
593 ok(!ret
, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf
->lfFaceName
));
595 hfont
= CreateFontIndirectW(lf
);
596 SelectObject(hdc
, hfont
);
598 otm
.otmSize
= sizeof(otm
);
599 ret
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
600 ok(ret
, "GetOutlineTextMetrics failed\n");
605 fm
->lfHeight
= -otm
.otmTextMetrics
.tmAscent
;
606 fm
->line_spacing
= ntm
.ntmCellHeight
;
607 fm
->font_size
= (REAL
)otm
.otmTextMetrics
.tmAscent
;
608 fm
->font_height
= (REAL
)fm
->line_spacing
* fm
->font_size
/ (REAL
)ntm
.ntmSizeEM
;
609 fm
->em_height
= ntm
.ntmSizeEM
;
610 fm
->ascent
= ntm
.ntmSizeEM
;
611 fm
->descent
= ntm
.ntmCellHeight
- ntm
.ntmSizeEM
;
614 static void gdip_get_font_metrics(GpFont
*font
, struct font_metrics
*fm
)
617 GpFontFamily
*family
;
620 stat
= GdipGetFontStyle(font
, &style
);
623 stat
= GdipGetFontHeight(NULL
, NULL
, &fm
->font_height
);
624 expect(InvalidParameter
, stat
);
626 stat
= GdipGetFontHeight(font
, NULL
, NULL
);
627 expect(InvalidParameter
, stat
);
629 stat
= GdipGetFontHeight(font
, NULL
, &fm
->font_height
);
631 stat
= GdipGetFontSize(font
, &fm
->font_size
);
634 fm
->lfHeight
= (INT
)(fm
->font_size
* -1.0);
636 stat
= GdipGetFamily(font
, &family
);
639 stat
= GdipGetEmHeight(family
, style
, &fm
->em_height
);
641 stat
= GdipGetLineSpacing(family
, style
, &fm
->line_spacing
);
643 stat
= GdipGetCellAscent(family
, style
, &fm
->ascent
);
645 stat
= GdipGetCellDescent(family
, style
, &fm
->descent
);
648 GdipDeleteFontFamily(family
);
651 static void cmp_font_metrics(struct font_metrics
*fm1
, struct font_metrics
*fm2
, int line
)
653 ok_(__FILE__
, line
)(fm1
->lfHeight
== fm2
->lfHeight
, "lfHeight %d != %d\n", fm1
->lfHeight
, fm2
->lfHeight
);
654 ok_(__FILE__
, line
)(fm1
->em_height
== fm2
->em_height
, "em_height %u != %u\n", fm1
->em_height
, fm2
->em_height
);
655 ok_(__FILE__
, line
)(fm1
->line_spacing
== fm2
->line_spacing
, "line_spacing %u != %u\n", fm1
->line_spacing
, fm2
->line_spacing
);
656 ok_(__FILE__
, line
)(abs(fm1
->ascent
- fm2
->ascent
) <= 1, "ascent %u != %u\n", fm1
->ascent
, fm2
->ascent
);
657 ok_(__FILE__
, line
)(abs(fm1
->descent
- fm2
->descent
) <= 1, "descent %u != %u\n", fm1
->descent
, fm2
->descent
);
658 ok(fm1
->font_height
> 0.0, "fm1->font_height should be positive, got %f\n", fm1
->font_height
);
659 ok(fm2
->font_height
> 0.0, "fm2->font_height should be positive, got %f\n", fm2
->font_height
);
660 ok_(__FILE__
, line
)(fm1
->font_height
== fm2
->font_height
, "font_height %f != %f\n", fm1
->font_height
, fm2
->font_height
);
661 ok(fm1
->font_size
> 0.0, "fm1->font_size should be positive, got %f\n", fm1
->font_size
);
662 ok(fm2
->font_size
> 0.0, "fm2->font_size should be positive, got %f\n", fm2
->font_size
);
663 ok_(__FILE__
, line
)(fm1
->font_size
== fm2
->font_size
, "font_size %f != %f\n", fm1
->font_size
, fm2
->font_size
);
666 static void test_font_metrics(void)
670 GpFontFamily
*family
;
671 GpGraphics
*graphics
;
674 struct font_metrics fm_gdi
, fm_gdip
;
677 hdc
= CreateCompatibleDC(0);
678 stat
= GdipCreateFromHDC(hdc
, &graphics
);
681 memset(&lf
, 0, sizeof(lf
));
684 lstrcpyW(lf
.lfFaceName
, Tahoma
);
686 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
689 stat
= GdipGetFontUnit(font
, &unit
);
691 expect(UnitWorld
, unit
);
693 gdip_get_font_metrics(font
, &fm_gdip
);
695 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
696 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
697 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
698 fm_gdip
.font_height
, fm_gdip
.font_size
);
700 gdi_get_font_metrics(&lf
, &fm_gdi
);
702 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
703 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
704 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
705 fm_gdi
.font_height
, fm_gdi
.font_size
);
707 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
709 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
711 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
712 gdi_get_font_metrics(&lf
, &fm_gdi
);
714 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
715 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
716 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
717 fm_gdi
.font_height
, fm_gdi
.font_size
);
718 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
720 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
722 GdipDeleteFont(font
);
725 lstrcpyW(lf
.lfFaceName
, Tahoma
);
727 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
730 stat
= GdipGetFontUnit(font
, &unit
);
732 expect(UnitWorld
, unit
);
734 gdip_get_font_metrics(font
, &fm_gdip
);
736 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
737 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
738 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
739 fm_gdip
.font_height
, fm_gdip
.font_size
);
741 gdi_get_font_metrics(&lf
, &fm_gdi
);
743 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
744 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
745 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
746 fm_gdi
.font_height
, fm_gdi
.font_size
);
748 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
750 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
752 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
753 gdi_get_font_metrics(&lf
, &fm_gdi
);
755 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
756 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
757 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
758 fm_gdi
.font_height
, fm_gdi
.font_size
);
759 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
761 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
763 GdipDeleteFont(font
);
765 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &family
);
769 stat
= GdipCreateFont(family
, 13.0, FontStyleRegular
, UnitPixel
, &font
);
772 gdip_get_font_metrics(font
, &fm_gdip
);
774 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
775 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
776 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
777 fm_gdip
.font_height
, fm_gdip
.font_size
);
779 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
781 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
782 gdi_get_font_metrics(&lf
, &fm_gdi
);
784 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
785 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
786 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
787 fm_gdi
.font_height
, fm_gdi
.font_size
);
788 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
790 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
792 stat
= GdipGetLogFontW(font
, NULL
, &lf
);
793 expect(InvalidParameter
, stat
);
795 GdipDeleteFont(font
);
797 stat
= GdipCreateFont(family
, -13.0, FontStyleRegular
, UnitPixel
, &font
);
798 expect(InvalidParameter
, stat
);
800 GdipDeleteFontFamily(family
);
802 GdipDeleteGraphics(graphics
);
806 static void test_font_substitution(void)
808 WCHAR ms_shell_dlg
[LF_FACESIZE
];
809 char fallback_font
[LF_FACESIZE
];
814 GpGraphics
*graphics
;
816 GpFontFamily
*family
;
819 hdc
= CreateCompatibleDC(0);
820 status
= GdipCreateFromHDC(hdc
, &graphics
);
823 hfont
= GetStockObject(DEFAULT_GUI_FONT
);
824 ok(hfont
!= 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
826 memset(&lf
, 0xfe, sizeof(lf
));
827 ret
= GetObjectA(hfont
, sizeof(lf
), &lf
);
828 ok(ret
== sizeof(lf
), "GetObject failed\n");
829 ok(!lstrcmpA(lf
.lfFaceName
, "MS Shell Dlg"), "wrong face name %s\n", lf
.lfFaceName
);
830 MultiByteToWideChar(CP_ACP
, 0, lf
.lfFaceName
, -1, ms_shell_dlg
, LF_FACESIZE
);
832 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
834 memset(&lf
, 0xfe, sizeof(lf
));
835 status
= GdipGetLogFontA(font
, graphics
, &lf
);
837 ok(!lstrcmpA(lf
.lfFaceName
, "Microsoft Sans Serif") ||
838 !lstrcmpA(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
839 GdipDeleteFont(font
);
841 status
= GdipCreateFontFamilyFromName(ms_shell_dlg
, NULL
, &family
);
843 status
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPoint
, &font
);
845 memset(&lf
, 0xfe, sizeof(lf
));
846 status
= GdipGetLogFontA(font
, graphics
, &lf
);
848 ok(!lstrcmpA(lf
.lfFaceName
, "Microsoft Sans Serif") ||
849 !lstrcmpA(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
850 GdipDeleteFont(font
);
851 GdipDeleteFontFamily(family
);
853 status
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &family
);
854 ok(status
== FontFamilyNotFound
, "expected FontFamilyNotFound, got %d\n", status
);
856 /* nonexistent fonts fallback to Arial, or something else if it's missing */
857 strcpy(lf
.lfFaceName
,"Arial");
858 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
860 status
= GdipGetLogFontA(font
, graphics
, &lf
);
862 strcpy(fallback_font
,lf
.lfFaceName
);
863 trace("fallback font %s\n", fallback_font
);
864 GdipDeleteFont(font
);
866 lstrcpyA(lf
.lfFaceName
, "ThisFontShouldNotExist");
867 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
869 memset(&lf
, 0xfe, sizeof(lf
));
870 status
= GdipGetLogFontA(font
, graphics
, &lf
);
872 ok(!lstrcmpA(lf
.lfFaceName
, fallback_font
), "wrong face name %s / %s\n", lf
.lfFaceName
, fallback_font
);
873 GdipDeleteFont(font
);
876 lf
.lfFaceName
[0] = 0;
877 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
879 memset(&lf
, 0xfe, sizeof(lf
));
880 status
= GdipGetLogFontA(font
, graphics
, &lf
);
882 ok(!lstrcmpA(lf
.lfFaceName
, fallback_font
), "wrong face name %s / %s\n", lf
.lfFaceName
, fallback_font
);
883 GdipDeleteFont(font
);
885 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
888 lstrcpyA(lf
.lfFaceName
, "ThisFontShouldNotExist");
890 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
892 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
893 "expected NotTrueTypeFont, got %d\n", status
);
894 /* FIXME: remove when wine is fixed */
895 if (font
) GdipDeleteFont(font
);
898 lf
.lfFaceName
[0] = 0;
900 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
902 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
903 "expected NotTrueTypeFont, got %d\n", status
);
904 /* FIXME: remove when wine is fixed */
905 if (font
) GdipDeleteFont(font
);
907 GdipDeleteGraphics(graphics
);
911 static void test_font_transform(void)
913 static const WCHAR string
[] = { 'A',0 };
918 GpGraphics
*graphics
;
920 GpStringFormat
*format
, *typographic
;
921 PointF pos
[1] = { { 0,0 } };
922 REAL height
, margin_y
;
925 hdc
= CreateCompatibleDC(0);
926 status
= GdipCreateFromHDC(hdc
, &graphics
);
929 status
= GdipSetPageUnit(graphics
, UnitPixel
);
932 status
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
934 status
= GdipStringFormatGetGenericTypographic(&typographic
);
937 memset(&lf
, 0, sizeof(lf
));
938 lstrcpyA(lf
.lfFaceName
, "Tahoma");
941 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
944 margin_y
= 100.0 / 8.0;
946 /* identity matrix */
947 status
= GdipCreateMatrix(&matrix
);
949 status
= GdipSetWorldTransform(graphics
, matrix
);
951 status
= GdipGetLogFontA(font
, graphics
, &lf
);
953 expect(-100, lf
.lfHeight
);
954 expect(0, lf
.lfWidth
);
955 expect(0, lf
.lfEscapement
);
956 expect(0, lf
.lfOrientation
);
957 status
= GdipGetFontHeight(font
, graphics
, &height
);
959 expectf(120.703125, height
);
960 set_rect_empty(&rect
);
961 set_rect_empty(&bounds
);
962 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
964 expectf(0.0, bounds
.X
);
965 expectf(0.0, bounds
.Y
);
967 expectf(height
+ margin_y
, bounds
.Height
);
968 set_rect_empty(&rect
);
969 set_rect_empty(&bounds
);
970 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
972 expectf(0.0, bounds
.X
);
973 expectf(0.0, bounds
.Y
);
974 expectf_(height
, bounds
.Height
, 1.0);
975 set_rect_empty(&bounds
);
976 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
977 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
979 expectf(0.0, bounds
.X
);
980 expectf_(-100.0, bounds
.Y
, 0.05);
981 expectf_(height
, bounds
.Height
, 0.5);
982 set_rect_empty(&bounds
);
983 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
984 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
986 expectf(0.0, bounds
.X
);
987 expectf_(-100.0, bounds
.Y
, 0.05);
988 expectf_(height
, bounds
.Height
, 0.5);
991 status
= GdipScaleMatrix(matrix
, 2.0, 3.0, MatrixOrderAppend
);
993 status
= GdipSetWorldTransform(graphics
, matrix
);
995 status
= GdipGetLogFontA(font
, graphics
, &lf
);
997 expect(-300, lf
.lfHeight
);
998 expect(0, lf
.lfWidth
);
999 expect(0, lf
.lfEscapement
);
1000 expect(0, lf
.lfOrientation
);
1001 status
= GdipGetFontHeight(font
, graphics
, &height
);
1003 expectf(120.703125, height
);
1004 set_rect_empty(&rect
);
1005 set_rect_empty(&bounds
);
1006 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1008 expectf(0.0, bounds
.X
);
1009 expectf(0.0, bounds
.Y
);
1011 expectf(height
+ margin_y
, bounds
.Height
);
1012 set_rect_empty(&rect
);
1013 set_rect_empty(&bounds
);
1014 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1016 expectf(0.0, bounds
.X
);
1017 expectf(0.0, bounds
.Y
);
1018 expectf_(height
, bounds
.Height
, 0.05);
1019 set_rect_empty(&bounds
);
1020 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1021 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1023 expectf(0.0, bounds
.X
);
1024 expectf_(-100.0, bounds
.Y
, 0.05);
1025 expectf_(height
, bounds
.Height
, 0.2);
1026 set_rect_empty(&bounds
);
1027 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1028 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1030 expectf(0.0, bounds
.X
);
1032 expectf_(-300.0, bounds
.Y
, 0.15);
1034 expectf(height
* 3.0, bounds
.Height
);
1036 /* scale + ratate matrix */
1037 status
= GdipRotateMatrix(matrix
, 45.0, MatrixOrderAppend
);
1039 status
= GdipSetWorldTransform(graphics
, matrix
);
1041 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1043 expect(-300, lf
.lfHeight
);
1044 expect(0, lf
.lfWidth
);
1045 expect_(3151, lf
.lfEscapement
, 1);
1046 expect_(3151, lf
.lfOrientation
, 1);
1047 status
= GdipGetFontHeight(font
, graphics
, &height
);
1049 expectf(120.703125, height
);
1050 set_rect_empty(&rect
);
1051 set_rect_empty(&bounds
);
1052 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1054 expectf(0.0, bounds
.X
);
1055 expectf(0.0, bounds
.Y
);
1057 expectf(height
+ margin_y
, bounds
.Height
);
1058 set_rect_empty(&rect
);
1059 set_rect_empty(&bounds
);
1060 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1062 expectf(0.0, bounds
.X
);
1063 expectf(0.0, bounds
.Y
);
1064 expectf_(height
, bounds
.Height
, 0.05);
1065 set_rect_empty(&bounds
);
1066 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1067 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1069 expectf(0.0, bounds
.X
);
1070 expectf_(-100.0, bounds
.Y
, 0.05);
1071 expectf_(height
, bounds
.Height
, 0.2);
1072 set_rect_empty(&bounds
);
1073 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1074 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1077 expectf_(-43.814377, bounds
.X
, 0.05);
1079 expectf_(-212.235611, bounds
.Y
, 0.05);
1081 expectf_(340.847534, bounds
.Height
, 0.05);
1083 /* scale + ratate + shear matrix */
1084 status
= GdipShearMatrix(matrix
, 4.0, 5.0, MatrixOrderAppend
);
1086 status
= GdipSetWorldTransform(graphics
, matrix
);
1088 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1091 expect(1032, lf
.lfHeight
);
1092 expect(0, lf
.lfWidth
);
1093 expect_(3099, lf
.lfEscapement
, 1);
1094 expect_(3099, lf
.lfOrientation
, 1);
1095 status
= GdipGetFontHeight(font
, graphics
, &height
);
1097 expectf(120.703125, height
);
1098 set_rect_empty(&rect
);
1099 set_rect_empty(&bounds
);
1100 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1102 expectf(0.0, bounds
.X
);
1103 expectf(0.0, bounds
.Y
);
1105 expectf(height
+ margin_y
, bounds
.Height
);
1106 set_rect_empty(&rect
);
1107 set_rect_empty(&bounds
);
1108 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1110 expectf(0.0, bounds
.X
);
1111 expectf(0.0, bounds
.Y
);
1112 expectf_(height
, bounds
.Height
, 0.2);
1113 set_rect_empty(&bounds
);
1114 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1115 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1117 expectf(0.0, bounds
.X
);
1118 expectf_(-100.0, bounds
.Y
, 0.2);
1119 expectf_(height
, bounds
.Height
, 0.2);
1120 set_rect_empty(&bounds
);
1121 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1122 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1125 expectf_(-636.706848, bounds
.X
, 0.05);
1127 expectf_(-175.257523, bounds
.Y
, 0.05);
1129 expectf_(1532.984985, bounds
.Height
, 0.05);
1131 /* scale + ratate + shear + translate matrix */
1132 status
= GdipTranslateMatrix(matrix
, 10.0, 20.0, MatrixOrderAppend
);
1134 status
= GdipSetWorldTransform(graphics
, matrix
);
1136 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1139 expect(1032, lf
.lfHeight
);
1140 expect(0, lf
.lfWidth
);
1141 expect_(3099, lf
.lfEscapement
, 1);
1142 expect_(3099, lf
.lfOrientation
, 1);
1143 status
= GdipGetFontHeight(font
, graphics
, &height
);
1145 expectf(120.703125, height
);
1146 set_rect_empty(&rect
);
1147 set_rect_empty(&bounds
);
1148 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1150 expectf(0.0, bounds
.X
);
1151 expectf(0.0, bounds
.Y
);
1153 expectf(height
+ margin_y
, bounds
.Height
);
1154 set_rect_empty(&rect
);
1155 set_rect_empty(&bounds
);
1156 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1158 expectf(0.0, bounds
.X
);
1159 expectf(0.0, bounds
.Y
);
1160 expectf_(height
, bounds
.Height
, 0.1);
1161 set_rect_empty(&bounds
);
1162 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1163 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1165 expectf(0.0, bounds
.X
);
1166 expectf_(-100.0, bounds
.Y
, 0.2);
1167 expectf_(height
, bounds
.Height
, 0.2);
1168 set_rect_empty(&bounds
);
1169 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1170 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1173 expectf_(-626.706848, bounds
.X
, 0.05);
1175 expectf_(-155.257523, bounds
.Y
, 0.05);
1177 expectf_(1532.984985, bounds
.Height
, 0.05);
1179 GdipDeleteMatrix(matrix
);
1180 GdipDeleteFont(font
);
1181 GdipDeleteGraphics(graphics
);
1182 GdipDeleteStringFormat(typographic
);
1183 GdipDeleteStringFormat(format
);
1187 static void test_GdipGetFontCollectionFamilyList(void)
1189 GpFontFamily
*family
, *family2
;
1190 GpFontCollection
*collection
;
1194 status
= GdipNewInstalledFontCollection(&collection
);
1195 ok(status
== Ok
, "Failed to get system collection, status %d.\n", status
);
1198 status
= GdipGetFontCollectionFamilyCount(collection
, &count
);
1199 ok(status
== Ok
, "Failed to get family count, status %d.\n", status
);
1200 ok(count
> 0, "Unexpected empty collection.\n");
1202 status
= GdipGetFontCollectionFamilyList(NULL
, 0, NULL
, NULL
);
1203 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1206 status
= GdipGetFontCollectionFamilyList(NULL
, 0, NULL
, &found
);
1207 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1208 ok(found
== 123, "Unexpected list count %d.\n", found
);
1210 status
= GdipGetFontCollectionFamilyList(collection
, 0, NULL
, NULL
);
1211 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1214 status
= GdipGetFontCollectionFamilyList(collection
, 0, NULL
, &found
);
1215 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1216 ok(found
== 123, "Unexpected list count %d.\n", found
);
1219 status
= GdipGetFontCollectionFamilyList(collection
, 1, NULL
, &found
);
1220 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1221 ok(found
== 123, "Unexpected list count %d.\n", found
);
1225 status
= GdipGetFontCollectionFamilyList(collection
, 1, &family
, &found
);
1226 ok(status
== Ok
, "Failed to get family list, status %d.\n", status
);
1227 ok(found
== 1, "Unexpected list count %d.\n", found
);
1228 ok(family
!= NULL
, "Expected family instance.\n");
1232 status
= GdipGetFontCollectionFamilyList(collection
, 1, &family2
, &found
);
1233 ok(status
== Ok
, "Failed to get family list, status %d.\n", status
);
1234 ok(found
== 1, "Unexpected list count %d.\n", found
);
1235 ok(family2
!= family
, "Unexpected family instance.\n");
1237 GdipDeleteFontFamily(family
);
1238 GdipDeleteFontFamily(family2
);
1241 static void test_GdipGetFontCollectionFamilyCount(void)
1243 GpFontCollection
*collection
;
1247 status
= GdipGetFontCollectionFamilyCount(NULL
, NULL
);
1248 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1251 status
= GdipGetFontCollectionFamilyCount(NULL
, &count
);
1252 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1253 ok(count
== 123, "Unexpected family count %d.\n", count
);
1255 status
= GdipNewInstalledFontCollection(&collection
);
1256 ok(status
== Ok
, "Failed to get system collection, status %d.\n", status
);
1258 status
= GdipGetFontCollectionFamilyCount(collection
, NULL
);
1259 ok(status
== InvalidParameter
, "Unexpected status %d.\n", status
);
1264 struct GdiplusStartupInput gdiplusStartupInput
;
1265 ULONG_PTR gdiplusToken
;
1267 int (CDECL
* _controlfp_s
)(unsigned int *cur
, unsigned int newval
, unsigned int mask
);
1269 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
1270 hmsvcrt
= LoadLibraryA("msvcrt");
1271 _controlfp_s
= (void*)GetProcAddress(hmsvcrt
, "_controlfp_s");
1272 if (_controlfp_s
) _controlfp_s(0, 0, 0x0008001e);
1274 gdiplusStartupInput
.GdiplusVersion
= 1;
1275 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1276 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1277 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1279 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1282 test_font_transform();
1283 test_font_substitution();
1284 test_font_metrics();
1288 test_fontfamily_properties();
1290 test_installedfonts();
1291 test_heightgivendpi();
1292 test_GdipGetFontCollectionFamilyList();
1293 test_GdipGetFontCollectionFamilyCount();
1295 GdiplusShutdown(gdiplusToken
);