4 * Copyright (c) 2004 Zach Gorman
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #include "wine/test.h"
31 static void test_DrawTextCalcRect(void)
35 HFONT hFont
, hOldFont
;
37 const char text
[] = "Example text for testing DrawText in "
39 INT textlen
,textheight
;
40 RECT rect
= { 0, 0, 100, 0 };
44 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
45 0, 0, 200, 200, 0, 0, 0, NULL
);
46 ok(hwnd
!= 0, "CreateWindowExA error %lu\n", GetLastError());
48 ok(hdc
!= 0, "GetDC error %lu\n", GetLastError());
49 trace("hdc %p\n", hdc
);
50 textlen
= lstrlenA(text
);
52 /* LOGFONT initialization */
53 memset(&lf
, 0, sizeof(lf
));
54 lf
.lfCharSet
= ANSI_CHARSET
;
55 lf
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
56 lf
.lfWeight
= FW_DONTCARE
;
57 lf
.lfHeight
= 0; /* mapping mode dependent */
58 lf
.lfQuality
= DEFAULT_QUALITY
;
59 lstrcpyA(lf
.lfFaceName
, "Arial");
61 /* DrawText in MM_HIENGLISH with DT_CALCRECT */
62 SetMapMode(hdc
, MM_HIENGLISH
);
63 lf
.lfHeight
= 100 * 9 / 72; /* 9 point */
64 hFont
= CreateFontIndirectA(&lf
);
65 ok(hFont
!= 0, "CreateFontIndirectA error %lu\n",
67 hOldFont
= SelectObject(hdc
, hFont
);
69 textheight
= DrawTextA(hdc
, text
, textlen
, &rect
, DT_CALCRECT
|
70 DT_EXTERNALLEADING
| DT_WORDBREAK
| DT_NOCLIP
| DT_LEFT
|
72 ok( textheight
, "DrawTextA error %lu\n", GetLastError());
74 trace("MM_HIENGLISH rect.bottom %ld\n", rect
.bottom
);
75 todo_wine
ok(rect
.bottom
< 0, "In MM_HIENGLISH, DrawText with "
76 "DT_CALCRECT should return a negative rectangle bottom. "
77 "(bot=%ld)\n", rect
.bottom
);
79 SelectObject(hdc
, hOldFont
);
80 ret
= DeleteObject(hFont
);
81 ok( ret
, "DeleteObject error %lu\n", GetLastError());
84 /* DrawText in MM_TEXT with DT_CALCRECT */
85 SetMapMode(hdc
, MM_TEXT
);
86 lf
.lfHeight
= -MulDiv(9, GetDeviceCaps(hdc
,
87 LOGPIXELSY
), 72); /* 9 point */
88 hFont
= CreateFontIndirectA(&lf
);
89 ok(hFont
!= 0, "CreateFontIndirectA error %lu\n",
91 hOldFont
= SelectObject(hdc
, hFont
);
93 textheight
= DrawTextA(hdc
, text
, textlen
, &rect
, DT_CALCRECT
|
94 DT_EXTERNALLEADING
| DT_WORDBREAK
| DT_NOCLIP
| DT_LEFT
|
96 ok( textheight
, "DrawTextA error %lu\n", GetLastError());
98 trace("MM_TEXT rect.bottom %ld\n", rect
.bottom
);
99 ok(rect
.bottom
> 0, "In MM_TEXT, DrawText with DT_CALCRECT "
100 "should return a positive rectangle bottom. (bot=%ld)\n",
103 SelectObject(hdc
, hOldFont
);
104 ret
= DeleteObject(hFont
);
105 ok( ret
, "DeleteObject error %lu\n", GetLastError());
108 ret
= ReleaseDC(hwnd
, hdc
);
109 ok( ret
, "ReleaseDC error %lu\n", GetLastError());
110 ret
= DestroyWindow(hwnd
);
111 ok( ret
, "DestroyWindow error %lu\n", GetLastError());
116 test_DrawTextCalcRect();