4 * Copyright 1993, 1994 Alexandre Julliard
12 #include "wine/winuser16.h"
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(text);
21 /***********************************************************************
24 * Returns a '\0' terminated Unicode translation of str using the
25 * charset of the currently selected font in hdc. If count is -1 then
26 * str is assumed to be '\0' terminated, otherwise it contains the
27 * number of bytes to convert. If plenW is non-NULL, on return it
28 * will point to the number of WCHARs (excluding the '\0') that have
29 * been written. If pCP is non-NULL, on return it will point to the
30 * codepage used in the conversion. The caller should free the
31 * returned LPWSTR from the process heap itself.
33 LPWSTR FONT_mbtowc(HDC hdc, LPCSTR str, INT count, INT *plenW, UINT *pCP)
39 int charset = GetTextCharset(hdc);
41 /* Hmm, nicely designed api this one! */
42 if(TranslateCharsetInfo((DWORD*)charset, &csi, TCI_SRCCHARSET))
46 case SYMBOL_CHARSET: /* We don't want any translation here */
63 /* FIXME: These have no place here, but because x11drv
64 enumerates fonts with these (made up) charsets some apps
65 might use them and then the FIXME below would become
66 annoying. Now we could pick the intended codepage for
67 each of these, but since it's broken anyway we'll just
68 use CP_ACP and hope it'll go away...
75 FIXME("Can't find codepage for charset %d\n", charset);
80 lenW = MultiByteToWideChar(cp, 0, str, count, NULL, 0);
81 strW = HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR));
82 MultiByteToWideChar(cp, 0, str, count, strW, lenW);
84 if(plenW) *plenW = lenW;
89 /***********************************************************************
90 * ExtTextOut (GDI.351)
92 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
93 const RECT16 *lprect, LPCSTR str, UINT16 count,
102 lpdx32 = (LPINT)HeapAlloc( GetProcessHeap(),0, sizeof(INT)*count );
103 if(lpdx32 == NULL) return FALSE;
104 for (i=count;i--;) lpdx32[i]=lpDx[i];
106 if (lprect) CONV_RECT16TO32(lprect,&rect32);
107 ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
108 if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
113 /***********************************************************************
114 * ExtTextOutA (GDI32.@)
116 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
117 const RECT *lprect, LPCSTR str, UINT count, const INT *lpDx )
121 LPWSTR p = FONT_mbtowc(hdc, str, count, &wlen, &codepage);
126 unsigned int i = 0, j = 0;
128 lpDxW = (LPINT)HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(INT));
130 if(IsDBCSLeadByteEx(codepage, str[i])) {
131 lpDxW[j++] = lpDx[i] + lpDx[i+1];
134 lpDxW[j++] = lpDx[i];
140 ret = ExtTextOutW( hdc, x, y, flags, lprect, p, wlen, lpDxW );
142 HeapFree( GetProcessHeap(), 0, p );
143 if (lpDxW) HeapFree( GetProcessHeap(), 0, lpDxW );
148 /***********************************************************************
149 * ExtTextOutW (GDI32.@)
151 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
152 const RECT *lprect, LPCWSTR str, UINT count, const INT *lpDx )
155 DC * dc = DC_GetDCUpdate( hdc );
158 if(dc->funcs->pExtTextOut)
159 ret = dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
160 GDI_ReleaseObj( hdc );
166 /***********************************************************************
169 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
171 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
175 /***********************************************************************
178 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
180 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
184 /***********************************************************************
187 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
189 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
193 /***********************************************************************
194 * GetTextCharset [GDI32.@] Gets character set for font in DC
197 * Should it return a UINT32 instead of an INT32?
198 * => YES, as GetTextCharsetInfo returns UINT32
201 * Success: Character set identifier
202 * Failure: DEFAULT_CHARSET
204 UINT WINAPI GetTextCharset(
205 HDC hdc) /* [in] Handle to device context */
207 /* MSDN docs say this is equivalent */
208 return GetTextCharsetInfo(hdc, NULL, 0);
211 /***********************************************************************
212 * GetTextCharset [GDI.612]
214 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
216 return (UINT16)GetTextCharset(hdc);
219 /***********************************************************************
220 * GetTextCharsetInfo [GDI32.@] Gets character set for font
223 * Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
224 * Should it return a UINT32 instead of an INT32?
225 * => YES and YES, from win32.hlp from Borland
227 * This returns the actual charset selected by the driver rather than the
228 * value in lf.lfCharSet during CreateFont, to get that use
229 * GetObject(GetCurrentObject(...),...)
232 * Success: Character set identifier
233 * Failure: DEFAULT_CHARSET
235 UINT WINAPI GetTextCharsetInfo(
236 HDC hdc, /* [in] Handle to device context */
237 LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
238 DWORD flags) /* [in] Reserved - must be 0 */
240 UINT charSet = DEFAULT_CHARSET;
244 if(!GetTextMetricsW(hdc, &tm)) return DEFAULT_CHARSET;
245 charSet = tm.tmCharSet;
248 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
249 return DEFAULT_CHARSET;
250 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
255 /***********************************************************************
256 * PolyTextOutA (GDI32.@)
258 * Draw several Strings
260 BOOL WINAPI PolyTextOutA (
261 HDC hdc, /* [in] Handle to device context */
262 PPOLYTEXTA pptxt, /* [in] Array of strings */
263 INT cStrings /* [in] Number of strings in array */
267 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
273 /***********************************************************************
274 * PolyTextOutW (GDI32.@)
276 * Draw several Strings
278 BOOL WINAPI PolyTextOutW (
279 HDC hdc, /* [in] Handle to device context */
280 PPOLYTEXTW pptxt, /* [in] Array of strings */
281 INT cStrings /* [in] Number of strings in array */
285 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );