Fixed DrawTextW length handling.
[wine.git] / objects / text.c
blob3d0de8d420efc8ca3a181fcf5a0b7b13ac9b4261
1 /*
2 * text functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 */
8 #include <string.h>
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "wine/winuser16.h"
13 #include "winbase.h"
14 #include "winuser.h"
15 #include "winerror.h"
16 #include "dc.h"
17 #include "gdi.h"
18 #include "heap.h"
19 #include "debugtools.h"
20 #include "cache.h"
21 #include "winnls.h"
23 DEFAULT_DEBUG_CHANNEL(text);
25 #define TAB 9
26 #define LF 10
27 #define CR 13
28 #define SPACE 32
29 #define PREFIX 38
31 #define SWAP_INT(a,b) { int t = a; a = b; b = t; }
33 static int tabstop = 8;
34 static int tabwidth;
35 static int spacewidth;
36 static int prefix_offset;
38 static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
39 char *dest, int *len, int width, WORD format)
41 /* Return next line of text from a string.
43 * hdc - handle to DC.
44 * str - string to parse into lines.
45 * count - length of str.
46 * dest - destination in which to return line.
47 * len - length of resultant line in dest in chars.
48 * width - maximum width of line in pixels.
49 * format - format type passed to DrawText.
51 * Returns pointer to next char in str after end of the line
52 * or NULL if end of str reached.
55 int i = 0, j = 0, k;
56 int plen = 0;
57 int numspaces;
58 SIZE16 size;
59 int lasttab = 0;
60 int wb_i = 0, wb_j = 0, wb_count = 0;
62 while (*count)
64 switch (str[i])
66 case CR:
67 case LF:
68 if (!(format & DT_SINGLELINE))
70 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
72 (*count)--;
73 i++;
75 i++;
76 *len = j;
77 (*count)--;
78 return (&str[i]);
80 dest[j++] = str[i++];
81 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
82 (format & DT_WORDBREAK))
84 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
85 return NULL;
86 plen += size.cx;
88 break;
90 case PREFIX:
91 if (!(format & DT_NOPREFIX) && *count > 1)
93 if (str[++i] == PREFIX)
94 (*count)--;
95 else {
96 prefix_offset = j;
97 break;
100 dest[j++] = str[i++];
101 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
102 (format & DT_WORDBREAK))
104 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
105 return NULL;
106 plen += size.cx;
108 break;
110 case TAB:
111 if (format & DT_EXPANDTABS)
113 wb_i = ++i;
114 wb_j = j;
115 wb_count = *count;
117 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
118 &size))
119 return NULL;
121 numspaces = (tabwidth - size.cx) / spacewidth;
122 for (k = 0; k < numspaces; k++)
123 dest[j++] = SPACE;
124 plen += tabwidth - size.cx;
125 lasttab = wb_j + numspaces;
127 else
129 dest[j++] = str[i++];
130 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
131 (format & DT_WORDBREAK))
133 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
134 return NULL;
135 plen += size.cx;
138 break;
140 case SPACE:
141 dest[j++] = str[i++];
142 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
143 (format & DT_WORDBREAK))
145 wb_i = i;
146 wb_j = j - 1;
147 wb_count = *count;
148 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
149 return NULL;
150 plen += size.cx;
152 break;
154 default:
155 dest[j++] = str[i++];
156 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
157 (format & DT_WORDBREAK))
159 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
160 return NULL;
161 plen += size.cx;
165 (*count)--;
166 if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
168 if (plen > width)
170 if (format & DT_WORDBREAK)
172 if (wb_j)
174 *len = wb_j;
175 *count = wb_count - 1;
176 return (&str[wb_i]);
179 else
181 *len = j;
182 return (&str[i]);
188 *len = j;
189 return NULL;
193 /***********************************************************************
194 * DrawText16 (USER.85)
196 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
197 LPRECT16 rect, UINT16 flags )
199 SIZE16 size;
200 const char *strPtr;
201 static char line[1024];
202 int len, lh, count=i_count;
203 int prefix_x = 0;
204 int prefix_end = 0;
205 TEXTMETRIC16 tm;
206 int x = rect->left, y = rect->top;
207 int width = rect->right - rect->left;
208 int max_width = 0;
210 TRACE("%s, %d , [(%d,%d),(%d,%d)]\n",
211 debugstr_an (str, count), count,
212 rect->left, rect->top, rect->right, rect->bottom);
214 if (!str) return 0;
215 if (count == -1) count = strlen(str);
216 strPtr = str;
218 GetTextMetrics16(hdc, &tm);
219 if (flags & DT_EXTERNALLEADING)
220 lh = tm.tmHeight + tm.tmExternalLeading;
221 else
222 lh = tm.tmHeight;
224 if (flags & DT_TABSTOP)
225 tabstop = flags >> 8;
227 if (flags & DT_EXPANDTABS)
229 GetTextExtentPoint16(hdc, " ", 1, &size);
230 spacewidth = size.cx;
231 GetTextExtentPoint16(hdc, "o", 1, &size);
232 tabwidth = size.cx * tabstop;
235 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
239 prefix_offset = -1;
240 strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
242 if (prefix_offset != -1)
244 GetTextExtentPoint16(hdc, line, prefix_offset, &size);
245 prefix_x = size.cx;
246 GetTextExtentPoint16(hdc, line, prefix_offset + 1, &size);
247 prefix_end = size.cx - 1;
250 if (!GetTextExtentPoint16(hdc, line, len, &size)) return 0;
251 if (flags & DT_CENTER) x = (rect->left + rect->right -
252 size.cx) / 2;
253 else if (flags & DT_RIGHT) x = rect->right - size.cx;
255 if (flags & DT_SINGLELINE)
257 if (flags & DT_VCENTER) y = rect->top +
258 (rect->bottom - rect->top) / 2 - size.cy / 2;
259 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
261 if (!(flags & DT_CALCRECT))
263 if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
264 rect, line, len, NULL )) return 0;
265 if (prefix_offset != -1)
267 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
268 HPEN oldPen = SelectObject( hdc, hpen );
269 MoveTo16(hdc, x + prefix_x, y + tm.tmAscent + 1 );
270 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
271 SelectObject( hdc, oldPen );
272 DeleteObject( hpen );
275 else if (size.cx > max_width)
276 max_width = size.cx;
278 y += lh;
279 if (strPtr)
281 if (!(flags & DT_NOCLIP))
283 if (y > rect->bottom - lh)
284 break;
288 while (strPtr);
289 if (flags & DT_CALCRECT)
291 rect->right = rect->left + max_width;
292 rect->bottom = y;
294 return y - rect->top;
298 /***********************************************************************
299 * DrawTextA (USER32.164)
301 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count,
302 LPRECT rect, UINT flags )
304 RECT16 rect16;
305 INT16 ret;
307 if (!rect)
308 return DrawText16( (HDC16)hdc, str, (INT16)count, NULL, (UINT16)flags);
309 CONV_RECT32TO16( rect, &rect16 );
310 ret = DrawText16( (HDC16)hdc, str, (INT16)count, &rect16, (UINT16)flags );
311 CONV_RECT16TO32( &rect16, rect );
312 return ret;
316 /***********************************************************************
317 * DrawTextW (USER32.167)
319 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
320 LPRECT rect, UINT flags )
322 LPSTR p;
323 INT acount;
324 INT ret;
325 UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
327 acount = WideCharToMultiByte(codepage,0,str,count,NULL,0,NULL,NULL);
328 p = HeapAlloc( GetProcessHeap(), 0, acount );
329 acount = WideCharToMultiByte(codepage,0,str,count,p,acount,NULL,NULL);
330 if (count == -1) acount = -1;
331 ret = DrawTextA( hdc, p, acount, rect, flags );
333 HeapFree( GetProcessHeap(), 0, p );
334 return ret;
337 /***********************************************************************
338 * DrawTextExA (USER32.165)
340 INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
341 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
343 TRACE("(%d,'%s',%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
344 if(dtp) {
345 FIXME("Ignores params:%d,%d,%d,%d,%d\n",dtp->cbSize,
346 dtp->iTabLength,dtp->iLeftMargin,dtp->iRightMargin,
347 dtp->uiLengthDrawn);
349 return DrawTextA(hdc,str,count,rect,flags);
352 /***********************************************************************
353 * DrawTextExW (USER32.166)
355 INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT count,
356 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
358 TRACE("(%d,%p,%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
359 FIXME("ignores extended functionality\n");
360 return DrawTextW(hdc,str,count,rect,flags);
363 /***********************************************************************
364 * ExtTextOut16 (GDI.351)
366 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
367 const RECT16 *lprect, LPCSTR str, UINT16 count,
368 const INT16 *lpDx )
370 BOOL ret;
371 int i;
372 RECT rect32;
373 LPINT lpdx32 = NULL;
375 if (lpDx) {
376 lpdx32 = (LPINT)HeapAlloc( GetProcessHeap(),0, sizeof(INT)*count );
377 if(lpdx32 == NULL) return FALSE;
378 for (i=count;i--;) lpdx32[i]=lpDx[i];
380 if (lprect) CONV_RECT16TO32(lprect,&rect32);
381 ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
382 if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
383 return ret;
387 /***********************************************************************
388 * ExtTextOutA (GDI32.98)
390 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
391 const RECT *lprect, LPCSTR str, UINT count,
392 const INT *lpDx )
394 LPWSTR p;
395 INT ret;
396 UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
397 UINT wlen;
398 LPINT lpDxW = NULL;
400 wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0);
401 if(lpDx){
402 int i, j;
403 i = 0; j = 0;
405 lpDxW = (LPINT)HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(INT));
406 while(i < count){
407 if(IsDBCSLeadByteEx(codepage, str[i])){
408 lpDxW[j++] = lpDx[i] + lpDx[i+1];
409 i = i + 2;
411 else{
412 lpDxW[j++] = lpDx[i];
413 i = i + 1;
416 lpDx = lpDxW;
418 p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) );
419 wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen);
420 ret = ExtTextOutW( hdc, x, y, flags, lprect, p, wlen, lpDxW );
421 if (lpDxW) HeapFree( GetProcessHeap(), 0, lpDxW );
422 HeapFree( GetProcessHeap(), 0, p );
423 return ret;
427 /***********************************************************************
428 * ExtTextOutW (GDI32.99)
430 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
431 const RECT *lprect, LPCWSTR str, UINT count,
432 const INT *lpDx )
434 DC * dc = DC_GetDCPtr( hdc );
435 return dc && dc->funcs->pExtTextOut &&
436 dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
440 /***********************************************************************
441 * TextOut16 (GDI.33)
443 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
445 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
449 /***********************************************************************
450 * TextOutA (GDI32.355)
452 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
454 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
458 /***********************************************************************
459 * TextOutW (GDI32.356)
461 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
463 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
467 /***********************************************************************
468 * TEXT_GrayString
470 * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
471 * heap and we can guarantee that the handles fit in an INT16. We have to
472 * rethink the strategy once the migration to NT handles is complete.
473 * We are going to get a lot of code-duplication once this migration is
474 * completed...
477 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb,
478 GRAYSTRINGPROC fn, LPARAM lp, INT len,
479 INT x, INT y, INT cx, INT cy,
480 BOOL unicode, BOOL _32bit)
482 HBITMAP hbm, hbmsave;
483 HBRUSH hbsave;
484 HFONT hfsave;
485 HDC memdc = CreateCompatibleDC(hdc);
486 int slen = len;
487 BOOL retval = TRUE;
488 COLORREF fg, bg;
490 if(!hdc) return FALSE;
492 if(len == 0)
494 if(unicode)
495 slen = lstrlenW((LPCWSTR)lp);
496 else if(_32bit)
497 slen = lstrlenA((LPCSTR)lp);
498 else
499 slen = lstrlenA((LPCSTR)PTR_SEG_TO_LIN(lp));
502 if((cx == 0 || cy == 0) && slen != -1)
504 SIZE s;
505 if(unicode)
506 GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
507 else if(_32bit)
508 GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
509 else
510 GetTextExtentPoint32A(hdc, (LPCSTR)PTR_SEG_TO_LIN(lp), slen, &s);
511 if(cx == 0) cx = s.cx;
512 if(cy == 0) cy = s.cy;
515 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
516 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
517 hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
518 PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
519 SelectObject( memdc, hbsave );
520 SetTextColor(memdc, RGB(255, 255, 255));
521 SetBkColor(memdc, RGB(0, 0, 0));
522 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
524 if(fn)
525 if(_32bit)
526 retval = fn(memdc, lp, slen);
527 else
528 retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
529 else
530 if(unicode)
531 TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
532 else if(_32bit)
533 TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
534 else
535 TextOutA(memdc, 0, 0, (LPCSTR)PTR_SEG_TO_LIN(lp), slen);
537 SelectObject(memdc, hfsave);
540 * Windows doc says that the bitmap isn't grayed when len == -1 and
541 * the callback function returns FALSE. However, testing this on
542 * win95 showed otherwise...
544 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
545 if(retval || len != -1)
546 #endif
548 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
549 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
550 SelectObject(memdc, hbsave);
553 if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
554 fg = SetTextColor(hdc, RGB(0, 0, 0));
555 bg = SetBkColor(hdc, RGB(255, 255, 255));
556 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
557 SetTextColor(hdc, fg);
558 SetBkColor(hdc, bg);
559 if(hb) SelectObject(hdc, hbsave);
561 SelectObject(memdc, hbmsave);
562 DeleteObject(hbm);
563 DeleteDC(memdc);
564 return retval;
568 /***********************************************************************
569 * GrayString16 (USER.185)
571 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
572 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
573 INT16 cx, INT16 cy )
575 return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch, x, y, cx, cy, FALSE, FALSE);
579 /***********************************************************************
580 * GrayStringA (USER32.315)
582 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
583 LPARAM lParam, INT cch, INT x, INT y,
584 INT cx, INT cy )
586 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, FALSE, TRUE);
590 /***********************************************************************
591 * GrayStringW (USER32.316)
593 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
594 LPARAM lParam, INT cch, INT x, INT y,
595 INT cx, INT cy )
597 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, TRUE, TRUE);
601 /***********************************************************************
602 * TEXT_TabbedTextOut
604 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
605 * Note: this doesn't work too well for text-alignment modes other
606 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
608 LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
609 INT count, INT cTabStops, const INT16 *lpTabPos16,
610 const INT *lpTabPos32, INT nTabOrg,
611 BOOL fDisplayText )
613 INT defWidth;
614 DWORD extent = 0;
615 int i, tabPos = x;
616 int start = x;
618 if (cTabStops == 1)
620 defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
621 cTabStops = 0;
623 else
625 TEXTMETRIC16 tm;
626 GetTextMetrics16( hdc, &tm );
627 defWidth = 8 * tm.tmAveCharWidth;
630 while (count > 0)
632 for (i = 0; i < count; i++)
633 if (lpstr[i] == '\t') break;
634 extent = GetTextExtent16( hdc, lpstr, i );
635 if (lpTabPos32)
637 while ((cTabStops > 0) &&
638 (nTabOrg + *lpTabPos32 <= x + LOWORD(extent)))
640 lpTabPos32++;
641 cTabStops--;
644 else
646 while ((cTabStops > 0) &&
647 (nTabOrg + *lpTabPos16 <= x + LOWORD(extent)))
649 lpTabPos16++;
650 cTabStops--;
653 if (i == count)
654 tabPos = x + LOWORD(extent);
655 else if (cTabStops > 0)
656 tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
657 else
658 tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth;
659 if (fDisplayText)
661 RECT r;
662 r.left = x;
663 r.top = y;
664 r.right = tabPos;
665 r.bottom = y + HIWORD(extent);
666 ExtTextOutA( hdc, x, y,
667 GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
668 &r, lpstr, i, NULL );
670 x = tabPos;
671 count -= i+1;
672 lpstr += i+1;
674 return MAKELONG(tabPos - start, HIWORD(extent));
678 /***********************************************************************
679 * TabbedTextOut16 (USER.196)
681 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
682 INT16 count, INT16 cTabStops,
683 const INT16 *lpTabPos, INT16 nTabOrg )
685 TRACE("%04x %d,%d '%.*s' %d\n",
686 hdc, x, y, count, lpstr, count );
687 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
688 lpTabPos, NULL, nTabOrg, TRUE );
692 /***********************************************************************
693 * TabbedTextOutA (USER32.542)
695 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr,
696 INT count, INT cTabStops,
697 const INT *lpTabPos, INT nTabOrg )
699 TRACE("%04x %d,%d '%.*s' %d\n",
700 hdc, x, y, count, lpstr, count );
701 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
702 NULL, lpTabPos, nTabOrg, TRUE );
706 /***********************************************************************
707 * TabbedTextOutW (USER32.543)
709 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
710 INT count, INT cTabStops,
711 const INT *lpTabPos, INT nTabOrg )
713 LONG ret;
714 LPSTR p;
715 INT acount;
716 UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
718 acount = WideCharToMultiByte(codepage,0,str,count,NULL,0,NULL,NULL);
719 p = HeapAlloc( GetProcessHeap(), 0, acount );
720 if(p == NULL) return 0; /* FIXME: is this the correct return on failure */
721 acount = WideCharToMultiByte(codepage,0,str,count,p,acount,NULL,NULL);
722 ret = TabbedTextOutA( hdc, x, y, p, acount, cTabStops,
723 lpTabPos, nTabOrg );
724 HeapFree( GetProcessHeap(), 0, p );
725 return ret;
729 /***********************************************************************
730 * GetTabbedTextExtent16 (USER.197)
732 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
733 INT16 cTabStops, const INT16 *lpTabPos )
735 TRACE("%04x '%.*s' %d\n",
736 hdc, count, lpstr, count );
737 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
738 lpTabPos, NULL, 0, FALSE );
742 /***********************************************************************
743 * GetTabbedTextExtentA (USER32.293)
745 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
746 INT cTabStops, const INT *lpTabPos )
748 TRACE("%04x '%.*s' %d\n",
749 hdc, count, lpstr, count );
750 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
751 NULL, lpTabPos, 0, FALSE );
755 /***********************************************************************
756 * GetTabbedTextExtentW (USER32.294)
758 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
759 INT cTabStops, const INT *lpTabPos )
761 LONG ret;
762 LPSTR p;
763 INT acount;
764 UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
766 acount = WideCharToMultiByte(codepage,0,lpstr,count,NULL,0,NULL,NULL);
767 p = HeapAlloc( GetProcessHeap(), 0, acount );
768 if(p == NULL) return 0; /* FIXME: is this the correct failure value? */
769 acount = WideCharToMultiByte(codepage,0,lpstr,count,p,acount,NULL,NULL);
770 ret = GetTabbedTextExtentA( hdc, p, acount, cTabStops, lpTabPos );
771 HeapFree( GetProcessHeap(), 0, p );
772 return ret;
775 /***********************************************************************
776 * GetTextCharset [GDI32.226] Gets character set for font in DC
778 * NOTES
779 * Should it return a UINT32 instead of an INT32?
780 * => YES, as GetTextCharsetInfo returns UINT32
782 * RETURNS
783 * Success: Character set identifier
784 * Failure: DEFAULT_CHARSET
786 UINT WINAPI GetTextCharset(
787 HDC hdc) /* [in] Handle to device context */
789 /* MSDN docs say this is equivalent */
790 return GetTextCharsetInfo(hdc, NULL, 0);
793 /***********************************************************************
794 * GetTextCharset16 [GDI.612]
796 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
798 return (UINT16)GetTextCharset(hdc);
801 /***********************************************************************
802 * GetTextCharsetInfo [GDI32.381] Gets character set for font
804 * NOTES
805 * Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
806 * Should it return a UINT32 instead of an INT32?
807 * => YES and YES, from win32.hlp from Borland
809 * RETURNS
810 * Success: Character set identifier
811 * Failure: DEFAULT_CHARSET
813 UINT WINAPI GetTextCharsetInfo(
814 HDC hdc, /* [in] Handle to device context */
815 LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
816 DWORD flags) /* [in] Reserved - must be 0 */
818 HGDIOBJ hFont;
819 UINT charSet = DEFAULT_CHARSET;
820 LOGFONTW lf;
821 CHARSETINFO csinfo;
823 hFont = GetCurrentObject(hdc, OBJ_FONT);
824 if (hFont == 0)
825 return(DEFAULT_CHARSET);
826 if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
827 charSet = lf.lfCharSet;
829 if (fs != NULL) {
830 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
831 return (DEFAULT_CHARSET);
832 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
834 return charSet;
837 /***********************************************************************
838 * PolyTextOutA [GDI.402] Draw several Strings
840 BOOL WINAPI PolyTextOutA (
841 HDC hdc, /* Handle to device context */
842 PPOLYTEXTA pptxt, /* array of strings */
843 INT cStrings /* Number of strings in array */
846 FIXME("stub!\n");
847 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
848 return 0;
853 /***********************************************************************
854 * PolyTextOutW [GDI.403] Draw several Strings
856 BOOL WINAPI PolyTextOutW (
857 HDC hdc, /* Handle to device context */
858 PPOLYTEXTW pptxt, /* array of strings */
859 INT cStrings /* Number of strings in array */
862 FIXME("stub!\n");
863 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
864 return 0;