Some more minor GDI fixes.
[wine] / objects / text.c
1 /*
2  * text functions
3  *
4  * Copyright 1993, 1994 Alexandre Julliard
5  *
6  */
7
8 #include <string.h>
9
10 #include "wine/winuser16.h"
11 #include "winbase.h"
12 #include "winuser.h"
13 #include "dc.h"
14 #include "gdi.h"
15 #include "heap.h"
16 #include "debugtools.h"
17 #include "cache.h"
18 #include "debugstr.h"
19
20 DEFAULT_DEBUG_CHANNEL(text)
21
22 #define TAB     9
23 #define LF     10
24 #define CR     13
25 #define SPACE  32
26 #define PREFIX 38
27
28 #define SWAP_INT(a,b)  { int t = a; a = b; b = t; }
29
30 static int tabstop = 8;
31 static int tabwidth;
32 static int spacewidth;
33 static int prefix_offset;
34
35 static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
36                                   char *dest, int *len, int width, WORD format)
37 {
38     /* Return next line of text from a string.
39      * 
40      * hdc - handle to DC.
41      * str - string to parse into lines.
42      * count - length of str.
43      * dest - destination in which to return line.
44      * len - length of resultant line in dest in chars.
45      * width - maximum width of line in pixels.
46      * format - format type passed to DrawText.
47      *
48      * Returns pointer to next char in str after end of the line
49      * or NULL if end of str reached.
50      */
51
52     int i = 0, j = 0, k;
53     int plen = 0;
54     int numspaces;
55     SIZE16 size;
56     int lasttab = 0;
57     int wb_i = 0, wb_j = 0, wb_count = 0;
58
59     while (*count)
60     {
61         switch (str[i])
62         {
63         case CR:
64         case LF:
65             if (!(format & DT_SINGLELINE))
66             {
67                 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
68                 {
69                     (*count)--;
70                     i++;
71                 }
72                 i++;
73                 *len = j;
74                 (*count)--;
75                 return (&str[i]);
76             }
77             dest[j++] = str[i++];
78             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
79                 (format & DT_WORDBREAK))
80             {
81                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
82                     return NULL;
83                 plen += size.cx;
84             }
85             break;
86             
87         case PREFIX:
88             if (!(format & DT_NOPREFIX) && *count > 1)
89                 {
90                 if (str[++i] == PREFIX)
91                     (*count)--;
92                 else {
93                     prefix_offset = j;
94                     break;
95                 }
96             }
97             dest[j++] = str[i++];
98             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
99                 (format & DT_WORDBREAK))
100             {
101                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
102                     return NULL;
103                 plen += size.cx;
104             }
105             break;
106             
107         case TAB:
108             if (format & DT_EXPANDTABS)
109             {
110                 wb_i = ++i;
111                 wb_j = j;
112                 wb_count = *count;
113
114                 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
115                                                                  &size))
116                     return NULL;
117
118                 numspaces = (tabwidth - size.cx) / spacewidth;
119                 for (k = 0; k < numspaces; k++)
120                     dest[j++] = SPACE;
121                 plen += tabwidth - size.cx;
122                 lasttab = wb_j + numspaces;
123             }
124             else
125             {
126                 dest[j++] = str[i++];
127                 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
128                     (format & DT_WORDBREAK))
129                 {
130                     if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
131                         return NULL;
132                     plen += size.cx;
133                 }
134             }
135             break;
136
137         case SPACE:
138             dest[j++] = str[i++];
139             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
140                 (format & DT_WORDBREAK))
141             {
142                 wb_i = i;
143                 wb_j = j - 1;
144                 wb_count = *count;
145                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
146                     return NULL;
147                 plen += size.cx;
148             }
149             break;
150
151         default:
152             dest[j++] = str[i++];
153             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
154                 (format & DT_WORDBREAK))
155             {
156                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
157                     return NULL;
158                 plen += size.cx;
159             }
160         }
161
162         (*count)--;
163         if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
164         {
165             if (plen > width)
166             {
167                 if (format & DT_WORDBREAK)
168                 {
169                     if (wb_j)
170                     {
171                         *len = wb_j;
172                         *count = wb_count - 1;
173                         return (&str[wb_i]);
174                     }
175                 }
176                 else
177                 {
178                     *len = j;
179                     return (&str[i]);
180                 }
181             }
182         }
183     }
184     
185     *len = j;
186     return NULL;
187 }
188
189
190 /***********************************************************************
191  *           DrawText16    (USER.85)
192  */
193 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
194                          LPRECT16 rect, UINT16 flags )
195 {
196     SIZE16 size;
197     const char *strPtr;
198     static char line[1024];
199     int len, lh, count=i_count;
200     int prefix_x = 0;
201     int prefix_end = 0;
202     TEXTMETRIC16 tm;
203     int x = rect->left, y = rect->top;
204     int width = rect->right - rect->left;
205     int max_width = 0;
206
207     TRACE("%s, %d , [(%d,%d),(%d,%d)]\n",
208           debugstr_an (str, count), count,
209           rect->left, rect->top, rect->right, rect->bottom);
210     
211     if (count == -1) count = strlen(str);
212     strPtr = str;
213
214     GetTextMetrics16(hdc, &tm);
215     if (flags & DT_EXTERNALLEADING)
216         lh = tm.tmHeight + tm.tmExternalLeading;
217     else
218         lh = tm.tmHeight;
219
220     if (flags & DT_TABSTOP)
221         tabstop = flags >> 8;
222
223     if (flags & DT_EXPANDTABS)
224     {
225         GetTextExtentPoint16(hdc, " ", 1, &size);
226         spacewidth = size.cx;
227         GetTextExtentPoint16(hdc, "o", 1, &size);
228         tabwidth = size.cx * tabstop;
229     }
230
231     if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
232
233     do
234     {
235         prefix_offset = -1;
236         strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
237
238         if (prefix_offset != -1)
239         {
240             GetTextExtentPoint16(hdc, line, prefix_offset, &size);
241             prefix_x = size.cx;
242             GetTextExtentPoint16(hdc, line, prefix_offset + 1, &size);
243             prefix_end = size.cx - 1;
244         }
245
246         if (!GetTextExtentPoint16(hdc, line, len, &size)) return 0;
247         if (flags & DT_CENTER) x = (rect->left + rect->right -
248                                     size.cx) / 2;
249         else if (flags & DT_RIGHT) x = rect->right - size.cx;
250
251         if (flags & DT_SINGLELINE)
252         {
253             if (flags & DT_VCENTER) y = rect->top + 
254                 (rect->bottom - rect->top) / 2 - size.cy / 2;
255             else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
256         }
257         if (!(flags & DT_CALCRECT))
258         {
259             if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
260                               rect, line, len, NULL )) return 0;
261             if (prefix_offset != -1)
262             {
263                 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
264                 HPEN oldPen = SelectObject( hdc, hpen );
265                 MoveTo16(hdc, x + prefix_x, y + tm.tmAscent + 1 );
266                 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
267                 SelectObject( hdc, oldPen );
268                 DeleteObject( hpen );
269             }
270         }
271         else if (size.cx > max_width)
272             max_width = size.cx;
273
274         y += lh;
275         if (strPtr)
276         {
277             if (!(flags & DT_NOCLIP))
278             {
279                 if (y > rect->bottom - lh)
280                     break;
281             }
282         }
283     }
284     while (strPtr);
285     if (flags & DT_CALCRECT)
286     {
287         rect->right = rect->left + max_width;
288         rect->bottom = y;
289     }
290     return y - rect->top;
291 }
292
293
294 /***********************************************************************
295  *           DrawText32A    (USER32.164)
296  */
297 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count,
298                           LPRECT rect, UINT flags )
299 {
300     RECT16 rect16;
301     INT16 ret;
302
303     if (!rect)
304         return DrawText16( (HDC16)hdc, str, (INT16)count, NULL, (UINT16)flags);
305     CONV_RECT32TO16( rect, &rect16 );
306     ret = DrawText16( (HDC16)hdc, str, (INT16)count, &rect16, (UINT16)flags );
307     CONV_RECT16TO32( &rect16, rect );
308     return ret;
309 }
310
311
312 /***********************************************************************
313  *           DrawText32W    (USER32.167)
314  */
315 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
316                           LPRECT rect, UINT flags )
317 {
318     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
319     INT ret = DrawTextA( hdc, p, count, rect, flags );
320     HeapFree( GetProcessHeap(), 0, p );
321     return ret;
322 }
323
324 /***********************************************************************
325  *           DrawTextEx32A    (USER32.165)
326  */
327 INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
328                      LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
329 {
330     TRACE("(%d,'%s',%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
331     if(dtp) {
332         FIXME("Ignores params:%d,%d,%d,%d,%d\n",dtp->cbSize,
333                    dtp->iTabLength,dtp->iLeftMargin,dtp->iRightMargin,
334                    dtp->uiLengthDrawn);
335     }
336     return DrawTextA(hdc,str,count,rect,flags);
337 }
338
339 /***********************************************************************
340  *           DrawTextEx32W    (USER32.166)
341  */
342 INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT count,
343                      LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
344 {
345     TRACE("(%d,%p,%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
346     FIXME("ignores extended functionality\n");
347     return DrawTextW(hdc,str,count,rect,flags);
348 }
349
350 /***********************************************************************
351  *           ExtTextOut16    (GDI.351)
352  */
353 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
354                             const RECT16 *lprect, LPCSTR str, UINT16 count,
355                             const INT16 *lpDx )
356 {
357     BOOL        ret;
358     int         i;
359     RECT        rect32;
360     LPINT       lpdx32 = NULL;
361
362     if (lpDx) lpdx32 = (LPINT)HEAP_xalloc( GetProcessHeap(), 0,
363                                              sizeof(INT)*count );
364     if (lprect) CONV_RECT16TO32(lprect,&rect32);
365     if (lpdx32) for (i=count;i--;) lpdx32[i]=lpDx[i];
366     ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
367     if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
368     return ret;
369
370
371 }
372
373
374 /***********************************************************************
375  *           ExtTextOut32A    (GDI32.98)
376  */
377 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
378                              const RECT *lprect, LPCSTR str, UINT count,
379                              const INT *lpDx )
380 {
381     DC * dc = DC_GetDCPtr( hdc );
382     return dc && dc->funcs->pExtTextOut && 
383            dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
384 }
385
386
387 /***********************************************************************
388  *           ExtTextOut32W    (GDI32.99)
389  */
390 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
391                              const RECT *lprect, LPCWSTR str, UINT count,
392                              const INT *lpDx )
393 {
394     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
395     INT ret = ExtTextOutA( hdc, x, y, flags, lprect, p, count, lpDx );
396     HeapFree( GetProcessHeap(), 0, p );
397     return ret;
398 }
399
400
401 /***********************************************************************
402  *           TextOut16    (GDI.33)
403  */
404 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
405 {
406     return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
407 }
408
409
410 /***********************************************************************
411  *           TextOut32A    (GDI32.355)
412  */
413 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
414 {
415     return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
416 }
417
418
419 /***********************************************************************
420  *           TextOut32W    (GDI32.356)
421  */
422 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
423 {
424     return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
425 }
426
427
428 /***********************************************************************
429  *           TEXT_GrayString
430  *
431  * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
432  * heap and we can guarantee that the handles fit in an INT16. We have to
433  * rethink the strategy once the migration to NT handles is complete.
434  * We are going to get a lot of code-duplication once this migration is
435  * completed...
436  * 
437  */
438 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, 
439                               GRAYSTRINGPROC fn, LPARAM lp, INT len,
440                               INT x, INT y, INT cx, INT cy, 
441                               BOOL unicode, BOOL _32bit)
442 {
443     HBITMAP hbm, hbmsave;
444     HBRUSH hbsave;
445     HFONT hfsave;
446     HDC memdc = CreateCompatibleDC(hdc);
447     int slen = len;
448     BOOL retval = TRUE;
449     RECT r;
450     COLORREF fg, bg;
451
452     if(!hdc) return FALSE;
453     
454     if(len == 0)
455     {
456         if(unicode)
457             slen = lstrlenW((LPCWSTR)lp);
458         else if(_32bit)
459             slen = lstrlenA((LPCSTR)lp);
460         else
461             slen = lstrlenA((LPCSTR)PTR_SEG_TO_LIN(lp));
462     }
463
464     if((cx == 0 || cy == 0) && slen != -1)
465     {
466         SIZE s;
467         if(unicode)
468             GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
469         else if(_32bit)
470             GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
471         else
472             GetTextExtentPoint32A(hdc, (LPCSTR)PTR_SEG_TO_LIN(lp), slen, &s);
473         if(cx == 0) cx = s.cx;
474         if(cy == 0) cy = s.cy;
475     }
476
477     r.left = r.top = 0;
478     r.right = cx;
479     r.bottom = cy;
480
481     hbm = CreateBitmap(cx, cy, 1, 1, NULL);
482     hbmsave = (HBITMAP)SelectObject(memdc, hbm);
483     FillRect(memdc, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
484     SetTextColor(memdc, RGB(255, 255, 255));
485     SetBkColor(memdc, RGB(0, 0, 0));
486     hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
487             
488     if(fn)
489         if(_32bit)
490             retval = fn(memdc, lp, slen);
491         else
492             retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
493     else
494         if(unicode)
495             TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
496         else if(_32bit)
497             TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
498         else
499             TextOutA(memdc, 0, 0, (LPCSTR)PTR_SEG_TO_LIN(lp), slen);
500
501     SelectObject(memdc, hfsave);
502
503 /*
504  * Windows doc says that the bitmap isn't grayed when len == -1 and
505  * the callback function returns FALSE. However, testing this on
506  * win95 showed otherwise...
507 */
508 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
509     if(retval || len != -1)
510 #endif
511     {
512         hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
513         PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
514         SelectObject(memdc, hbsave);
515     }
516
517     if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
518     fg = SetTextColor(hdc, RGB(0, 0, 0));
519     bg = SetBkColor(hdc, RGB(255, 255, 255));
520     BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
521     SetTextColor(hdc, fg);
522     SetBkColor(hdc, bg);
523     if(hb) SelectObject(hdc, hbsave);
524
525     SelectObject(memdc, hbmsave);
526     DeleteObject(hbm);
527     DeleteDC(memdc);
528     return retval;
529 }
530
531
532 /***********************************************************************
533  *           GrayString16   (USER.185)
534  */
535 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
536                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
537                             INT16 cx, INT16 cy )
538 {
539     return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch, x, y, cx, cy, FALSE, FALSE);
540 }
541
542
543 /***********************************************************************
544  *           GrayString32A   (USER32.315)
545  */
546 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
547                              LPARAM lParam, INT cch, INT x, INT y,
548                              INT cx, INT cy )
549 {
550     return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, FALSE, TRUE);
551 }
552
553
554 /***********************************************************************
555  *           GrayString32W   (USER32.316)
556  */
557 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
558                              LPARAM lParam, INT cch, INT x, INT y,
559                              INT cx, INT cy )
560 {
561     return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, TRUE, TRUE);
562 }
563
564
565 /***********************************************************************
566  *           TEXT_TabbedTextOut
567  *
568  * Helper function for TabbedTextOut() and GetTabbedTextExtent().
569  * Note: this doesn't work too well for text-alignment modes other
570  *       than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
571  */
572 LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
573                          INT count, INT cTabStops, const INT16 *lpTabPos16,
574                          const INT *lpTabPos32, INT nTabOrg,
575                          BOOL fDisplayText )
576 {
577     INT defWidth;
578     DWORD extent = 0;
579     int i, tabPos = x;
580     int start = x;
581
582     if (cTabStops == 1)
583     {
584         defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
585         cTabStops = 0;
586     }
587     else
588     {
589         TEXTMETRIC16 tm;
590         GetTextMetrics16( hdc, &tm );
591         defWidth = 8 * tm.tmAveCharWidth;
592     }
593     
594     while (count > 0)
595     {
596         for (i = 0; i < count; i++)
597             if (lpstr[i] == '\t') break;
598         extent = GetTextExtent16( hdc, lpstr, i );
599         if (lpTabPos32)
600         {
601             while ((cTabStops > 0) &&
602                    (nTabOrg + *lpTabPos32 <= x + LOWORD(extent)))
603             {
604                 lpTabPos32++;
605                 cTabStops--;
606             }
607         }
608         else
609         {
610             while ((cTabStops > 0) &&
611                    (nTabOrg + *lpTabPos16 <= x + LOWORD(extent)))
612             {
613                 lpTabPos16++;
614                 cTabStops--;
615             }
616         }
617         if (i == count)
618             tabPos = x + LOWORD(extent);
619         else if (cTabStops > 0)
620             tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
621         else
622             tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth;
623         if (fDisplayText)
624         {
625             RECT r;
626             SetRect( &r, x, y, tabPos, y+HIWORD(extent) );
627             ExtTextOutA( hdc, x, y,
628                            GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
629                            &r, lpstr, i, NULL );
630         }
631         x = tabPos;
632         count -= i+1;
633         lpstr += i+1;
634     }
635     return MAKELONG(tabPos - start, HIWORD(extent));
636 }
637
638
639 /***********************************************************************
640  *           TabbedTextOut16    (USER.196)
641  */
642 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
643                              INT16 count, INT16 cTabStops,
644                              const INT16 *lpTabPos, INT16 nTabOrg )
645 {
646     TRACE("%04x %d,%d '%.*s' %d\n",
647                   hdc, x, y, count, lpstr, count );
648     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
649                                lpTabPos, NULL, nTabOrg, TRUE );
650 }
651
652
653 /***********************************************************************
654  *           TabbedTextOut32A    (USER32.542)
655  */
656 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr,
657                               INT count, INT cTabStops,
658                               const INT *lpTabPos, INT nTabOrg )
659 {
660     TRACE("%04x %d,%d '%.*s' %d\n",
661                   hdc, x, y, count, lpstr, count );
662     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
663                                NULL, lpTabPos, nTabOrg, TRUE );
664 }
665
666
667 /***********************************************************************
668  *           TabbedTextOut32W    (USER32.543)
669  */
670 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
671                               INT count, INT cTabStops,
672                               const INT *lpTabPos, INT nTabOrg )
673 {
674     LONG ret;
675     LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
676     lstrcpynWtoA( p, str, count + 1 );
677     ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops,
678                             lpTabPos, nTabOrg );
679     HeapFree( GetProcessHeap(), 0, p );
680     return ret;
681 }
682
683
684 /***********************************************************************
685  *           GetTabbedTextExtent16    (USER.197)
686  */
687 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count, 
688                                     INT16 cTabStops, const INT16 *lpTabPos )
689 {
690     TRACE("%04x '%.*s' %d\n",
691                   hdc, count, lpstr, count );
692     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
693                                lpTabPos, NULL, 0, FALSE );
694 }
695
696
697 /***********************************************************************
698  *           GetTabbedTextExtent32A    (USER32.293)
699  */
700 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count, 
701                                      INT cTabStops, const INT *lpTabPos )
702 {
703     TRACE("%04x '%.*s' %d\n",
704                   hdc, count, lpstr, count );
705     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
706                                NULL, lpTabPos, 0, FALSE );
707 }
708
709
710 /***********************************************************************
711  *           GetTabbedTextExtent32W    (USER32.294)
712  */
713 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count, 
714                                      INT cTabStops, const INT *lpTabPos )
715 {
716     LONG ret;
717     LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
718     lstrcpynWtoA( p, lpstr, count + 1 );
719     ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos );
720     HeapFree( GetProcessHeap(), 0, p );
721     return ret;
722 }
723
724 /***********************************************************************
725  * GetTextCharset32 [GDI32.226]  Gets character set for font in DC
726  *
727  * NOTES
728  *    Should it return a UINT32 instead of an INT32?
729  *    => YES, as GetTextCharsetInfo returns UINT32
730  *
731  * RETURNS
732  *    Success: Character set identifier
733  *    Failure: DEFAULT_CHARSET
734  */
735 UINT WINAPI GetTextCharset(
736     HDC hdc) /* [in] Handle to device context */
737 {
738     /* MSDN docs say this is equivalent */
739     return GetTextCharsetInfo(hdc, NULL, 0);
740 }
741
742 /***********************************************************************
743  * GetTextCharset16 [GDI.612]
744  */
745 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
746 {
747     return (UINT16)GetTextCharset(hdc);
748 }
749
750 /***********************************************************************
751  * GetTextCharsetInfo [GDI32.381]  Gets character set for font
752  *
753  * NOTES
754  *    Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
755  *    Should it return a UINT32 instead of an INT32?
756  *    => YES and YES, from win32.hlp from Borland
757  *
758  * RETURNS
759  *    Success: Character set identifier
760  *    Failure: DEFAULT_CHARSET
761  */
762 UINT WINAPI GetTextCharsetInfo(
763     HDC hdc,          /* [in]  Handle to device context */
764     LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
765     DWORD flags)        /* [in]  Reserved - must be 0 */
766 {
767     HGDIOBJ hFont;
768     UINT charSet = DEFAULT_CHARSET;
769     LOGFONTW lf;
770     CHARSETINFO csinfo;
771
772     hFont = GetCurrentObject(hdc, OBJ_FONT);
773     if (hFont == 0)
774         return(DEFAULT_CHARSET);
775     if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
776         charSet = lf.lfCharSet;
777
778     if (fs != NULL) {
779       if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
780            return  (DEFAULT_CHARSET);
781       memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
782     }
783     return charSet;
784 }