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());
114 /* replace tabs by \t */
115 static void strfmt( char *str, char *strout)
118 for(i=0,j=0;i<=strlen(str);i++,j++)
119 if((strout[j]=str[i])=='\t') {
126 #define TABTEST( tabval, tabcount, string, _exp) \
127 { int i,x_act, x_exp; char strdisp[64];\
128 for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
129 extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
130 strfmt( string, strdisp); \
131 /* trace( "Extent is %08lx\n", extent); */\
132 x_act = LOWORD( extent); \
134 ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
135 strdisp, x_act, x_exp, tabval, tabcount); \
139 static void test_TabbedText()
146 INT tabs[8], cx, cy, tab, tabcount,t,align;
149 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
150 0, 0, 200, 200, 0, 0, 0, NULL);
151 ok(hwnd != 0, "CreateWindowExA error %lu\n", GetLastError());
153 ok(hdc != 0, "GetDC error %lu\n", GetLastError());
155 ret = GetTextMetricsA( hdc, &tm);
156 ok( ret, "GetTextMetrics error %lu\n", GetLastError());
158 extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
159 cx = LOWORD( extent);
160 cy = HIWORD( extent);
161 trace( "cx is %d cy is %d\n", cx, cy);
164 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
165 catch the one off errors */
167 /* test the special case tabcount =1 and the general array (80 of tabs */
168 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
169 TABTEST( align * tab, tabcount, "\t", tab)
170 TABTEST( align * tab, tabcount, "xxx\t", tab)
171 TABTEST( align * tab, tabcount, "\tx", tab+cx)
172 TABTEST( align * tab, tabcount, "\t\t", tab*2)
173 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
174 TABTEST( align * tab, tabcount, "x\tx", tab+cx)
175 TABTEST( align * tab, tabcount, "xx\tx", tab+cx)
176 TABTEST( align * tab, tabcount, "xxx\tx", tab+cx)
177 TABTEST( align * tab, tabcount, "xxxx\tx", t>0 ? tab + cx : 2*tab+cx)
178 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab+cx)
182 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
183 catch the one off errors */
185 /* test the special case tabcount =1 and the general array (8) of tabs */
186 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
187 TABTEST( align * tab, tabcount, "\t", tab)
188 TABTEST( align * tab, tabcount, "xxx\t", tab)
189 TABTEST( align * tab, tabcount, "\tx", tab)
190 TABTEST( align * tab, tabcount, "\t\t", tab*2)
191 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
192 TABTEST( align * tab, tabcount, "x\tx", tab)
193 TABTEST( align * tab, tabcount, "xx\tx", tab)
194 TABTEST( align * tab, tabcount, "xxx\tx", 4 * cx >= tab ? 2*tab :tab)
195 TABTEST( align * tab, tabcount, "xxxx\tx", 2*tab)
196 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab)
206 test_DrawTextCalcRect();