3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * PROJECT: ReactOS user32.dll
21 * FILE: win32ss/user/user32/windows/font.c
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * 09-05-2001 CSH Created
28 /* INCLUDES ******************************************************************/
32 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(text
);
36 DWORD WINAPI
GdiGetCodePage(HDC hdc
);
38 INT WINAPI
DrawTextExWorker( HDC hdc
, LPWSTR str
, INT i_count
,
39 LPRECT rect
, UINT flags
, LPDRAWTEXTPARAMS dtp
);
41 LONG
TEXT_TabbedTextOut( HDC hdc
, INT x
, INT y
, LPCWSTR lpstr
,
42 INT count
, INT cTabStops
, const INT
*lpTabPos
, INT nTabOrg
,
45 /* FUNCTIONS *****************************************************************/
59 CONST INT
*lpnTabStopPositions
,
65 UINT cp
= GdiGetCodePage( hDC
); // CP_ACP
67 len
= MultiByteToWideChar(cp
, 0, lpString
, nCount
, NULL
, 0);
69 strW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
71 MultiByteToWideChar(cp
, 0, lpString
, nCount
, strW
, len
);
72 ret
= TabbedTextOutW(hDC
, X
, Y
, strW
, len
, nTabPositions
, lpnTabStopPositions
, nTabOrigin
);
73 HeapFree(GetProcessHeap(), 0, strW
);
89 CONST INT
*lpnTabStopPositions
,
92 return TEXT_TabbedTextOut(hDC
, X
, Y
, lpString
, nCount
, nTabPositions
, lpnTabStopPositions
, nTabOrigin
, TRUE
);
95 /* WINE synced 22-May-2006 */
101 GetTabbedTextExtentA(
106 CONST INT
*lpnTabStopPositions
)
109 UINT cp
= GdiGetCodePage( hDC
); // CP_ACP
113 len
= MultiByteToWideChar(cp
, 0, lpString
, nCount
, NULL
, 0);
115 strW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
117 MultiByteToWideChar(cp
, 0, lpString
, nCount
, strW
, len
);
118 ret
= GetTabbedTextExtentW(hDC
, strW
, len
, nTabPositions
, lpnTabStopPositions
);
119 HeapFree(GetProcessHeap(), 0, strW
);
128 GetTabbedTextExtentW(
133 CONST INT
*lpnTabStopPositions
)
135 return TEXT_TabbedTextOut(hDC
, 0, 0, lpString
, nCount
, nTabPositions
, lpnTabStopPositions
, 0, FALSE
);
139 /***********************************************************************
140 * DrawTextExW (USER32.@)
142 * The documentation on the extra space required for DT_MODIFYSTRING at MSDN
143 * is not quite complete, especially with regard to \0. We will assume that
144 * the returned string could have a length of up to i_count+3 and also have
145 * a trailing \0 (which would be 4 more than a not-null-terminated string but
146 * 3 more than a null-terminated string). If this is not so then increase
147 * the allowance in DrawTextExA.
149 #define MAX_BUFFER 1024
153 * Synced with Wine Staging 1.7.37
155 INT WINAPI
DrawTextExW( HDC hdc
, LPWSTR str
, INT i_count
,
156 LPRECT rect
, UINT flags
, LPDRAWTEXTPARAMS dtp
)
158 return DrawTextExWorker( hdc
, str
, i_count
, rect
, flags
, dtp
);
161 /***********************************************************************
162 * DrawTextExA (USER32.@)
164 * If DT_MODIFYSTRING is specified then there must be room for up to
165 * 4 extra characters. We take great care about just how much modified
170 * Synced with Wine Staging 1.7.37
172 INT WINAPI
DrawTextExA( HDC hdc
, LPSTR str
, INT count
,
173 LPRECT rect
, UINT flags
, LPDRAWTEXTPARAMS dtp
)
184 if (!count
) return 0;
185 if (!str
&& count
> 0) return 0;
186 if( !str
|| ((count
== -1) && !(count
= strlen(str
))))
191 if (dtp
&& dtp
->cbSize
!= sizeof(DRAWTEXTPARAMS
))
194 GetTextMetricsA(hdc
, &tm
);
195 if (flags
& DT_EXTERNALLEADING
)
196 lh
= tm
.tmHeight
+ tm
.tmExternalLeading
;
200 if( flags
& DT_CALCRECT
)
202 rect
->right
= rect
->left
;
203 if( flags
& DT_SINGLELINE
)
204 rect
->bottom
= rect
->top
+ lh
;
206 rect
->bottom
= rect
->top
;
210 cp
= GdiGetCodePage( hdc
);
211 wcount
= MultiByteToWideChar( cp
, 0, str
, count
, NULL
, 0 );
214 if (flags
& DT_MODIFYSTRING
)
219 wstr
= HeapAlloc(GetProcessHeap(), 0, wmax
* sizeof(WCHAR
));
222 MultiByteToWideChar( cp
, 0, str
, count
, wstr
, wcount
);
223 if (flags
& DT_MODIFYSTRING
)
224 for (i
=4, p
=wstr
+wcount
; i
--; p
++) *p
=0xFFFE;
225 /* Initialise the extra characters so that we can see which ones
226 * change. U+FFFE is guaranteed to be not a unicode character and
227 * so will not be generated by DrawTextEx itself.
229 ret
= DrawTextExW( hdc
, wstr
, wcount
, rect
, flags
, dtp
);
230 if (flags
& DT_MODIFYSTRING
)
232 /* Unfortunately the returned string may contain multiple \0s
233 * and so we need to measure it ourselves.
235 for (i
=4, p
=wstr
+wcount
; i
-- && *p
!= 0xFFFE; p
++) wcount
++;
236 WideCharToMultiByte( cp
, 0, wstr
, wcount
, str
, amax
, NULL
, NULL
);
238 HeapFree(GetProcessHeap(), 0, wstr
);
243 /***********************************************************************
244 * DrawTextW (USER32.@)
247 * Synced with Wine Staging 1.7.37
249 INT WINAPI
DrawTextW( HDC hdc
, LPCWSTR str
, INT count
, LPRECT rect
, UINT flags
)
253 memset (&dtp
, 0, sizeof(dtp
));
254 dtp
.cbSize
= sizeof(dtp
);
255 if (flags
& DT_TABSTOP
)
257 dtp
.iTabLength
= (flags
>> 8) & 0xff;
260 return DrawTextExW(hdc
, (LPWSTR
)str
, count
, rect
, flags
, &dtp
);
263 /***********************************************************************
264 * DrawTextA (USER32.@)
267 * Synced with Wine Staging 1.7.37
269 INT WINAPI
DrawTextA( HDC hdc
, LPCSTR str
, INT count
, LPRECT rect
, UINT flags
)
273 memset (&dtp
, 0, sizeof(dtp
));
274 dtp
.cbSize
= sizeof(dtp
);
275 if (flags
& DT_TABSTOP
)
277 dtp
.iTabLength
= (flags
>> 8) & 0xff;
280 return DrawTextExA( hdc
, (LPSTR
)str
, count
, rect
, flags
, &dtp
);