2 * Implementation of Uniscribe Script Processor (usp10.dll)
4 * Copyright 2005 Steven Edwards for CodeWeavers
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
21 * Uniscribe allows for processing of complex scripts such as joining
22 * and filtering characters and bi-directional text with custom line breaks.
33 #include "wine/debug.h"
36 * some documentation here:
37 * http://www.microsoft.com/typography/developers/uniscribe/uniscribe.htm
40 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
44 /* Set up a default for ScriptGetProperties */
45 static const SCRIPT_PROPERTIES Default_Script_0 = {0, 0, 0, 0, 0, 0, 0, 0,
47 static const SCRIPT_PROPERTIES Default_Script_1 = {0, 0, 0, 0, 0, 0, 0, 0,
49 static const SCRIPT_PROPERTIES Default_Script_2 = {0, 0, 0, 0, 0, 0, 0, 0,
51 static const SCRIPT_PROPERTIES Default_Script_3 = {9, 0, 0, 0, 0, 0, 0, 0,
53 static const SCRIPT_PROPERTIES Default_Script_4 = {9, 1, 0, 0, 0, 0, 0, 0,
55 static const SCRIPT_PROPERTIES Default_Script_5 = {9, 0, 0, 0, 0, 0, 0, 0,
57 static const SCRIPT_PROPERTIES Default_Script_6 = {9, 1, 0, 0, 0, 0, 0, 0,
59 static const SCRIPT_PROPERTIES Default_Script_7 = {8, 0, 0, 0, 0, 161, 0, 0,
61 static const SCRIPT_PROPERTIES *Global_Script[MAX_SCRIPTS] =
71 typedef struct scriptcache {
75 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
78 case DLL_PROCESS_ATTACH:
79 DisableThreadLibraryCalls(hInstDLL);
81 case DLL_PROCESS_DETACH:
87 /***********************************************************************
88 * ScriptFreeCache (USP10.@)
91 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
96 HeapFree ( GetProcessHeap(), 0, *psc);
102 /***********************************************************************
103 * ScriptGetProperties (USP10.@)
106 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***ppSp, int *piNumScripts)
108 TRACE("%p,%p\n",ppSp, piNumScripts);
110 /* Set up a sensible default and intialise pointers */
111 *piNumScripts = MAX_SCRIPTS;
112 *ppSp = Global_Script;
113 TRACE("ppSp:%p, *ppSp:%p, **ppSp:%p, %d\n", ppSp, *ppSp, **ppSp,
118 /***********************************************************************
119 * ScriptGetFontProperties (USP10.@)
122 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
125 Scriptcache *pScriptcache;
128 TRACE("%p,%p,%p\n", hdc, psc, sfp);
134 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
138 pScriptcache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Scriptcache) );
139 pScriptcache->hdc = (HDC) hdc;
141 *psc = (Scriptcache *) pScriptcache;
144 pScriptcache = (Scriptcache *) *psc;
145 phdc = pScriptcache->hdc;
148 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
151 /* return something sensible? */
153 if (GetTextMetricsW(phdc, &ptm))
154 sfp->wgDefault = ptm.tmDefaultChar;
158 sfp->wgKashida = 0xffff;
159 sfp->iKashidaWidth = 0;
163 /***********************************************************************
164 * ScriptRecordDigitSubstitution (USP10.@)
167 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID Locale,SCRIPT_DIGITSUBSTITUTE *psds)
169 FIXME("%ld,%p\n",Locale,psds);
173 /***********************************************************************
174 * ScriptApplyDigitSubstitution (USP10.@)
177 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE* psds,
178 SCRIPT_CONTROL* psc, SCRIPT_STATE* pss)
180 FIXME("%p,%p,%p\n",psds,psc,pss);
184 /***********************************************************************
185 * ScriptItemize (USP10.@)
188 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
189 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
190 SCRIPT_ITEM *pItems, int *pcItems)
192 /* This implementation currently treats the entire string represented in
193 * pwcInChars as a single entity. Hence pcItems will be set to 1. */
195 FIXME("%s,%d,%d,%p,%p,%p,%p: semi-stub\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
196 psControl, psState, pItems, pcItems);
198 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
201 /* Set a sensible default */
202 /* Set SCRIPT_ITEM */
203 pItems[0].iCharPos = 0;
204 /* Set the SCRIPT_ANALYSIS */
205 pItems[0].a.eScript = SCRIPT_UNDEFINED;
206 pItems[0].a.fRTL = 0;
207 pItems[0].a.fLayoutRTL = 0;
208 pItems[0].a.fLinkBefore = 0;
209 pItems[0].a.fLinkAfter = 0;
210 pItems[0].a.fLogicalOrder = 0;
211 pItems[0].a.fNoGlyphIndex = 0;
212 /* set the SCRIPT_STATE */
213 pItems[0].a.s.uBidiLevel = 0;
214 pItems[0].a.s.fOverrideDirection = 0;
215 pItems[0].a.s.fInhibitSymSwap = FALSE;
216 pItems[0].a.s.fCharShape = 0;
217 pItems[0].a.s.fDigitSubstitute = 0;
218 pItems[0].a.s.fInhibitLigate = 0;
219 pItems[0].a.s.fDisplayZWG = 0;
220 pItems[0].a.s.fArabicNumContext = 0;
221 pItems[0].a.s.fGcpClusters = 0;
222 pItems[0].a.s.fReserved = 0;
223 pItems[0].a.s.fEngineReserved = 0;
225 /* While not strickly necessary according to the spec, make sure the n+1
226 * item is set up to prevent random behaviour if the caller eroneously
227 * checks the n+1 structure */
228 pItems[1].a.eScript = 0;
229 pItems[1].a.fRTL = 0;
230 pItems[1].a.fLayoutRTL = 0;
231 pItems[1].a.fLinkBefore = 0;
232 pItems[1].a.fLinkAfter = 0;
233 pItems[1].a.fLogicalOrder = 0;
234 pItems[1].a.fNoGlyphIndex = 0;
235 /* set the SCRIPT_STATE */
236 pItems[1].a.s.uBidiLevel = 0;
237 pItems[1].a.s.fOverrideDirection = 0;
238 pItems[1].a.s.fInhibitSymSwap = FALSE;
239 pItems[1].a.s.fCharShape = 0;
240 pItems[1].a.s.fDigitSubstitute = 0;
241 pItems[1].a.s.fInhibitLigate = 0;
242 pItems[1].a.s.fDisplayZWG = 0;
243 pItems[1].a.s.fArabicNumContext = 0;
244 pItems[1].a.s.fGcpClusters = 0;
245 pItems[1].a.s.fReserved = 0;
246 pItems[1].a.s.fEngineReserved = 0;
248 /* Set one SCRIPT_STATE item being returned */
251 /* Set SCRIPT_ITEM */
252 pItems[1].iCharPos = cInChars - pItems[0].iCharPos ; /* the last + 1 item
253 contains the ptr to the lastchar */
254 TRACE("%s,%d,%d,%p,%p,%p,%p,%d\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
255 psControl, psState, pItems, pcItems, *pcItems);
256 TRACE("Start Pos in string: %d, Stop Pos %d\n", pItems[0].iCharPos, pItems[1].iCharPos);
260 /***********************************************************************
261 * ScriptStringAnalyse (USP10.@)
264 HRESULT WINAPI ScriptStringAnalyse(HDC hdc,
271 SCRIPT_CONTROL *psControl,
272 SCRIPT_STATE *psState,
274 SCRIPT_TABDEF *pTabdef,
275 const BYTE *pbInClass,
276 SCRIPT_STRING_ANALYSIS *pssa)
278 FIXME("(%p,%p,%d,%d,%d,0x%lx,%d,%p,%p,%p,%p,%p,%p): stub\n",
279 hdc, pString, cString, cGlyphs, iCharset, dwFlags,
280 iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa);
281 if (1 > cString || NULL == pString) {
284 if ((dwFlags & SSA_GLYPHS) && NULL == hdc) {
291 /***********************************************************************
292 * ScriptStringFree (USP10.@)
295 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa) {
296 FIXME("(%p): stub\n",pssa);
300 /***********************************************************************
301 * ScriptIsComplex (USP10.@)
304 HRESULT WINAPI ScriptIsComplex(const WCHAR* pwcInChars, int cInChars, DWORD dwFlags) {
305 FIXME("(%s,%d,0x%lx): stub\n", debugstr_wn(pwcInChars, cInChars), cInChars, dwFlags);
309 /***********************************************************************
310 * ScriptShape (USP10.@)
313 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
314 int cChars, int cMaxGlyphs,
315 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
316 SCRIPT_VISATTR *psva, int *pcGlyphs)
318 /* Note SCRIPT_CACHE (*psc) appears to be a good place to save info that needs to be
319 * passed between functions. */
324 Scriptcache *pScriptcache;
326 FIXME("(%p, %p, %p, %d, %d, %p): semi-stub\n", hdc, psc, pwcChars,
327 cChars, cMaxGlyphs, psa);
328 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
329 psa->fLinkBefore, psa->fLinkAfter,
330 psa->fLogicalOrder, psa->fNoGlyphIndex);
332 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
335 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
339 pScriptcache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Scriptcache) );
340 pScriptcache->hdc = (HDC) hdc;
342 *psc = (Scriptcache *) pScriptcache;
345 pScriptcache = (Scriptcache *) *psc;
346 phdc = pScriptcache->hdc;
350 for (cnt = 0; cnt < cChars; cnt++)
351 TRACE("%4x",pwcChars[cnt]);
354 if (!psa->fNoGlyphIndex) { /* Glyph translate */
355 hr = GetGlyphIndicesW(phdc, pwcChars, cChars, pwOutGlyphs, 0);
357 for (cnt = 0; cnt < cChars; cnt++) {
358 TRACE("%04x",pwOutGlyphs[cnt]);
364 for (cnt = 0; cnt < cChars; cnt++) { /* no translate so set up */
365 pwOutGlyphs[cnt] = pwcChars[cnt]; /* copy in to out and */
366 TRACE("%04x",pwOutGlyphs[cnt]);
371 /* Set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
372 for (cnt = 0; cnt < cChars; cnt++) {
373 psva[cnt].uJustification = 2;
374 psva[cnt].fClusterStart = 1;
375 psva[cnt].fDiacritic = 0;
376 psva[cnt].fZeroWidth = 0;
377 pwLogClust[cnt] = cnt;
382 /***********************************************************************
383 * ScriptPlace (USP10.@)
386 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
387 int cGlyphs, const SCRIPT_VISATTR *psva,
388 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
393 Scriptcache *pScriptcache;
394 FIXME("(%p, %p, %p, %s, %d, %p, %p, %p): semi-stub\n", hdc, psc, pwGlyphs,
395 debugstr_wn(pwGlyphs, cGlyphs),
399 /* We need a valid hdc to do any of the font calls. The spec says that hdc is optional and
400 * psc will be used first. If psc and hdc are not specified E_PENDING is returned to get
401 * the caller to return the hdc. For convience, the hdc is cached in SCRIPT_CACHE. */
404 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
408 pScriptcache = HeapAlloc( GetProcessHeap(), 0, sizeof(Scriptcache) );
409 pScriptcache->hdc = hdc;
415 phdc = pScriptcache->hdc;
418 /* Here we need to calculate the width of the run unit. At this point the input string
419 * has been converted to glyphs and we till need to translate back to the original chars
420 * to get the correct ABC widths. */
422 lpABC = HeapAlloc(GetProcessHeap(), 0 , sizeof(ABC)*cGlyphs);
426 if (!GetCharABCWidthsI(phdc, 0, cGlyphs, (WORD *) pwGlyphs, lpABC ))
428 WARN("Could not get ABC values\n");
429 for (wcnt = 0; wcnt < cGlyphs; wcnt++) {
431 pGoffset[wcnt].du = 0;
432 pGoffset[wcnt].dv = 0;
437 for (wcnt = 0; wcnt < cGlyphs ; wcnt++) { /* add up the char lengths */
438 TRACE(" Glyph=%04x, abcA=%d, abcB=%d, abcC=%d wcnt=%d\n",
442 lpABC[wcnt].abcC, wcnt);
443 pABC->abcA += lpABC[wcnt].abcA;
444 pABC->abcB += lpABC[wcnt].abcB;
445 pABC->abcC += lpABC[wcnt].abcC;
446 piAdvance[wcnt] = lpABC[wcnt].abcA + lpABC[wcnt].abcB + lpABC[wcnt].abcC;
447 pGoffset[wcnt].du = 0;
448 pGoffset[wcnt].dv = 0;
451 TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
453 HeapFree(GetProcessHeap(), 0, lpABC );
458 /***********************************************************************
459 * ScriptGetCMap (USP10.@)
462 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
463 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
468 Scriptcache *pScriptcache;
469 FIXME("(%p,%p,%s,%d,0x%lx,%p): semi-stub\n", hdc, psc, debugstr_wn(pwcInChars,cChars), cChars, dwFlags, pwOutGlyphs);
472 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
476 pScriptcache = HeapAlloc( GetProcessHeap(), 0, sizeof(Scriptcache) );
477 pScriptcache->hdc = hdc;
483 phdc = pScriptcache->hdc;
487 for (cnt = 0; cnt < cChars; cnt++)
488 TRACE("%4x",pwcInChars[cnt]);
491 hr = GetGlyphIndicesW(phdc, pwcInChars, cChars, pwOutGlyphs, 0);
493 for (cnt = 0; cnt < cChars; cnt++) {
494 TRACE("%04x",pwOutGlyphs[cnt]);
501 /***********************************************************************
502 * ScriptTextOut (USP10.@)
505 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
506 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
507 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
508 const int *piJustify, const GOFFSET *pGoffset)
510 FIXME("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p): stub\n",
511 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
512 piAdvance, piJustify, pGoffset);