Added TASK_GetPtr/TASK_GetCurrent functions to get the TDB for a task
[wine/multimedia.git] / objects / text.c
blob12bc71b1cf67dcdba9ed4a03e9431b6bd6d3fc39
1 /*
2 * text functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 */
8 #include <string.h>
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "wine/winuser16.h"
13 #include "winbase.h"
14 #include "winerror.h"
15 #include "gdi.h"
16 #include "heap.h"
17 #include "debugtools.h"
18 #include "winnls.h"
20 DEFAULT_DEBUG_CHANNEL(text);
23 /***********************************************************************
24 * ExtTextOut16 (DISPLAY.351)
25 * ExtTextOut16 (GDI.351)
27 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
28 const RECT16 *lprect, LPCSTR str, UINT16 count,
29 const INT16 *lpDx )
31 BOOL ret;
32 int i;
33 RECT rect32;
34 LPINT lpdx32 = NULL;
36 if (lpDx) {
37 lpdx32 = (LPINT)HeapAlloc( GetProcessHeap(),0, sizeof(INT)*count );
38 if(lpdx32 == NULL) return FALSE;
39 for (i=count;i--;) lpdx32[i]=lpDx[i];
41 if (lprect) CONV_RECT16TO32(lprect,&rect32);
42 ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
43 if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
44 return ret;
48 /***********************************************************************
49 * ExtTextOutA (GDI32.@)
51 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
52 const RECT *lprect, LPCSTR str, UINT count,
53 const INT *lpDx )
55 DC * dc = DC_GetDCUpdate( hdc );
56 LPWSTR p;
57 UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
58 BOOL ret = FALSE;
59 LPINT lpDxW = NULL;
61 if (!dc) return FALSE;
63 if (dc->funcs->pExtTextOut)
65 UINT wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0);
66 if (lpDx)
68 unsigned int i = 0, j = 0;
70 lpDxW = (LPINT)HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(INT));
71 while(i < count)
73 if(IsDBCSLeadByteEx(codepage, str[i]))
75 lpDxW[j++] = lpDx[i] + lpDx[i+1];
76 i = i + 2;
78 else
80 lpDxW[j++] = lpDx[i];
81 i = i + 1;
85 if ((p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) )))
87 wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen);
88 ret = dc->funcs->pExtTextOut( dc, x, y, flags, lprect, p, wlen, lpDxW );
89 HeapFree( GetProcessHeap(), 0, p );
91 if (lpDxW) HeapFree( GetProcessHeap(), 0, lpDxW );
93 GDI_ReleaseObj( hdc );
94 return ret;
98 /***********************************************************************
99 * ExtTextOutW (GDI32.@)
101 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
102 const RECT *lprect, LPCWSTR str, UINT count,
103 const INT *lpDx )
105 BOOL ret = FALSE;
106 DC * dc = DC_GetDCUpdate( hdc );
107 if (dc)
109 if(dc->funcs->pExtTextOut)
110 ret = dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
111 GDI_ReleaseObj( hdc );
113 return ret;
117 /***********************************************************************
118 * TextOut16 (GDI.33)
120 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
122 return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
126 /***********************************************************************
127 * TextOutA (GDI32.@)
129 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
131 return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
135 /***********************************************************************
136 * TextOutW (GDI32.@)
138 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
140 return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
144 /***********************************************************************
145 * GetTextCharset [GDI32.@] Gets character set for font in DC
147 * NOTES
148 * Should it return a UINT32 instead of an INT32?
149 * => YES, as GetTextCharsetInfo returns UINT32
151 * RETURNS
152 * Success: Character set identifier
153 * Failure: DEFAULT_CHARSET
155 UINT WINAPI GetTextCharset(
156 HDC hdc) /* [in] Handle to device context */
158 /* MSDN docs say this is equivalent */
159 return GetTextCharsetInfo(hdc, NULL, 0);
162 /***********************************************************************
163 * GetTextCharset16 [GDI.612]
165 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
167 return (UINT16)GetTextCharset(hdc);
170 /***********************************************************************
171 * GetTextCharsetInfo [GDI32.@] Gets character set for font
173 * NOTES
174 * Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
175 * Should it return a UINT32 instead of an INT32?
176 * => YES and YES, from win32.hlp from Borland
178 * RETURNS
179 * Success: Character set identifier
180 * Failure: DEFAULT_CHARSET
182 UINT WINAPI GetTextCharsetInfo(
183 HDC hdc, /* [in] Handle to device context */
184 LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
185 DWORD flags) /* [in] Reserved - must be 0 */
187 HGDIOBJ hFont;
188 UINT charSet = DEFAULT_CHARSET;
189 LOGFONTW lf;
190 CHARSETINFO csinfo;
192 hFont = GetCurrentObject(hdc, OBJ_FONT);
193 if (hFont == 0)
194 return(DEFAULT_CHARSET);
195 if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
196 charSet = lf.lfCharSet;
198 if (fs != NULL) {
199 if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
200 return (DEFAULT_CHARSET);
201 memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
203 return charSet;
206 /***********************************************************************
207 * PolyTextOutA (GDI.402)
208 * PolyTextOutA (GDI32.@)
210 * Draw several Strings
212 BOOL WINAPI PolyTextOutA (
213 HDC hdc, /* [in] Handle to device context */
214 PPOLYTEXTA pptxt, /* [in] Array of strings */
215 INT cStrings /* [in] Number of strings in array */
218 FIXME("stub!\n");
219 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
220 return 0;
225 /***********************************************************************
226 * PolyTextOutW (GDI.403)
227 * PolyTextOutW (GDI32.@)
229 * Draw several Strings
231 BOOL WINAPI PolyTextOutW (
232 HDC hdc, /* [in] Handle to device context */
233 PPOLYTEXTW pptxt, /* [in] Array of strings */
234 INT cStrings /* [in] Number of strings in array */
237 FIXME("stub!\n");
238 SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
239 return 0;