3b23d0ac44204e57619c778f37afb42b989d9874
[reactos.git] / rostests / winetests / gdiplus / font.c
1 /*
2 * Unit test suite for fonts
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <math.h>
23
24 #include "windows.h"
25 #include "gdiplus.h"
26 #include "wine/test.h"
27
28 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
29 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %f, got %f\n", expected, got)
30
31 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'};
32 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
33 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
34 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
35 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
36 static const WCHAR Tahoma[] = {'T','a','h','o','m','a',0};
37 static const WCHAR LiberationSerif[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f',0};
38
39 static void test_createfont(void)
40 {
41 GpFontFamily* fontfamily = NULL, *fontfamily2;
42 GpFont* font = NULL;
43 GpStatus stat;
44 Unit unit;
45 UINT i;
46 REAL size;
47 WCHAR familyname[LF_FACESIZE];
48
49 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
50 expect (FontFamilyNotFound, stat);
51 stat = GdipDeleteFont(font);
52 expect (InvalidParameter, stat);
53 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
54 expect (Ok, stat);
55 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
56 expect (Ok, stat);
57 stat = GdipGetFontUnit (font, &unit);
58 expect (Ok, stat);
59 expect (UnitPoint, unit);
60
61 stat = GdipGetFamily(font, &fontfamily2);
62 expect(Ok, stat);
63 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
64 expect(Ok, stat);
65 ok (lstrcmpiW(Tahoma, familyname) == 0, "Expected Tahoma, got %s\n",
66 wine_dbgstr_w(familyname));
67 stat = GdipDeleteFontFamily(fontfamily2);
68 expect(Ok, stat);
69
70 /* Test to see if returned size is based on unit (its not) */
71 GdipGetFontSize(font, &size);
72 ok (size == 12, "Expected 12, got %f\n", size);
73 GdipDeleteFont(font);
74
75 /* Make sure everything is converted correctly for all Units */
76 for (i = UnitWorld; i <=UnitMillimeter; i++)
77 {
78 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
79 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
80 GdipGetFontSize (font, &size);
81 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
82 GdipGetFontUnit (font, &unit);
83 expect (i, unit);
84 GdipDeleteFont(font);
85 }
86
87 GdipDeleteFontFamily(fontfamily);
88 }
89
90 #if CORE_6660_IS_FIXED
91 static void test_logfont(void)
92 {
93 LOGFONTA lfa, lfa2;
94 GpFont *font;
95 GpFontFamily *family;
96 GpStatus stat;
97 GpGraphics *graphics;
98 HDC hdc = GetDC(0);
99 INT style;
100 REAL rval;
101 UINT16 em_height, line_spacing;
102 Unit unit;
103
104 GdipCreateFromHDC(hdc, &graphics);
105
106 memset(&lfa, 0, sizeof(LOGFONTA));
107 memset(&lfa2, 0xff, sizeof(LOGFONTA));
108
109 /* empty FaceName */
110 lfa.lfFaceName[0] = 0;
111 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
112 expect(NotTrueTypeFont, stat);
113
114 lstrcpyA(lfa.lfFaceName, "Tahoma");
115
116 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
117 expect(Ok, stat);
118 stat = GdipGetLogFontA(font, graphics, &lfa2);
119 expect(Ok, stat);
120
121 ok(lfa2.lfHeight < 0, "Expected negative height\n");
122 expect(0, lfa2.lfWidth);
123 expect(0, lfa2.lfEscapement);
124 expect(0, lfa2.lfOrientation);
125 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
126 expect(0, lfa2.lfItalic);
127 expect(0, lfa2.lfUnderline);
128 expect(0, lfa2.lfStrikeOut);
129 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
130 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
131 expect(0, lfa2.lfOutPrecision);
132 expect(0, lfa2.lfClipPrecision);
133 expect(0, lfa2.lfQuality);
134 expect(0, lfa2.lfPitchAndFamily);
135
136 GdipDeleteFont(font);
137
138 memset(&lfa, 0, sizeof(LOGFONTA));
139 lfa.lfHeight = 25;
140 lfa.lfWidth = 25;
141 lfa.lfEscapement = lfa.lfOrientation = 50;
142 lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE;
143
144 memset(&lfa2, 0xff, sizeof(LOGFONTA));
145 lstrcpyA(lfa.lfFaceName, "Tahoma");
146
147 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
148 expect(Ok, stat);
149 stat = GdipGetLogFontA(font, graphics, &lfa2);
150 expect(Ok, stat);
151
152 ok(lfa2.lfHeight < 0, "Expected negative height\n");
153 expect(0, lfa2.lfWidth);
154 expect(0, lfa2.lfEscapement);
155 expect(0, lfa2.lfOrientation);
156 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
157 expect(TRUE, lfa2.lfItalic);
158 expect(TRUE, lfa2.lfUnderline);
159 expect(TRUE, lfa2.lfStrikeOut);
160 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
161 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
162 expect(0, lfa2.lfOutPrecision);
163 expect(0, lfa2.lfClipPrecision);
164 expect(0, lfa2.lfQuality);
165 expect(0, lfa2.lfPitchAndFamily);
166
167 stat = GdipGetFontStyle(font, &style);
168 expect(Ok, stat);
169 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
170 "Expected , got %d\n", style);
171
172 stat = GdipGetFontUnit(font, &unit);
173 expect(Ok, stat);
174 expect(UnitWorld, unit);
175
176 stat = GdipGetFontHeight(font, graphics, &rval);
177 expect(Ok, stat);
178 expectf(25.347656, rval);
179 stat = GdipGetFontSize(font, &rval);
180 expect(Ok, stat);
181 expectf(21.0, rval);
182
183 stat = GdipGetFamily(font, &family);
184 expect(Ok, stat);
185 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
186 expect(Ok, stat);
187 expect(2048, em_height);
188 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
189 expect(Ok, stat);
190 expect(2472, line_spacing);
191 GdipDeleteFontFamily(family);
192
193 GdipDeleteFont(font);
194
195 memset(&lfa, 0, sizeof(lfa));
196 lfa.lfHeight = -25;
197 lstrcpyA(lfa.lfFaceName, "Tahoma");
198 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
199 expect(Ok, stat);
200 memset(&lfa2, 0xff, sizeof(lfa2));
201 stat = GdipGetLogFontA(font, graphics, &lfa2);
202 expect(Ok, stat);
203 expect(lfa.lfHeight, lfa2.lfHeight);
204
205 stat = GdipGetFontUnit(font, &unit);
206 expect(Ok, stat);
207 expect(UnitWorld, unit);
208
209 stat = GdipGetFontHeight(font, graphics, &rval);
210 expect(Ok, stat);
211 expectf(30.175781, rval);
212 stat = GdipGetFontSize(font, &rval);
213 expect(Ok, stat);
214 expectf(25.0, rval);
215
216 stat = GdipGetFamily(font, &family);
217 expect(Ok, stat);
218 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
219 expect(Ok, stat);
220 expect(2048, em_height);
221 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
222 expect(Ok, stat);
223 expect(2472, line_spacing);
224 GdipDeleteFontFamily(family);
225
226 GdipDeleteFont(font);
227
228 GdipDeleteGraphics(graphics);
229 ReleaseDC(0, hdc);
230 }
231
232 static void test_fontfamily (void)
233 {
234 GpFontFamily *family, *clonedFontFamily;
235 WCHAR itsName[LF_FACESIZE];
236 GpStatus stat;
237
238 /* FontFamily cannot be NULL */
239 stat = GdipCreateFontFamilyFromName (Tahoma , NULL, NULL);
240 expect (InvalidParameter, stat);
241
242 /* FontFamily must be able to actually find the family.
243 * If it can't, any subsequent calls should fail.
244 */
245 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
246 expect (FontFamilyNotFound, stat);
247
248 /* Bitmap fonts are not found */
249 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
250 expect (FontFamilyNotFound, stat);
251 if(stat == Ok) GdipDeleteFontFamily(family);
252
253 stat = GdipCreateFontFamilyFromName (Tahoma, NULL, &family);
254 expect (Ok, stat);
255
256 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
257 expect (Ok, stat);
258 expect (0, lstrcmpiW(itsName, Tahoma));
259
260 if (0)
261 {
262 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
263 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
264 expect (Ok, stat);
265 }
266
267 /* Make sure we don't read old data */
268 ZeroMemory (itsName, sizeof(itsName));
269 stat = GdipCloneFontFamily(family, &clonedFontFamily);
270 expect (Ok, stat);
271 GdipDeleteFontFamily(family);
272 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
273 expect(Ok, stat);
274 expect(0, lstrcmpiW(itsName, Tahoma));
275
276 GdipDeleteFontFamily(clonedFontFamily);
277 }
278 #endif // CORE_6660_IS_FIXED
279
280 static void test_fontfamily_properties (void)
281 {
282 GpFontFamily* FontFamily = NULL;
283 GpStatus stat;
284 UINT16 result = 0;
285
286 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &FontFamily);
287 expect(Ok, stat);
288
289 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
290 expect(Ok, stat);
291 ok (result == 2472, "Expected 2472, got %d\n", result);
292 result = 0;
293 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
294 expect(Ok, stat);
295 ok(result == 2048, "Expected 2048, got %d\n", result);
296 result = 0;
297 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
298 expect(Ok, stat);
299 ok(result == 2049, "Expected 2049, got %d\n", result);
300 result = 0;
301 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
302 expect(Ok, stat);
303 ok(result == 423, "Expected 423, got %d\n", result);
304 GdipDeleteFontFamily(FontFamily);
305
306 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
307 if(stat == FontFamilyNotFound)
308 skip("Times New Roman not installed\n");
309 else
310 {
311 result = 0;
312 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
313 expect(Ok, stat);
314 ok(result == 2355, "Expected 2355, got %d\n", result);
315 result = 0;
316 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
317 expect(Ok, stat);
318 ok(result == 2048, "Expected 2048, got %d\n", result);
319 result = 0;
320 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
321 expect(Ok, stat);
322 ok(result == 1825, "Expected 1825, got %d\n", result);
323 result = 0;
324 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
325 expect(Ok, stat);
326 ok(result == 443, "Expected 443 got %d\n", result);
327 GdipDeleteFontFamily(FontFamily);
328 }
329 }
330
331 static void check_family(const char* context, GpFontFamily *family, WCHAR *name)
332 {
333 GpStatus stat;
334 GpFont* font;
335
336 *name = 0;
337 stat = GdipGetFamilyName(family, name, LANG_NEUTRAL);
338 ok(stat == Ok, "could not get the %s family name: %.8x\n", context, stat);
339
340 stat = GdipCreateFont(family, 12, FontStyleRegular, UnitPixel, &font);
341 ok(stat == Ok, "could not create a font for the %s family: %.8x\n", context, stat);
342 if (stat == Ok)
343 {
344 stat = GdipDeleteFont(font);
345 ok(stat == Ok, "could not delete the %s family font: %.8x\n", context, stat);
346 }
347
348 stat = GdipDeleteFontFamily(family);
349 ok(stat == Ok, "could not delete the %s family: %.8x\n", context, stat);
350 }
351
352 static void test_getgenerics (void)
353 {
354 GpStatus stat;
355 GpFontFamily *family;
356 WCHAR sansname[LF_FACESIZE], serifname[LF_FACESIZE], mononame[LF_FACESIZE];
357 int missingfonts = 0;
358
359 stat = GdipGetGenericFontFamilySansSerif(&family);
360 expect (Ok, stat);
361 if (stat == FontFamilyNotFound)
362 missingfonts = 1;
363 else
364 check_family("Sans Serif", family, sansname);
365
366 stat = GdipGetGenericFontFamilySerif(&family);
367 expect (Ok, stat);
368 if (stat == FontFamilyNotFound)
369 missingfonts = 1;
370 else
371 check_family("Serif", family, serifname);
372
373 stat = GdipGetGenericFontFamilyMonospace(&family);
374 expect (Ok, stat);
375 if (stat == FontFamilyNotFound)
376 missingfonts = 1;
377 else
378 check_family("Monospace", family, mononame);
379
380 if (missingfonts && strcmp(winetest_platform, "wine") == 0)
381 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
382
383 /* Check that the family names are all different */
384 ok(lstrcmpiW(sansname, serifname) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname));
385 ok(lstrcmpiW(sansname, mononame) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname));
386 ok(lstrcmpiW(serifname, mononame) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname));
387 }
388
389 static void test_installedfonts (void)
390 {
391 GpStatus stat;
392 GpFontCollection* collection=NULL;
393
394 stat = GdipNewInstalledFontCollection(NULL);
395 expect (InvalidParameter, stat);
396
397 stat = GdipNewInstalledFontCollection(&collection);
398 expect (Ok, stat);
399 ok (collection != NULL, "got NULL font collection\n");
400 }
401
402 static void test_heightgivendpi(void)
403 {
404 GpStatus stat;
405 GpFont* font = NULL;
406 GpFontFamily* fontfamily = NULL;
407 REAL height;
408 Unit unit;
409
410 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
411 expect(Ok, stat);
412
413 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font);
414 expect(Ok, stat);
415
416 stat = GdipGetFontHeightGivenDPI(NULL, 96, &height);
417 expect(InvalidParameter, stat);
418
419 stat = GdipGetFontHeightGivenDPI(font, 96, NULL);
420 expect(InvalidParameter, stat);
421
422 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
423 expect(Ok, stat);
424 expectf(36.210938, height);
425 GdipDeleteFont(font);
426
427 height = 12345;
428 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font);
429 expect(Ok, stat);
430
431 stat = GdipGetFontUnit(font, &unit);
432 expect(Ok, stat);
433 expect(UnitWorld, unit);
434
435 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
436 expect(Ok, stat);
437 expectf(36.210938, height);
438 GdipDeleteFont(font);
439
440 height = 12345;
441 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font);
442 expect(Ok, stat);
443 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
444 expect(Ok, stat);
445 expectf(48.281250, height);
446 GdipDeleteFont(font);
447
448 height = 12345;
449 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font);
450 expect(Ok, stat);
451
452 stat = GdipGetFontUnit(font, &unit);
453 expect(Ok, stat);
454 expect(UnitInch, unit);
455
456 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
457 expect(Ok, stat);
458 expectf(3476.250000, height);
459 GdipDeleteFont(font);
460
461 height = 12345;
462 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font);
463 expect(Ok, stat);
464
465 stat = GdipGetFontUnit(font, &unit);
466 expect(Ok, stat);
467 expect(UnitDocument, unit);
468
469 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
470 expect(Ok, stat);
471 expectf(11.587500, height);
472 GdipDeleteFont(font);
473
474 height = 12345;
475 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font);
476 expect(Ok, stat);
477
478 stat = GdipGetFontUnit(font, &unit);
479 expect(Ok, stat);
480 expect(UnitMillimeter, unit);
481
482 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
483 expect(Ok, stat);
484 expectf(136.860245, height);
485 GdipDeleteFont(font);
486
487 GdipDeleteFontFamily(fontfamily);
488 }
489
490 #if CORE_6660_IS_FIXED
491 static int CALLBACK font_enum_proc(const LOGFONTW *lfe, const TEXTMETRICW *ntme,
492 DWORD type, LPARAM lparam)
493 {
494 NEWTEXTMETRICW *ntm = (NEWTEXTMETRICW *)lparam;
495
496 if (type != TRUETYPE_FONTTYPE) return 1;
497
498 *ntm = *(NEWTEXTMETRICW *)ntme;
499 return 0;
500 }
501
502 struct font_metrics
503 {
504 UINT16 em_height, line_spacing, ascent, descent;
505 REAL font_height, font_size;
506 INT lfHeight;
507 };
508
509 static void gdi_get_font_metrics(LOGFONTW *lf, struct font_metrics *fm)
510 {
511 HDC hdc;
512 HFONT hfont;
513 NEWTEXTMETRICW ntm;
514 OUTLINETEXTMETRICW otm;
515 int ret;
516
517 hdc = CreateCompatibleDC(0);
518
519 /* it's the only way to get extended NEWTEXTMETRIC fields */
520 ret = EnumFontFamiliesExW(hdc, lf, font_enum_proc, (LPARAM)&ntm, 0);
521 ok(!ret, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf->lfFaceName));
522
523 hfont = CreateFontIndirectW(lf);
524 SelectObject(hdc, hfont);
525
526 otm.otmSize = sizeof(otm);
527 ret = GetOutlineTextMetricsW(hdc, otm.otmSize, &otm);
528 ok(ret, "GetOutlineTextMetrics failed\n");
529
530 DeleteDC(hdc);
531 DeleteObject(hfont);
532
533 fm->lfHeight = -otm.otmTextMetrics.tmAscent;
534 fm->line_spacing = ntm.ntmCellHeight;
535 fm->font_size = (REAL)otm.otmTextMetrics.tmAscent;
536 fm->font_height = (REAL)fm->line_spacing * fm->font_size / (REAL)ntm.ntmSizeEM;
537 fm->em_height = ntm.ntmSizeEM;
538 fm->ascent = ntm.ntmSizeEM;
539 fm->descent = ntm.ntmCellHeight - ntm.ntmSizeEM;
540 }
541
542 static void gdip_get_font_metrics(GpFont *font, struct font_metrics *fm)
543 {
544 INT style;
545 GpFontFamily *family;
546 GpStatus stat;
547
548 stat = GdipGetFontStyle(font, &style);
549 expect(Ok, stat);
550
551 stat = GdipGetFontHeight(font, NULL, &fm->font_height);
552 expect(Ok, stat);
553 stat = GdipGetFontSize(font, &fm->font_size);
554 expect(Ok, stat);
555
556 fm->lfHeight = (INT)(fm->font_size * -1.0);
557
558 stat = GdipGetFamily(font, &family);
559 expect(Ok, stat);
560
561 stat = GdipGetEmHeight(family, style, &fm->em_height);
562 expect(Ok, stat);
563 stat = GdipGetLineSpacing(family, style, &fm->line_spacing);
564 expect(Ok, stat);
565 stat = GdipGetCellAscent(family, style, &fm->ascent);
566 expect(Ok, stat);
567 stat = GdipGetCellDescent(family, style, &fm->descent);
568 expect(Ok, stat);
569
570 GdipDeleteFontFamily(family);
571 }
572
573 static void cmp_font_metrics(struct font_metrics *fm1, struct font_metrics *fm2, int line)
574 {
575 ok_(__FILE__, line)(fm1->lfHeight == fm2->lfHeight, "lfHeight %d != %d\n", fm1->lfHeight, fm2->lfHeight);
576 ok_(__FILE__, line)(fm1->em_height == fm2->em_height, "em_height %u != %u\n", fm1->em_height, fm2->em_height);
577 ok_(__FILE__, line)(fm1->line_spacing == fm2->line_spacing, "line_spacing %u != %u\n", fm1->line_spacing, fm2->line_spacing);
578 ok_(__FILE__, line)(abs(fm1->ascent - fm2->ascent) <= 1, "ascent %u != %u\n", fm1->ascent, fm2->ascent);
579 ok_(__FILE__, line)(abs(fm1->descent - fm2->descent) <= 1, "descent %u != %u\n", fm1->descent, fm2->descent);
580 ok(fm1->font_height > 0.0, "fm1->font_height should be positive, got %f\n", fm1->font_height);
581 ok(fm2->font_height > 0.0, "fm2->font_height should be positive, got %f\n", fm2->font_height);
582 ok_(__FILE__, line)(fm1->font_height == fm2->font_height, "font_height %f != %f\n", fm1->font_height, fm2->font_height);
583 ok(fm1->font_size > 0.0, "fm1->font_size should be positive, got %f\n", fm1->font_size);
584 ok(fm2->font_size > 0.0, "fm2->font_size should be positive, got %f\n", fm2->font_size);
585 ok_(__FILE__, line)(fm1->font_size == fm2->font_size, "font_size %f != %f\n", fm1->font_size, fm2->font_size);
586 }
587
588 static void test_font_metrics(void)
589 {
590 LOGFONTW lf;
591 GpFont *font;
592 GpFontFamily *family;
593 GpGraphics *graphics;
594 GpStatus stat;
595 Unit unit;
596 struct font_metrics fm_gdi, fm_gdip;
597 HDC hdc;
598
599 hdc = CreateCompatibleDC(0);
600 stat = GdipCreateFromHDC(hdc, &graphics);
601 expect(Ok, stat);
602
603 memset(&lf, 0, sizeof(lf));
604
605 /* Tahoma,-13 */
606 lstrcpyW(lf.lfFaceName, Tahoma);
607 lf.lfHeight = -13;
608 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
609 expect(Ok, stat);
610
611 stat = GdipGetFontUnit(font, &unit);
612 expect(Ok, stat);
613 expect(UnitWorld, unit);
614
615 gdip_get_font_metrics(font, &fm_gdip);
616 trace("gdiplus:\n");
617 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
618 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
619 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
620 fm_gdip.font_height, fm_gdip.font_size);
621
622 gdi_get_font_metrics(&lf, &fm_gdi);
623 trace("gdi:\n");
624 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
625 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
626 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
627 fm_gdi.font_height, fm_gdi.font_size);
628
629 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
630
631 stat = GdipGetLogFontW(font, graphics, &lf);
632 expect(Ok, stat);
633 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
634 gdi_get_font_metrics(&lf, &fm_gdi);
635 trace("gdi:\n");
636 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
637 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
638 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
639 fm_gdi.font_height, fm_gdi.font_size);
640 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
641
642 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
643
644 GdipDeleteFont(font);
645
646 /* Tahoma,13 */
647 lstrcpyW(lf.lfFaceName, Tahoma);
648 lf.lfHeight = 13;
649 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
650 expect(Ok, stat);
651
652 stat = GdipGetFontUnit(font, &unit);
653 expect(Ok, stat);
654 expect(UnitWorld, unit);
655
656 gdip_get_font_metrics(font, &fm_gdip);
657 trace("gdiplus:\n");
658 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
659 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
660 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
661 fm_gdip.font_height, fm_gdip.font_size);
662
663 gdi_get_font_metrics(&lf, &fm_gdi);
664 trace("gdi:\n");
665 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
666 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
667 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
668 fm_gdi.font_height, fm_gdi.font_size);
669
670 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
671
672 stat = GdipGetLogFontW(font, graphics, &lf);
673 expect(Ok, stat);
674 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
675 gdi_get_font_metrics(&lf, &fm_gdi);
676 trace("gdi:\n");
677 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
678 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
679 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
680 fm_gdi.font_height, fm_gdi.font_size);
681 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
682
683 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
684
685 GdipDeleteFont(font);
686
687 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &family);
688 expect(Ok, stat);
689
690 /* Tahoma,13 */
691 stat = GdipCreateFont(family, 13.0, FontStyleRegular, UnitPixel, &font);
692 expect(Ok, stat);
693
694 gdip_get_font_metrics(font, &fm_gdip);
695 trace("gdiplus:\n");
696 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
697 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
698 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
699 fm_gdip.font_height, fm_gdip.font_size);
700
701 stat = GdipGetLogFontW(font, graphics, &lf);
702 expect(Ok, stat);
703 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
704 gdi_get_font_metrics(&lf, &fm_gdi);
705 trace("gdi:\n");
706 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
707 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
708 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
709 fm_gdi.font_height, fm_gdi.font_size);
710 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
711
712 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
713
714 stat = GdipGetLogFontW(font, NULL, &lf);
715 expect(InvalidParameter, stat);
716
717 GdipDeleteFont(font);
718
719 stat = GdipCreateFont(family, -13.0, FontStyleRegular, UnitPixel, &font);
720 expect(InvalidParameter, stat);
721
722 GdipDeleteFontFamily(family);
723
724 GdipDeleteGraphics(graphics);
725 DeleteDC(hdc);
726 }
727 #endif // CORE_6660_IS_FIXED
728
729 START_TEST(font)
730 {
731 struct GdiplusStartupInput gdiplusStartupInput;
732 ULONG_PTR gdiplusToken;
733
734 gdiplusStartupInput.GdiplusVersion = 1;
735 gdiplusStartupInput.DebugEventCallback = NULL;
736 gdiplusStartupInput.SuppressBackgroundThread = 0;
737 gdiplusStartupInput.SuppressExternalCodecs = 0;
738
739 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
740
741 #if CORE_6660_IS_FIXED
742 test_font_metrics();
743 #endif
744 test_createfont();
745 #if CORE_6660_IS_FIXED
746 test_logfont();
747 test_fontfamily();
748 #endif
749 test_fontfamily_properties();
750 test_getgenerics();
751 test_installedfonts();
752 test_heightgivendpi();
753
754 GdiplusShutdown(gdiplusToken);
755 }