2004-07-21 00:09:14 +02:00
|
|
|
/*
|
|
|
|
* DrawText tests
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Zach Gorman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-07-21 00:09:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void test_DrawTextCalcRect(void)
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
HDC hdc;
|
|
|
|
HFONT hFont, hOldFont;
|
|
|
|
LOGFONTA lf;
|
2006-08-07 21:52:33 +02:00
|
|
|
static CHAR text[] = "Example text for testing DrawText in "
|
2004-07-21 00:09:14 +02:00
|
|
|
"MM_HIENGLISH mode";
|
2006-08-07 21:52:33 +02:00
|
|
|
static WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
|
2006-01-27 15:47:15 +01:00
|
|
|
's','t','r','i','n','g','\0'};
|
2006-08-07 21:52:33 +02:00
|
|
|
static CHAR emptystring[] = "";
|
|
|
|
static WCHAR emptystringW[] = { 0 };
|
|
|
|
INT textlen, textheight;
|
2004-07-21 00:09:14 +02:00
|
|
|
RECT rect = { 0, 0, 100, 0 };
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2004-07-21 00:09:14 +02:00
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
|
|
|
|
0, 0, 200, 200, 0, 0, 0, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
|
2004-07-21 00:09:14 +02:00
|
|
|
hdc = GetDC(hwnd);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hdc != 0, "GetDC error %u\n", GetLastError());
|
2004-07-21 00:09:14 +02:00
|
|
|
trace("hdc %p\n", hdc);
|
2005-03-31 12:07:26 +02:00
|
|
|
textlen = lstrlenA(text);
|
2004-07-21 00:09:14 +02:00
|
|
|
|
|
|
|
/* LOGFONT initialization */
|
|
|
|
memset(&lf, 0, sizeof(lf));
|
|
|
|
lf.lfCharSet = ANSI_CHARSET;
|
|
|
|
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
|
|
|
lf.lfWeight = FW_DONTCARE;
|
|
|
|
lf.lfHeight = 0; /* mapping mode dependent */
|
|
|
|
lf.lfQuality = DEFAULT_QUALITY;
|
|
|
|
lstrcpyA(lf.lfFaceName, "Arial");
|
|
|
|
|
|
|
|
/* DrawText in MM_HIENGLISH with DT_CALCRECT */
|
|
|
|
SetMapMode(hdc, MM_HIENGLISH);
|
|
|
|
lf.lfHeight = 100 * 9 / 72; /* 9 point */
|
|
|
|
hFont = CreateFontIndirectA(&lf);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hFont != 0, "CreateFontIndirectA error %u\n",
|
2004-07-21 00:09:14 +02:00
|
|
|
GetLastError());
|
|
|
|
hOldFont = SelectObject(hdc, hFont);
|
|
|
|
|
2005-03-31 12:07:26 +02:00
|
|
|
textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
|
2004-07-21 00:09:14 +02:00
|
|
|
DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
|
2004-12-27 18:26:37 +01:00
|
|
|
DT_NOPREFIX);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( textheight, "DrawTextA error %u\n", GetLastError());
|
2004-07-21 00:09:14 +02:00
|
|
|
|
2006-10-07 21:45:11 +02:00
|
|
|
trace("MM_HIENGLISH rect.bottom %d\n", rect.bottom);
|
2004-07-21 00:09:14 +02:00
|
|
|
todo_wine ok(rect.bottom < 0, "In MM_HIENGLISH, DrawText with "
|
|
|
|
"DT_CALCRECT should return a negative rectangle bottom. "
|
2006-10-07 21:45:11 +02:00
|
|
|
"(bot=%d)\n", rect.bottom);
|
2004-07-21 00:09:14 +02:00
|
|
|
|
|
|
|
SelectObject(hdc, hOldFont);
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteObject(hFont);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "DeleteObject error %u\n", GetLastError());
|
2004-07-21 00:09:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* DrawText in MM_TEXT with DT_CALCRECT */
|
|
|
|
SetMapMode(hdc, MM_TEXT);
|
|
|
|
lf.lfHeight = -MulDiv(9, GetDeviceCaps(hdc,
|
|
|
|
LOGPIXELSY), 72); /* 9 point */
|
|
|
|
hFont = CreateFontIndirectA(&lf);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hFont != 0, "CreateFontIndirectA error %u\n",
|
2004-07-21 00:09:14 +02:00
|
|
|
GetLastError());
|
|
|
|
hOldFont = SelectObject(hdc, hFont);
|
|
|
|
|
2005-03-31 12:07:26 +02:00
|
|
|
textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
|
2004-07-21 00:09:14 +02:00
|
|
|
DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
|
2004-12-27 18:26:37 +01:00
|
|
|
DT_NOPREFIX);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( textheight, "DrawTextA error %u\n", GetLastError());
|
2004-07-21 00:09:14 +02:00
|
|
|
|
2006-10-07 21:45:11 +02:00
|
|
|
trace("MM_TEXT rect.bottom %d\n", rect.bottom);
|
2004-07-21 00:09:14 +02:00
|
|
|
ok(rect.bottom > 0, "In MM_TEXT, DrawText with DT_CALCRECT "
|
2006-10-07 21:45:11 +02:00
|
|
|
"should return a positive rectangle bottom. (bot=%d)\n",
|
2004-07-21 00:09:14 +02:00
|
|
|
rect.bottom);
|
|
|
|
|
2006-01-27 15:47:15 +01:00
|
|
|
/* empty or null text should in some cases calc an empty rectangle */
|
|
|
|
/* note: testing the function's return value is useless, it differs
|
|
|
|
* ( 0 or 1) on every Windows version I tried */
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
2006-08-07 21:52:33 +02:00
|
|
|
textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT, NULL );
|
2006-01-27 15:47:15 +01:00
|
|
|
ok( !(rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should NOT be empty.\n");
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
|
|
|
SetLastError( 0);
|
2006-08-07 21:52:33 +02:00
|
|
|
textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT, NULL );
|
2006-01-27 15:47:15 +01:00
|
|
|
ok( (rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should be empty.\n");
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
|
|
|
SetLastError( 0);
|
|
|
|
textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
|
|
|
|
ok( (rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should be empty.\n");
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
|
|
|
textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
|
|
|
|
ok( !(rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should NOT be empty.\n");
|
|
|
|
|
|
|
|
/* Wide char versions */
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
|
|
|
SetLastError( 0);
|
2006-08-07 21:52:33 +02:00
|
|
|
textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT, NULL );
|
2006-01-27 15:47:15 +01:00
|
|
|
if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
|
|
|
|
ok( !(rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should NOT be empty.\n");
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
2006-08-07 21:52:33 +02:00
|
|
|
textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT, NULL );
|
2006-01-27 15:47:15 +01:00
|
|
|
ok( (rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should be empty.\n");
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
|
|
|
textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
|
|
|
|
ok( !(rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should NOT be empty.\n");
|
|
|
|
SetRect( &rect, 10,10, 100, 100);
|
|
|
|
textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
|
|
|
|
ok( !(rect.left == rect.right && rect.bottom == rect.top),
|
|
|
|
"rectangle should NOT be empty.\n");
|
|
|
|
}
|
2006-08-07 21:52:33 +02:00
|
|
|
|
2004-07-21 00:09:14 +02:00
|
|
|
SelectObject(hdc, hOldFont);
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteObject(hFont);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "DeleteObject error %u\n", GetLastError());
|
2004-07-21 00:09:14 +02:00
|
|
|
|
|
|
|
/* Clean up */
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = ReleaseDC(hwnd, hdc);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "ReleaseDC error %u\n", GetLastError());
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DestroyWindow(hwnd);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "DestroyWindow error %u\n", GetLastError());
|
2004-07-21 00:09:14 +02:00
|
|
|
}
|
|
|
|
|
2005-10-26 12:04:21 +02:00
|
|
|
/* replace tabs by \t */
|
2006-08-07 21:52:33 +02:00
|
|
|
static void strfmt( const char *str, char *strout)
|
2005-10-26 12:04:21 +02:00
|
|
|
{
|
|
|
|
unsigned int i,j ;
|
|
|
|
for(i=0,j=0;i<=strlen(str);i++,j++)
|
|
|
|
if((strout[j]=str[i])=='\t') {
|
|
|
|
strout[j++]='\\';
|
|
|
|
strout[j]='t';
|
|
|
|
}
|
|
|
|
}
|
2006-08-07 21:52:33 +02:00
|
|
|
|
2005-10-26 12:04:21 +02:00
|
|
|
|
|
|
|
#define TABTEST( tabval, tabcount, string, _exp) \
|
|
|
|
{ int i,x_act, x_exp; char strdisp[64];\
|
|
|
|
for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
|
|
|
|
extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
|
|
|
|
strfmt( string, strdisp); \
|
|
|
|
/* trace( "Extent is %08lx\n", extent); */\
|
|
|
|
x_act = LOWORD( extent); \
|
|
|
|
x_exp = (_exp); \
|
|
|
|
ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
|
|
|
|
strdisp, x_act, x_exp, tabval, tabcount); \
|
|
|
|
} \
|
|
|
|
|
|
|
|
|
2006-02-06 13:13:28 +01:00
|
|
|
static void test_TabbedText(void)
|
2005-10-26 12:04:21 +02:00
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
HDC hdc;
|
|
|
|
BOOL ret;
|
|
|
|
TEXTMETRICA tm;
|
|
|
|
DWORD extent;
|
|
|
|
INT tabs[8], cx, cy, tab, tabcount,t,align;
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
|
|
|
|
0, 0, 200, 200, 0, 0, 0, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
|
2005-10-26 12:04:21 +02:00
|
|
|
hdc = GetDC(hwnd);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hdc != 0, "GetDC error %u\n", GetLastError());
|
2005-10-26 12:04:21 +02:00
|
|
|
|
|
|
|
ret = GetTextMetricsA( hdc, &tm);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "GetTextMetrics error %u\n", GetLastError());
|
2005-10-26 12:04:21 +02:00
|
|
|
|
|
|
|
extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
|
|
|
|
cx = LOWORD( extent);
|
|
|
|
cy = HIWORD( extent);
|
|
|
|
trace( "cx is %d cy is %d\n", cx, cy);
|
|
|
|
|
|
|
|
align=1;
|
|
|
|
for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
|
|
|
|
catch the one off errors */
|
|
|
|
tab = (cx *4 + t);
|
|
|
|
/* test the special case tabcount =1 and the general array (80 of tabs */
|
|
|
|
for( tabcount = 1; tabcount <= 8; tabcount +=7) {
|
|
|
|
TABTEST( align * tab, tabcount, "\t", tab)
|
|
|
|
TABTEST( align * tab, tabcount, "xxx\t", tab)
|
|
|
|
TABTEST( align * tab, tabcount, "\tx", tab+cx)
|
|
|
|
TABTEST( align * tab, tabcount, "\t\t", tab*2)
|
|
|
|
TABTEST( align * tab, tabcount, "\tx\t", tab*2)
|
|
|
|
TABTEST( align * tab, tabcount, "x\tx", tab+cx)
|
|
|
|
TABTEST( align * tab, tabcount, "xx\tx", tab+cx)
|
|
|
|
TABTEST( align * tab, tabcount, "xxx\tx", tab+cx)
|
|
|
|
TABTEST( align * tab, tabcount, "xxxx\tx", t>0 ? tab + cx : 2*tab+cx)
|
|
|
|
TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab+cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
align=-1;
|
|
|
|
for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
|
|
|
|
catch the one off errors */
|
|
|
|
tab = (cx *4 + t);
|
|
|
|
/* test the special case tabcount =1 and the general array (8) of tabs */
|
|
|
|
for( tabcount = 1; tabcount <= 8; tabcount +=7) {
|
|
|
|
TABTEST( align * tab, tabcount, "\t", tab)
|
|
|
|
TABTEST( align * tab, tabcount, "xxx\t", tab)
|
|
|
|
TABTEST( align * tab, tabcount, "\tx", tab)
|
|
|
|
TABTEST( align * tab, tabcount, "\t\t", tab*2)
|
|
|
|
TABTEST( align * tab, tabcount, "\tx\t", tab*2)
|
|
|
|
TABTEST( align * tab, tabcount, "x\tx", tab)
|
|
|
|
TABTEST( align * tab, tabcount, "xx\tx", tab)
|
|
|
|
TABTEST( align * tab, tabcount, "xxx\tx", 4 * cx >= tab ? 2*tab :tab)
|
|
|
|
TABTEST( align * tab, tabcount, "xxxx\tx", 2*tab)
|
|
|
|
TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-07-21 00:09:14 +02:00
|
|
|
START_TEST(text)
|
|
|
|
{
|
2005-10-26 12:04:21 +02:00
|
|
|
test_TabbedText();
|
2004-07-21 00:09:14 +02:00
|
|
|
test_DrawTextCalcRect();
|
|
|
|
}
|