Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbeyj@wpi.edu>
[wine.git] / objects / text.c
blob00a0923a65e269ea75ef0f02de48a67b175a35b6
1 /*
2 * text functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 */
8 #include <string.h>
9 #include "winbase.h"
10 #include "winuser.h"
11 #include "dc.h"
12 #include "gdi.h"
13 #include "heap.h"
14 #include "debug.h"
15 #include "cache.h"
16 #include "debugstr.h"
18 DEFAULT_DEBUG_CHANNEL(text)
20 #define TAB 9
21 #define LF 10
22 #define CR 13
23 #define SPACE 32
24 #define PREFIX 38
26 #define SWAP_INT(a,b) { int t = a; a = b; b = t; }
28 static int tabstop = 8;
29 static int tabwidth;
30 static int spacewidth;
31 static int prefix_offset;
33 static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
34 char *dest, int *len, int width, WORD format)
36 /* Return next line of text from a string.
38 * hdc - handle to DC.
39 * str - string to parse into lines.
40 * count - length of str.
41 * dest - destination in which to return line.
42 * len - length of resultant line in dest in chars.
43 * width - maximum width of line in pixels.
44 * format - format type passed to DrawText.
46 * Returns pointer to next char in str after end of the line
47 * or NULL if end of str reached.
50 int i = 0, j = 0, k;
51 int plen = 0;
52 int numspaces;
53 SIZE16 size;
54 int lasttab = 0;
55 int wb_i = 0, wb_j = 0, wb_count = 0;
57 while (*count)
59 switch (str[i])
61 case CR:
62 case LF:
63 if (!(format & DT_SINGLELINE))
65 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
67 (*count)--;
68 i++;
70 i++;
71 *len = j;
72 (*count)--;
73 return (&str[i]);
75 dest[j++] = str[i++];
76 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
77 (format & DT_WORDBREAK))
79 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
80 return NULL;
81 plen += size.cx;
83 break;
85 case PREFIX:
86 if (!(format & DT_NOPREFIX) && *count > 1)
88 if (str[++i] == PREFIX)
89 (*count)--;
90 else {
91 prefix_offset = j;
92 break;
95 dest[j++] = str[i++];
96 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
97 (format & DT_WORDBREAK))
99 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
100 return NULL;
101 plen += size.cx;
103 break;
105 case TAB:
106 if (format & DT_EXPANDTABS)
108 wb_i = ++i;
109 wb_j = j;
110 wb_count = *count;
112 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
113 &size))
114 return NULL;
116 numspaces = (tabwidth - size.cx) / spacewidth;
117 for (k = 0; k < numspaces; k++)
118 dest[j++] = SPACE;
119 plen += tabwidth - size.cx;
120 lasttab = wb_j + numspaces;
122 else
124 dest[j++] = str[i++];
125 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
126 (format & DT_WORDBREAK))
128 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
129 return NULL;
130 plen += size.cx;
133 break;
135 case SPACE:
136 dest[j++] = str[i++];
137 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
138 (format & DT_WORDBREAK))
140 wb_i = i;
141 wb_j = j - 1;
142 wb_count = *count;
143 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
144 return NULL;
145 plen += size.cx;
147 break;
149 default:
150 dest[j++] = str[i++];
151 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
152 (format & DT_WORDBREAK))
154 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
155 return NULL;
156 plen += size.cx;
160 (*count)--;
161 if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
163 if (plen > width)
165 if (format & DT_WORDBREAK)
167 if (wb_j)
169 *len = wb_j;
170 *count = wb_count - 1;
171 return (&str[wb_i]);
174 else
176 *len = j;
177 return (&str[i]);
183 *len = j;
184 return NULL;
188 /***********************************************************************
189 * DrawText16 (USER.85)
191 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
192 LPRECT16 rect, UINT16 flags )
194 SIZE16 size;
195 const char *strPtr;
196 static char line[1024];
197 int len, lh, count=i_count;
198 int prefix_x = 0;
199 int prefix_end = 0;
200 TEXTMETRIC16 tm;
201 int x = rect->left, y = rect->top;
202 int width = rect->right - rect->left;
203 int max_width = 0;
205 TRACE(text,"%s, %d , [(%d,%d),(%d,%d)]\n",
206 debugstr_an (str, count), count,
207 rect->left, rect->top, rect->right, rect->bottom);
209 if (count == -1) count = strlen(str);
210 strPtr = str;
212 GetTextMetrics16(hdc, &tm);
213 if (flags & DT_EXTERNALLEADING)
214 lh = tm.tmHeight + tm.tmExternalLeading;
215 else
216 lh = tm.tmHeight;
218 if (flags & DT_TABSTOP)
219 tabstop = flags >> 8;
221 if (flags & DT_EXPANDTABS)
223 GetTextExtentPoint16(hdc, " ", 1, &size);
224 spacewidth = size.cx;
225 GetTextExtentPoint16(hdc, "o", 1, &size);
226 tabwidth = size.cx * tabstop;
229 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
233 prefix_offset = -1;
234 strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
236 if (prefix_offset != -1)
238 GetTextExtentPoint16(hdc, line, prefix_offset, &size);
239 prefix_x = size.cx;
240 GetTextExtentPoint16(hdc, line, prefix_offset + 1, &size);
241 prefix_end = size.cx - 1;
244 if (!GetTextExtentPoint16(hdc, line, len, &size)) return 0;
245 if (flags & DT_CENTER) x = (rect->left + rect->right -
246 size.cx) / 2;
247 else if (flags & DT_RIGHT) x = rect->right - size.cx;
249 if (flags & DT_SINGLELINE)
251 if (flags & DT_VCENTER) y = rect->top +
252 (rect->bottom - rect->top) / 2 - size.cy / 2;
253 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
255 if (!(flags & DT_CALCRECT))
257 if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
258 rect, line, len, NULL )) return 0;
259 if (prefix_offset != -1)
261 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
262 HPEN oldPen = SelectObject( hdc, hpen );
263 MoveTo16(hdc, x + prefix_x, y + tm.tmAscent + 1 );
264 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
265 SelectObject( hdc, oldPen );
266 DeleteObject( hpen );
269 else if (size.cx > max_width)
270 max_width = size.cx;
272 y += lh;
273 if (strPtr)
275 if (!(flags & DT_NOCLIP))
277 if (y > rect->bottom - lh)
278 break;
282 while (strPtr);
283 if (flags & DT_CALCRECT)
285 rect->right = rect->left + max_width;
286 rect->bottom = y;
288 return y - rect->top;
292 /***********************************************************************
293 * DrawText32A (USER32.164)
295 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count,
296 LPRECT rect, UINT flags )
298 RECT16 rect16;
299 INT16 ret;
301 if (!rect)
302 return DrawText16( (HDC16)hdc, str, (INT16)count, NULL, (UINT16)flags);
303 CONV_RECT32TO16( rect, &rect16 );
304 ret = DrawText16( (HDC16)hdc, str, (INT16)count, &rect16, (UINT16)flags );
305 CONV_RECT16TO32( &rect16, rect );
306 return ret;
310 /***********************************************************************
311 * DrawText32W (USER32.167)
313 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
314 LPRECT rect, UINT flags )
316 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
317 INT ret = DrawTextA( hdc, p, count, rect, flags );
318 HeapFree( GetProcessHeap(), 0, p );
319 return ret;
322 /***********************************************************************
323 * DrawTextEx32A (USER32.165)
325 INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
326 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
328 TRACE(text,"(%d,'%s',%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
329 if(dtp) {
330 FIXME(text,"Ignores params:%d,%d,%d,%d,%d\n",dtp->cbSize,
331 dtp->iTabLength,dtp->iLeftMargin,dtp->iRightMargin,
332 dtp->uiLengthDrawn);
334 return DrawTextA(hdc,str,count,rect,flags);
337 /***********************************************************************
338 * DrawTextEx32W (USER32.166)
340 INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT count,
341 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
343 TRACE(text,"(%d,%p,%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
344 FIXME(text,"ignores extended functionality\n");
345 return DrawTextW(hdc,str,count,rect,flags);
348 /***********************************************************************
349 * ExtTextOut16 (GDI.351)
351 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
352 const RECT16 *lprect, LPCSTR str, UINT16 count,
353 const INT16 *lpDx )
355 BOOL ret;
356 int i;
357 RECT rect32;
358 LPINT lpdx32 = NULL;
360 if (lpDx) lpdx32 = (LPINT)HEAP_xalloc( GetProcessHeap(), 0,
361 sizeof(INT)*count );
362 if (lprect) CONV_RECT16TO32(lprect,&rect32);
363 if (lpdx32) for (i=count;i--;) lpdx32[i]=lpDx[i];
364 ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
365 if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
366 return ret;
372 /***********************************************************************
373 * ExtTextOut32A (GDI32.98)
375 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
376 const RECT *lprect, LPCSTR str, UINT count,
377 const INT *lpDx )
379 DC * dc = DC_GetDCPtr( hdc );
380 return dc && dc->funcs->pExtTextOut &&
381 dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
385 /***********************************************************************
386 * ExtTextOut32W (GDI32.99)
388 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
389 const RECT *lprect, LPCWSTR str, UINT count,
390 const INT *lpDx )
392 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
393 INT ret = ExtTextOutA( hdc, x, y, flags, lprect, p, count, lpDx );
394 HeapFree( GetProcessHeap(), 0, p );
395 return ret;
399 /***********************************************************************
400 * TextOut16 (GDI.33)
402 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
404 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
408 /***********************************************************************
409 * TextOut32A (GDI32.355)
411 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
413 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
417 /***********************************************************************
418 * TextOut32W (GDI32.356)
420 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
422 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
426 /***********************************************************************
427 * TEXT_GrayString
429 * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
430 * heap and we can guarantee that the handles fit in an INT16. We have to
431 * rethink the strategy once the migration to NT handles is complete.
432 * We are going to get a lot of code-duplication once this migration is
433 * completed...
436 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb,
437 GRAYSTRINGPROC fn, LPARAM lp, INT len,
438 INT x, INT y, INT cx, INT cy,
439 BOOL unicode, BOOL _32bit)
441 HBITMAP hbm, hbmsave;
442 HBRUSH hbsave;
443 HFONT hfsave;
444 HDC memdc = CreateCompatibleDC(hdc);
445 int slen = len;
446 BOOL retval = TRUE;
447 RECT r;
448 COLORREF fg, bg;
450 if(!hdc) return FALSE;
452 if(len == 0)
454 if(unicode)
455 slen = lstrlenW((LPCWSTR)lp);
456 else if(_32bit)
457 slen = lstrlenA((LPCSTR)lp);
458 else
459 slen = lstrlenA((LPCSTR)PTR_SEG_TO_LIN(lp));
462 if((cx == 0 || cy == 0) && slen != -1)
464 SIZE s;
465 if(unicode)
466 GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
467 else if(_32bit)
468 GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
469 else
470 GetTextExtentPoint32A(hdc, (LPCSTR)PTR_SEG_TO_LIN(lp), slen, &s);
471 if(cx == 0) cx = s.cx;
472 if(cy == 0) cy = s.cy;
475 r.left = r.top = 0;
476 r.right = cx;
477 r.bottom = cy;
479 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
480 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
481 FillRect(memdc, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
482 SetTextColor(memdc, RGB(255, 255, 255));
483 SetBkColor(memdc, RGB(0, 0, 0));
484 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
486 if(fn)
487 if(_32bit)
488 retval = fn(memdc, lp, slen);
489 else
490 retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
491 else
492 if(unicode)
493 TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
494 else if(_32bit)
495 TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
496 else
497 TextOutA(memdc, 0, 0, (LPCSTR)PTR_SEG_TO_LIN(lp), slen);
499 SelectObject(memdc, hfsave);
502 * Windows doc says that the bitmap isn't grayed when len == -1 and
503 * the callback function returns FALSE. However, testing this on
504 * win95 showed otherwise...
506 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
507 if(retval || len != -1)
508 #endif
510 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
511 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
512 SelectObject(memdc, hbsave);
515 if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
516 fg = SetTextColor(hdc, RGB(0, 0, 0));
517 bg = SetBkColor(hdc, RGB(255, 255, 255));
518 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
519 SetTextColor(hdc, fg);
520 SetBkColor(hdc, bg);
521 if(hb) SelectObject(hdc, hbsave);
523 SelectObject(memdc, hbmsave);
524 DeleteObject(hbm);
525 DeleteDC(memdc);
526 return retval;
530 /***********************************************************************
531 * GrayString16 (USER.185)
533 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
534 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
535 INT16 cx, INT16 cy )
537 return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch, x, y, cx, cy, FALSE, FALSE);
541 /***********************************************************************
542 * GrayString32A (USER32.315)
544 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
545 LPARAM lParam, INT cch, INT x, INT y,
546 INT cx, INT cy )
548 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, FALSE, TRUE);
552 /***********************************************************************
553 * GrayString32W (USER32.316)
555 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
556 LPARAM lParam, INT cch, INT x, INT y,
557 INT cx, INT cy )
559 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, TRUE, TRUE);
563 /***********************************************************************
564 * TEXT_TabbedTextOut
566 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
567 * Note: this doesn't work too well for text-alignment modes other
568 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
570 LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
571 INT count, INT cTabStops, const INT16 *lpTabPos16,
572 const INT *lpTabPos32, INT nTabOrg,
573 BOOL fDisplayText )
575 INT defWidth;
576 DWORD extent = 0;
577 int i, tabPos = x;
578 int start = x;
580 if (cTabStops == 1)
582 defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
583 cTabStops = 0;
585 else
587 TEXTMETRIC16 tm;
588 GetTextMetrics16( hdc, &tm );
589 defWidth = 8 * tm.tmAveCharWidth;
592 while (count > 0)
594 for (i = 0; i < count; i++)
595 if (lpstr[i] == '\t') break;
596 extent = GetTextExtent16( hdc, lpstr, i );
597 if (lpTabPos32)
599 while ((cTabStops > 0) &&
600 (nTabOrg + *lpTabPos32 <= x + LOWORD(extent)))
602 lpTabPos32++;
603 cTabStops--;
606 else
608 while ((cTabStops > 0) &&
609 (nTabOrg + *lpTabPos16 <= x + LOWORD(extent)))
611 lpTabPos16++;
612 cTabStops--;
615 if (i == count)
616 tabPos = x + LOWORD(extent);
617 else if (cTabStops > 0)
618 tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
619 else
620 tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth;
621 if (fDisplayText)
623 RECT r;
624 SetRect( &r, x, y, tabPos, y+HIWORD(extent) );
625 ExtTextOutA( hdc, x, y,
626 GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
627 &r, lpstr, i, NULL );
629 x = tabPos;
630 count -= i+1;
631 lpstr += i+1;
633 return MAKELONG(tabPos - start, HIWORD(extent));
637 /***********************************************************************
638 * TabbedTextOut16 (USER.196)
640 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
641 INT16 count, INT16 cTabStops,
642 const INT16 *lpTabPos, INT16 nTabOrg )
644 TRACE(text, "%04x %d,%d '%.*s' %d\n",
645 hdc, x, y, count, lpstr, count );
646 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
647 lpTabPos, NULL, nTabOrg, TRUE );
651 /***********************************************************************
652 * TabbedTextOut32A (USER32.542)
654 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr,
655 INT count, INT cTabStops,
656 const INT *lpTabPos, INT nTabOrg )
658 TRACE(text, "%04x %d,%d '%.*s' %d\n",
659 hdc, x, y, count, lpstr, count );
660 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
661 NULL, lpTabPos, nTabOrg, TRUE );
665 /***********************************************************************
666 * TabbedTextOut32W (USER32.543)
668 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
669 INT count, INT cTabStops,
670 const INT *lpTabPos, INT nTabOrg )
672 LONG ret;
673 LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
674 lstrcpynWtoA( p, str, count + 1 );
675 ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops,
676 lpTabPos, nTabOrg );
677 HeapFree( GetProcessHeap(), 0, p );
678 return ret;
682 /***********************************************************************
683 * GetTabbedTextExtent16 (USER.197)
685 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
686 INT16 cTabStops, const INT16 *lpTabPos )
688 TRACE(text, "%04x '%.*s' %d\n",
689 hdc, count, lpstr, count );
690 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
691 lpTabPos, NULL, 0, FALSE );
695 /***********************************************************************
696 * GetTabbedTextExtent32A (USER32.293)
698 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
699 INT cTabStops, const INT *lpTabPos )
701 TRACE(text, "%04x '%.*s' %d\n",
702 hdc, count, lpstr, count );
703 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
704 NULL, lpTabPos, 0, FALSE );
708 /***********************************************************************
709 * GetTabbedTextExtent32W (USER32.294)
711 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
712 INT cTabStops, const INT *lpTabPos )
714 LONG ret;
715 LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
716 lstrcpynWtoA( p, lpstr, count + 1 );
717 ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos );
718 HeapFree( GetProcessHeap(), 0, p );
719 return ret;
722 /***********************************************************************
723 * GetTextCharset32 [GDI32.226] Gets character set for font in DC
725 * NOTES
726 * Should it return a UINT32 instead of an INT32?
727 * => YES, as GetTextCharsetInfo returns UINT32
729 * RETURNS
730 * Success: Character set identifier
731 * Failure: DEFAULT_CHARSET
733 UINT WINAPI GetTextCharset(
734 HDC hdc) /* [in] Handle to device context */
736 /* MSDN docs say this is equivalent */
737 return GetTextCharsetInfo(hdc, NULL, 0);
740 /***********************************************************************
741 * GetTextCharset16 [GDI.612]
743 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
745 return (UINT16)GetTextCharset(hdc);
748 /***********************************************************************
749 * GetTextCharsetInfo [GDI32.381] Gets character set for font
751 * NOTES
752 * Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
753 * Should it return a UINT32 instead of an INT32?
754 * => YES and YES, from win32.hlp from Borland
756 * RETURNS
757 * Success: Character set identifier
758 * Failure: DEFAULT_CHARSET
760 UINT WINAPI GetTextCharsetInfo(
761 HDC hdc, /* [in] Handle to device context */
762 LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
763 DWORD flags) /* [in] Reserved - must be 0 */
765 HGDIOBJ hFont;
766 UINT charSet = DEFAULT_CHARSET;
767 LOGFONTW lf;
768 CHARSETINFO csinfo;
770 hFont = GetCurrentObject(hdc, OBJ_FONT);
771 if (hFont == 0)
772 return(DEFAULT_CHARSET);
773 if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
774 charSet = lf.lfCharSet;
776 if (fs != NULL) {
777 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
778 return (DEFAULT_CHARSET);
779 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
781 return charSet;