4 * Copyright 1993, 1994 Alexandre Julliard
5 * Copyright 2003 Shachar Shemesh
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/winuser16.h"
31 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(text
);
36 /***********************************************************************
39 * Returns a '\0' terminated Unicode translation of str using the
40 * charset of the currently selected font in hdc. If count is -1 then
41 * str is assumed to be '\0' terminated, otherwise it contains the
42 * number of bytes to convert. If plenW is non-NULL, on return it
43 * will point to the number of WCHARs (excluding the '\0') that have
44 * been written. If pCP is non-NULL, on return it will point to the
45 * codepage used in the conversion (NB, this may be CP_SYMBOL so watch
46 * out). The caller should free the returned LPWSTR from the process
49 LPWSTR
FONT_mbtowc(HDC hdc
, LPCSTR str
, INT count
, INT
*plenW
, UINT
*pCP
)
55 int charset
= GetTextCharset(hdc
);
57 /* Hmm, nicely designed api this one! */
58 if(TranslateCharsetInfo((DWORD
*)charset
, &csi
, TCI_SRCCHARSET
))
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 TRACE("cp == %d\n", cp
);
95 if(count
== -1) count
= strlen(str
);
97 lenW
= MultiByteToWideChar(cp
, 0, str
, count
, NULL
, 0);
98 strW
= HeapAlloc(GetProcessHeap(), 0, (lenW
+ 1) * sizeof(WCHAR
));
99 MultiByteToWideChar(cp
, 0, str
, count
, strW
, lenW
);
102 strW
= HeapAlloc(GetProcessHeap(), 0, (lenW
+ 1) * sizeof(WCHAR
));
103 for(i
= 0; i
< count
; i
++) strW
[i
] = (BYTE
)str
[i
];
106 TRACE("mapped %s -> %s\n", debugstr_an(str
, count
), debugstr_wn(strW
, lenW
));
107 if(plenW
) *plenW
= lenW
;
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(PATH_IsPathOpen(dc
->path
))
159 FIXME("called on an open path\n");
160 else if(dc
->funcs
->pExtTextOut
)
162 if( !(flags
&(ETO_GLYPH_INDEX
|ETO_IGNORELANGUAGE
)) && BidiAvail
&& count
>0 )
164 /* The caller did not specify that language processing was already done.
166 LPWSTR lpReorderedString
=HeapAlloc(GetProcessHeap(), 0, count
*sizeof(WCHAR
));
168 BIDI_Reorder( str
, count
, GCP_REORDER
,
169 ((flags
&ETO_RTLREADING
)!=0 || (GetTextAlign(hdc
)&TA_RTLREADING
)!=0)?
170 WINE_GCPW_FORCE_RTL
:WINE_GCPW_FORCE_LTR
,
171 lpReorderedString
, count
, NULL
);
173 ret
= dc
->funcs
->pExtTextOut(dc
->physDev
,x
,y
,flags
|ETO_IGNORELANGUAGE
,
174 lprect
,lpReorderedString
,count
,lpDx
);
175 HeapFree(GetProcessHeap(), 0, lpReorderedString
);
177 ret
= dc
->funcs
->pExtTextOut(dc
->physDev
,x
,y
,flags
,lprect
,str
,count
,lpDx
);
179 GDI_ReleaseObj( hdc
);
185 /***********************************************************************
188 BOOL WINAPI
TextOutA( HDC hdc
, INT x
, INT y
, LPCSTR str
, INT count
)
190 return ExtTextOutA( hdc
, x
, y
, 0, NULL
, str
, count
, NULL
);
194 /***********************************************************************
197 BOOL WINAPI
TextOutW(HDC hdc
, INT x
, INT y
, LPCWSTR str
, INT count
)
199 return ExtTextOutW( hdc
, x
, y
, 0, NULL
, str
, count
, NULL
);
203 /***********************************************************************
204 * PolyTextOutA (GDI32.@)
206 * Draw several Strings
208 BOOL WINAPI
PolyTextOutA (
209 HDC hdc
, /* [in] Handle to device context */
210 PPOLYTEXTA pptxt
, /* [in] Array of strings */
211 INT cStrings
/* [in] Number of strings in array */
214 for (; cStrings
>0; cStrings
--, pptxt
++)
215 if (!ExtTextOutA( hdc
, pptxt
->x
, pptxt
->y
, pptxt
->uiFlags
, &pptxt
->rcl
, pptxt
->lpstr
, pptxt
->n
, pptxt
->pdx
))
222 /***********************************************************************
223 * PolyTextOutW (GDI32.@)
225 * Draw several Strings
227 BOOL WINAPI
PolyTextOutW (
228 HDC hdc
, /* [in] Handle to device context */
229 PPOLYTEXTW pptxt
, /* [in] Array of strings */
230 INT cStrings
/* [in] Number of strings in array */
233 for (; cStrings
>0; cStrings
--, pptxt
++)
234 if (!ExtTextOutW( hdc
, pptxt
->x
, pptxt
->y
, pptxt
->uiFlags
, &pptxt
->rcl
, pptxt
->lpstr
, pptxt
->n
, pptxt
->pdx
))