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 MicrosoftSansSerif
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
36 static const WCHAR TimesNewRoman
[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
37 static const WCHAR CourierNew
[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
38 static const WCHAR Tahoma
[] = {'T','a','h','o','m','a',0};
39 static const WCHAR LiberationSerif
[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f',0};
41 static void set_rect_empty(RectF
*rc
)
49 static void test_createfont(void)
51 GpFontFamily
* fontfamily
= NULL
, *fontfamily2
;
57 WCHAR familyname
[LF_FACESIZE
];
59 stat
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &fontfamily
);
60 expect (FontFamilyNotFound
, stat
);
61 stat
= GdipDeleteFont(font
);
62 expect (InvalidParameter
, stat
);
63 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &fontfamily
);
65 stat
= GdipCreateFont(fontfamily
, 12, FontStyleRegular
, UnitPoint
, &font
);
67 stat
= GdipGetFontUnit (font
, &unit
);
69 expect (UnitPoint
, unit
);
71 stat
= GdipGetFamily(font
, &fontfamily2
);
73 stat
= GdipGetFamilyName(fontfamily2
, familyname
, 0);
75 ok (lstrcmpiW(Tahoma
, familyname
) == 0, "Expected Tahoma, got %s\n",
76 wine_dbgstr_w(familyname
));
77 stat
= GdipDeleteFontFamily(fontfamily2
);
80 /* Test to see if returned size is based on unit (its not) */
81 GdipGetFontSize(font
, &size
);
82 ok (size
== 12, "Expected 12, got %f\n", size
);
85 /* Make sure everything is converted correctly for all Units */
86 for (i
= UnitWorld
; i
<=UnitMillimeter
; i
++)
88 if (i
== UnitDisplay
) continue; /* Crashes WindowsXP, wtf? */
89 GdipCreateFont(fontfamily
, 24, FontStyleRegular
, i
, &font
);
90 GdipGetFontSize (font
, &size
);
91 ok (size
== 24, "Expected 24, got %f (with unit: %d)\n", size
, i
);
92 GdipGetFontUnit (font
, &unit
);
97 GdipDeleteFontFamily(fontfamily
);
100 static void test_logfont(void)
104 GpFontFamily
*family
;
106 GpGraphics
*graphics
;
110 UINT16 em_height
, line_spacing
;
113 GdipCreateFromHDC(hdc
, &graphics
);
115 memset(&lfa
, 0, sizeof(LOGFONTA
));
116 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
117 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
119 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
121 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
124 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
125 expect(0, lfa2
.lfWidth
);
126 expect(0, lfa2
.lfEscapement
);
127 expect(0, lfa2
.lfOrientation
);
128 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
129 expect(0, lfa2
.lfItalic
);
130 expect(0, lfa2
.lfUnderline
);
131 expect(0, lfa2
.lfStrikeOut
);
132 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
133 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
134 expect(0, lfa2
.lfOutPrecision
);
135 expect(0, lfa2
.lfClipPrecision
);
136 expect(0, lfa2
.lfQuality
);
137 expect(0, lfa2
.lfPitchAndFamily
);
139 GdipDeleteFont(font
);
141 memset(&lfa
, 0, sizeof(LOGFONTA
));
144 lfa
.lfEscapement
= lfa
.lfOrientation
= 50;
145 lfa
.lfItalic
= lfa
.lfUnderline
= lfa
.lfStrikeOut
= TRUE
;
147 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
148 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
150 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
152 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
155 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
156 expect(0, lfa2
.lfWidth
);
157 expect(0, lfa2
.lfEscapement
);
158 expect(0, lfa2
.lfOrientation
);
159 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
160 expect(TRUE
, lfa2
.lfItalic
);
161 expect(TRUE
, lfa2
.lfUnderline
);
162 expect(TRUE
, lfa2
.lfStrikeOut
);
163 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
164 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
165 expect(0, lfa2
.lfOutPrecision
);
166 expect(0, lfa2
.lfClipPrecision
);
167 expect(0, lfa2
.lfQuality
);
168 expect(0, lfa2
.lfPitchAndFamily
);
170 stat
= GdipGetFontStyle(font
, &style
);
172 ok (style
== (FontStyleItalic
| FontStyleUnderline
| FontStyleStrikeout
),
173 "Expected , got %d\n", style
);
175 stat
= GdipGetFontUnit(font
, &unit
);
177 expect(UnitWorld
, unit
);
179 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
181 expectf(25.347656, rval
);
182 stat
= GdipGetFontSize(font
, &rval
);
186 stat
= GdipGetFamily(font
, &family
);
188 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
190 expect(2048, em_height
);
191 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
193 expect(2472, line_spacing
);
194 GdipDeleteFontFamily(family
);
196 GdipDeleteFont(font
);
198 memset(&lfa
, 0, sizeof(lfa
));
200 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
201 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
203 memset(&lfa2
, 0xff, sizeof(lfa2
));
204 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
206 expect(lfa
.lfHeight
, lfa2
.lfHeight
);
208 stat
= GdipGetFontUnit(font
, &unit
);
210 expect(UnitWorld
, unit
);
212 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
214 expectf(30.175781, rval
);
215 stat
= GdipGetFontSize(font
, &rval
);
219 stat
= GdipGetFamily(font
, &family
);
221 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
223 expect(2048, em_height
);
224 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
226 expect(2472, line_spacing
);
227 GdipDeleteFontFamily(family
);
229 GdipDeleteFont(font
);
231 GdipDeleteGraphics(graphics
);
235 static void test_fontfamily (void)
237 GpFontFamily
*family
, *clonedFontFamily
;
238 WCHAR itsName
[LF_FACESIZE
];
241 /* FontFamily cannot be NULL */
242 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, NULL
);
243 expect (InvalidParameter
, stat
);
245 /* FontFamily must be able to actually find the family.
246 * If it can't, any subsequent calls should fail.
248 stat
= GdipCreateFontFamilyFromName (nonexistent
, NULL
, &family
);
249 expect (FontFamilyNotFound
, stat
);
251 /* Bitmap fonts are not found */
252 stat
= GdipCreateFontFamilyFromName (MSSansSerif
, NULL
, &family
);
253 expect (FontFamilyNotFound
, stat
);
254 if(stat
== Ok
) GdipDeleteFontFamily(family
);
256 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, &family
);
259 stat
= GdipGetFamilyName (family
, itsName
, LANG_NEUTRAL
);
261 expect (0, lstrcmpiW(itsName
, Tahoma
));
265 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
266 stat
= GdipGetFamilyName (family
, NULL
, LANG_NEUTRAL
);
270 /* Make sure we don't read old data */
271 ZeroMemory (itsName
, sizeof(itsName
));
272 stat
= GdipCloneFontFamily(family
, &clonedFontFamily
);
274 GdipDeleteFontFamily(family
);
275 stat
= GdipGetFamilyName(clonedFontFamily
, itsName
, LANG_NEUTRAL
);
277 expect(0, lstrcmpiW(itsName
, Tahoma
));
279 GdipDeleteFontFamily(clonedFontFamily
);
282 static void test_fontfamily_properties (void)
284 GpFontFamily
* FontFamily
= NULL
;
288 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &FontFamily
);
291 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
293 ok (result
== 2472, "Expected 2472, got %d\n", result
);
295 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
297 ok(result
== 2048, "Expected 2048, got %d\n", result
);
299 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
301 ok(result
== 2049, "Expected 2049, got %d\n", result
);
303 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
305 ok(result
== 423, "Expected 423, got %d\n", result
);
306 GdipDeleteFontFamily(FontFamily
);
308 stat
= GdipCreateFontFamilyFromName(TimesNewRoman
, NULL
, &FontFamily
);
309 if(stat
== FontFamilyNotFound
)
310 skip("Times New Roman not installed\n");
314 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
316 ok(result
== 2355, "Expected 2355, got %d\n", result
);
318 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
320 ok(result
== 2048, "Expected 2048, got %d\n", result
);
322 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
324 ok(result
== 1825, "Expected 1825, got %d\n", result
);
326 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
328 ok(result
== 443, "Expected 443 got %d\n", result
);
329 GdipDeleteFontFamily(FontFamily
);
333 static void check_family(const char* context
, GpFontFamily
*family
, WCHAR
*name
)
339 stat
= GdipGetFamilyName(family
, name
, LANG_NEUTRAL
);
340 ok(stat
== Ok
, "could not get the %s family name: %.8x\n", context
, stat
);
342 stat
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPixel
, &font
);
343 ok(stat
== Ok
, "could not create a font for the %s family: %.8x\n", context
, stat
);
346 stat
= GdipDeleteFont(font
);
347 ok(stat
== Ok
, "could not delete the %s family font: %.8x\n", context
, stat
);
350 stat
= GdipDeleteFontFamily(family
);
351 ok(stat
== Ok
, "could not delete the %s family: %.8x\n", context
, stat
);
354 static void test_getgenerics (void)
357 GpFontFamily
*family
;
358 WCHAR sansname
[LF_FACESIZE
], serifname
[LF_FACESIZE
], mononame
[LF_FACESIZE
];
359 int missingfonts
= 0;
361 stat
= GdipGetGenericFontFamilySansSerif(&family
);
363 if (stat
== FontFamilyNotFound
)
366 check_family("Sans Serif", family
, sansname
);
368 stat
= GdipGetGenericFontFamilySerif(&family
);
370 if (stat
== FontFamilyNotFound
)
373 check_family("Serif", family
, serifname
);
375 stat
= GdipGetGenericFontFamilyMonospace(&family
);
377 if (stat
== FontFamilyNotFound
)
380 check_family("Monospace", family
, mononame
);
382 if (missingfonts
&& strcmp(winetest_platform
, "wine") == 0)
383 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
385 /* Check that the family names are all different */
386 ok(lstrcmpiW(sansname
, serifname
) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname
));
387 ok(lstrcmpiW(sansname
, mononame
) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname
));
388 ok(lstrcmpiW(serifname
, mononame
) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname
));
391 static void test_installedfonts (void)
394 GpFontCollection
* collection
=NULL
;
396 stat
= GdipNewInstalledFontCollection(NULL
);
397 expect (InvalidParameter
, stat
);
399 stat
= GdipNewInstalledFontCollection(&collection
);
401 ok (collection
!= NULL
, "got NULL font collection\n");
404 static void test_heightgivendpi(void)
408 GpFontFamily
* fontfamily
= NULL
;
412 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &fontfamily
);
415 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPixel
, &font
);
418 stat
= GdipGetFontHeightGivenDPI(NULL
, 96, &height
);
419 expect(InvalidParameter
, stat
);
421 stat
= GdipGetFontHeightGivenDPI(font
, 96, NULL
);
422 expect(InvalidParameter
, stat
);
424 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
426 expectf(36.210938, height
);
427 GdipDeleteFont(font
);
430 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitWorld
, &font
);
433 stat
= GdipGetFontUnit(font
, &unit
);
435 expect(UnitWorld
, unit
);
437 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
439 expectf(36.210938, height
);
440 GdipDeleteFont(font
);
443 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPoint
, &font
);
445 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
447 expectf(48.281250, height
);
448 GdipDeleteFont(font
);
451 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitInch
, &font
);
454 stat
= GdipGetFontUnit(font
, &unit
);
456 expect(UnitInch
, unit
);
458 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
460 expectf(3476.250000, height
);
461 GdipDeleteFont(font
);
464 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitDocument
, &font
);
467 stat
= GdipGetFontUnit(font
, &unit
);
469 expect(UnitDocument
, unit
);
471 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
473 expectf(11.587500, height
);
474 GdipDeleteFont(font
);
477 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitMillimeter
, &font
);
480 stat
= GdipGetFontUnit(font
, &unit
);
482 expect(UnitMillimeter
, unit
);
484 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
486 expectf(136.860245, height
);
487 GdipDeleteFont(font
);
489 GdipDeleteFontFamily(fontfamily
);
492 static int CALLBACK
font_enum_proc(const LOGFONTW
*lfe
, const TEXTMETRICW
*ntme
,
493 DWORD type
, LPARAM lparam
)
495 NEWTEXTMETRICW
*ntm
= (NEWTEXTMETRICW
*)lparam
;
497 if (type
!= TRUETYPE_FONTTYPE
) return 1;
499 *ntm
= *(NEWTEXTMETRICW
*)ntme
;
505 UINT16 em_height
, line_spacing
, ascent
, descent
;
506 REAL font_height
, font_size
;
510 static void gdi_get_font_metrics(LOGFONTW
*lf
, struct font_metrics
*fm
)
515 OUTLINETEXTMETRICW otm
;
518 hdc
= CreateCompatibleDC(0);
520 /* it's the only way to get extended NEWTEXTMETRIC fields */
521 ret
= EnumFontFamiliesExW(hdc
, lf
, font_enum_proc
, (LPARAM
)&ntm
, 0);
522 ok(!ret
, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf
->lfFaceName
));
524 hfont
= CreateFontIndirectW(lf
);
525 SelectObject(hdc
, hfont
);
527 otm
.otmSize
= sizeof(otm
);
528 ret
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
529 ok(ret
, "GetOutlineTextMetrics failed\n");
534 fm
->lfHeight
= -otm
.otmTextMetrics
.tmAscent
;
535 fm
->line_spacing
= ntm
.ntmCellHeight
;
536 fm
->font_size
= (REAL
)otm
.otmTextMetrics
.tmAscent
;
537 fm
->font_height
= (REAL
)fm
->line_spacing
* fm
->font_size
/ (REAL
)ntm
.ntmSizeEM
;
538 fm
->em_height
= ntm
.ntmSizeEM
;
539 fm
->ascent
= ntm
.ntmSizeEM
;
540 fm
->descent
= ntm
.ntmCellHeight
- ntm
.ntmSizeEM
;
543 static void gdip_get_font_metrics(GpFont
*font
, struct font_metrics
*fm
)
546 GpFontFamily
*family
;
549 stat
= GdipGetFontStyle(font
, &style
);
552 stat
= GdipGetFontHeight(font
, NULL
, &fm
->font_height
);
554 stat
= GdipGetFontSize(font
, &fm
->font_size
);
557 fm
->lfHeight
= (INT
)(fm
->font_size
* -1.0);
559 stat
= GdipGetFamily(font
, &family
);
562 stat
= GdipGetEmHeight(family
, style
, &fm
->em_height
);
564 stat
= GdipGetLineSpacing(family
, style
, &fm
->line_spacing
);
566 stat
= GdipGetCellAscent(family
, style
, &fm
->ascent
);
568 stat
= GdipGetCellDescent(family
, style
, &fm
->descent
);
571 GdipDeleteFontFamily(family
);
574 static void cmp_font_metrics(struct font_metrics
*fm1
, struct font_metrics
*fm2
, int line
)
576 ok_(__FILE__
, line
)(fm1
->lfHeight
== fm2
->lfHeight
, "lfHeight %d != %d\n", fm1
->lfHeight
, fm2
->lfHeight
);
577 ok_(__FILE__
, line
)(fm1
->em_height
== fm2
->em_height
, "em_height %u != %u\n", fm1
->em_height
, fm2
->em_height
);
578 ok_(__FILE__
, line
)(fm1
->line_spacing
== fm2
->line_spacing
, "line_spacing %u != %u\n", fm1
->line_spacing
, fm2
->line_spacing
);
579 ok_(__FILE__
, line
)(abs(fm1
->ascent
- fm2
->ascent
) <= 1, "ascent %u != %u\n", fm1
->ascent
, fm2
->ascent
);
580 ok_(__FILE__
, line
)(abs(fm1
->descent
- fm2
->descent
) <= 1, "descent %u != %u\n", fm1
->descent
, fm2
->descent
);
581 ok(fm1
->font_height
> 0.0, "fm1->font_height should be positive, got %f\n", fm1
->font_height
);
582 ok(fm2
->font_height
> 0.0, "fm2->font_height should be positive, got %f\n", fm2
->font_height
);
583 ok_(__FILE__
, line
)(fm1
->font_height
== fm2
->font_height
, "font_height %f != %f\n", fm1
->font_height
, fm2
->font_height
);
584 ok(fm1
->font_size
> 0.0, "fm1->font_size should be positive, got %f\n", fm1
->font_size
);
585 ok(fm2
->font_size
> 0.0, "fm2->font_size should be positive, got %f\n", fm2
->font_size
);
586 ok_(__FILE__
, line
)(fm1
->font_size
== fm2
->font_size
, "font_size %f != %f\n", fm1
->font_size
, fm2
->font_size
);
589 static void test_font_metrics(void)
593 GpFontFamily
*family
;
594 GpGraphics
*graphics
;
597 struct font_metrics fm_gdi
, fm_gdip
;
600 hdc
= CreateCompatibleDC(0);
601 stat
= GdipCreateFromHDC(hdc
, &graphics
);
604 memset(&lf
, 0, sizeof(lf
));
607 lstrcpyW(lf
.lfFaceName
, Tahoma
);
609 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
612 stat
= GdipGetFontUnit(font
, &unit
);
614 expect(UnitWorld
, unit
);
616 gdip_get_font_metrics(font
, &fm_gdip
);
618 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
619 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
620 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
621 fm_gdip
.font_height
, fm_gdip
.font_size
);
623 gdi_get_font_metrics(&lf
, &fm_gdi
);
625 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
626 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
627 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
628 fm_gdi
.font_height
, fm_gdi
.font_size
);
630 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
632 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
634 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
635 gdi_get_font_metrics(&lf
, &fm_gdi
);
637 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
638 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
639 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
640 fm_gdi
.font_height
, fm_gdi
.font_size
);
641 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
643 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
645 GdipDeleteFont(font
);
648 lstrcpyW(lf
.lfFaceName
, Tahoma
);
650 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
653 stat
= GdipGetFontUnit(font
, &unit
);
655 expect(UnitWorld
, unit
);
657 gdip_get_font_metrics(font
, &fm_gdip
);
659 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
660 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
661 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
662 fm_gdip
.font_height
, fm_gdip
.font_size
);
664 gdi_get_font_metrics(&lf
, &fm_gdi
);
666 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
667 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
668 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
669 fm_gdi
.font_height
, fm_gdi
.font_size
);
671 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
673 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
675 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
676 gdi_get_font_metrics(&lf
, &fm_gdi
);
678 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
679 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
680 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
681 fm_gdi
.font_height
, fm_gdi
.font_size
);
682 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
684 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
686 GdipDeleteFont(font
);
688 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &family
);
692 stat
= GdipCreateFont(family
, 13.0, FontStyleRegular
, UnitPixel
, &font
);
695 gdip_get_font_metrics(font
, &fm_gdip
);
697 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
698 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
699 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
700 fm_gdip
.font_height
, fm_gdip
.font_size
);
702 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
704 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
705 gdi_get_font_metrics(&lf
, &fm_gdi
);
707 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
708 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
709 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
710 fm_gdi
.font_height
, fm_gdi
.font_size
);
711 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
713 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
715 stat
= GdipGetLogFontW(font
, NULL
, &lf
);
716 expect(InvalidParameter
, stat
);
718 GdipDeleteFont(font
);
720 stat
= GdipCreateFont(family
, -13.0, FontStyleRegular
, UnitPixel
, &font
);
721 expect(InvalidParameter
, stat
);
723 GdipDeleteFontFamily(family
);
725 GdipDeleteGraphics(graphics
);
729 static void test_font_substitution(void)
731 WCHAR ms_shell_dlg
[LF_FACESIZE
];
736 GpGraphics
*graphics
;
738 GpFontFamily
*family
;
741 hdc
= CreateCompatibleDC(0);
742 status
= GdipCreateFromHDC(hdc
, &graphics
);
745 hfont
= GetStockObject(DEFAULT_GUI_FONT
);
746 ok(hfont
!= 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
748 memset(&lf
, 0xfe, sizeof(lf
));
749 ret
= GetObject(hfont
, sizeof(lf
), &lf
);
750 ok(ret
== sizeof(lf
), "GetObject failed\n");
751 ok(!lstrcmp(lf
.lfFaceName
, "MS Shell Dlg"), "wrong face name %s\n", lf
.lfFaceName
);
752 MultiByteToWideChar(CP_ACP
, 0, lf
.lfFaceName
, -1, ms_shell_dlg
, LF_FACESIZE
);
754 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
756 memset(&lf
, 0xfe, sizeof(lf
));
757 status
= GdipGetLogFontA(font
, graphics
, &lf
);
759 ok(!lstrcmp(lf
.lfFaceName
, "Microsoft Sans Serif") ||
760 !lstrcmp(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
761 GdipDeleteFont(font
);
763 status
= GdipCreateFontFamilyFromName(ms_shell_dlg
, NULL
, &family
);
765 status
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPoint
, &font
);
767 memset(&lf
, 0xfe, sizeof(lf
));
768 status
= GdipGetLogFontA(font
, graphics
, &lf
);
770 ok(!lstrcmp(lf
.lfFaceName
, "Microsoft Sans Serif") ||
771 !lstrcmp(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
772 GdipDeleteFont(font
);
773 GdipDeleteFontFamily(family
);
775 status
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &family
);
776 ok(status
== FontFamilyNotFound
, "expected FontFamilyNotFound, got %d\n", status
);
778 lstrcpy(lf
.lfFaceName
, "ThisFontShouldNotExist");
779 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
781 memset(&lf
, 0xfe, sizeof(lf
));
782 status
= GdipGetLogFontA(font
, graphics
, &lf
);
784 ok(!lstrcmp(lf
.lfFaceName
, "Arial"), "wrong face name %s\n", lf
.lfFaceName
);
785 GdipDeleteFont(font
);
788 lf
.lfFaceName
[0] = 0;
789 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
791 memset(&lf
, 0xfe, sizeof(lf
));
792 status
= GdipGetLogFontA(font
, graphics
, &lf
);
794 ok(!lstrcmp(lf
.lfFaceName
, "Arial"), "wrong face name %s\n", lf
.lfFaceName
);
795 GdipDeleteFont(font
);
797 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
800 lstrcpy(lf
.lfFaceName
, "ThisFontShouldNotExist");
801 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
803 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
804 "expected NotTrueTypeFont, got %d\n", status
);
807 lf
.lfFaceName
[0] = 0;
808 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
810 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
811 "expected NotTrueTypeFont, got %d\n", status
);
813 GdipDeleteGraphics(graphics
);
817 static void test_font_transform(void)
819 static const WCHAR string
[] = { 'A',0 };
824 GpGraphics
*graphics
;
826 GpStringFormat
*format
, *typographic
;
827 PointF pos
[1] = { { 0,0 } };
828 REAL height
, margin_y
;
831 hdc
= CreateCompatibleDC(0);
832 status
= GdipCreateFromHDC(hdc
, &graphics
);
835 status
= GdipSetPageUnit(graphics
, UnitPixel
);
838 status
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
840 status
= GdipStringFormatGetGenericTypographic(&typographic
);
843 memset(&lf
, 0, sizeof(lf
));
844 lstrcpy(lf
.lfFaceName
, "Tahoma");
847 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
850 margin_y
= 100.0 / 8.0;
852 /* identity matrix */
853 status
= GdipCreateMatrix(&matrix
);
855 status
= GdipSetWorldTransform(graphics
, matrix
);
857 status
= GdipGetLogFontA(font
, graphics
, &lf
);
859 expect(-100, lf
.lfHeight
);
860 expect(0, lf
.lfWidth
);
861 expect(0, lf
.lfEscapement
);
862 expect(0, lf
.lfOrientation
);
863 status
= GdipGetFontHeight(font
, graphics
, &height
);
865 expectf(120.703125, height
);
866 set_rect_empty(&rect
);
867 set_rect_empty(&bounds
);
868 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
870 expectf(0.0, bounds
.X
);
871 expectf(0.0, bounds
.Y
);
873 expectf(height
+ margin_y
, bounds
.Height
);
874 set_rect_empty(&rect
);
875 set_rect_empty(&bounds
);
876 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
878 expectf(0.0, bounds
.X
);
879 expectf(0.0, bounds
.Y
);
880 expectf_(height
, bounds
.Height
, 1.0);
881 set_rect_empty(&bounds
);
882 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
883 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
885 expectf(0.0, bounds
.X
);
886 expectf_(-100.0, bounds
.Y
, 0.05);
887 expectf_(height
, bounds
.Height
, 0.5);
888 set_rect_empty(&bounds
);
889 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
890 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
892 expectf(0.0, bounds
.X
);
893 expectf_(-100.0, bounds
.Y
, 0.05);
894 expectf_(height
, bounds
.Height
, 0.5);
897 status
= GdipScaleMatrix(matrix
, 2.0, 3.0, MatrixOrderAppend
);
899 status
= GdipSetWorldTransform(graphics
, matrix
);
901 status
= GdipGetLogFontA(font
, graphics
, &lf
);
903 expect(-300, lf
.lfHeight
);
904 expect(0, lf
.lfWidth
);
905 expect(0, lf
.lfEscapement
);
906 expect(0, lf
.lfOrientation
);
907 status
= GdipGetFontHeight(font
, graphics
, &height
);
909 expectf(120.703125, height
);
910 set_rect_empty(&rect
);
911 set_rect_empty(&bounds
);
912 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
914 expectf(0.0, bounds
.X
);
915 expectf(0.0, bounds
.Y
);
917 expectf(height
+ margin_y
, bounds
.Height
);
918 set_rect_empty(&rect
);
919 set_rect_empty(&bounds
);
920 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
922 expectf(0.0, bounds
.X
);
923 expectf(0.0, bounds
.Y
);
924 expectf_(height
, bounds
.Height
, 0.05);
925 set_rect_empty(&bounds
);
926 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
927 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
929 expectf(0.0, bounds
.X
);
930 expectf_(-100.0, bounds
.Y
, 0.05);
931 expectf_(height
, bounds
.Height
, 0.2);
932 set_rect_empty(&bounds
);
933 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
934 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
936 expectf(0.0, bounds
.X
);
938 expectf_(-300.0, bounds
.Y
, 0.15);
940 expectf(height
* 3.0, bounds
.Height
);
942 /* scale + ratate matrix */
943 status
= GdipRotateMatrix(matrix
, 45.0, MatrixOrderAppend
);
945 status
= GdipSetWorldTransform(graphics
, matrix
);
947 status
= GdipGetLogFontA(font
, graphics
, &lf
);
949 expect(-300, lf
.lfHeight
);
950 expect(0, lf
.lfWidth
);
951 expect_(3151, lf
.lfEscapement
, 1);
952 expect_(3151, lf
.lfOrientation
, 1);
953 status
= GdipGetFontHeight(font
, graphics
, &height
);
955 expectf(120.703125, height
);
956 set_rect_empty(&rect
);
957 set_rect_empty(&bounds
);
958 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
960 expectf(0.0, bounds
.X
);
961 expectf(0.0, bounds
.Y
);
963 expectf(height
+ margin_y
, bounds
.Height
);
964 set_rect_empty(&rect
);
965 set_rect_empty(&bounds
);
966 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
968 expectf(0.0, bounds
.X
);
969 expectf(0.0, bounds
.Y
);
970 expectf_(height
, bounds
.Height
, 0.05);
971 set_rect_empty(&bounds
);
972 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
973 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
975 expectf(0.0, bounds
.X
);
976 expectf_(-100.0, bounds
.Y
, 0.05);
977 expectf_(height
, bounds
.Height
, 0.2);
978 set_rect_empty(&bounds
);
979 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
980 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
983 expectf_(-43.814377, bounds
.X
, 0.05);
985 expectf_(-212.235611, bounds
.Y
, 0.05);
987 expectf_(340.847534, bounds
.Height
, 0.05);
989 /* scale + ratate + shear matrix */
990 status
= GdipShearMatrix(matrix
, 4.0, 5.0, MatrixOrderAppend
);
992 status
= GdipSetWorldTransform(graphics
, matrix
);
994 status
= GdipGetLogFontA(font
, graphics
, &lf
);
997 expect(1032, lf
.lfHeight
);
998 expect(0, lf
.lfWidth
);
999 expect_(3099, lf
.lfEscapement
, 1);
1000 expect_(3099, lf
.lfOrientation
, 1);
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.2);
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.2);
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
);
1031 expectf_(-636.706848, bounds
.X
, 0.05);
1033 expectf_(-175.257523, bounds
.Y
, 0.05);
1035 expectf_(1532.984985, bounds
.Height
, 0.05);
1037 /* scale + ratate + shear + translate matrix */
1038 status
= GdipTranslateMatrix(matrix
, 10.0, 20.0, MatrixOrderAppend
);
1040 status
= GdipSetWorldTransform(graphics
, matrix
);
1042 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1045 expect(1032, lf
.lfHeight
);
1046 expect(0, lf
.lfWidth
);
1047 expect_(3099, lf
.lfEscapement
, 1);
1048 expect_(3099, lf
.lfOrientation
, 1);
1049 status
= GdipGetFontHeight(font
, graphics
, &height
);
1051 expectf(120.703125, height
);
1052 set_rect_empty(&rect
);
1053 set_rect_empty(&bounds
);
1054 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1056 expectf(0.0, bounds
.X
);
1057 expectf(0.0, bounds
.Y
);
1059 expectf(height
+ margin_y
, bounds
.Height
);
1060 set_rect_empty(&rect
);
1061 set_rect_empty(&bounds
);
1062 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1064 expectf(0.0, bounds
.X
);
1065 expectf(0.0, bounds
.Y
);
1066 expectf_(height
, bounds
.Height
, 0.1);
1067 set_rect_empty(&bounds
);
1068 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1069 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1071 expectf(0.0, bounds
.X
);
1072 expectf_(-100.0, bounds
.Y
, 0.2);
1073 expectf_(height
, bounds
.Height
, 0.2);
1074 set_rect_empty(&bounds
);
1075 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1076 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1079 expectf_(-626.706848, bounds
.X
, 0.05);
1081 expectf_(-155.257523, bounds
.Y
, 0.05);
1083 expectf_(1532.984985, bounds
.Height
, 0.05);
1085 GdipDeleteMatrix(matrix
);
1086 GdipDeleteFont(font
);
1087 GdipDeleteGraphics(graphics
);
1088 GdipDeleteStringFormat(typographic
);
1089 GdipDeleteStringFormat(format
);
1095 struct GdiplusStartupInput gdiplusStartupInput
;
1096 ULONG_PTR gdiplusToken
;
1098 gdiplusStartupInput
.GdiplusVersion
= 1;
1099 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1100 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1101 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1103 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1105 test_font_transform();
1106 test_font_substitution();
1107 test_font_metrics();
1111 test_fontfamily_properties();
1113 test_installedfonts();
1114 test_heightgivendpi();
1116 GdiplusShutdown(gdiplusToken
);