c49878c97871e5b9cd129531f7cf9419697da12f
[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 #define WIN32_NO_STATUS
25 #define _INC_WINDOWS
26 #define COM_NO_WINDOWS_H
27
28 //#include "windows.h"
29 #include <wine/test.h>
30 #include <wingdi.h>
31 #include <winnls.h>
32 #include <objbase.h>
33 #include <gdiplus.h>
34
35 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
36 #define expect_(expected, got, precision) ok(abs((expected) - (got)) <= (precision), "Expected %d, got %d\n", (expected), (got))
37 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
38 #define expectf(expected, got) expectf_((expected), (got), 0.001)
39
40 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'};
41 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
42 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
43 static const WCHAR Tahoma[] = {'T','a','h','o','m','a',0};
44
45 static void set_rect_empty(RectF *rc)
46 {
47 rc->X = 0.0;
48 rc->Y = 0.0;
49 rc->Width = 0.0;
50 rc->Height = 0.0;
51 }
52
53 static void test_createfont(void)
54 {
55 GpFontFamily* fontfamily = NULL, *fontfamily2;
56 GpFont* font = NULL;
57 GpStatus stat;
58 Unit unit;
59 UINT i;
60 REAL size;
61 WCHAR familyname[LF_FACESIZE];
62
63 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
64 expect (FontFamilyNotFound, stat);
65 stat = GdipDeleteFont(font);
66 expect (InvalidParameter, stat);
67 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
68 expect (Ok, stat);
69 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
70 expect (Ok, stat);
71 stat = GdipGetFontUnit (font, &unit);
72 expect (Ok, stat);
73 expect (UnitPoint, unit);
74
75 stat = GdipGetFamily(font, &fontfamily2);
76 expect(Ok, stat);
77 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
78 expect(Ok, stat);
79 ok (lstrcmpiW(Tahoma, familyname) == 0, "Expected Tahoma, got %s\n",
80 wine_dbgstr_w(familyname));
81 stat = GdipDeleteFontFamily(fontfamily2);
82 expect(Ok, stat);
83
84 /* Test to see if returned size is based on unit (it's not) */
85 GdipGetFontSize(font, &size);
86 ok (size == 12, "Expected 12, got %f\n", size);
87 GdipDeleteFont(font);
88
89 /* Make sure everything is converted correctly for all Units */
90 for (i = UnitWorld; i <=UnitMillimeter; i++)
91 {
92 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
93 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
94 GdipGetFontSize (font, &size);
95 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
96 GdipGetFontUnit (font, &unit);
97 expect (i, unit);
98 GdipDeleteFont(font);
99 }
100
101 GdipDeleteFontFamily(fontfamily);
102 }
103
104 static void test_logfont(void)
105 {
106 LOGFONTA lfa, lfa2;
107 GpFont *font;
108 GpFontFamily *family;
109 GpStatus stat;
110 GpGraphics *graphics;
111 HDC hdc = GetDC(0);
112 INT style;
113 REAL rval;
114 UINT16 em_height, line_spacing;
115 Unit unit;
116
117 GdipCreateFromHDC(hdc, &graphics);
118
119 memset(&lfa, 0, sizeof(LOGFONTA));
120 memset(&lfa2, 0xff, sizeof(LOGFONTA));
121 lstrcpyA(lfa.lfFaceName, "Tahoma");
122
123 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
124 expect(Ok, stat);
125 stat = GdipGetLogFontA(font, graphics, &lfa2);
126 expect(Ok, stat);
127
128 ok(lfa2.lfHeight < 0, "Expected negative height\n");
129 expect(0, lfa2.lfWidth);
130 expect(0, lfa2.lfEscapement);
131 expect(0, lfa2.lfOrientation);
132 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
133 expect(0, lfa2.lfItalic);
134 expect(0, lfa2.lfUnderline);
135 expect(0, lfa2.lfStrikeOut);
136 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
137 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
138 expect(0, lfa2.lfOutPrecision);
139 expect(0, lfa2.lfClipPrecision);
140 expect(0, lfa2.lfQuality);
141 expect(0, lfa2.lfPitchAndFamily);
142
143 GdipDeleteFont(font);
144
145 memset(&lfa, 0, sizeof(LOGFONTA));
146 lfa.lfHeight = 25;
147 lfa.lfWidth = 25;
148 lfa.lfEscapement = lfa.lfOrientation = 50;
149 lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE;
150
151 memset(&lfa2, 0xff, sizeof(LOGFONTA));
152 lstrcpyA(lfa.lfFaceName, "Tahoma");
153
154 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
155 expect(Ok, stat);
156 stat = GdipGetLogFontA(font, graphics, &lfa2);
157 expect(Ok, stat);
158
159 ok(lfa2.lfHeight < 0, "Expected negative height\n");
160 expect(0, lfa2.lfWidth);
161 expect(0, lfa2.lfEscapement);
162 expect(0, lfa2.lfOrientation);
163 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
164 expect(TRUE, lfa2.lfItalic);
165 expect(TRUE, lfa2.lfUnderline);
166 expect(TRUE, lfa2.lfStrikeOut);
167 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
168 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
169 expect(0, lfa2.lfOutPrecision);
170 expect(0, lfa2.lfClipPrecision);
171 expect(0, lfa2.lfQuality);
172 expect(0, lfa2.lfPitchAndFamily);
173
174 stat = GdipGetFontStyle(font, &style);
175 expect(Ok, stat);
176 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
177 "Expected , got %d\n", style);
178
179 stat = GdipGetFontUnit(font, &unit);
180 expect(Ok, stat);
181 expect(UnitWorld, unit);
182
183 stat = GdipGetFontHeight(font, graphics, &rval);
184 expect(Ok, stat);
185 expectf(25.347656, rval);
186 stat = GdipGetFontSize(font, &rval);
187 expect(Ok, stat);
188 expectf(21.0, rval);
189
190 stat = GdipGetFamily(font, &family);
191 expect(Ok, stat);
192 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
193 expect(Ok, stat);
194 expect(2048, em_height);
195 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
196 expect(Ok, stat);
197 expect(2472, line_spacing);
198 GdipDeleteFontFamily(family);
199
200 GdipDeleteFont(font);
201
202 memset(&lfa, 0, sizeof(lfa));
203 lfa.lfHeight = -25;
204 lstrcpyA(lfa.lfFaceName, "Tahoma");
205 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
206 expect(Ok, stat);
207 memset(&lfa2, 0xff, sizeof(lfa2));
208 stat = GdipGetLogFontA(font, graphics, &lfa2);
209 expect(Ok, stat);
210 expect(lfa.lfHeight, lfa2.lfHeight);
211
212 stat = GdipGetFontUnit(font, &unit);
213 expect(Ok, stat);
214 expect(UnitWorld, unit);
215
216 stat = GdipGetFontHeight(font, graphics, &rval);
217 expect(Ok, stat);
218 expectf(30.175781, rval);
219 stat = GdipGetFontSize(font, &rval);
220 expect(Ok, stat);
221 expectf(25.0, rval);
222
223 stat = GdipGetFamily(font, &family);
224 expect(Ok, stat);
225 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
226 expect(Ok, stat);
227 expect(2048, em_height);
228 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
229 expect(Ok, stat);
230 expect(2472, line_spacing);
231 GdipDeleteFontFamily(family);
232
233 GdipDeleteFont(font);
234
235 GdipDeleteGraphics(graphics);
236 ReleaseDC(0, hdc);
237 }
238
239 static void test_fontfamily (void)
240 {
241 GpFontFamily *family, *clonedFontFamily;
242 WCHAR itsName[LF_FACESIZE];
243 GpStatus stat;
244
245 /* FontFamily cannot be NULL */
246 stat = GdipCreateFontFamilyFromName (Tahoma , NULL, NULL);
247 expect (InvalidParameter, stat);
248
249 /* FontFamily must be able to actually find the family.
250 * If it can't, any subsequent calls should fail.
251 */
252 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
253 expect (FontFamilyNotFound, stat);
254
255 /* Bitmap fonts are not found */
256 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
257 expect (FontFamilyNotFound, stat);
258 if(stat == Ok) GdipDeleteFontFamily(family);
259
260 stat = GdipCreateFontFamilyFromName (Tahoma, NULL, &family);
261 expect (Ok, stat);
262
263 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
264 expect (Ok, stat);
265 expect (0, lstrcmpiW(itsName, Tahoma));
266
267 if (0)
268 {
269 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
270 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
271 expect (Ok, stat);
272 }
273
274 /* Make sure we don't read old data */
275 ZeroMemory (itsName, sizeof(itsName));
276 stat = GdipCloneFontFamily(family, &clonedFontFamily);
277 expect (Ok, stat);
278 GdipDeleteFontFamily(family);
279 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
280 expect(Ok, stat);
281 expect(0, lstrcmpiW(itsName, Tahoma));
282
283 GdipDeleteFontFamily(clonedFontFamily);
284 }
285
286 static void test_fontfamily_properties (void)
287 {
288 GpFontFamily* FontFamily = NULL;
289 GpStatus stat;
290 UINT16 result = 0;
291
292 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &FontFamily);
293 expect(Ok, stat);
294
295 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
296 expect(Ok, stat);
297 ok (result == 2472, "Expected 2472, got %d\n", result);
298 result = 0;
299 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
300 expect(Ok, stat);
301 ok(result == 2048, "Expected 2048, got %d\n", result);
302 result = 0;
303 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
304 expect(Ok, stat);
305 ok(result == 2049, "Expected 2049, got %d\n", result);
306 result = 0;
307 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
308 expect(Ok, stat);
309 ok(result == 423, "Expected 423, got %d\n", result);
310 GdipDeleteFontFamily(FontFamily);
311
312 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
313 if(stat == FontFamilyNotFound)
314 skip("Times New Roman not installed\n");
315 else
316 {
317 result = 0;
318 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
319 expect(Ok, stat);
320 ok(result == 2355, "Expected 2355, got %d\n", result);
321 result = 0;
322 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
323 expect(Ok, stat);
324 ok(result == 2048, "Expected 2048, got %d\n", result);
325 result = 0;
326 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
327 expect(Ok, stat);
328 ok(result == 1825, "Expected 1825, got %d\n", result);
329 result = 0;
330 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
331 expect(Ok, stat);
332 ok(result == 443, "Expected 443 got %d\n", result);
333 GdipDeleteFontFamily(FontFamily);
334 }
335 }
336
337 static void check_family(const char* context, GpFontFamily *family, WCHAR *name)
338 {
339 GpStatus stat;
340 GpFont* font;
341
342 *name = 0;
343 stat = GdipGetFamilyName(family, name, LANG_NEUTRAL);
344 ok(stat == Ok, "could not get the %s family name: %.8x\n", context, stat);
345
346 stat = GdipCreateFont(family, 12, FontStyleRegular, UnitPixel, &font);
347 ok(stat == Ok, "could not create a font for the %s family: %.8x\n", context, stat);
348 if (stat == Ok)
349 {
350 stat = GdipDeleteFont(font);
351 ok(stat == Ok, "could not delete the %s family font: %.8x\n", context, stat);
352 }
353
354 stat = GdipDeleteFontFamily(family);
355 ok(stat == Ok, "could not delete the %s family: %.8x\n", context, stat);
356 }
357
358 static void test_getgenerics (void)
359 {
360 GpStatus stat;
361 GpFontFamily *family;
362 WCHAR sansname[LF_FACESIZE], serifname[LF_FACESIZE], mononame[LF_FACESIZE];
363 int missingfonts = 0;
364
365 stat = GdipGetGenericFontFamilySansSerif(&family);
366 expect (Ok, stat);
367 if (stat == FontFamilyNotFound)
368 missingfonts = 1;
369 else
370 check_family("Sans Serif", family, sansname);
371
372 stat = GdipGetGenericFontFamilySerif(&family);
373 expect (Ok, stat);
374 if (stat == FontFamilyNotFound)
375 missingfonts = 1;
376 else
377 check_family("Serif", family, serifname);
378
379 stat = GdipGetGenericFontFamilyMonospace(&family);
380 expect (Ok, stat);
381 if (stat == FontFamilyNotFound)
382 missingfonts = 1;
383 else
384 check_family("Monospace", family, mononame);
385
386 if (missingfonts && strcmp(winetest_platform, "wine") == 0)
387 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
388
389 /* Check that the family names are all different */
390 ok(lstrcmpiW(sansname, serifname) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname));
391 ok(lstrcmpiW(sansname, mononame) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname));
392 ok(lstrcmpiW(serifname, mononame) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname));
393 }
394
395 static void test_installedfonts (void)
396 {
397 GpStatus stat;
398 GpFontCollection* collection=NULL;
399
400 stat = GdipNewInstalledFontCollection(NULL);
401 expect (InvalidParameter, stat);
402
403 stat = GdipNewInstalledFontCollection(&collection);
404 expect (Ok, stat);
405 ok (collection != NULL, "got NULL font collection\n");
406 }
407
408 static void test_heightgivendpi(void)
409 {
410 GpStatus stat;
411 GpFont* font = NULL;
412 GpFontFamily* fontfamily = NULL;
413 REAL height;
414 Unit unit;
415
416 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
417 expect(Ok, stat);
418
419 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font);
420 expect(Ok, stat);
421
422 stat = GdipGetFontHeightGivenDPI(NULL, 96, &height);
423 expect(InvalidParameter, stat);
424
425 stat = GdipGetFontHeightGivenDPI(font, 96, NULL);
426 expect(InvalidParameter, stat);
427
428 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
429 expect(Ok, stat);
430 expectf(36.210938, height);
431 GdipDeleteFont(font);
432
433 height = 12345;
434 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font);
435 expect(Ok, stat);
436
437 stat = GdipGetFontUnit(font, &unit);
438 expect(Ok, stat);
439 expect(UnitWorld, unit);
440
441 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
442 expect(Ok, stat);
443 expectf(36.210938, height);
444 GdipDeleteFont(font);
445
446 height = 12345;
447 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font);
448 expect(Ok, stat);
449 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
450 expect(Ok, stat);
451 expectf(48.281250, height);
452 GdipDeleteFont(font);
453
454 height = 12345;
455 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font);
456 expect(Ok, stat);
457
458 stat = GdipGetFontUnit(font, &unit);
459 expect(Ok, stat);
460 expect(UnitInch, unit);
461
462 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
463 expect(Ok, stat);
464 expectf(3476.250000, height);
465 GdipDeleteFont(font);
466
467 height = 12345;
468 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font);
469 expect(Ok, stat);
470
471 stat = GdipGetFontUnit(font, &unit);
472 expect(Ok, stat);
473 expect(UnitDocument, unit);
474
475 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
476 expect(Ok, stat);
477 expectf(11.587500, height);
478 GdipDeleteFont(font);
479
480 height = 12345;
481 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font);
482 expect(Ok, stat);
483
484 stat = GdipGetFontUnit(font, &unit);
485 expect(Ok, stat);
486 expect(UnitMillimeter, unit);
487
488 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
489 expect(Ok, stat);
490 expectf(136.860245, height);
491 GdipDeleteFont(font);
492
493 GdipDeleteFontFamily(fontfamily);
494 }
495
496 static int CALLBACK font_enum_proc(const LOGFONTW *lfe, const TEXTMETRICW *ntme,
497 DWORD type, LPARAM lparam)
498 {
499 NEWTEXTMETRICW *ntm = (NEWTEXTMETRICW *)lparam;
500
501 if (type != TRUETYPE_FONTTYPE) return 1;
502
503 *ntm = *(NEWTEXTMETRICW *)ntme;
504 return 0;
505 }
506
507 struct font_metrics
508 {
509 UINT16 em_height, line_spacing, ascent, descent;
510 REAL font_height, font_size;
511 INT lfHeight;
512 };
513
514 static void gdi_get_font_metrics(LOGFONTW *lf, struct font_metrics *fm)
515 {
516 HDC hdc;
517 HFONT hfont;
518 NEWTEXTMETRICW ntm;
519 OUTLINETEXTMETRICW otm;
520 int ret;
521
522 hdc = CreateCompatibleDC(0);
523
524 /* it's the only way to get extended NEWTEXTMETRIC fields */
525 ret = EnumFontFamiliesExW(hdc, lf, font_enum_proc, (LPARAM)&ntm, 0);
526 ok(!ret, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf->lfFaceName));
527
528 hfont = CreateFontIndirectW(lf);
529 SelectObject(hdc, hfont);
530
531 otm.otmSize = sizeof(otm);
532 ret = GetOutlineTextMetricsW(hdc, otm.otmSize, &otm);
533 ok(ret, "GetOutlineTextMetrics failed\n");
534
535 DeleteDC(hdc);
536 DeleteObject(hfont);
537
538 fm->lfHeight = -otm.otmTextMetrics.tmAscent;
539 fm->line_spacing = ntm.ntmCellHeight;
540 fm->font_size = (REAL)otm.otmTextMetrics.tmAscent;
541 fm->font_height = (REAL)fm->line_spacing * fm->font_size / (REAL)ntm.ntmSizeEM;
542 fm->em_height = ntm.ntmSizeEM;
543 fm->ascent = ntm.ntmSizeEM;
544 fm->descent = ntm.ntmCellHeight - ntm.ntmSizeEM;
545 }
546
547 static void gdip_get_font_metrics(GpFont *font, struct font_metrics *fm)
548 {
549 INT style;
550 GpFontFamily *family;
551 GpStatus stat;
552
553 stat = GdipGetFontStyle(font, &style);
554 expect(Ok, stat);
555
556 stat = GdipGetFontHeight(font, NULL, &fm->font_height);
557 expect(Ok, stat);
558 stat = GdipGetFontSize(font, &fm->font_size);
559 expect(Ok, stat);
560
561 fm->lfHeight = (INT)(fm->font_size * -1.0);
562
563 stat = GdipGetFamily(font, &family);
564 expect(Ok, stat);
565
566 stat = GdipGetEmHeight(family, style, &fm->em_height);
567 expect(Ok, stat);
568 stat = GdipGetLineSpacing(family, style, &fm->line_spacing);
569 expect(Ok, stat);
570 stat = GdipGetCellAscent(family, style, &fm->ascent);
571 expect(Ok, stat);
572 stat = GdipGetCellDescent(family, style, &fm->descent);
573 expect(Ok, stat);
574
575 GdipDeleteFontFamily(family);
576 }
577
578 static void cmp_font_metrics(struct font_metrics *fm1, struct font_metrics *fm2, int line)
579 {
580 ok_(__FILE__, line)(fm1->lfHeight == fm2->lfHeight, "lfHeight %d != %d\n", fm1->lfHeight, fm2->lfHeight);
581 ok_(__FILE__, line)(fm1->em_height == fm2->em_height, "em_height %u != %u\n", fm1->em_height, fm2->em_height);
582 ok_(__FILE__, line)(fm1->line_spacing == fm2->line_spacing, "line_spacing %u != %u\n", fm1->line_spacing, fm2->line_spacing);
583 ok_(__FILE__, line)(abs(fm1->ascent - fm2->ascent) <= 1, "ascent %u != %u\n", fm1->ascent, fm2->ascent);
584 ok_(__FILE__, line)(abs(fm1->descent - fm2->descent) <= 1, "descent %u != %u\n", fm1->descent, fm2->descent);
585 ok(fm1->font_height > 0.0, "fm1->font_height should be positive, got %f\n", fm1->font_height);
586 ok(fm2->font_height > 0.0, "fm2->font_height should be positive, got %f\n", fm2->font_height);
587 ok_(__FILE__, line)(fm1->font_height == fm2->font_height, "font_height %f != %f\n", fm1->font_height, fm2->font_height);
588 ok(fm1->font_size > 0.0, "fm1->font_size should be positive, got %f\n", fm1->font_size);
589 ok(fm2->font_size > 0.0, "fm2->font_size should be positive, got %f\n", fm2->font_size);
590 ok_(__FILE__, line)(fm1->font_size == fm2->font_size, "font_size %f != %f\n", fm1->font_size, fm2->font_size);
591 }
592
593 static void test_font_metrics(void)
594 {
595 LOGFONTW lf;
596 GpFont *font;
597 GpFontFamily *family;
598 GpGraphics *graphics;
599 GpStatus stat;
600 Unit unit;
601 struct font_metrics fm_gdi, fm_gdip;
602 HDC hdc;
603
604 hdc = CreateCompatibleDC(0);
605 stat = GdipCreateFromHDC(hdc, &graphics);
606 expect(Ok, stat);
607
608 memset(&lf, 0, sizeof(lf));
609
610 /* Tahoma,-13 */
611 lstrcpyW(lf.lfFaceName, Tahoma);
612 lf.lfHeight = -13;
613 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
614 expect(Ok, stat);
615
616 stat = GdipGetFontUnit(font, &unit);
617 expect(Ok, stat);
618 expect(UnitWorld, unit);
619
620 gdip_get_font_metrics(font, &fm_gdip);
621 trace("gdiplus:\n");
622 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
623 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
624 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
625 fm_gdip.font_height, fm_gdip.font_size);
626
627 gdi_get_font_metrics(&lf, &fm_gdi);
628 trace("gdi:\n");
629 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
630 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
631 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
632 fm_gdi.font_height, fm_gdi.font_size);
633
634 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
635
636 stat = GdipGetLogFontW(font, graphics, &lf);
637 expect(Ok, stat);
638 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
639 gdi_get_font_metrics(&lf, &fm_gdi);
640 trace("gdi:\n");
641 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
642 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
643 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
644 fm_gdi.font_height, fm_gdi.font_size);
645 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
646
647 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
648
649 GdipDeleteFont(font);
650
651 /* Tahoma,13 */
652 lstrcpyW(lf.lfFaceName, Tahoma);
653 lf.lfHeight = 13;
654 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
655 expect(Ok, stat);
656
657 stat = GdipGetFontUnit(font, &unit);
658 expect(Ok, stat);
659 expect(UnitWorld, unit);
660
661 gdip_get_font_metrics(font, &fm_gdip);
662 trace("gdiplus:\n");
663 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
664 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
665 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
666 fm_gdip.font_height, fm_gdip.font_size);
667
668 gdi_get_font_metrics(&lf, &fm_gdi);
669 trace("gdi:\n");
670 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
671 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
672 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
673 fm_gdi.font_height, fm_gdi.font_size);
674
675 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
676
677 stat = GdipGetLogFontW(font, graphics, &lf);
678 expect(Ok, stat);
679 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
680 gdi_get_font_metrics(&lf, &fm_gdi);
681 trace("gdi:\n");
682 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
683 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
684 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
685 fm_gdi.font_height, fm_gdi.font_size);
686 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
687
688 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
689
690 GdipDeleteFont(font);
691
692 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &family);
693 expect(Ok, stat);
694
695 /* Tahoma,13 */
696 stat = GdipCreateFont(family, 13.0, FontStyleRegular, UnitPixel, &font);
697 expect(Ok, stat);
698
699 gdip_get_font_metrics(font, &fm_gdip);
700 trace("gdiplus:\n");
701 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
702 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
703 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
704 fm_gdip.font_height, fm_gdip.font_size);
705
706 stat = GdipGetLogFontW(font, graphics, &lf);
707 expect(Ok, stat);
708 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
709 gdi_get_font_metrics(&lf, &fm_gdi);
710 trace("gdi:\n");
711 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
712 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
713 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
714 fm_gdi.font_height, fm_gdi.font_size);
715 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
716
717 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
718
719 stat = GdipGetLogFontW(font, NULL, &lf);
720 expect(InvalidParameter, stat);
721
722 GdipDeleteFont(font);
723
724 stat = GdipCreateFont(family, -13.0, FontStyleRegular, UnitPixel, &font);
725 expect(InvalidParameter, stat);
726
727 GdipDeleteFontFamily(family);
728
729 GdipDeleteGraphics(graphics);
730 DeleteDC(hdc);
731 }
732
733 static void test_font_substitution(void)
734 {
735 WCHAR ms_shell_dlg[LF_FACESIZE];
736 char fallback_font[LF_FACESIZE];
737 HDC hdc;
738 HFONT hfont;
739 LOGFONTA lf;
740 GpStatus status;
741 GpGraphics *graphics;
742 GpFont *font;
743 GpFontFamily *family;
744 int ret;
745
746 hdc = CreateCompatibleDC(0);
747 status = GdipCreateFromHDC(hdc, &graphics);
748 expect(Ok, status);
749
750 hfont = GetStockObject(DEFAULT_GUI_FONT);
751 ok(hfont != 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
752
753 memset(&lf, 0xfe, sizeof(lf));
754 ret = GetObjectA(hfont, sizeof(lf), &lf);
755 ok(ret == sizeof(lf), "GetObject failed\n");
756 ok(!lstrcmpA(lf.lfFaceName, "MS Shell Dlg"), "wrong face name %s\n", lf.lfFaceName);
757 MultiByteToWideChar(CP_ACP, 0, lf.lfFaceName, -1, ms_shell_dlg, LF_FACESIZE);
758
759 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
760 expect(Ok, status);
761 memset(&lf, 0xfe, sizeof(lf));
762 status = GdipGetLogFontA(font, graphics, &lf);
763 expect(Ok, status);
764 ok(!lstrcmpA(lf.lfFaceName, "Microsoft Sans Serif") ||
765 !lstrcmpA(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName);
766 GdipDeleteFont(font);
767
768 status = GdipCreateFontFamilyFromName(ms_shell_dlg, NULL, &family);
769 expect(Ok, status);
770 status = GdipCreateFont(family, 12, FontStyleRegular, UnitPoint, &font);
771 expect(Ok, status);
772 memset(&lf, 0xfe, sizeof(lf));
773 status = GdipGetLogFontA(font, graphics, &lf);
774 expect(Ok, status);
775 ok(!lstrcmpA(lf.lfFaceName, "Microsoft Sans Serif") ||
776 !lstrcmpA(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName);
777 GdipDeleteFont(font);
778 GdipDeleteFontFamily(family);
779
780 status = GdipCreateFontFamilyFromName(nonexistent, NULL, &family);
781 ok(status == FontFamilyNotFound, "expected FontFamilyNotFound, got %d\n", status);
782
783 /* nonexistent fonts fallback to Arial, or something else if it's missing */
784 strcpy(lf.lfFaceName,"Arial");
785 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
786 expect(Ok, status);
787 status = GdipGetLogFontA(font, graphics, &lf);
788 expect(Ok, status);
789 strcpy(fallback_font,lf.lfFaceName);
790 trace("fallback font %s\n", fallback_font);
791 GdipDeleteFont(font);
792
793 lstrcpyA(lf.lfFaceName, "ThisFontShouldNotExist");
794 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
795 expect(Ok, status);
796 memset(&lf, 0xfe, sizeof(lf));
797 status = GdipGetLogFontA(font, graphics, &lf);
798 expect(Ok, status);
799 ok(!lstrcmpA(lf.lfFaceName, fallback_font), "wrong face name %s / %s\n", lf.lfFaceName, fallback_font);
800 GdipDeleteFont(font);
801
802 /* empty FaceName */
803 lf.lfFaceName[0] = 0;
804 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
805 expect(Ok, status);
806 memset(&lf, 0xfe, sizeof(lf));
807 status = GdipGetLogFontA(font, graphics, &lf);
808 expect(Ok, status);
809 ok(!lstrcmpA(lf.lfFaceName, fallback_font), "wrong face name %s / %s\n", lf.lfFaceName, fallback_font);
810 GdipDeleteFont(font);
811
812 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
813 lf.lfWeight = 0;
814 lf.lfCharSet = 0;
815 lstrcpyA(lf.lfFaceName, "ThisFontShouldNotExist");
816 font = NULL;
817 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
818 todo_wine
819 ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */
820 "expected NotTrueTypeFont, got %d\n", status);
821 /* FIXME: remove when wine is fixed */
822 if (font) GdipDeleteFont(font);
823
824 /* empty FaceName */
825 lf.lfFaceName[0] = 0;
826 font = NULL;
827 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
828 todo_wine
829 ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */
830 "expected NotTrueTypeFont, got %d\n", status);
831 /* FIXME: remove when wine is fixed */
832 if (font) GdipDeleteFont(font);
833
834 GdipDeleteGraphics(graphics);
835 DeleteDC(hdc);
836 }
837
838 static void test_font_transform(void)
839 {
840 static const WCHAR string[] = { 'A',0 };
841 GpStatus status;
842 HDC hdc;
843 LOGFONTA lf;
844 GpFont *font;
845 GpGraphics *graphics;
846 GpMatrix *matrix;
847 GpStringFormat *format, *typographic;
848 PointF pos[1] = { { 0,0 } };
849 REAL height, margin_y;
850 RectF bounds, rect;
851
852 hdc = CreateCompatibleDC(0);
853 status = GdipCreateFromHDC(hdc, &graphics);
854 expect(Ok, status);
855
856 status = GdipSetPageUnit(graphics, UnitPixel);
857 expect(Ok, status);
858
859 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
860 expect(Ok, status);
861 status = GdipStringFormatGetGenericTypographic(&typographic);
862 expect(Ok, status);
863
864 memset(&lf, 0, sizeof(lf));
865 lstrcpyA(lf.lfFaceName, "Tahoma");
866 lf.lfHeight = -100;
867 lf.lfWidth = 100;
868 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
869 expect(Ok, status);
870
871 margin_y = 100.0 / 8.0;
872
873 /* identity matrix */
874 status = GdipCreateMatrix(&matrix);
875 expect(Ok, status);
876 status = GdipSetWorldTransform(graphics, matrix);
877 expect(Ok, status);
878 status = GdipGetLogFontA(font, graphics, &lf);
879 expect(Ok, status);
880 expect(-100, lf.lfHeight);
881 expect(0, lf.lfWidth);
882 expect(0, lf.lfEscapement);
883 expect(0, lf.lfOrientation);
884 status = GdipGetFontHeight(font, graphics, &height);
885 expect(Ok, status);
886 expectf(120.703125, height);
887 set_rect_empty(&rect);
888 set_rect_empty(&bounds);
889 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
890 expect(Ok, status);
891 expectf(0.0, bounds.X);
892 expectf(0.0, bounds.Y);
893 todo_wine
894 expectf(height + margin_y, bounds.Height);
895 set_rect_empty(&rect);
896 set_rect_empty(&bounds);
897 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
898 expect(Ok, status);
899 expectf(0.0, bounds.X);
900 expectf(0.0, bounds.Y);
901 expectf_(height, bounds.Height, 1.0);
902 set_rect_empty(&bounds);
903 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
904 DriverStringOptionsCmapLookup, NULL, &bounds);
905 expect(Ok, status);
906 expectf(0.0, bounds.X);
907 expectf_(-100.0, bounds.Y, 0.05);
908 expectf_(height, bounds.Height, 0.5);
909 set_rect_empty(&bounds);
910 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
911 DriverStringOptionsCmapLookup, matrix, &bounds);
912 expect(Ok, status);
913 expectf(0.0, bounds.X);
914 expectf_(-100.0, bounds.Y, 0.05);
915 expectf_(height, bounds.Height, 0.5);
916
917 /* scale matrix */
918 status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
919 expect(Ok, status);
920 status = GdipSetWorldTransform(graphics, matrix);
921 expect(Ok, status);
922 status = GdipGetLogFontA(font, graphics, &lf);
923 expect(Ok, status);
924 expect(-300, lf.lfHeight);
925 expect(0, lf.lfWidth);
926 expect(0, lf.lfEscapement);
927 expect(0, lf.lfOrientation);
928 status = GdipGetFontHeight(font, graphics, &height);
929 expect(Ok, status);
930 expectf(120.703125, height);
931 set_rect_empty(&rect);
932 set_rect_empty(&bounds);
933 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
934 expect(Ok, status);
935 expectf(0.0, bounds.X);
936 expectf(0.0, bounds.Y);
937 todo_wine
938 expectf(height + margin_y, bounds.Height);
939 set_rect_empty(&rect);
940 set_rect_empty(&bounds);
941 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
942 expect(Ok, status);
943 expectf(0.0, bounds.X);
944 expectf(0.0, bounds.Y);
945 expectf_(height, bounds.Height, 0.05);
946 set_rect_empty(&bounds);
947 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
948 DriverStringOptionsCmapLookup, NULL, &bounds);
949 expect(Ok, status);
950 expectf(0.0, bounds.X);
951 expectf_(-100.0, bounds.Y, 0.05);
952 expectf_(height, bounds.Height, 0.2);
953 set_rect_empty(&bounds);
954 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
955 DriverStringOptionsCmapLookup, matrix, &bounds);
956 expect(Ok, status);
957 expectf(0.0, bounds.X);
958 todo_wine
959 expectf_(-300.0, bounds.Y, 0.15);
960 todo_wine
961 expectf(height * 3.0, bounds.Height);
962
963 /* scale + ratate matrix */
964 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
965 expect(Ok, status);
966 status = GdipSetWorldTransform(graphics, matrix);
967 expect(Ok, status);
968 status = GdipGetLogFontA(font, graphics, &lf);
969 expect(Ok, status);
970 expect(-300, lf.lfHeight);
971 expect(0, lf.lfWidth);
972 expect_(3151, lf.lfEscapement, 1);
973 expect_(3151, lf.lfOrientation, 1);
974 status = GdipGetFontHeight(font, graphics, &height);
975 expect(Ok, status);
976 expectf(120.703125, height);
977 set_rect_empty(&rect);
978 set_rect_empty(&bounds);
979 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
980 expect(Ok, status);
981 expectf(0.0, bounds.X);
982 expectf(0.0, bounds.Y);
983 todo_wine
984 expectf(height + margin_y, bounds.Height);
985 set_rect_empty(&rect);
986 set_rect_empty(&bounds);
987 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
988 expect(Ok, status);
989 expectf(0.0, bounds.X);
990 expectf(0.0, bounds.Y);
991 expectf_(height, bounds.Height, 0.05);
992 set_rect_empty(&bounds);
993 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
994 DriverStringOptionsCmapLookup, NULL, &bounds);
995 expect(Ok, status);
996 expectf(0.0, bounds.X);
997 expectf_(-100.0, bounds.Y, 0.05);
998 expectf_(height, bounds.Height, 0.2);
999 set_rect_empty(&bounds);
1000 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1001 DriverStringOptionsCmapLookup, matrix, &bounds);
1002 expect(Ok, status);
1003 todo_wine
1004 expectf_(-43.814377, bounds.X, 0.05);
1005 todo_wine
1006 expectf_(-212.235611, bounds.Y, 0.05);
1007 todo_wine
1008 expectf_(340.847534, bounds.Height, 0.05);
1009
1010 /* scale + ratate + shear matrix */
1011 status = GdipShearMatrix(matrix, 4.0, 5.0, MatrixOrderAppend);
1012 expect(Ok, status);
1013 status = GdipSetWorldTransform(graphics, matrix);
1014 expect(Ok, status);
1015 status = GdipGetLogFontA(font, graphics, &lf);
1016 expect(Ok, status);
1017 todo_wine
1018 expect(1032, lf.lfHeight);
1019 expect(0, lf.lfWidth);
1020 expect_(3099, lf.lfEscapement, 1);
1021 expect_(3099, lf.lfOrientation, 1);
1022 status = GdipGetFontHeight(font, graphics, &height);
1023 expect(Ok, status);
1024 expectf(120.703125, height);
1025 set_rect_empty(&rect);
1026 set_rect_empty(&bounds);
1027 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
1028 expect(Ok, status);
1029 expectf(0.0, bounds.X);
1030 expectf(0.0, bounds.Y);
1031 todo_wine
1032 expectf(height + margin_y, bounds.Height);
1033 set_rect_empty(&rect);
1034 set_rect_empty(&bounds);
1035 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
1036 expect(Ok, status);
1037 expectf(0.0, bounds.X);
1038 expectf(0.0, bounds.Y);
1039 expectf_(height, bounds.Height, 0.2);
1040 set_rect_empty(&bounds);
1041 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1042 DriverStringOptionsCmapLookup, NULL, &bounds);
1043 expect(Ok, status);
1044 expectf(0.0, bounds.X);
1045 expectf_(-100.0, bounds.Y, 0.2);
1046 expectf_(height, bounds.Height, 0.2);
1047 set_rect_empty(&bounds);
1048 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1049 DriverStringOptionsCmapLookup, matrix, &bounds);
1050 expect(Ok, status);
1051 todo_wine
1052 expectf_(-636.706848, bounds.X, 0.05);
1053 todo_wine
1054 expectf_(-175.257523, bounds.Y, 0.05);
1055 todo_wine
1056 expectf_(1532.984985, bounds.Height, 0.05);
1057
1058 /* scale + ratate + shear + translate matrix */
1059 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
1060 expect(Ok, status);
1061 status = GdipSetWorldTransform(graphics, matrix);
1062 expect(Ok, status);
1063 status = GdipGetLogFontA(font, graphics, &lf);
1064 expect(Ok, status);
1065 todo_wine
1066 expect(1032, lf.lfHeight);
1067 expect(0, lf.lfWidth);
1068 expect_(3099, lf.lfEscapement, 1);
1069 expect_(3099, lf.lfOrientation, 1);
1070 status = GdipGetFontHeight(font, graphics, &height);
1071 expect(Ok, status);
1072 expectf(120.703125, height);
1073 set_rect_empty(&rect);
1074 set_rect_empty(&bounds);
1075 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
1076 expect(Ok, status);
1077 expectf(0.0, bounds.X);
1078 expectf(0.0, bounds.Y);
1079 todo_wine
1080 expectf(height + margin_y, bounds.Height);
1081 set_rect_empty(&rect);
1082 set_rect_empty(&bounds);
1083 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
1084 expect(Ok, status);
1085 expectf(0.0, bounds.X);
1086 expectf(0.0, bounds.Y);
1087 expectf_(height, bounds.Height, 0.1);
1088 set_rect_empty(&bounds);
1089 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1090 DriverStringOptionsCmapLookup, NULL, &bounds);
1091 expect(Ok, status);
1092 expectf(0.0, bounds.X);
1093 expectf_(-100.0, bounds.Y, 0.2);
1094 expectf_(height, bounds.Height, 0.2);
1095 set_rect_empty(&bounds);
1096 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1097 DriverStringOptionsCmapLookup, matrix, &bounds);
1098 expect(Ok, status);
1099 todo_wine
1100 expectf_(-626.706848, bounds.X, 0.05);
1101 todo_wine
1102 expectf_(-155.257523, bounds.Y, 0.05);
1103 todo_wine
1104 expectf_(1532.984985, bounds.Height, 0.05);
1105
1106 GdipDeleteMatrix(matrix);
1107 GdipDeleteFont(font);
1108 GdipDeleteGraphics(graphics);
1109 GdipDeleteStringFormat(typographic);
1110 GdipDeleteStringFormat(format);
1111 DeleteDC(hdc);
1112 }
1113
1114 START_TEST(font)
1115 {
1116 struct GdiplusStartupInput gdiplusStartupInput;
1117 ULONG_PTR gdiplusToken;
1118
1119 gdiplusStartupInput.GdiplusVersion = 1;
1120 gdiplusStartupInput.DebugEventCallback = NULL;
1121 gdiplusStartupInput.SuppressBackgroundThread = 0;
1122 gdiplusStartupInput.SuppressExternalCodecs = 0;
1123
1124 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1125
1126 test_font_transform();
1127 if (!winetest_interactive)
1128 skip("ROSTESTS-154: Skipping test_font_substitution because of improper error handling\n");
1129 else
1130 test_font_substitution();
1131 test_font_metrics();
1132 test_createfont();
1133 test_logfont();
1134 test_fontfamily();
1135 test_fontfamily_properties();
1136 test_getgenerics();
1137 test_installedfonts();
1138 test_heightgivendpi();
1139
1140 GdiplusShutdown(gdiplusToken);
1141 }