4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/winuser16.h"
29 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(text);
34 /***********************************************************************
37 * Returns a '\0' terminated Unicode translation of str using the
38 * charset of the currently selected font in hdc. If count is -1 then
39 * str is assumed to be '\0' terminated, otherwise it contains the
40 * number of bytes to convert. If plenW is non-NULL, on return it
41 * will point to the number of WCHARs (excluding the '\0') that have
42 * been written. If pCP is non-NULL, on return it will point to the
43 * codepage used in the conversion. The caller should free the
44 * returned LPWSTR from the process heap itself.
46 LPWSTR FONT_mbtowc(HDC hdc, LPCSTR str, INT count, INT *plenW, UINT *pCP)
52 int charset = GetTextCharset(hdc);
54 /* Hmm, nicely designed api this one! */
55 if(TranslateCharsetInfo((DWORD*)charset, &csi, TCI_SRCCHARSET))
59 case SYMBOL_CHARSET: /* We don't want any translation here */
76 /* FIXME: These have no place here, but because x11drv
77 enumerates fonts with these (made up) charsets some apps
78 might use them and then the FIXME below would become
79 annoying. Now we could pick the intended codepage for
80 each of these, but since it's broken anyway we'll just
81 use CP_ACP and hope it'll go away...
88 FIXME("Can't find codepage for charset %d\n", charset);
93 lenW = MultiByteToWideChar(cp, 0, str, count, NULL, 0);
94 strW = HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR));
95 MultiByteToWideChar(cp, 0, str, count, strW, lenW);
97 if(plenW) *plenW = lenW;
102 /***********************************************************************
103 * ExtTextOut (GDI.351)
105 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
106 const RECT16 *lprect, LPCSTR str, UINT16 count,
115 lpdx32 = (LPINT)HeapAlloc( GetProcessHeap(),0, sizeof(INT)*count );
116 if(lpdx32 == NULL) return FALSE;
117 for (i=count;i--;) lpdx32[i]=lpDx[i];
119 if (lprect) CONV_RECT16TO32(lprect,&rect32);
120 ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
121 if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
126 /***********************************************************************
127 * ExtTextOutA (GDI32.@)
129 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
130 const RECT *lprect, LPCSTR str, UINT count, const INT *lpDx )
134 LPWSTR p = FONT_mbtowc(hdc, str, count, &wlen, &codepage);
139 unsigned int i = 0, j = 0;
141 lpDxW = (LPINT)HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(INT));
143 if(IsDBCSLeadByteEx(codepage, str[i])) {
144 lpDxW[j++] = lpDx[i] + lpDx[i+1];
147 lpDxW[j++] = lpDx[i];
153 ret = ExtTextOutW( hdc, x, y, flags, lprect, p, wlen, lpDxW );
155 HeapFree( GetProcessHeap(), 0, p );
156 if (lpDxW) HeapFree( GetProcessHeap(), 0, lpDxW );
161 /***********************************************************************
162 * ExtTextOutW (GDI32.@)
164 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
165 const RECT *lprect, LPCWSTR str, UINT count, const INT *lpDx )
168 DC * dc = DC_GetDCUpdate( hdc );
171 if(dc->funcs->pExtTextOut)
172 ret = dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
173 GDI_ReleaseObj( hdc );
179 /***********************************************************************
182 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
184 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
188 /***********************************************************************
191 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
193 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
197 /***********************************************************************
200 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
202 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
206 /***********************************************************************
207 * GetTextCharset [GDI32.@] Gets character set for font in DC
210 * Should it return a UINT32 instead of an INT32?
211 * => YES, as GetTextCharsetInfo returns UINT32
214 * Success: Character set identifier
215 * Failure: DEFAULT_CHARSET
217 UINT WINAPI GetTextCharset(
218 HDC hdc) /* [in] Handle to device context */
220 /* MSDN docs say this is equivalent */
221 return GetTextCharsetInfo(hdc, NULL, 0);
224 /***********************************************************************
225 * GetTextCharset [GDI.612]
227 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
229 return (UINT16)GetTextCharset(hdc);
232 /***********************************************************************
233 * GetTextCharsetInfo [GDI32.@] Gets character set for font
236 * Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
237 * Should it return a UINT32 instead of an INT32?
238 * => YES and YES, from win32.hlp from Borland
240 * This returns the actual charset selected by the driver rather than the
241 * value in lf.lfCharSet during CreateFont, to get that use
242 * GetObject(GetCurrentObject(...),...)
245 * Success: Character set identifier
246 * Failure: DEFAULT_CHARSET
248 UINT WINAPI GetTextCharsetInfo(
249 HDC hdc, /* [in] Handle to device context */
250 LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
251 DWORD flags) /* [in] Reserved - must be 0 */
253 UINT charSet = DEFAULT_CHARSET;
257 if(!GetTextMetricsW(hdc, &tm)) return DEFAULT_CHARSET;
258 charSet = tm.tmCharSet;
261 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
262 return DEFAULT_CHARSET;
263 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
268 /***********************************************************************
269 * PolyTextOutA (GDI32.@)
271 * Draw several Strings
273 BOOL WINAPI PolyTextOutA (
274 HDC hdc, /* [in] Handle to device context */
275 PPOLYTEXTA pptxt, /* [in] Array of strings */
276 INT cStrings /* [in] Number of strings in array */
280 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
286 /***********************************************************************
287 * PolyTextOutW (GDI32.@)
289 * Draw several Strings
291 BOOL WINAPI PolyTextOutW (
292 HDC hdc, /* [in] Handle to device context */
293 PPOLYTEXTW pptxt, /* [in] Array of strings */
294 INT cStrings /* [in] Number of strings in array */
298 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );