Winspool DocumentProperties and DeviceCapabilities should now work on
[wine.git] / objects / text.c
blobbf6bf2a8cd123275e8e6fed0a02b85055cea5593
1 /*
2 * text functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 */
8 #include <string.h>
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"
20 DEFAULT_DEBUG_CHANNEL(text)
22 #define TAB 9
23 #define LF 10
24 #define CR 13
25 #define SPACE 32
26 #define PREFIX 38
28 #define SWAP_INT(a,b) { int t = a; a = b; b = t; }
30 static int tabstop = 8;
31 static int tabwidth;
32 static int spacewidth;
33 static int prefix_offset;
35 static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
36 char *dest, int *len, int width, WORD format)
38 /* Return next line of text from a string.
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.
48 * Returns pointer to next char in str after end of the line
49 * or NULL if end of str reached.
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;
59 while (*count)
61 switch (str[i])
63 case CR:
64 case LF:
65 if (!(format & DT_SINGLELINE))
67 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
69 (*count)--;
70 i++;
72 i++;
73 *len = j;
74 (*count)--;
75 return (&str[i]);
77 dest[j++] = str[i++];
78 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
79 (format & DT_WORDBREAK))
81 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
82 return NULL;
83 plen += size.cx;
85 break;
87 case PREFIX:
88 if (!(format & DT_NOPREFIX) && *count > 1)
90 if (str[++i] == PREFIX)
91 (*count)--;
92 else {
93 prefix_offset = j;
94 break;
97 dest[j++] = str[i++];
98 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
99 (format & DT_WORDBREAK))
101 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
102 return NULL;
103 plen += size.cx;
105 break;
107 case TAB:
108 if (format & DT_EXPANDTABS)
110 wb_i = ++i;
111 wb_j = j;
112 wb_count = *count;
114 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
115 &size))
116 return NULL;
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;
124 else
126 dest[j++] = str[i++];
127 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
128 (format & DT_WORDBREAK))
130 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
131 return NULL;
132 plen += size.cx;
135 break;
137 case SPACE:
138 dest[j++] = str[i++];
139 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
140 (format & DT_WORDBREAK))
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;
149 break;
151 default:
152 dest[j++] = str[i++];
153 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
154 (format & DT_WORDBREAK))
156 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
157 return NULL;
158 plen += size.cx;
162 (*count)--;
163 if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
165 if (plen > width)
167 if (format & DT_WORDBREAK)
169 if (wb_j)
171 *len = wb_j;
172 *count = wb_count - 1;
173 return (&str[wb_i]);
176 else
178 *len = j;
179 return (&str[i]);
185 *len = j;
186 return NULL;
190 /***********************************************************************
191 * DrawText16 (USER.85)
193 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
194 LPRECT16 rect, UINT16 flags )
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;
207 TRACE("%s, %d , [(%d,%d),(%d,%d)]\n",
208 debugstr_an (str, count), count,
209 rect->left, rect->top, rect->right, rect->bottom);
211 if (count == -1) count = strlen(str);
212 strPtr = str;
214 GetTextMetrics16(hdc, &tm);
215 if (flags & DT_EXTERNALLEADING)
216 lh = tm.tmHeight + tm.tmExternalLeading;
217 else
218 lh = tm.tmHeight;
220 if (flags & DT_TABSTOP)
221 tabstop = flags >> 8;
223 if (flags & DT_EXPANDTABS)
225 GetTextExtentPoint16(hdc, " ", 1, &size);
226 spacewidth = size.cx;
227 GetTextExtentPoint16(hdc, "o", 1, &size);
228 tabwidth = size.cx * tabstop;
231 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
235 prefix_offset = -1;
236 strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
238 if (prefix_offset != -1)
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;
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;
251 if (flags & DT_SINGLELINE)
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;
257 if (!(flags & DT_CALCRECT))
259 if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
260 rect, line, len, NULL )) return 0;
261 if (prefix_offset != -1)
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 );
271 else if (size.cx > max_width)
272 max_width = size.cx;
274 y += lh;
275 if (strPtr)
277 if (!(flags & DT_NOCLIP))
279 if (y > rect->bottom - lh)
280 break;
284 while (strPtr);
285 if (flags & DT_CALCRECT)
287 rect->right = rect->left + max_width;
288 rect->bottom = y;
290 return y - rect->top;
294 /***********************************************************************
295 * DrawText32A (USER32.164)
297 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count,
298 LPRECT rect, UINT flags )
300 RECT16 rect16;
301 INT16 ret;
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;
312 /***********************************************************************
313 * DrawText32W (USER32.167)
315 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
316 LPRECT rect, UINT flags )
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;
324 /***********************************************************************
325 * DrawTextEx32A (USER32.165)
327 INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
328 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
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);
336 return DrawTextA(hdc,str,count,rect,flags);
339 /***********************************************************************
340 * DrawTextEx32W (USER32.166)
342 INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT count,
343 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
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);
350 /***********************************************************************
351 * ExtTextOut16 (GDI.351)
353 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
354 const RECT16 *lprect, LPCSTR str, UINT16 count,
355 const INT16 *lpDx )
357 BOOL ret;
358 int i;
359 RECT rect32;
360 LPINT lpdx32 = NULL;
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;
374 /***********************************************************************
375 * ExtTextOut32A (GDI32.98)
377 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
378 const RECT *lprect, LPCSTR str, UINT count,
379 const INT *lpDx )
381 DC * dc = DC_GetDCPtr( hdc );
382 return dc && dc->funcs->pExtTextOut &&
383 dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
387 /***********************************************************************
388 * ExtTextOut32W (GDI32.99)
390 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
391 const RECT *lprect, LPCWSTR str, UINT count,
392 const INT *lpDx )
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;
401 /***********************************************************************
402 * TextOut16 (GDI.33)
404 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
406 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
410 /***********************************************************************
411 * TextOut32A (GDI32.355)
413 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
415 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
419 /***********************************************************************
420 * TextOut32W (GDI32.356)
422 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
424 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
428 /***********************************************************************
429 * TEXT_GrayString
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...
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)
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;
452 if(!hdc) return FALSE;
454 if(len == 0)
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));
464 if((cx == 0 || cy == 0) && slen != -1)
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;
477 r.left = r.top = 0;
478 r.right = cx;
479 r.bottom = cy;
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));
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);
501 SelectObject(memdc, hfsave);
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...
508 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
509 if(retval || len != -1)
510 #endif
512 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
513 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
514 SelectObject(memdc, hbsave);
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);
525 SelectObject(memdc, hbmsave);
526 DeleteObject(hbm);
527 DeleteDC(memdc);
528 return retval;
532 /***********************************************************************
533 * GrayString16 (USER.185)
535 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
536 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
537 INT16 cx, INT16 cy )
539 return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch, x, y, cx, cy, FALSE, FALSE);
543 /***********************************************************************
544 * GrayString32A (USER32.315)
546 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
547 LPARAM lParam, INT cch, INT x, INT y,
548 INT cx, INT cy )
550 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, FALSE, TRUE);
554 /***********************************************************************
555 * GrayString32W (USER32.316)
557 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
558 LPARAM lParam, INT cch, INT x, INT y,
559 INT cx, INT cy )
561 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, TRUE, TRUE);
565 /***********************************************************************
566 * TEXT_TabbedTextOut
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 :-)
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 )
577 INT defWidth;
578 DWORD extent = 0;
579 int i, tabPos = x;
580 int start = x;
582 if (cTabStops == 1)
584 defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
585 cTabStops = 0;
587 else
589 TEXTMETRIC16 tm;
590 GetTextMetrics16( hdc, &tm );
591 defWidth = 8 * tm.tmAveCharWidth;
594 while (count > 0)
596 for (i = 0; i < count; i++)
597 if (lpstr[i] == '\t') break;
598 extent = GetTextExtent16( hdc, lpstr, i );
599 if (lpTabPos32)
601 while ((cTabStops > 0) &&
602 (nTabOrg + *lpTabPos32 <= x + LOWORD(extent)))
604 lpTabPos32++;
605 cTabStops--;
608 else
610 while ((cTabStops > 0) &&
611 (nTabOrg + *lpTabPos16 <= x + LOWORD(extent)))
613 lpTabPos16++;
614 cTabStops--;
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)
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 );
631 x = tabPos;
632 count -= i+1;
633 lpstr += i+1;
635 return MAKELONG(tabPos - start, HIWORD(extent));
639 /***********************************************************************
640 * TabbedTextOut16 (USER.196)
642 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
643 INT16 count, INT16 cTabStops,
644 const INT16 *lpTabPos, INT16 nTabOrg )
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 );
653 /***********************************************************************
654 * TabbedTextOut32A (USER32.542)
656 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr,
657 INT count, INT cTabStops,
658 const INT *lpTabPos, INT nTabOrg )
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 );
667 /***********************************************************************
668 * TabbedTextOut32W (USER32.543)
670 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
671 INT count, INT cTabStops,
672 const INT *lpTabPos, INT nTabOrg )
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;
684 /***********************************************************************
685 * GetTabbedTextExtent16 (USER.197)
687 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
688 INT16 cTabStops, const INT16 *lpTabPos )
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 );
697 /***********************************************************************
698 * GetTabbedTextExtent32A (USER32.293)
700 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
701 INT cTabStops, const INT *lpTabPos )
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 );
710 /***********************************************************************
711 * GetTabbedTextExtent32W (USER32.294)
713 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
714 INT cTabStops, const INT *lpTabPos )
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;
724 /***********************************************************************
725 * GetTextCharset32 [GDI32.226] Gets character set for font in DC
727 * NOTES
728 * Should it return a UINT32 instead of an INT32?
729 * => YES, as GetTextCharsetInfo returns UINT32
731 * RETURNS
732 * Success: Character set identifier
733 * Failure: DEFAULT_CHARSET
735 UINT WINAPI GetTextCharset(
736 HDC hdc) /* [in] Handle to device context */
738 /* MSDN docs say this is equivalent */
739 return GetTextCharsetInfo(hdc, NULL, 0);
742 /***********************************************************************
743 * GetTextCharset16 [GDI.612]
745 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
747 return (UINT16)GetTextCharset(hdc);
750 /***********************************************************************
751 * GetTextCharsetInfo [GDI32.381] Gets character set for font
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
758 * RETURNS
759 * Success: Character set identifier
760 * Failure: DEFAULT_CHARSET
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 */
767 HGDIOBJ hFont;
768 UINT charSet = DEFAULT_CHARSET;
769 LOGFONTW lf;
770 CHARSETINFO csinfo;
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;
778 if (fs != NULL) {
779 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
780 return (DEFAULT_CHARSET);
781 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
783 return charSet;