usp10: Implement ScriptStringFree.
[wine/multimedia.git] / dlls / usp10 / usp10.c
blobfeedc5b89cb1edaf7aca1364f072f4deaebb6468
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Notes:
21 * Uniscribe allows for processing of complex scripts such as joining
22 * and filtering characters and bi-directional text with custom line breaks.
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winnls.h"
32 #include "usp10.h"
34 #include "wine/debug.h"
36 /**
37 * some documentation here:
38 * http://www.microsoft.com/typography/developers/uniscribe/uniscribe.htm
41 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
43 #define MAX_SCRIPTS 8
45 /* Set up a default for ScriptGetProperties */
46 static const SCRIPT_PROPERTIES Default_Script_0 = {0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0};
48 static const SCRIPT_PROPERTIES Default_Script_1 = {0, 0, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, 0, 0, 0};
50 static const SCRIPT_PROPERTIES Default_Script_2 = {0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0};
52 static const SCRIPT_PROPERTIES Default_Script_3 = {9, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0};
54 static const SCRIPT_PROPERTIES Default_Script_4 = {9, 1, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0, 0, 0};
56 static const SCRIPT_PROPERTIES Default_Script_5 = {9, 0, 0, 0, 0, 0, 0, 0,
57 0, 0, 0, 0, 1, 0, 0};
58 static const SCRIPT_PROPERTIES Default_Script_6 = {9, 1, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 1, 0, 0};
60 static const SCRIPT_PROPERTIES Default_Script_7 = {8, 0, 0, 0, 0, 161, 0, 0,
61 0, 0, 0, 0, 0, 0, 0};
62 static const SCRIPT_PROPERTIES *Global_Script[MAX_SCRIPTS] =
63 {&Default_Script_0,
64 &Default_Script_1,
65 &Default_Script_2,
66 &Default_Script_3,
67 &Default_Script_4,
68 &Default_Script_5,
69 &Default_Script_6,
70 &Default_Script_7};
72 typedef struct scriptcache {
73 HDC hdc;
74 } Scriptcache;
76 typedef struct {
77 int numGlyphs;
78 WORD* glyphs;
79 WORD* pwLogClust;
80 int* piAdvance;
81 SCRIPT_VISATTR* psva;
82 GOFFSET* pGoffset;
83 ABC* abc;
84 } StringGlyphs;
86 typedef struct {
87 BOOL invalid;
88 HDC hdc;
89 int cItems;
90 int cMaxGlyphs;
91 SCRIPT_ITEM* pItem;
92 int numItems;
93 StringGlyphs* glyphs;
94 SIZE* sz;
95 } StringAnalysis;
97 /***********************************************************************
98 * DllMain
101 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
103 switch(fdwReason) {
104 case DLL_PROCESS_ATTACH:
105 DisableThreadLibraryCalls(hInstDLL);
106 break;
107 case DLL_PROCESS_DETACH:
108 break;
110 return TRUE;
113 /***********************************************************************
114 * ScriptFreeCache (USP10.@)
117 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
119 TRACE("%p\n", psc);
121 if (psc) {
122 HeapFree ( GetProcessHeap(), 0, *psc);
123 *psc = NULL;
125 return 0;
128 /***********************************************************************
129 * ScriptGetProperties (USP10.@)
132 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***ppSp, int *piNumScripts)
134 TRACE("%p,%p\n", ppSp, piNumScripts);
136 if (!ppSp && !piNumScripts) return E_INVALIDARG;
138 /* Set up a sensible default and intialise pointers */
139 if (piNumScripts) *piNumScripts = MAX_SCRIPTS;
140 if (ppSp) *ppSp = Global_Script;
141 TRACE("ppSp:%p, *ppSp:%p, **ppSp:%p, %d\n",
142 ppSp, ppSp ? *ppSp : NULL, (ppSp && *ppSp) ? **ppSp : NULL,
143 piNumScripts ? *piNumScripts : -1);
144 return 0;
147 /***********************************************************************
148 * ScriptGetFontProperties (USP10.@)
151 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
153 HDC phdc;
154 Scriptcache *pScriptcache;
155 TEXTMETRICW ptm;
157 TRACE("%p,%p,%p\n", hdc, psc, sfp);
159 if (!psc || !sfp)
160 return E_INVALIDARG;
161 if (!hdc && !*psc) {
162 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
163 return E_PENDING;
164 } else
165 if (hdc && !*psc) {
166 pScriptcache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Scriptcache) );
167 pScriptcache->hdc = (HDC) hdc;
168 phdc = hdc;
169 *psc = (Scriptcache *) pScriptcache;
170 } else
171 if (*psc) {
172 pScriptcache = (Scriptcache *) *psc;
173 phdc = pScriptcache->hdc;
176 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
177 return E_INVALIDARG;
179 /* return something sensible? */
180 sfp->wgBlank = 0;
181 if (GetTextMetricsW(phdc, &ptm))
182 sfp->wgDefault = ptm.tmDefaultChar;
183 else
184 sfp->wgDefault = 0;
185 sfp->wgInvalid = 0;
186 sfp->wgKashida = 0xffff;
187 sfp->iKashidaWidth = 0;
188 return 0;
191 /***********************************************************************
192 * ScriptRecordDigitSubstitution (USP10.@)
194 * Record digit substitution settings for a given locale.
196 * PARAMS
197 * locale [I] Locale identifier.
198 * sds [I] Structure to record substitution settings.
200 * RETURNS
201 * Success: S_OK
202 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
204 * SEE ALSO
205 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
207 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
209 DWORD plgid, sub;
211 TRACE("0x%x, %p\n", locale, sds);
213 /* This implementation appears to be correct for all languages, but it's
214 * not clear if sds->DigitSubstitute is ever set to anything except
215 * CONTEXT or NONE in reality */
217 if (!sds) return E_POINTER;
219 locale = ConvertDefaultLocale(locale);
221 if (!IsValidLocale(locale, LCID_INSTALLED))
222 return E_INVALIDARG;
224 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
225 sds->TraditionalDigitLanguage = plgid;
227 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
228 sds->NationalDigitLanguage = plgid;
229 else
230 sds->NationalDigitLanguage = LANG_ENGLISH;
232 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
233 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
235 switch (sub)
237 case 0:
238 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
239 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
240 else
241 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
242 break;
243 case 1:
244 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
245 break;
246 case 2:
247 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
248 break;
249 default:
250 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
251 break;
254 sds->dwReserved = 0;
255 return S_OK;
258 /***********************************************************************
259 * ScriptApplyDigitSubstitution (USP10.@)
261 * Apply digit substitution settings.
263 * PARAMS
264 * sds [I] Structure with recorded substitution settings.
265 * sc [I] Script control structure.
266 * ss [I] Script state structure.
268 * RETURNS
269 * Success: S_OK
270 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
272 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
273 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
275 SCRIPT_DIGITSUBSTITUTE psds;
277 TRACE("%p, %p, %p\n", sds, sc, ss);
279 if (!sc || !ss) return E_POINTER;
280 if (!sds)
282 sds = &psds;
283 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
284 return E_INVALIDARG;
287 sc->uDefaultLanguage = LANG_ENGLISH;
288 sc->fContextDigits = 0;
289 ss->fDigitSubstitute = 0;
291 switch (sds->DigitSubstitute) {
292 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
293 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
294 case SCRIPT_DIGITSUBSTITUTE_NONE:
295 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
296 return S_OK;
297 default:
298 return E_INVALIDARG;
302 /***********************************************************************
303 * ScriptItemize (USP10.@)
306 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
307 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
308 SCRIPT_ITEM *pItems, int *pcItems)
311 #define Numeric_start 0x0030
312 #define Numeric_stop 0x0039
313 #define Numeric_space 0x0020
314 #define Arabic_start 0x0600
315 #define Arabic_stop 0x06ff
316 #define Latin_start 0x0001
317 #define Latin_stop 0x024f
318 #define Script_Arabic 6
319 #define Script_Latin 1
320 #define Script_Numeric 5
322 int cnt = 0, index = 0;
323 int New_Script = SCRIPT_UNDEFINED;
325 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
326 psControl, psState, pItems, pcItems);
328 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
329 return E_INVALIDARG;
331 if (pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
332 pItems[index].a.eScript = Script_Numeric;
333 else
334 if (pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
335 pItems[index].a.eScript = Script_Arabic;
336 else
337 if (pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
338 pItems[index].a.eScript = Script_Latin;
339 else
340 pItems[index].a.eScript = SCRIPT_UNDEFINED;
341 pItems[index].iCharPos = 0;
342 /* Set the SCRIPT_ANALYSIS */
343 pItems[index].a.fRTL = 0;
344 pItems[index].a.fLayoutRTL = 0;
345 pItems[index].a.fLinkBefore = 0;
346 pItems[index].a.fLinkAfter = 0;
347 pItems[index].a.fLogicalOrder = 0;
348 pItems[index].a.fNoGlyphIndex = 0;
349 /* set the SCRIPT_STATE */
350 if (pItems[index].a.eScript == Script_Arabic)
351 pItems[index].a.s.uBidiLevel = 1;
352 else
353 pItems[index].a.s.uBidiLevel = 0;
354 pItems[index].a.s.fOverrideDirection = 0;
355 pItems[index].a.s.fInhibitSymSwap = FALSE;
356 pItems[index].a.s.fCharShape = 0;
357 pItems[index].a.s.fDigitSubstitute = 0;
358 pItems[index].a.s.fInhibitLigate = 0;
359 pItems[index].a.s.fDisplayZWG = 0;
360 pItems[index].a.s.fArabicNumContext = 0;
361 pItems[index].a.s.fGcpClusters = 0;
362 pItems[index].a.s.fReserved = 0;
363 pItems[index].a.s.fEngineReserved = 0;
364 TRACE("New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
365 New_Script, pItems[index].a.eScript, index, cnt,
366 pItems[index].iCharPos = cnt);
368 for (cnt=0; cnt < cInChars; cnt++)
370 if ((pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
371 || (New_Script == Script_Numeric && pwcInChars[cnt] == Numeric_space))
372 New_Script = Script_Numeric;
373 else
374 if ((pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
375 || (New_Script == Script_Arabic && pwcInChars[cnt] == Numeric_space))
376 New_Script = Script_Arabic;
377 else
378 if ((WCHAR) pwcInChars[cnt] >= Latin_start && (WCHAR) pwcInChars[cnt] <= Latin_stop)
379 New_Script = Script_Latin;
380 else
381 New_Script = SCRIPT_UNDEFINED;
383 if (New_Script != pItems[index].a.eScript)
385 TRACE("New_Script=%d, eScript=%d ", New_Script, pItems[index].a.eScript);
386 index++;
387 if (index+1 > cMaxItems)
388 return E_OUTOFMEMORY;
389 pItems[index].iCharPos = cnt;
390 if (New_Script == Script_Arabic)
391 pItems[index].a.s.uBidiLevel = 1;
392 /* Set SCRIPT_ITEM */
393 pItems[index].iCharPos = cnt;
394 /* Set the SCRIPT_ANALYSIS */
395 pItems[index].a.eScript = New_Script;
396 pItems[index].a.fRTL = 0;
397 pItems[index].a.fLayoutRTL = 0;
398 pItems[index].a.fLinkBefore = 0;
399 pItems[index].a.fLinkAfter = 0;
400 pItems[index].a.fLogicalOrder = 0;
401 pItems[index].a.fNoGlyphIndex = 0;
402 /* set the SCRIPT_STATE */
403 if (New_Script == Script_Arabic)
404 pItems[index].a.s.uBidiLevel = 1;
405 else
406 pItems[index].a.s.uBidiLevel = 0;
407 pItems[index].a.s.fOverrideDirection = 0;
408 pItems[index].a.s.fInhibitSymSwap = FALSE;
409 pItems[index].a.s.fCharShape = 0;
410 pItems[index].a.s.fDigitSubstitute = 0;
411 pItems[index].a.s.fInhibitLigate = 0;
412 pItems[index].a.s.fDisplayZWG = 0;
413 pItems[index].a.s.fArabicNumContext = 0;
414 pItems[index].a.s.fGcpClusters = 0;
415 pItems[index].a.s.fReserved = 0;
416 pItems[index].a.s.fEngineReserved = 0;
417 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos = cnt);
421 /* While not strictly necessary according to the spec, make sure the n+1
422 * item is set up to prevent random behaviour if the caller erroneously
423 * checks the n+1 structure */
424 pItems[index+1].a.eScript = 0;
425 pItems[index+1].a.fRTL = 0;
426 pItems[index+1].a.fLayoutRTL = 0;
427 pItems[index+1].a.fLinkBefore = 0;
428 pItems[index+1].a.fLinkAfter = 0;
429 pItems[index+1].a.fLogicalOrder = 0;
430 pItems[index+1].a.fNoGlyphIndex = 0;
431 /* set the SCRIPT_STATE */
432 pItems[index+1].a.s.uBidiLevel = 0;
433 pItems[index+1].a.s.fOverrideDirection = 0;
434 pItems[index+1].a.s.fInhibitSymSwap = FALSE;
435 pItems[index+1].a.s.fCharShape = 0;
436 pItems[index+1].a.s.fDigitSubstitute = 0;
437 pItems[index+1].a.s.fInhibitLigate = 0;
438 pItems[index+1].a.s.fDisplayZWG = 0;
439 pItems[index+1].a.s.fArabicNumContext = 0;
440 pItems[index+1].a.s.fGcpClusters = 0;
441 pItems[index+1].a.s.fReserved = 0;
442 pItems[index+1].a.s.fEngineReserved = 0;
443 TRACE("index=%d cnt=%d iCharPos=%d\n", index+1, cnt, pItems[index+1].iCharPos = cnt);
445 /* Set one SCRIPT_STATE item being returned */
446 *pcItems = index + 1;
448 /* Set SCRIPT_ITEM */
449 pItems[index+1].iCharPos = cnt; /* the last + 1 item
450 contains the ptr to the lastchar */
451 return S_OK;
454 /***********************************************************************
455 * ScriptStringAnalyse (USP10.@)
458 HRESULT WINAPI ScriptStringAnalyse(HDC hdc,
459 const void *pString,
460 int cString,
461 int cGlyphs,
462 int iCharset,
463 DWORD dwFlags,
464 int iReqWidth,
465 SCRIPT_CONTROL *psControl,
466 SCRIPT_STATE *psState,
467 const int *piDx,
468 SCRIPT_TABDEF *pTabdef,
469 const BYTE *pbInClass,
470 SCRIPT_STRING_ANALYSIS *pssa)
472 HRESULT hr;
473 StringAnalysis* analysis;
474 int numItemizedItems;
475 int i;
476 SCRIPT_CACHE* sc = 0;
478 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
479 hdc, pString, cString, cGlyphs, iCharset, dwFlags,
480 iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa);
482 if (1 > cString || NULL == pString) {
483 return E_INVALIDARG;
485 if ((dwFlags & SSA_GLYPHS) && NULL == hdc) {
486 return E_PENDING;
489 analysis = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
490 sizeof(StringAnalysis));
492 analysis->hdc = hdc;
493 numItemizedItems = 255;
494 analysis->pItem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
495 numItemizedItems*sizeof(SCRIPT_ITEM)+1);
497 hr = ScriptItemize(pString, cString, numItemizedItems, psControl,
498 psState, analysis->pItem, &analysis->numItems);
500 while(hr == E_OUTOFMEMORY)
502 numItemizedItems *= 2;
503 HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, analysis->pItem,
504 numItemizedItems*sizeof(SCRIPT_ITEM)+1);
505 hr = ScriptItemize(pString, cString, numItemizedItems, psControl,
506 psState, analysis->pItem, &analysis->numItems);
509 analysis->glyphs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
510 sizeof(StringGlyphs)*analysis->numItems);
511 sc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SCRIPT_CACHE));
513 for(i=0; i<analysis->numItems; i++)
515 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
516 int numGlyphs = 1.5 * cChar + 16;
517 WORD* glyphs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WORD)*numGlyphs);
518 WORD* pwLogClust = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WORD)*cChar);
519 int* piAdvance = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int)*numGlyphs);
520 SCRIPT_VISATTR* psva = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SCRIPT_VISATTR)*cChar);
521 GOFFSET* pGoffset = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GOFFSET)*numGlyphs);
522 ABC* abc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ABC));
523 int numGlyphsReturned;
525 /* FIXME: non unicode strings */
526 WCHAR* pStr = (WCHAR*)pString;
527 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
528 cChar, numGlyphs, &analysis->pItem[i].a,
529 glyphs, pwLogClust, psva, &numGlyphsReturned);
530 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
531 piAdvance, pGoffset, abc);
533 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
534 analysis->glyphs[i].glyphs = glyphs;
535 analysis->glyphs[i].pwLogClust = pwLogClust;
536 analysis->glyphs[i].piAdvance = piAdvance;
537 analysis->glyphs[i].psva = psva;
538 analysis->glyphs[i].pGoffset = pGoffset;
539 analysis->glyphs[i].abc = abc;
542 HeapFree(GetProcessHeap(), 0, sc);
544 *pssa = analysis;
546 return S_OK;
549 /***********************************************************************
550 * ScriptStringOut (USP10.@)
553 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
554 int iX,
555 int iY,
556 UINT uOptions,
557 const RECT *prc,
558 int iMinSel,
559 int iMaxSel,
560 BOOL fDisabled)
562 FIXME("(%p,%d,%d,0x%1x,%p,%d,%d,%d): stub\n",
563 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
564 if (!ssa) {
565 return E_INVALIDARG;
568 return E_NOTIMPL;
571 /***********************************************************************
572 * ScriptStringCPtoX (USP10.@)
575 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
577 FIXME("(%p), %d, %d, (%p): stub\n", ssa, icp, fTrailing, pX);
578 *pX = 0; /* Set a reasonable value */
579 return S_OK;
582 /***********************************************************************
583 * ScriptStringXtoCP (USP10.@)
586 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
588 FIXME("(%p), %d, (%p), (%p): stub\n", ssa, iX, piCh, piTrailing);
589 *piCh = 0; /* Set a reasonable value */
590 *piTrailing = 0;
591 return S_OK;
594 /***********************************************************************
595 * ScriptStringFree (USP10.@)
598 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
600 StringAnalysis* analysis;
601 BOOL invalid;
602 int i;
603 TRACE("(%p)\n",pssa);
605 if(!pssa)
606 return E_INVALIDARG;
608 analysis = *pssa;
609 if(!analysis)
610 return E_INVALIDARG;
612 invalid = analysis->invalid;
614 for(i=0; i<analysis->numItems; i++)
616 HeapFree(GetProcessHeap(), 0, analysis->glyphs[i].glyphs);
617 HeapFree(GetProcessHeap(), 0, analysis->glyphs[i].pwLogClust);
618 HeapFree(GetProcessHeap(), 0, analysis->glyphs[i].piAdvance);
619 HeapFree(GetProcessHeap(), 0, analysis->glyphs[i].psva);
620 HeapFree(GetProcessHeap(), 0, analysis->glyphs[i].pGoffset);
621 HeapFree(GetProcessHeap(), 0, analysis->glyphs[i].abc);
624 HeapFree(GetProcessHeap(), 0, analysis->glyphs);
625 HeapFree(GetProcessHeap(), 0, analysis->pItem);
626 HeapFree(GetProcessHeap(), 0, analysis);
628 if(invalid)
629 return E_INVALIDARG;
631 return S_OK;
634 /***********************************************************************
635 * ScriptCPtoX (USP10.@)
638 HRESULT WINAPI ScriptCPtoX(int iCP,
639 BOOL fTrailing,
640 int cChars,
641 int cGlyphs,
642 const WORD *pwLogClust,
643 const SCRIPT_VISATTR *psva,
644 const int *piAdvance,
645 const SCRIPT_ANALYSIS *psa,
646 int *piX)
648 int item;
649 int iPosX;
650 float fMaxPosX = 0;
651 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
652 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
653 psa, piX);
654 for (item=0; item < cGlyphs; item++) /* total piAdvance */
655 fMaxPosX += piAdvance[item];
656 iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing);
657 if (iPosX > fMaxPosX)
658 iPosX = fMaxPosX;
659 *piX = iPosX; /* Return something in range */
661 TRACE("*piX=%d\n", *piX);
662 return S_OK;
665 /***********************************************************************
666 * ScriptXtoCP (USP10.@)
669 HRESULT WINAPI ScriptXtoCP(int iX,
670 int cChars,
671 int cGlyphs,
672 const WORD *pwLogClust,
673 const SCRIPT_VISATTR *psva,
674 const int *piAdvance,
675 const SCRIPT_ANALYSIS *psa,
676 int *piCP,
677 int *piTrailing)
679 int item;
680 int iPosX;
681 float fMaxPosX = 1;
682 float fAvePosX;
683 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
684 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
685 psa, piCP, piTrailing);
686 if (iX < 0) /* iX is before start of run */
688 *piCP = -1;
689 *piTrailing = TRUE;
690 return S_OK;
693 for (item=0; item < cGlyphs; item++) /* total piAdvance */
694 fMaxPosX += piAdvance[item];
696 if (iX >= fMaxPosX) /* iX too large */
698 *piCP = cChars;
699 *piTrailing = FALSE;
700 return S_OK;
703 fAvePosX = fMaxPosX / cGlyphs;
704 iPosX = fAvePosX;
705 for (item = 1; item < cGlyphs && iPosX < iX; item++)
706 iPosX += fAvePosX;
707 if (iPosX - iX > fAvePosX/2)
708 *piTrailing = 0;
709 else
710 *piTrailing = 1; /* yep we are over halfway */
712 *piCP = item -1; /* Return character position */
713 TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX);
714 return S_OK;
717 /***********************************************************************
718 * ScriptBreak (USP10.@)
721 HRESULT WINAPI ScriptBreak(const WCHAR *pwcChars, int cChars, const SCRIPT_ANALYSIS *psa,
722 SCRIPT_LOGATTR *psla)
724 FIXME("(%p,%d,%p,%p): stub\n",
725 pwcChars, cChars, psa, psla);
727 return S_OK;
730 static const struct
732 WCHAR start;
733 WCHAR end;
734 DWORD flag;
736 complex_ranges[] =
738 { 0, 0x0b, SIC_COMPLEX },
739 { 0x0c, 0x0c, SIC_NEUTRAL },
740 { 0x0d, 0x1f, SIC_COMPLEX },
741 { 0x20, 0x2f, SIC_NEUTRAL },
742 { 0x30, 0x39, SIC_ASCIIDIGIT },
743 { 0x3a, 0x40, SIC_NEUTRAL },
744 { 0x5b, 0x60, SIC_NEUTRAL },
745 { 0x7b, 0x7e, SIC_NEUTRAL },
746 { 0x7f, 0x9f, SIC_COMPLEX },
747 { 0xa0, 0xa5, SIC_NEUTRAL },
748 { 0xa7, 0xa8, SIC_NEUTRAL },
749 { 0xab, 0xab, SIC_NEUTRAL },
750 { 0xad, 0xad, SIC_NEUTRAL },
751 { 0xaf, 0xaf, SIC_NEUTRAL },
752 { 0xb0, 0xb1, SIC_NEUTRAL },
753 { 0xb4, 0xb4, SIC_NEUTRAL },
754 { 0xb6, 0xb8, SIC_NEUTRAL },
755 { 0xbb, 0xbf, SIC_NEUTRAL },
756 { 0xd7, 0xd7, SIC_NEUTRAL },
757 { 0xf7, 0xf7, SIC_NEUTRAL },
758 { 0x2b9, 0x2ba, SIC_NEUTRAL },
759 { 0x2c2, 0x2cf, SIC_NEUTRAL },
760 { 0x2d2, 0x2df, SIC_NEUTRAL },
761 { 0x2e5, 0x2e9, SIC_COMPLEX },
762 { 0x2ea, 0x2ed, SIC_NEUTRAL },
763 { 0x300, 0x362, SIC_COMPLEX },
764 { 0x530, 0x60b, SIC_COMPLEX },
765 { 0x60c, 0x60d, SIC_NEUTRAL },
766 { 0x60e, 0x669, SIC_COMPLEX },
767 { 0x66a, 0x66a, SIC_NEUTRAL },
768 { 0x66b, 0x6e8, SIC_COMPLEX },
769 { 0x6e9, 0x6e9, SIC_NEUTRAL },
770 { 0x6ea, 0x7bf, SIC_COMPLEX },
771 { 0x900, 0x1360, SIC_COMPLEX },
772 { 0x137d, 0x137f, SIC_COMPLEX },
773 { 0x1680, 0x1680, SIC_NEUTRAL },
774 { 0x1780, 0x18af, SIC_COMPLEX },
775 { 0x2000, 0x200a, SIC_NEUTRAL },
776 { 0x200b, 0x200f, SIC_COMPLEX },
777 { 0x2010, 0x2016, SIC_NEUTRAL },
778 { 0x2018, 0x2022, SIC_NEUTRAL },
779 { 0x2024, 0x2028, SIC_NEUTRAL },
780 { 0x2029, 0x202e, SIC_COMPLEX },
781 { 0x202f, 0x2037, SIC_NEUTRAL },
782 { 0x2039, 0x203c, SIC_NEUTRAL },
783 { 0x2044, 0x2046, SIC_NEUTRAL },
784 { 0x206a, 0x206f, SIC_COMPLEX },
785 { 0x207a, 0x207e, SIC_NEUTRAL },
786 { 0x208a, 0x20aa, SIC_NEUTRAL },
787 { 0x20ac, 0x20cf, SIC_NEUTRAL },
788 { 0x20d0, 0x20ff, SIC_COMPLEX },
789 { 0x2103, 0x2103, SIC_NEUTRAL },
790 { 0x2105, 0x2105, SIC_NEUTRAL },
791 { 0x2109, 0x2109, SIC_NEUTRAL },
792 { 0x2116, 0x2116, SIC_NEUTRAL },
793 { 0x2121, 0x2122, SIC_NEUTRAL },
794 { 0x212e, 0x212e, SIC_NEUTRAL },
795 { 0x2153, 0x2154, SIC_NEUTRAL },
796 { 0x215b, 0x215e, SIC_NEUTRAL },
797 { 0x2190, 0x2199, SIC_NEUTRAL },
798 { 0x21b8, 0x21b9, SIC_NEUTRAL },
799 { 0x21d2, 0x21d2, SIC_NEUTRAL },
800 { 0x21d4, 0x21d4, SIC_NEUTRAL },
801 { 0x21e7, 0x21e7, SIC_NEUTRAL },
802 { 0x2200, 0x2200, SIC_NEUTRAL },
803 { 0x2202, 0x2203, SIC_NEUTRAL },
804 { 0x2207, 0x2208, SIC_NEUTRAL },
805 { 0x220b, 0x220b, SIC_NEUTRAL },
806 { 0x220f, 0x220f, SIC_NEUTRAL },
807 { 0x2211, 0x2213, SIC_NEUTRAL },
808 { 0x2215, 0x2215, SIC_NEUTRAL },
809 { 0x221a, 0x221a, SIC_NEUTRAL },
810 { 0x221d, 0x2220, SIC_NEUTRAL },
811 { 0x2223, 0x2223, SIC_NEUTRAL },
812 { 0x2225, 0x2225, SIC_NEUTRAL },
813 { 0x2227, 0x222c, SIC_NEUTRAL },
814 { 0x222e, 0x222e, SIC_NEUTRAL },
815 { 0x2234, 0x2237, SIC_NEUTRAL },
816 { 0x223c, 0x223d, SIC_NEUTRAL },
817 { 0x2248, 0x2248, SIC_NEUTRAL },
818 { 0x224c, 0x224c, SIC_NEUTRAL },
819 { 0x2252, 0x2252, SIC_NEUTRAL },
820 { 0x2260, 0x2261, SIC_NEUTRAL },
821 { 0x2264, 0x2267, SIC_NEUTRAL },
822 { 0x226a, 0x226b, SIC_NEUTRAL },
823 { 0x226e, 0x226f, SIC_NEUTRAL },
824 { 0x2282, 0x2283, SIC_NEUTRAL },
825 { 0x2286, 0x2287, SIC_NEUTRAL },
826 { 0x2295, 0x2295, SIC_NEUTRAL },
827 { 0x2299, 0x2299, SIC_NEUTRAL },
828 { 0x22a5, 0x22a5, SIC_NEUTRAL },
829 { 0x22bf, 0x22bf, SIC_NEUTRAL },
830 { 0x2312, 0x2312, SIC_NEUTRAL },
831 { 0x24ea, 0x24ea, SIC_COMPLEX },
832 { 0x2500, 0x254b, SIC_NEUTRAL },
833 { 0x2550, 0x256d, SIC_NEUTRAL },
834 { 0x256e, 0x2574, SIC_NEUTRAL },
835 { 0x2581, 0x258f, SIC_NEUTRAL },
836 { 0x2592, 0x2595, SIC_NEUTRAL },
837 { 0x25a0, 0x25a1, SIC_NEUTRAL },
838 { 0x25a3, 0x25a9, SIC_NEUTRAL },
839 { 0x25b2, 0x25b3, SIC_NEUTRAL },
840 { 0x25b6, 0x25b7, SIC_NEUTRAL },
841 { 0x25bc, 0x25bd, SIC_NEUTRAL },
842 { 0x25c0, 0x25c1, SIC_NEUTRAL },
843 { 0x25c6, 0x25c8, SIC_NEUTRAL },
844 { 0x25cb, 0x25cb, SIC_NEUTRAL },
845 { 0x25ce, 0x25d1, SIC_NEUTRAL },
846 { 0x25e2, 0x25e5, SIC_NEUTRAL },
847 { 0x25ef, 0x25ef, SIC_NEUTRAL },
848 { 0x2605, 0x2606, SIC_NEUTRAL },
849 { 0x2609, 0x2609, SIC_NEUTRAL },
850 { 0x260e, 0x260f, SIC_NEUTRAL },
851 { 0x261c, 0x261c, SIC_NEUTRAL },
852 { 0x261e, 0x261e, SIC_NEUTRAL },
853 { 0x2640, 0x2640, SIC_NEUTRAL },
854 { 0x2642, 0x2642, SIC_NEUTRAL },
855 { 0x2660, 0x2661, SIC_NEUTRAL },
856 { 0x2663, 0x2665, SIC_NEUTRAL },
857 { 0x2667, 0x266a, SIC_NEUTRAL },
858 { 0x266c, 0x266d, SIC_NEUTRAL },
859 { 0x266f, 0x266f, SIC_NEUTRAL },
860 { 0x273d, 0x273d, SIC_NEUTRAL },
861 { 0x2e80, 0x312f, SIC_COMPLEX },
862 { 0x3190, 0x31bf, SIC_COMPLEX },
863 { 0x31f0, 0x31ff, SIC_COMPLEX },
864 { 0x3220, 0x325f, SIC_COMPLEX },
865 { 0x3280, 0xa4ff, SIC_COMPLEX },
866 { 0xd800, 0xdfff, SIC_COMPLEX },
867 { 0xe000, 0xf8ff, SIC_NEUTRAL },
868 { 0xf900, 0xfaff, SIC_COMPLEX },
869 { 0xfb13, 0xfb28, SIC_COMPLEX },
870 { 0xfb29, 0xfb29, SIC_NEUTRAL },
871 { 0xfb2a, 0xfb4f, SIC_COMPLEX },
872 { 0xfd3e, 0xfd3f, SIC_NEUTRAL },
873 { 0xfdd0, 0xfdef, SIC_COMPLEX },
874 { 0xfe20, 0xfe6f, SIC_COMPLEX },
875 { 0xfeff, 0xfeff, SIC_COMPLEX },
876 { 0xff01, 0xff5e, SIC_COMPLEX },
877 { 0xff61, 0xff9f, SIC_COMPLEX },
878 { 0xffe0, 0xffe6, SIC_COMPLEX },
879 { 0xffe8, 0xffee, SIC_COMPLEX },
880 { 0xfff9, 0xfffb, SIC_COMPLEX },
881 { 0xfffe, 0xfffe, SIC_COMPLEX }
884 /***********************************************************************
885 * ScriptIsComplex (USP10.@)
887 * Determine if a string is complex.
889 * PARAMS
890 * chars [I] Array of characters to test.
891 * len [I] Length in characters.
892 * flag [I] Flag.
894 * RETURNS
895 * Success: S_OK
896 * Failure: S_FALSE
898 * NOTES
899 * Behaviour matches that of WinXP.
901 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
903 unsigned int i, j;
905 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
907 for (i = 0; i < len; i++)
909 for (j = 0; j < sizeof(complex_ranges)/sizeof(complex_ranges[0]); j++)
911 if (chars[i] >= complex_ranges[j].start &&
912 chars[i] <= complex_ranges[j].end &&
913 (flag & complex_ranges[j].flag)) return S_OK;
916 return S_FALSE;
919 /***********************************************************************
920 * ScriptShape (USP10.@)
923 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
924 int cChars, int cMaxGlyphs,
925 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
926 SCRIPT_VISATTR *psva, int *pcGlyphs)
928 /* Note SCRIPT_CACHE (*psc) appears to be a good place to save info that needs to be
929 * passed between functions. */
931 HDC phdc;
932 int cnt;
933 DWORD hr;
934 Scriptcache *pScriptcache;
935 *pcGlyphs = cChars;
936 FIXME("(%p, %p, %p, %d, %d, %p): semi-stub\n", hdc, psc, pwcChars,
937 cChars, cMaxGlyphs, psa);
938 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
939 psa->fLinkBefore, psa->fLinkAfter,
940 psa->fLogicalOrder, psa->fNoGlyphIndex);
942 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
944 if (!hdc && !*psc) {
945 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
946 return E_PENDING;
947 } else
948 if (hdc && !*psc) {
949 pScriptcache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Scriptcache) );
950 pScriptcache->hdc = (HDC) hdc;
951 phdc = hdc;
952 *psc = (Scriptcache *) pScriptcache;
953 } else
954 if (*psc) {
955 pScriptcache = (Scriptcache *) *psc;
956 phdc = pScriptcache->hdc;
959 TRACE("Before: ");
960 for (cnt = 0; cnt < cChars; cnt++)
961 TRACE("%4x",pwcChars[cnt]);
962 TRACE("\n");
964 if (!psa->fNoGlyphIndex) { /* Glyph translate */
965 hr = GetGlyphIndicesW(phdc, pwcChars, cChars, pwOutGlyphs, 0);
966 TRACE("After: ");
967 for (cnt = 0; cnt < cChars; cnt++) {
968 TRACE("%04x",pwOutGlyphs[cnt]);
970 TRACE("\n");
972 else {
973 TRACE("After: ");
974 for (cnt = 0; cnt < cChars; cnt++) { /* no translate so set up */
975 pwOutGlyphs[cnt] = pwcChars[cnt]; /* copy in to out and */
976 TRACE("%04x",pwOutGlyphs[cnt]);
978 TRACE("\n");
981 /* Set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
982 for (cnt = 0; cnt < cChars; cnt++) {
983 psva[cnt].uJustification = 2;
984 psva[cnt].fClusterStart = 1;
985 psva[cnt].fDiacritic = 0;
986 psva[cnt].fZeroWidth = 0;
987 pwLogClust[cnt] = cnt;
989 return 0;
992 /***********************************************************************
993 * ScriptPlace (USP10.@)
996 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
997 int cGlyphs, const SCRIPT_VISATTR *psva,
998 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
1000 HDC phdc;
1001 int wcnt;
1002 LPABC lpABC;
1003 Scriptcache *pScriptcache;
1004 FIXME("(%p, %p, %p, %s, %d, %p, %p, %p): semi-stub\n", hdc, psc, pwGlyphs,
1005 debugstr_wn(pwGlyphs, cGlyphs),
1006 cGlyphs, psva, psa,
1007 piAdvance);
1009 /* We need a valid hdc to do any of the font calls. The spec says that hdc is optional and
1010 * psc will be used first. If psc and hdc are not specified E_PENDING is returned to get
1011 * the caller to return the hdc. For convenience, the hdc is cached in SCRIPT_CACHE. */
1013 if (!hdc && !*psc) {
1014 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
1015 return E_PENDING;
1016 } else
1017 if (hdc && !*psc) {
1018 pScriptcache = HeapAlloc( GetProcessHeap(), 0, sizeof(Scriptcache) );
1019 pScriptcache->hdc = hdc;
1020 phdc = hdc;
1021 *psc = pScriptcache;
1022 } else
1023 if (*psc) {
1024 pScriptcache = *psc;
1025 phdc = pScriptcache->hdc;
1028 /* Here we need to calculate the width of the run unit. At this point the input string
1029 * has been converted to glyphs and we still need to translate back to the original chars
1030 * to get the correct ABC widths. */
1032 lpABC = HeapAlloc(GetProcessHeap(), 0 , sizeof(ABC)*cGlyphs);
1033 pABC->abcA = 0;
1034 pABC->abcB = 0;
1035 pABC->abcC = 0;
1036 if (!GetCharABCWidthsI(phdc, 0, cGlyphs, (WORD *) pwGlyphs, lpABC ))
1038 WARN("Could not get ABC values\n");
1039 for (wcnt = 0; wcnt < cGlyphs; wcnt++) {
1040 piAdvance[wcnt] = 0;
1041 pGoffset[wcnt].du = 0;
1042 pGoffset[wcnt].dv = 0;
1045 else
1047 for (wcnt = 0; wcnt < cGlyphs ; wcnt++) { /* add up the char lengths */
1048 TRACE(" Glyph=%04x, abcA=%d, abcB=%d, abcC=%d wcnt=%d\n",
1049 pwGlyphs[wcnt],
1050 lpABC[wcnt].abcA,
1051 lpABC[wcnt].abcB,
1052 lpABC[wcnt].abcC, wcnt);
1053 pABC->abcA += lpABC[wcnt].abcA;
1054 pABC->abcB += lpABC[wcnt].abcB;
1055 pABC->abcC += lpABC[wcnt].abcC;
1056 piAdvance[wcnt] = lpABC[wcnt].abcA + lpABC[wcnt].abcB + lpABC[wcnt].abcC;
1057 pGoffset[wcnt].du = 0;
1058 pGoffset[wcnt].dv = 0;
1061 TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
1063 HeapFree(GetProcessHeap(), 0, lpABC );
1065 return 0;
1068 /***********************************************************************
1069 * ScriptGetCMap (USP10.@)
1072 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
1073 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
1075 HDC phdc;
1076 int cnt;
1077 DWORD hr;
1078 Scriptcache *pScriptcache;
1079 FIXME("(%p,%p,%s,%d,0x%x,%p): semi-stub\n", hdc, psc, debugstr_wn(pwcInChars,cChars),
1080 cChars, dwFlags, pwOutGlyphs);
1082 if (!psc)
1083 return E_INVALIDARG;
1085 if (!hdc && !*psc) {
1086 TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
1087 return E_PENDING;
1088 } else
1089 if (hdc && !*psc) {
1090 pScriptcache = HeapAlloc( GetProcessHeap(), 0, sizeof(Scriptcache) );
1091 pScriptcache->hdc = hdc;
1092 phdc = hdc;
1093 *psc = pScriptcache;
1094 } else
1095 if (*psc) {
1096 pScriptcache = *psc;
1097 phdc = pScriptcache->hdc;
1100 TRACE("Before: ");
1101 for (cnt = 0; cnt < cChars; cnt++)
1102 TRACE("%4x",pwcInChars[cnt]);
1103 TRACE("\n");
1105 hr = GetGlyphIndicesW(phdc, pwcInChars, cChars, pwOutGlyphs, 0);
1106 TRACE("After: ");
1107 for (cnt = 0; cnt < cChars; cnt++) {
1108 TRACE("%04x",pwOutGlyphs[cnt]);
1110 TRACE("\n");
1112 return 0;
1115 /***********************************************************************
1116 * ScriptTextOut (USP10.@)
1119 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
1120 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
1121 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
1122 const int *piJustify, const GOFFSET *pGoffset)
1124 HDC phdc;
1125 DWORD hr;
1126 Scriptcache *pScriptcache;
1127 TRACE ("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p): stub\n",
1128 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
1129 piAdvance, piJustify, pGoffset);
1131 if (!hdc || !psc || !piAdvance || !psa || !pwGlyphs) /* hdc is mandatory */
1132 return E_INVALIDARG;
1134 if (!*psc) {
1135 pScriptcache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Scriptcache) );
1136 pScriptcache->hdc = hdc;
1137 phdc = hdc;
1138 *psc = pScriptcache;
1139 } else {
1140 pScriptcache = *psc;
1141 phdc = pScriptcache->hdc;
1144 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
1145 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
1146 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
1148 hr = ExtTextOutW(phdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL);
1150 if (hr) return S_OK;
1151 else {
1152 FIXME("ExtTextOut returned:=%d\n", hr);
1153 return hr;
1157 /***********************************************************************
1158 * ScriptCacheGetHeight (USP10.@)
1160 * Retrieve the height of the font in the cache.
1162 * PARAMS
1163 * hdc [I] Device context.
1164 * psc [I/O] Opaque pointer to a script cache.
1165 * height [O] Receives font height.
1167 * RETURNS
1168 * Success: S_OK
1169 * Failure: Non-zero HRESULT value.
1171 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, long *height)
1173 HDC phdc;
1174 Scriptcache *pScriptcache;
1175 TEXTMETRICW metric;
1177 TRACE("(%p, %p, %p)\n", hdc, psc, height);
1179 if (!psc || !height)
1180 return E_INVALIDARG;
1182 if (!hdc) return E_PENDING;
1184 if (!*psc) {
1185 pScriptcache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Scriptcache));
1186 pScriptcache->hdc = hdc;
1187 phdc = hdc;
1188 *psc = pScriptcache;
1189 } else {
1190 pScriptcache = *psc;
1191 phdc = pScriptcache->hdc;
1194 /* FIXME: get this from the cache */
1195 if (!GetTextMetricsW(phdc, &metric))
1196 return E_INVALIDARG;
1198 *height = metric.tmHeight;
1199 return S_OK;
1202 /***********************************************************************
1203 * ScriptGetGlyphABCWidth (USP10.@)
1205 * Retrieve the width of a glyph.
1207 * PARAMS
1208 * hdc [I] Device context.
1209 * psc [I/O] Opaque pointer to a script cache.
1210 * glyph [I] Glyph to retrieve the width for.
1211 * abc [O] ABC widths of the glyph.
1213 * RETURNS
1214 * Success: S_OK
1215 * Failure: Non-zero HRESULT value.
1217 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
1219 HDC phdc;
1220 Scriptcache *pScriptcache;
1222 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
1224 if (!psc)
1225 return E_INVALIDARG;
1227 if (!hdc) return E_PENDING;
1229 if (!*psc) {
1230 pScriptcache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Scriptcache));
1231 pScriptcache->hdc = hdc;
1232 phdc = hdc;
1233 *psc = pScriptcache;
1234 } else {
1235 pScriptcache = *psc;
1236 phdc = pScriptcache->hdc;
1239 /* FIXME: get this from the cache */
1240 if (!GetCharABCWidthsW(phdc, glyph, glyph, abc))
1241 return E_HANDLE;
1243 return S_OK;
1246 /***********************************************************************
1247 * ScriptLayout (USP10.@)
1249 * Map embedding levels to visual and/or logical order.
1251 * PARAMS
1252 * runs [I] Size of level array.
1253 * level [I] Array of embedding levels.
1254 * vistolog [O] Map of embedding levels from visual to logical order.
1255 * logtovis [O] Map of embedding levels from logical to visual order.
1257 * RETURNS
1258 * Success: S_OK
1259 * Failure: Non-zero HRESULT value.
1261 * BUGS
1262 * This stub works correctly for any sequence of a single
1263 * embedding level but not for sequences of different
1264 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1266 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
1268 int i, j = runs - 1, k = 0;
1270 FIXME("(%d, %p, %p, %p): stub\n", runs, level, vistolog, logtovis);
1272 if (!level || (!vistolog && !logtovis))
1273 return E_INVALIDARG;
1275 for (i = 0; i < runs; i++)
1277 if (level[i] % 2)
1279 if (vistolog) *vistolog++ = j;
1280 if (logtovis) *logtovis++ = j;
1281 j--;
1283 else
1285 if (vistolog) *vistolog++ = k;
1286 if (logtovis) *logtovis++ = k;
1287 k++;
1290 return S_OK;
1293 /***********************************************************************
1294 * ScriptStringValidate (USP10.@)
1296 * Validate a string analysis.
1298 * PARAMS
1299 * ssa [I] string analysis.
1301 * RETURNS
1302 * Success: S_OK
1303 * Failure: S_FALSE if invalid sequences are found
1304 * or a non-zero HRESULT if it fails.
1306 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
1308 FIXME("(%p): stub\n", ssa);
1309 return S_OK;