Initialize the output buffer parameters to 0 in RegQueryValue*
[wine.git] / objects / text.c
blob727e891fd355b72ffd6a3142c12c0c809b97a596
1 /*
2 * text functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 */
8 #include <string.h>
9 #include "wingdi.h"
10 #include "winuser.h"
11 #include "wine/winuser16.h"
12 #include "dc.h"
13 #include "gdi.h"
14 #include "heap.h"
15 #include "debug.h"
16 #include "cache.h"
17 #include "debugstr.h"
19 DEFAULT_DEBUG_CHANNEL(text)
21 #define TAB 9
22 #define LF 10
23 #define CR 13
24 #define SPACE 32
25 #define PREFIX 38
27 #define SWAP_INT(a,b) { int t = a; a = b; b = t; }
29 static int tabstop = 8;
30 static int tabwidth;
31 static int spacewidth;
32 static int prefix_offset;
34 static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
35 char *dest, int *len, int width, WORD format)
37 /* Return next line of text from a string.
39 * hdc - handle to DC.
40 * str - string to parse into lines.
41 * count - length of str.
42 * dest - destination in which to return line.
43 * len - length of resultant line in dest in chars.
44 * width - maximum width of line in pixels.
45 * format - format type passed to DrawText.
47 * Returns pointer to next char in str after end of the line
48 * or NULL if end of str reached.
51 int i = 0, j = 0, k;
52 int plen = 0;
53 int numspaces;
54 SIZE16 size;
55 int lasttab = 0;
56 int wb_i = 0, wb_j = 0, wb_count = 0;
58 while (*count)
60 switch (str[i])
62 case CR:
63 case LF:
64 if (!(format & DT_SINGLELINE))
66 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
68 (*count)--;
69 i++;
71 i++;
72 *len = j;
73 (*count)--;
74 return (&str[i]);
76 dest[j++] = str[i++];
77 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
78 (format & DT_WORDBREAK))
80 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
81 return NULL;
82 plen += size.cx;
84 break;
86 case PREFIX:
87 if (!(format & DT_NOPREFIX) && *count > 1)
89 if (str[++i] == PREFIX)
90 (*count)--;
91 else {
92 prefix_offset = j;
93 break;
96 dest[j++] = str[i++];
97 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
98 (format & DT_WORDBREAK))
100 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
101 return NULL;
102 plen += size.cx;
104 break;
106 case TAB:
107 if (format & DT_EXPANDTABS)
109 wb_i = ++i;
110 wb_j = j;
111 wb_count = *count;
113 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
114 &size))
115 return NULL;
117 numspaces = (tabwidth - size.cx) / spacewidth;
118 for (k = 0; k < numspaces; k++)
119 dest[j++] = SPACE;
120 plen += tabwidth - size.cx;
121 lasttab = wb_j + numspaces;
123 else
125 dest[j++] = str[i++];
126 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
127 (format & DT_WORDBREAK))
129 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
130 return NULL;
131 plen += size.cx;
134 break;
136 case SPACE:
137 dest[j++] = str[i++];
138 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
139 (format & DT_WORDBREAK))
141 wb_i = i;
142 wb_j = j - 1;
143 wb_count = *count;
144 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
145 return NULL;
146 plen += size.cx;
148 break;
150 default:
151 dest[j++] = str[i++];
152 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
153 (format & DT_WORDBREAK))
155 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
156 return NULL;
157 plen += size.cx;
161 (*count)--;
162 if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
164 if (plen > width)
166 if (format & DT_WORDBREAK)
168 if (wb_j)
170 *len = wb_j;
171 *count = wb_count - 1;
172 return (&str[wb_i]);
175 else
177 *len = j;
178 return (&str[i]);
184 *len = j;
185 return NULL;
189 /***********************************************************************
190 * DrawText16 (USER.85)
192 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
193 LPRECT16 rect, UINT16 flags )
195 SIZE16 size;
196 const char *strPtr;
197 static char line[1024];
198 int len, lh, count=i_count;
199 int prefix_x = 0;
200 int prefix_end = 0;
201 TEXTMETRIC16 tm;
202 int x = rect->left, y = rect->top;
203 int width = rect->right - rect->left;
204 int max_width = 0;
206 TRACE(text,"%s, %d , [(%d,%d),(%d,%d)]\n",
207 debugstr_an (str, count), count,
208 rect->left, rect->top, rect->right, rect->bottom);
210 if (count == -1) count = strlen(str);
211 strPtr = str;
213 GetTextMetrics16(hdc, &tm);
214 if (flags & DT_EXTERNALLEADING)
215 lh = tm.tmHeight + tm.tmExternalLeading;
216 else
217 lh = tm.tmHeight;
219 if (flags & DT_TABSTOP)
220 tabstop = flags >> 8;
222 if (flags & DT_EXPANDTABS)
224 GetTextExtentPoint16(hdc, " ", 1, &size);
225 spacewidth = size.cx;
226 GetTextExtentPoint16(hdc, "o", 1, &size);
227 tabwidth = size.cx * tabstop;
230 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
234 prefix_offset = -1;
235 strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
237 if (prefix_offset != -1)
239 GetTextExtentPoint16(hdc, line, prefix_offset, &size);
240 prefix_x = size.cx;
241 GetTextExtentPoint16(hdc, line, prefix_offset + 1, &size);
242 prefix_end = size.cx - 1;
245 if (!GetTextExtentPoint16(hdc, line, len, &size)) return 0;
246 if (flags & DT_CENTER) x = (rect->left + rect->right -
247 size.cx) / 2;
248 else if (flags & DT_RIGHT) x = rect->right - size.cx;
250 if (flags & DT_SINGLELINE)
252 if (flags & DT_VCENTER) y = rect->top +
253 (rect->bottom - rect->top) / 2 - size.cy / 2;
254 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
256 if (!(flags & DT_CALCRECT))
258 if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
259 rect, line, len, NULL )) return 0;
260 if (prefix_offset != -1)
262 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
263 HPEN oldPen = SelectObject( hdc, hpen );
264 MoveTo16(hdc, x + prefix_x, y + tm.tmAscent + 1 );
265 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
266 SelectObject( hdc, oldPen );
267 DeleteObject( hpen );
270 else if (size.cx > max_width)
271 max_width = size.cx;
273 y += lh;
274 if (strPtr)
276 if (!(flags & DT_NOCLIP))
278 if (y > rect->bottom - lh)
279 break;
283 while (strPtr);
284 if (flags & DT_CALCRECT)
286 rect->right = rect->left + max_width;
287 rect->bottom = y;
289 return y - rect->top;
293 /***********************************************************************
294 * DrawText32A (USER32.164)
296 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count,
297 LPRECT rect, UINT flags )
299 RECT16 rect16;
300 INT16 ret;
302 if (!rect)
303 return DrawText16( (HDC16)hdc, str, (INT16)count, NULL, (UINT16)flags);
304 CONV_RECT32TO16( rect, &rect16 );
305 ret = DrawText16( (HDC16)hdc, str, (INT16)count, &rect16, (UINT16)flags );
306 CONV_RECT16TO32( &rect16, rect );
307 return ret;
311 /***********************************************************************
312 * DrawText32W (USER32.167)
314 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
315 LPRECT rect, UINT flags )
317 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
318 INT ret = DrawTextA( hdc, p, count, rect, flags );
319 HeapFree( GetProcessHeap(), 0, p );
320 return ret;
323 /***********************************************************************
324 * DrawTextEx32A (USER32.165)
326 INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
327 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
329 TRACE(text,"(%d,'%s',%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
330 if(dtp) {
331 FIXME(text,"Ignores params:%d,%d,%d,%d,%d\n",dtp->cbSize,
332 dtp->iTabLength,dtp->iLeftMargin,dtp->iRightMargin,
333 dtp->uiLengthDrawn);
335 return DrawTextA(hdc,str,count,rect,flags);
338 /***********************************************************************
339 * DrawTextEx32W (USER32.166)
341 INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT count,
342 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
344 TRACE(text,"(%d,%p,%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
345 FIXME(text,"ignores extended functionality\n");
346 return DrawTextW(hdc,str,count,rect,flags);
349 /***********************************************************************
350 * ExtTextOut16 (GDI.351)
352 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
353 const RECT16 *lprect, LPCSTR str, UINT16 count,
354 const INT16 *lpDx )
356 BOOL ret;
357 int i;
358 RECT rect32;
359 LPINT lpdx32 = NULL;
361 if (lpDx) lpdx32 = (LPINT)HEAP_xalloc( GetProcessHeap(), 0,
362 sizeof(INT)*count );
363 if (lprect) CONV_RECT16TO32(lprect,&rect32);
364 if (lpdx32) for (i=count;i--;) lpdx32[i]=lpDx[i];
365 ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
366 if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
367 return ret;
373 /***********************************************************************
374 * ExtTextOut32A (GDI32.98)
376 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
377 const RECT *lprect, LPCSTR str, UINT count,
378 const INT *lpDx )
380 DC * dc = DC_GetDCPtr( hdc );
381 return dc && dc->funcs->pExtTextOut &&
382 dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
386 /***********************************************************************
387 * ExtTextOut32W (GDI32.99)
389 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
390 const RECT *lprect, LPCWSTR str, UINT count,
391 const INT *lpDx )
393 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
394 INT ret = ExtTextOutA( hdc, x, y, flags, lprect, p, count, lpDx );
395 HeapFree( GetProcessHeap(), 0, p );
396 return ret;
400 /***********************************************************************
401 * TextOut16 (GDI.33)
403 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
405 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
409 /***********************************************************************
410 * TextOut32A (GDI32.355)
412 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
414 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
418 /***********************************************************************
419 * TextOut32W (GDI32.356)
421 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
423 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
427 /***********************************************************************
428 * TEXT_GrayString
430 * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
431 * heap and we can guarantee that the handles fit in an INT16. We have to
432 * rethink the strategy once the migration to NT handles is complete.
433 * We are going to get a lot of code-duplication once this migration is
434 * completed...
437 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb,
438 GRAYSTRINGPROC fn, LPARAM lp, INT len,
439 INT x, INT y, INT cx, INT cy,
440 BOOL unicode, BOOL _32bit)
442 HBITMAP hbm, hbmsave;
443 HBRUSH hbsave;
444 HFONT hfsave;
445 HDC memdc = CreateCompatibleDC(hdc);
446 int slen = len;
447 BOOL retval = TRUE;
448 RECT r;
449 COLORREF fg, bg;
451 if(!hdc) return FALSE;
453 if(len == 0)
455 if(unicode)
456 slen = lstrlenW((LPCWSTR)lp);
457 else if(_32bit)
458 slen = lstrlenA((LPCSTR)lp);
459 else
460 slen = lstrlenA((LPCSTR)PTR_SEG_TO_LIN(lp));
463 if((cx == 0 || cy == 0) && slen != -1)
465 SIZE s;
466 if(unicode)
467 GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
468 else if(_32bit)
469 GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
470 else
471 GetTextExtentPoint32A(hdc, (LPCSTR)PTR_SEG_TO_LIN(lp), slen, &s);
472 if(cx == 0) cx = s.cx;
473 if(cy == 0) cy = s.cy;
476 r.left = r.top = 0;
477 r.right = cx;
478 r.bottom = cy;
480 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
481 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
482 FillRect(memdc, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
483 SetTextColor(memdc, RGB(255, 255, 255));
484 SetBkColor(memdc, RGB(0, 0, 0));
485 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
487 if(fn)
488 if(_32bit)
489 retval = fn(memdc, lp, slen);
490 else
491 retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
492 else
493 if(unicode)
494 TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
495 else if(_32bit)
496 TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
497 else
498 TextOutA(memdc, 0, 0, (LPCSTR)PTR_SEG_TO_LIN(lp), slen);
500 SelectObject(memdc, hfsave);
503 * Windows doc says that the bitmap isn't grayed when len == -1 and
504 * the callback function returns FALSE. However, testing this on
505 * win95 showed otherwise...
507 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
508 if(retval || len != -1)
509 #endif
511 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
512 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
513 SelectObject(memdc, hbsave);
516 if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
517 fg = SetTextColor(hdc, RGB(0, 0, 0));
518 bg = SetBkColor(hdc, RGB(255, 255, 255));
519 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
520 SetTextColor(hdc, fg);
521 SetBkColor(hdc, bg);
522 if(hb) SelectObject(hdc, hbsave);
524 SelectObject(memdc, hbmsave);
525 DeleteObject(hbm);
526 DeleteDC(memdc);
527 return retval;
531 /***********************************************************************
532 * GrayString16 (USER.185)
534 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
535 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
536 INT16 cx, INT16 cy )
538 return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch, x, y, cx, cy, FALSE, FALSE);
542 /***********************************************************************
543 * GrayString32A (USER32.315)
545 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
546 LPARAM lParam, INT cch, INT x, INT y,
547 INT cx, INT cy )
549 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, FALSE, TRUE);
553 /***********************************************************************
554 * GrayString32W (USER32.316)
556 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
557 LPARAM lParam, INT cch, INT x, INT y,
558 INT cx, INT cy )
560 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, TRUE, TRUE);
564 /***********************************************************************
565 * TEXT_TabbedTextOut
567 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
568 * Note: this doesn't work too well for text-alignment modes other
569 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
571 LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
572 INT count, INT cTabStops, const INT16 *lpTabPos16,
573 const INT *lpTabPos32, INT nTabOrg,
574 BOOL fDisplayText )
576 INT defWidth;
577 DWORD extent = 0;
578 int i, tabPos = x;
579 int start = x;
581 if (cTabStops == 1)
583 defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
584 cTabStops = 0;
586 else
588 TEXTMETRIC16 tm;
589 GetTextMetrics16( hdc, &tm );
590 defWidth = 8 * tm.tmAveCharWidth;
593 while (count > 0)
595 for (i = 0; i < count; i++)
596 if (lpstr[i] == '\t') break;
597 extent = GetTextExtent16( hdc, lpstr, i );
598 if (lpTabPos32)
600 while ((cTabStops > 0) &&
601 (nTabOrg + *lpTabPos32 <= x + LOWORD(extent)))
603 lpTabPos32++;
604 cTabStops--;
607 else
609 while ((cTabStops > 0) &&
610 (nTabOrg + *lpTabPos16 <= x + LOWORD(extent)))
612 lpTabPos16++;
613 cTabStops--;
616 if (i == count)
617 tabPos = x + LOWORD(extent);
618 else if (cTabStops > 0)
619 tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
620 else
621 tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth;
622 if (fDisplayText)
624 RECT r;
625 SetRect( &r, x, y, tabPos, y+HIWORD(extent) );
626 ExtTextOutA( hdc, x, y,
627 GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
628 &r, lpstr, i, NULL );
630 x = tabPos;
631 count -= i+1;
632 lpstr += i+1;
634 return MAKELONG(tabPos - start, HIWORD(extent));
638 /***********************************************************************
639 * TabbedTextOut16 (USER.196)
641 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
642 INT16 count, INT16 cTabStops,
643 const INT16 *lpTabPos, INT16 nTabOrg )
645 TRACE(text, "%04x %d,%d '%.*s' %d\n",
646 hdc, x, y, count, lpstr, count );
647 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
648 lpTabPos, NULL, nTabOrg, TRUE );
652 /***********************************************************************
653 * TabbedTextOut32A (USER32.542)
655 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr,
656 INT count, INT cTabStops,
657 const INT *lpTabPos, INT nTabOrg )
659 TRACE(text, "%04x %d,%d '%.*s' %d\n",
660 hdc, x, y, count, lpstr, count );
661 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
662 NULL, lpTabPos, nTabOrg, TRUE );
666 /***********************************************************************
667 * TabbedTextOut32W (USER32.543)
669 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
670 INT count, INT cTabStops,
671 const INT *lpTabPos, INT nTabOrg )
673 LONG ret;
674 LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
675 lstrcpynWtoA( p, str, count + 1 );
676 ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops,
677 lpTabPos, nTabOrg );
678 HeapFree( GetProcessHeap(), 0, p );
679 return ret;
683 /***********************************************************************
684 * GetTabbedTextExtent16 (USER.197)
686 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
687 INT16 cTabStops, const INT16 *lpTabPos )
689 TRACE(text, "%04x '%.*s' %d\n",
690 hdc, count, lpstr, count );
691 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
692 lpTabPos, NULL, 0, FALSE );
696 /***********************************************************************
697 * GetTabbedTextExtent32A (USER32.293)
699 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
700 INT cTabStops, const INT *lpTabPos )
702 TRACE(text, "%04x '%.*s' %d\n",
703 hdc, count, lpstr, count );
704 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
705 NULL, lpTabPos, 0, FALSE );
709 /***********************************************************************
710 * GetTabbedTextExtent32W (USER32.294)
712 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
713 INT cTabStops, const INT *lpTabPos )
715 LONG ret;
716 LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
717 lstrcpynWtoA( p, lpstr, count + 1 );
718 ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos );
719 HeapFree( GetProcessHeap(), 0, p );
720 return ret;
723 /***********************************************************************
724 * GetTextCharset32 [GDI32.226] Gets character set for font in DC
726 * NOTES
727 * Should it return a UINT32 instead of an INT32?
728 * => YES, as GetTextCharsetInfo returns UINT32
730 * RETURNS
731 * Success: Character set identifier
732 * Failure: DEFAULT_CHARSET
734 UINT WINAPI GetTextCharset(
735 HDC hdc) /* [in] Handle to device context */
737 /* MSDN docs say this is equivalent */
738 return GetTextCharsetInfo(hdc, NULL, 0);
741 /***********************************************************************
742 * GetTextCharset16 [GDI.612]
744 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
746 return (UINT16)GetTextCharset(hdc);
749 /***********************************************************************
750 * GetTextCharsetInfo [GDI32.381] Gets character set for font
752 * NOTES
753 * Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
754 * Should it return a UINT32 instead of an INT32?
755 * => YES and YES, from win32.hlp from Borland
757 * RETURNS
758 * Success: Character set identifier
759 * Failure: DEFAULT_CHARSET
761 UINT WINAPI GetTextCharsetInfo(
762 HDC hdc, /* [in] Handle to device context */
763 LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
764 DWORD flags) /* [in] Reserved - must be 0 */
766 HGDIOBJ hFont;
767 UINT charSet = DEFAULT_CHARSET;
768 LOGFONTW lf;
769 CHARSETINFO csinfo;
771 hFont = GetCurrentObject(hdc, OBJ_FONT);
772 if (hFont == 0)
773 return(DEFAULT_CHARSET);
774 if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
775 charSet = lf.lfCharSet;
777 if (fs != NULL) {
778 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
779 return (DEFAULT_CHARSET);
780 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
782 return charSet;