blob: 286824a223e3f4f19579e2121b7628bb5a93a1d6 [file] [log] [blame]
Alexandre Julliard401710d1993-09-04 10:09:32 +00001/*
2 * text functions
3 *
Alexandre Julliardaca05781994-10-17 18:12:41 +00004 * Copyright 1993, 1994 Alexandre Julliard
Alexandre Julliard234bc241994-12-10 13:02:28 +00005 *
Alexandre Julliard7e56f681996-01-31 19:02:28 +00006 */
7
David Luyeree517e81999-02-28 12:27:56 +00008#include <string.h>
Marcus Meissner61afa331999-02-22 10:16:00 +00009#include "wingdi.h"
10#include "winuser.h"
11#include "wine/winuser16.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +000012#include "dc.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000013#include "gdi.h"
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +000014#include "heap.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000015#include "debug.h"
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000016#include "cache.h"
Alexandre Julliardf90efa91998-06-14 15:24:15 +000017#include "debugstr.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000018
Alexandre Julliard0e607781993-11-03 19:23:37 +000019#define TAB 9
20#define LF 10
21#define CR 13
22#define SPACE 32
23#define PREFIX 38
24
Alexandre Julliardaca05781994-10-17 18:12:41 +000025#define SWAP_INT(a,b) { int t = a; a = b; b = t; }
26
Alexandre Julliard0e607781993-11-03 19:23:37 +000027static int tabstop = 8;
28static int tabwidth;
29static int spacewidth;
30static int prefix_offset;
31
Alexandre Julliard530ee841996-10-23 16:59:13 +000032static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
Alexandre Julliard7e56f681996-01-31 19:02:28 +000033 char *dest, int *len, int width, WORD format)
Alexandre Julliard0e607781993-11-03 19:23:37 +000034{
35 /* Return next line of text from a string.
36 *
37 * hdc - handle to DC.
38 * str - string to parse into lines.
39 * count - length of str.
40 * dest - destination in which to return line.
41 * len - length of resultant line in dest in chars.
42 * width - maximum width of line in pixels.
43 * format - format type passed to DrawText.
44 *
45 * Returns pointer to next char in str after end of the line
46 * or NULL if end of str reached.
47 */
48
49 int i = 0, j = 0, k;
50 int plen = 0;
51 int numspaces;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000052 SIZE16 size;
Alexandre Julliard0e607781993-11-03 19:23:37 +000053 int lasttab = 0;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +000054 int wb_i = 0, wb_j = 0, wb_count = 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +000055
56 while (*count)
57 {
58 switch (str[i])
59 {
60 case CR:
61 case LF:
62 if (!(format & DT_SINGLELINE))
63 {
Alexandre Julliard491502b1997-11-01 19:08:16 +000064 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
65 {
66 (*count)--;
67 i++;
68 }
Alexandre Julliard3a405ba1994-10-30 16:25:19 +000069 i++;
Alexandre Julliard0e607781993-11-03 19:23:37 +000070 *len = j;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000071 (*count)--;
Alexandre Julliard0e607781993-11-03 19:23:37 +000072 return (&str[i]);
73 }
74 dest[j++] = str[i++];
Alexandre Julliard490a27e1994-06-08 13:57:50 +000075 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
76 (format & DT_WORDBREAK))
Alexandre Julliard0e607781993-11-03 19:23:37 +000077 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000078 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
Alexandre Julliard0e607781993-11-03 19:23:37 +000079 return NULL;
80 plen += size.cx;
81 }
82 break;
Alexandre Julliard490a27e1994-06-08 13:57:50 +000083
Alexandre Julliard0e607781993-11-03 19:23:37 +000084 case PREFIX:
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000085 if (!(format & DT_NOPREFIX) && *count > 1)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000086 {
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000087 if (str[++i] == PREFIX)
88 (*count)--;
89 else {
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000090 prefix_offset = j;
91 break;
92 }
Alexandre Julliard0e607781993-11-03 19:23:37 +000093 }
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000094 dest[j++] = str[i++];
95 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
96 (format & DT_WORDBREAK))
97 {
98 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
99 return NULL;
100 plen += size.cx;
101 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000102 break;
Alexandre Julliard490a27e1994-06-08 13:57:50 +0000103
Alexandre Julliard0e607781993-11-03 19:23:37 +0000104 case TAB:
105 if (format & DT_EXPANDTABS)
106 {
107 wb_i = ++i;
108 wb_j = j;
109 wb_count = *count;
110
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000111 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
Alexandre Julliard0e607781993-11-03 19:23:37 +0000112 &size))
113 return NULL;
114
115 numspaces = (tabwidth - size.cx) / spacewidth;
116 for (k = 0; k < numspaces; k++)
117 dest[j++] = SPACE;
118 plen += tabwidth - size.cx;
119 lasttab = wb_j + numspaces;
120 }
121 else
122 {
123 dest[j++] = str[i++];
Alexandre Julliard490a27e1994-06-08 13:57:50 +0000124 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
125 (format & DT_WORDBREAK))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000126 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000127 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000128 return NULL;
129 plen += size.cx;
130 }
131 }
132 break;
133
134 case SPACE:
135 dest[j++] = str[i++];
Alexandre Julliard490a27e1994-06-08 13:57:50 +0000136 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
137 (format & DT_WORDBREAK))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000138 {
139 wb_i = i;
140 wb_j = j - 1;
141 wb_count = *count;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000142 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000143 return NULL;
144 plen += size.cx;
145 }
146 break;
147
148 default:
149 dest[j++] = str[i++];
Alexandre Julliard490a27e1994-06-08 13:57:50 +0000150 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
151 (format & DT_WORDBREAK))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000152 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000153 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000154 return NULL;
155 plen += size.cx;
156 }
157 }
158
159 (*count)--;
160 if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
161 {
162 if (plen > width)
163 {
164 if (format & DT_WORDBREAK)
165 {
Alexandre Julliardecc37121994-11-22 16:31:29 +0000166 if (wb_j)
167 {
168 *len = wb_j;
169 *count = wb_count - 1;
170 return (&str[wb_i]);
171 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000172 }
173 else
174 {
175 *len = j;
176 return (&str[i]);
177 }
178 }
179 }
180 }
181
182 *len = j;
183 return NULL;
184}
185
Alexandre Julliard401710d1993-09-04 10:09:32 +0000186
187/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000188 * DrawText16 (USER.85)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000189 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000190INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
191 LPRECT16 rect, UINT16 flags )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000192{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000193 SIZE16 size;
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000194 const char *strPtr;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000195 static char line[1024];
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000196 int len, lh, count=i_count;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +0000197 int prefix_x = 0;
198 int prefix_end = 0;
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000199 TEXTMETRIC16 tm;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000200 int x = rect->left, y = rect->top;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000201 int width = rect->right - rect->left;
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000202 int max_width = 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000203
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000204 TRACE(text,"%s, %d , [(%d,%d),(%d,%d)]\n",
205 debugstr_an (str, count), count,
206 rect->left, rect->top, rect->right, rect->bottom);
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000207
Alexandre Julliard401710d1993-09-04 10:09:32 +0000208 if (count == -1) count = strlen(str);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000209 strPtr = str;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000210
Alexandre Julliard3051b641996-07-05 17:14:13 +0000211 GetTextMetrics16(hdc, &tm);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000212 if (flags & DT_EXTERNALLEADING)
213 lh = tm.tmHeight + tm.tmExternalLeading;
214 else
215 lh = tm.tmHeight;
Alexandre Julliardf41aeca1993-09-14 16:47:10 +0000216
Alexandre Julliard0e607781993-11-03 19:23:37 +0000217 if (flags & DT_TABSTOP)
218 tabstop = flags >> 8;
219
220 if (flags & DT_EXPANDTABS)
221 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000222 GetTextExtentPoint16(hdc, " ", 1, &size);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000223 spacewidth = size.cx;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000224 GetTextExtentPoint16(hdc, "o", 1, &size);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000225 tabwidth = size.cx * tabstop;
226 }
227
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000228 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
229
Alexandre Julliard0e607781993-11-03 19:23:37 +0000230 do
231 {
232 prefix_offset = -1;
233 strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
234
235 if (prefix_offset != -1)
236 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000237 GetTextExtentPoint16(hdc, line, prefix_offset, &size);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000238 prefix_x = size.cx;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000239 GetTextExtentPoint16(hdc, line, prefix_offset + 1, &size);
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000240 prefix_end = size.cx - 1;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000241 }
242
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000243 if (!GetTextExtentPoint16(hdc, line, len, &size)) return 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000244 if (flags & DT_CENTER) x = (rect->left + rect->right -
245 size.cx) / 2;
246 else if (flags & DT_RIGHT) x = rect->right - size.cx;
247
248 if (flags & DT_SINGLELINE)
249 {
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000250 if (flags & DT_VCENTER) y = rect->top +
251 (rect->bottom - rect->top) / 2 - size.cy / 2;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000252 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
253 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000254 if (!(flags & DT_CALCRECT))
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000255 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000256 if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
257 rect, line, len, NULL )) return 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000258 if (prefix_offset != -1)
259 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000260 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
261 HPEN oldPen = SelectObject( hdc, hpen );
262 MoveTo16(hdc, x + prefix_x, y + tm.tmAscent + 1 );
263 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
264 SelectObject( hdc, oldPen );
265 DeleteObject( hpen );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000266 }
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000267 }
268 else if (size.cx > max_width)
269 max_width = size.cx;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000270
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000271 y += lh;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000272 if (strPtr)
273 {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000274 if (!(flags & DT_NOCLIP))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000275 {
276 if (y > rect->bottom - lh)
277 break;
278 }
279 }
280 }
281 while (strPtr);
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000282 if (flags & DT_CALCRECT)
283 {
284 rect->right = rect->left + max_width;
285 rect->bottom = y;
286 }
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000287 return y - rect->top;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000288}
289
290
291/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000292 * DrawText32A (USER32.164)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000293 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000294INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count,
295 LPRECT rect, UINT flags )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000296{
297 RECT16 rect16;
298 INT16 ret;
299
300 if (!rect)
301 return DrawText16( (HDC16)hdc, str, (INT16)count, NULL, (UINT16)flags);
302 CONV_RECT32TO16( rect, &rect16 );
303 ret = DrawText16( (HDC16)hdc, str, (INT16)count, &rect16, (UINT16)flags );
304 CONV_RECT16TO32( &rect16, rect );
305 return ret;
306}
307
308
309/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000310 * DrawText32W (USER32.167)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000311 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000312INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
313 LPRECT rect, UINT flags )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000314{
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000315 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000316 INT ret = DrawTextA( hdc, p, count, rect, flags );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000317 HeapFree( GetProcessHeap(), 0, p );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000318 return ret;
319}
320
Alexandre Julliard77b99181997-09-14 17:17:23 +0000321/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000322 * DrawTextEx32A (USER32.165)
Alexandre Julliard77b99181997-09-14 17:17:23 +0000323 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000324INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
325 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
Alexandre Julliard77b99181997-09-14 17:17:23 +0000326{
Alexandre Julliard54c27111998-03-29 19:44:57 +0000327 TRACE(text,"(%d,'%s',%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000328 if(dtp) {
329 FIXME(text,"Ignores params:%d,%d,%d,%d,%d\n",dtp->cbSize,
330 dtp->iTabLength,dtp->iLeftMargin,dtp->iRightMargin,
331 dtp->uiLengthDrawn);
332 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000333 return DrawTextA(hdc,str,count,rect,flags);
Alexandre Julliard77b99181997-09-14 17:17:23 +0000334}
335
336/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000337 * DrawTextEx32W (USER32.166)
Alexandre Julliard77b99181997-09-14 17:17:23 +0000338 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000339INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT count,
340 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
Alexandre Julliard77b99181997-09-14 17:17:23 +0000341{
Alexandre Julliard54c27111998-03-29 19:44:57 +0000342 TRACE(text,"(%d,%p,%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
343 FIXME(text,"ignores extended functionality\n");
Alexandre Julliarda3960291999-02-26 11:11:13 +0000344 return DrawTextW(hdc,str,count,rect,flags);
Alexandre Julliard77b99181997-09-14 17:17:23 +0000345}
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000346
347/***********************************************************************
348 * ExtTextOut16 (GDI.351)
349 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000350BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
351 const RECT16 *lprect, LPCSTR str, UINT16 count,
352 const INT16 *lpDx )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000353{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000354 BOOL ret;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000355 int i;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000356 RECT rect32;
357 LPINT lpdx32 = NULL;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000358
Alexandre Julliarda3960291999-02-26 11:11:13 +0000359 if (lpDx) lpdx32 = (LPINT)HEAP_xalloc( GetProcessHeap(), 0,
360 sizeof(INT)*count );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000361 if (lprect) CONV_RECT16TO32(lprect,&rect32);
362 if (lpdx32) for (i=count;i--;) lpdx32[i]=lpDx[i];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000363 ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
Alexandre Julliard491502b1997-11-01 19:08:16 +0000364 if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000365 return ret;
Alexandre Julliard73450d61994-05-18 18:29:32 +0000366
Alexandre Julliard401710d1993-09-04 10:09:32 +0000367
Alexandre Julliard401710d1993-09-04 10:09:32 +0000368}
Alexandre Julliard58199531994-04-21 01:20:00 +0000369
Alexandre Julliardaca05781994-10-17 18:12:41 +0000370
371/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000372 * ExtTextOut32A (GDI32.98)
Alexandre Julliardaca05781994-10-17 18:12:41 +0000373 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000374BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
375 const RECT *lprect, LPCSTR str, UINT count,
376 const INT *lpDx )
Alexandre Julliardaca05781994-10-17 18:12:41 +0000377{
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000378 DC * dc = DC_GetDCPtr( hdc );
379 return dc && dc->funcs->pExtTextOut &&
380 dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000381}
382
383
384/***********************************************************************
385 * ExtTextOut32W (GDI32.99)
386 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000387BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
388 const RECT *lprect, LPCWSTR str, UINT count,
389 const INT *lpDx )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000390{
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000391 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000392 INT ret = ExtTextOutA( hdc, x, y, flags, lprect, p, count, lpDx );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000393 HeapFree( GetProcessHeap(), 0, p );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000394 return ret;
395}
396
397
398/***********************************************************************
399 * TextOut16 (GDI.33)
400 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000401BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000402{
403 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
404}
405
406
407/***********************************************************************
408 * TextOut32A (GDI32.355)
409 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000410BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000411{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000412 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000413}
414
415
416/***********************************************************************
417 * TextOut32W (GDI32.356)
418 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000419BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000420{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000421 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000422}
423
424
Alexandre Julliard58199531994-04-21 01:20:00 +0000425/***********************************************************************
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000426 * TEXT_GrayString
427 *
428 * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
429 * heap and we can guarantee that the handles fit in an INT16. We have to
430 * rethink the strategy once the migration to NT handles is complete.
431 * We are going to get a lot of code-duplication once this migration is
432 * completed...
433 *
434 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000435static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb,
436 GRAYSTRINGPROC fn, LPARAM lp, INT len,
437 INT x, INT y, INT cx, INT cy,
438 BOOL unicode, BOOL _32bit)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000439{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000440 HBITMAP hbm, hbmsave;
441 HBRUSH hbsave;
442 HFONT hfsave;
443 HDC memdc = CreateCompatibleDC(hdc);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000444 int slen = len;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000445 BOOL retval = TRUE;
446 RECT r;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000447 COLORREF fg, bg;
448
449 if(!hdc) return FALSE;
450
451 if(len == 0)
452 {
453 if(unicode)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000454 slen = lstrlenW((LPCWSTR)lp);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000455 else if(_32bit)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000456 slen = lstrlenA((LPCSTR)lp);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000457 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000458 slen = lstrlenA((LPCSTR)PTR_SEG_TO_LIN(lp));
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000459 }
460
461 if((cx == 0 || cy == 0) && slen != -1)
462 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000463 SIZE s;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000464 if(unicode)
465 GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
466 else if(_32bit)
467 GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
468 else
469 GetTextExtentPoint32A(hdc, (LPCSTR)PTR_SEG_TO_LIN(lp), slen, &s);
470 if(cx == 0) cx = s.cx;
471 if(cy == 0) cy = s.cy;
472 }
473
474 r.left = r.top = 0;
475 r.right = cx;
476 r.bottom = cy;
477
Alexandre Julliarda3960291999-02-26 11:11:13 +0000478 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
479 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
480 FillRect(memdc, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
481 SetTextColor(memdc, RGB(255, 255, 255));
482 SetBkColor(memdc, RGB(0, 0, 0));
483 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000484
485 if(fn)
486 if(_32bit)
487 retval = fn(memdc, lp, slen);
488 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000489 retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000490 else
491 if(unicode)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000492 TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000493 else if(_32bit)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000494 TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000495 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000496 TextOutA(memdc, 0, 0, (LPCSTR)PTR_SEG_TO_LIN(lp), slen);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000497
Alexandre Julliarda3960291999-02-26 11:11:13 +0000498 SelectObject(memdc, hfsave);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000499
500/*
501 * Windows doc says that the bitmap isn't grayed when len == -1 and
502 * the callback function returns FALSE. However, testing this on
503 * win95 showed otherwise...
504*/
505#ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
506 if(retval || len != -1)
507#endif
508 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000509 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
510 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
511 SelectObject(memdc, hbsave);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000512 }
513
Alexandre Julliarda3960291999-02-26 11:11:13 +0000514 if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
515 fg = SetTextColor(hdc, RGB(0, 0, 0));
516 bg = SetBkColor(hdc, RGB(255, 255, 255));
517 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
518 SetTextColor(hdc, fg);
519 SetBkColor(hdc, bg);
520 if(hb) SelectObject(hdc, hbsave);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000521
Alexandre Julliarda3960291999-02-26 11:11:13 +0000522 SelectObject(memdc, hbmsave);
523 DeleteObject(hbm);
524 DeleteDC(memdc);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000525 return retval;
526}
527
528
529/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000530 * GrayString16 (USER.185)
Alexandre Julliard58199531994-04-21 01:20:00 +0000531 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000532BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
533 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
534 INT16 cx, INT16 cy )
Alexandre Julliard58199531994-04-21 01:20:00 +0000535{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000536 return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch, x, y, cx, cy, FALSE, FALSE);
Alexandre Julliard58199531994-04-21 01:20:00 +0000537}
Alexandre Julliard73450d61994-05-18 18:29:32 +0000538
Alexandre Julliardaca05781994-10-17 18:12:41 +0000539
Alexandre Julliard73450d61994-05-18 18:29:32 +0000540/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000541 * GrayString32A (USER32.315)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000542 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000543BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
544 LPARAM lParam, INT cch, INT x, INT y,
545 INT cx, INT cy )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000546{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000547 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, FALSE, TRUE);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000548}
549
550
551/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000552 * GrayString32W (USER32.316)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000553 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000554BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
555 LPARAM lParam, INT cch, INT x, INT y,
556 INT cx, INT cy )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000557{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000558 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, TRUE, TRUE);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000559}
560
561
562/***********************************************************************
Alexandre Julliard234bc241994-12-10 13:02:28 +0000563 * TEXT_TabbedTextOut
564 *
565 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
566 * Note: this doesn't work too well for text-alignment modes other
567 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +0000568 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000569LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
570 INT count, INT cTabStops, const INT16 *lpTabPos16,
571 const INT *lpTabPos32, INT nTabOrg,
572 BOOL fDisplayText )
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +0000573{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000574 INT defWidth;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000575 DWORD extent = 0;
576 int i, tabPos = x;
577 int start = x;
Alexandre Julliard234bc241994-12-10 13:02:28 +0000578
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000579 if (cTabStops == 1)
580 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000581 defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000582 cTabStops = 0;
583 }
Alexandre Julliard234bc241994-12-10 13:02:28 +0000584 else
585 {
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000586 TEXTMETRIC16 tm;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000587 GetTextMetrics16( hdc, &tm );
Alexandre Julliard234bc241994-12-10 13:02:28 +0000588 defWidth = 8 * tm.tmAveCharWidth;
589 }
590
591 while (count > 0)
592 {
593 for (i = 0; i < count; i++)
594 if (lpstr[i] == '\t') break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000595 extent = GetTextExtent16( hdc, lpstr, i );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000596 if (lpTabPos32)
Alexandre Julliard234bc241994-12-10 13:02:28 +0000597 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000598 while ((cTabStops > 0) &&
599 (nTabOrg + *lpTabPos32 <= x + LOWORD(extent)))
600 {
601 lpTabPos32++;
602 cTabStops--;
603 }
604 }
605 else
606 {
607 while ((cTabStops > 0) &&
608 (nTabOrg + *lpTabPos16 <= x + LOWORD(extent)))
609 {
610 lpTabPos16++;
611 cTabStops--;
612 }
Alexandre Julliard234bc241994-12-10 13:02:28 +0000613 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000614 if (i == count)
Alexandre Julliard234bc241994-12-10 13:02:28 +0000615 tabPos = x + LOWORD(extent);
616 else if (cTabStops > 0)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000617 tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
Alexandre Julliard234bc241994-12-10 13:02:28 +0000618 else
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000619 tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth;
Alexandre Julliard234bc241994-12-10 13:02:28 +0000620 if (fDisplayText)
621 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000622 RECT r;
623 SetRect( &r, x, y, tabPos, y+HIWORD(extent) );
624 ExtTextOutA( hdc, x, y,
625 GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000626 &r, lpstr, i, NULL );
Alexandre Julliard234bc241994-12-10 13:02:28 +0000627 }
628 x = tabPos;
629 count -= i+1;
630 lpstr += i+1;
631 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000632 return MAKELONG(tabPos - start, HIWORD(extent));
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +0000633}
634
635
636/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000637 * TabbedTextOut16 (USER.196)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000638 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000639LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
640 INT16 count, INT16 cTabStops,
641 const INT16 *lpTabPos, INT16 nTabOrg )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000642{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000643 TRACE(text, "%04x %d,%d '%.*s' %d\n",
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000644 hdc, x, y, count, lpstr, count );
Alexandre Julliard234bc241994-12-10 13:02:28 +0000645 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000646 lpTabPos, NULL, nTabOrg, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000647}
648
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +0000649
Alexandre Julliard234bc241994-12-10 13:02:28 +0000650/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000651 * TabbedTextOut32A (USER32.542)
Alexandre Julliard234bc241994-12-10 13:02:28 +0000652 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000653LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr,
654 INT count, INT cTabStops,
655 const INT *lpTabPos, INT nTabOrg )
Alexandre Julliard234bc241994-12-10 13:02:28 +0000656{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000657 TRACE(text, "%04x %d,%d '%.*s' %d\n",
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000658 hdc, x, y, count, lpstr, count );
659 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
660 NULL, lpTabPos, nTabOrg, TRUE );
661}
662
663
664/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000665 * TabbedTextOut32W (USER32.543)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000666 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000667LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
668 INT count, INT cTabStops,
669 const INT *lpTabPos, INT nTabOrg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000670{
671 LONG ret;
672 LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
673 lstrcpynWtoA( p, str, count + 1 );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000674 ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000675 lpTabPos, nTabOrg );
676 HeapFree( GetProcessHeap(), 0, p );
677 return ret;
678}
679
680
681/***********************************************************************
682 * GetTabbedTextExtent16 (USER.197)
683 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000684DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
685 INT16 cTabStops, const INT16 *lpTabPos )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000686{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000687 TRACE(text, "%04x '%.*s' %d\n",
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000688 hdc, count, lpstr, count );
Alexandre Julliard234bc241994-12-10 13:02:28 +0000689 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000690 lpTabPos, NULL, 0, FALSE );
691}
692
693
694/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000695 * GetTabbedTextExtent32A (USER32.293)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000696 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000697DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
698 INT cTabStops, const INT *lpTabPos )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000699{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000700 TRACE(text, "%04x '%.*s' %d\n",
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000701 hdc, count, lpstr, count );
702 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
703 NULL, lpTabPos, 0, FALSE );
704}
705
706
707/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000708 * GetTabbedTextExtent32W (USER32.294)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000709 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000710DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
711 INT cTabStops, const INT *lpTabPos )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000712{
713 LONG ret;
714 LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
715 lstrcpynWtoA( p, lpstr, count + 1 );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000716 ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000717 HeapFree( GetProcessHeap(), 0, p );
718 return ret;
Alexandre Julliard234bc241994-12-10 13:02:28 +0000719}
Alexandre Julliard33072e11997-06-29 18:08:02 +0000720
721/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000722 * GetTextCharset32 [GDI32.226] Gets character set for font in DC
723 *
724 * NOTES
725 * Should it return a UINT32 instead of an INT32?
Gael de Chalendard5af0171998-11-22 12:19:49 +0000726 * => YES, as GetTextCharsetInfo returns UINT32
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000727 *
728 * RETURNS
729 * Success: Character set identifier
730 * Failure: DEFAULT_CHARSET
Alexandre Julliard33072e11997-06-29 18:08:02 +0000731 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000732UINT WINAPI GetTextCharset(
733 HDC hdc) /* [in] Handle to device context */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000734{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000735 /* MSDN docs say this is equivalent */
736 return GetTextCharsetInfo(hdc, NULL, 0);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000737}
738
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000739/***********************************************************************
740 * GetTextCharset16 [GDI.612]
741 */
Gael de Chalendard5af0171998-11-22 12:19:49 +0000742UINT16 WINAPI GetTextCharset16(HDC16 hdc)
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000743{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000744 return (UINT16)GetTextCharset(hdc);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000745}
Alexandre Julliarde658d821997-11-30 17:45:40 +0000746
747/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000748 * GetTextCharsetInfo [GDI32.381] Gets character set for font
749 *
750 * NOTES
751 * Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
752 * Should it return a UINT32 instead of an INT32?
Gael de Chalendard5af0171998-11-22 12:19:49 +0000753 * => YES and YES, from win32.hlp from Borland
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000754 *
755 * RETURNS
756 * Success: Character set identifier
757 * Failure: DEFAULT_CHARSET
Alexandre Julliarde658d821997-11-30 17:45:40 +0000758 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000759UINT WINAPI GetTextCharsetInfo(
760 HDC hdc, /* [in] Handle to device context */
Gael de Chalendard5af0171998-11-22 12:19:49 +0000761 LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
762 DWORD flags) /* [in] Reserved - must be 0 */
Alexandre Julliarde658d821997-11-30 17:45:40 +0000763{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000764 HGDIOBJ hFont;
765 UINT charSet = DEFAULT_CHARSET;
766 LOGFONTW lf;
Guy Albertelli53292171999-01-24 09:50:09 +0000767 CHARSETINFO csinfo;
Gael de Chalendard5af0171998-11-22 12:19:49 +0000768
Gael de Chalendard5af0171998-11-22 12:19:49 +0000769 hFont = GetCurrentObject(hdc, OBJ_FONT);
770 if (hFont == 0)
771 return(DEFAULT_CHARSET);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000772 if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
Gael de Chalendard5af0171998-11-22 12:19:49 +0000773 charSet = lf.lfCharSet;
774
775 if (fs != NULL) {
Marcus Meissner03479f81999-01-28 10:06:38 +0000776 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
Guy Albertelli53292171999-01-24 09:50:09 +0000777 return (DEFAULT_CHARSET);
778 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000779 }
Gael de Chalendard5af0171998-11-22 12:19:49 +0000780 return charSet;
Alexandre Julliarde658d821997-11-30 17:45:40 +0000781}