4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 #define EXPECT_HR(hr,hr_exp) \
31 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
33 static IDWriteFactory
*factory
;
35 static void test_CreateFontFromLOGFONT(void)
37 static const WCHAR arialW
[] = {'A','r','i','a','l',0};
38 static const WCHAR blahW
[] = {'B','l','a','h','!',0};
39 IDWriteGdiInterop
*interop
;
40 DWRITE_FONT_WEIGHT weight
;
41 DWRITE_FONT_STYLE style
;
45 {FW_NORMAL
, DWRITE_FONT_WEIGHT_NORMAL
},
46 {FW_BOLD
, DWRITE_FONT_WEIGHT_BOLD
},
47 { 0, DWRITE_FONT_WEIGHT_NORMAL
},
48 { 50, DWRITE_FONT_WEIGHT_NORMAL
},
49 {150, DWRITE_FONT_WEIGHT_NORMAL
},
50 {250, DWRITE_FONT_WEIGHT_NORMAL
},
51 {350, DWRITE_FONT_WEIGHT_NORMAL
},
52 {450, DWRITE_FONT_WEIGHT_NORMAL
},
53 {650, DWRITE_FONT_WEIGHT_BOLD
},
54 {750, DWRITE_FONT_WEIGHT_BOLD
},
55 {850, DWRITE_FONT_WEIGHT_BOLD
},
56 {950, DWRITE_FONT_WEIGHT_BOLD
},
57 {960, DWRITE_FONT_WEIGHT_BOLD
},
63 hr
= IDWriteFactory_GetGdiInterop(factory
, &interop
);
67 /* null out parameter crashes this call */
68 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, NULL
, NULL
);
70 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, NULL
, &font
);
71 EXPECT_HR(hr
, E_INVALIDARG
);
73 memset(&logfont
, 0, sizeof(logfont
));
74 logfont
.lfHeight
= 12;
76 logfont
.lfWeight
= FW_NORMAL
;
78 lstrcpyW(logfont
.lfFaceName
, arialW
);
80 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
83 /* now check properties */
84 weight
= IDWriteFont_GetWeight(font
);
86 ok(weight
== DWRITE_FONT_WEIGHT_NORMAL
, "got %d\n", weight
);
88 style
= IDWriteFont_GetStyle(font
);
89 ok(style
== DWRITE_FONT_STYLE_ITALIC
, "got %d\n", style
);
91 ret
= IDWriteFont_IsSymbolFont(font
);
92 ok(!ret
, "got %d\n", ret
);
94 IDWriteFont_Release(font
);
97 for (i
= 0; i
< sizeof(weights
)/(2*sizeof(LONG
)); i
++)
99 memset(&logfont
, 0, sizeof(logfont
));
100 logfont
.lfHeight
= 12;
101 logfont
.lfWidth
= 12;
102 logfont
.lfWeight
= weights
[i
][0];
103 lstrcpyW(logfont
.lfFaceName
, arialW
);
105 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
108 weight
= IDWriteFont_GetWeight(font
);
110 ok(weight
== weights
[i
][1],
111 "%d: got %d, expected %d\n", i
, weight
, weights
[i
][1]);
112 IDWriteFont_Release(font
);
115 /* weight not from enum */
116 memset(&logfont
, 0, sizeof(logfont
));
117 logfont
.lfHeight
= 12;
118 logfont
.lfWidth
= 12;
119 logfont
.lfWeight
= 550;
120 lstrcpyW(logfont
.lfFaceName
, arialW
);
122 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
125 weight
= IDWriteFont_GetWeight(font
);
127 ok(weight
== DWRITE_FONT_WEIGHT_NORMAL
|| broken(weight
== DWRITE_FONT_WEIGHT_BOLD
) /* win7 w/o SP */,
129 IDWriteFont_Release(font
);
131 /* empty or nonexistent face name */
132 memset(&logfont
, 0, sizeof(logfont
));
133 logfont
.lfHeight
= 12;
134 logfont
.lfWidth
= 12;
135 logfont
.lfWeight
= FW_NORMAL
;
136 lstrcpyW(logfont
.lfFaceName
, blahW
);
138 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
140 EXPECT_HR(hr
, DWRITE_E_NOFONT
);
142 memset(&logfont
, 0, sizeof(logfont
));
143 logfont
.lfHeight
= 12;
144 logfont
.lfWidth
= 12;
145 logfont
.lfWeight
= FW_NORMAL
;
147 hr
= IDWriteGdiInterop_CreateFontFromLOGFONT(interop
, &logfont
, &font
);
149 EXPECT_HR(hr
, DWRITE_E_NOFONT
);
151 IDWriteGdiInterop_Release(interop
);
158 hr
= DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED
, &IID_IDWriteFactory
, (IUnknown
**)&factory
);
159 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
162 win_skip("failed to create factory\n");
166 test_CreateFontFromLOGFONT();
168 IDWriteFactory_Release(factory
);