ole32/tests: Mark the draw_continue callbacks as optional. Win9x can skip calls under...
[wine/wine-gecko.git] / dlls / usp10 / usp10.c
blob65f6d2c4321842ec1d7ebd3dc5288f4a0532ee7c
1 /*
2 * Implementation of Uniscribe Script Processor (usp10.dll)
4 * Copyright 2005 Steven Edwards for CodeWeavers
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Notes:
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
27 #include <stdarg.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "usp10.h"
36 #include "usp10_internal.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
43 typedef struct _scriptRange
45 WORD script;
46 WORD rangeFirst;
47 WORD rangeLast;
48 WORD numericScript;
49 WORD punctScript;
50 } scriptRange;
52 static const scriptRange scriptRanges[] = {
53 /* Basic Latin: U+0000–U+007A */
54 /* Latin-1 Supplement: U+0080–U+00FF */
55 /* Latin Extended-A: U+0100–U+017F */
56 /* Latin Extended-B: U+0180–U+024F */
57 /* IPA Extensions: U+0250–U+02AF */
58 { Script_Latin, 0x00, 0x2af , Script_Numeric, Script_Punctuation},
59 /* Greek: U+0370–U+03FF */
60 { Script_Greek, 0x370, 0x3ff, 0, 0},
61 /* Cyrillic: U+0400–U+04FF */
62 /* Cyrillic Supplement: U+0500–U+052F */
63 { Script_Cyrillic, 0x400, 0x52f, 0, 0},
64 /* Armenian: U+0530–U+058F */
65 { Script_Armenian, 0x530, 0x58f, 0, 0},
66 /* Hebrew: U+0590–U+05FF */
67 { Script_Hebrew, 0x590, 0x5ff, 0, 0},
68 /* Arabic: U+0600–U+06FF */
69 { Script_Arabic, 0x600, 0x6ef, Script_Arabic_Numeric, 0},
70 /* Defined by Windows */
71 { Script_Persian, 0x6f0, 0x6f9, 0, 0},
72 /* Continue Arabic: U+0600–U+06FF */
73 { Script_Arabic, 0x6fa, 0x6ff, 0, 0},
74 /* Syriac: U+0700–U+074F*/
75 { Script_Syriac, 0x700, 0x74f, 0, 0},
76 /* Arabic Supplement: U+0750–U+077F */
77 { Script_Arabic, 0x750, 0x77f, 0, 0},
78 /* Thaana: U+0780–U+07BF */
79 { Script_Thaana, 0x780, 0x7bf, 0, 0},
80 /* Sinhala: U+0D80–U+0DFF */
81 { Script_Sinhala, 0xd80, 0xdff, 0, 0},
82 /* Thai: U+0E00–U+0E7F */
83 { Script_Thai, 0xe00, 0xe7f, Script_Thai_Numeric, 0},
84 /* Lao: U+0E80–U+0EFF */
85 { Script_Lao, 0xe80, 0xeff, Script_Lao_Numeric, 0},
86 /* Tibetan: U+0F00–U+0FFF */
87 { Script_Tibetan, 0xf00, 0xfff, Script_Tibetan_Numeric, 0},
88 /* Georgian: U+10A0–U+10FF */
89 { Script_Georgian, 0x10a0, 0x10ff, 0, 0},
90 /* Phonetic Extensions: U+1D00–U+1DBF */
91 { Script_Latin, 0x1d00, 0x1dbf, 0, 0},
92 /* Latin Extended Additional: U+1E00–U+1EFF */
93 { Script_Latin, 0x1e00, 0x1eff, 0, 0},
94 /* Greek Extended: U+1F00–U+1FFF */
95 { Script_Greek, 0x1f00, 0x1fff, 0, 0},
96 /* Latin Extended-C: U+2C60–U+2C7F */
97 { Script_Latin, 0x2c60, 0x2c7f, 0, 0},
98 /* Georgian: U+2D00–U+2D2F */
99 { Script_Georgian, 0x2d00, 0x2d2f, 0, 0},
100 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
101 { Script_Cyrillic, 0x2de0, 0x2dff, 0, 0},
102 /* Cyrillic Extended-B: U+A640–U+A69F */
103 { Script_Cyrillic, 0xa640, 0xa69f, 0, 0},
104 /* Modifier Tone Letters: U+A700–U+A71F */
105 /* Latin Extended-D: U+A720–U+A7FF */
106 { Script_Latin, 0xa700, 0xa7ff, 0, 0},
107 /* Phags-pa: U+A840–U+A87F */
108 { Script_Phags_pa, 0xa840, 0xa87f, 0, 0},
109 /* Latin Ligatures: U+FB00–U+FB06 */
110 { Script_Latin, 0xfb00, 0xfb06, 0, 0},
111 /* Armenian ligatures U+FB13..U+FB17 */
112 { Script_Armenian, 0xfb13, 0xfb17, 0, 0},
113 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
114 { Script_Hebrew, 0xfb1d, 0xfb4f, 0, 0},
115 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
116 { Script_Arabic, 0xfb50, 0xfdff, 0, 0},
117 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
118 { Script_Arabic, 0xfe70, 0xfeff, 0, 0},
119 /* END */
120 { SCRIPT_UNDEFINED, 0, 0, 0}
123 typedef struct _scriptData
125 SCRIPT_ANALYSIS a;
126 SCRIPT_PROPERTIES props;
127 } scriptData;
129 /* the must be in order so that the index matches the Script value */
130 static const scriptData scriptInformation[] = {
131 {{SCRIPT_UNDEFINED, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
132 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
133 {{Script_Latin, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
134 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0}},
135 {{Script_CR, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
136 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
137 {{Script_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
138 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
139 {{Script_Control, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
140 {LANG_ENGLISH, 0, 1, 0, 0, ANSI_CHARSET, 1, 0, 0, 0, 0, 0, 1, 0, 0}},
141 {{Script_Punctuation, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
142 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
143 {{Script_Arabic, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
144 {LANG_ARABIC, 0, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 1, 0}},
145 {{Script_Arabic_Numeric, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
146 {LANG_ARABIC, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0}},
147 {{Script_Hebrew, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
148 {LANG_HEBREW, 0, 1, 0, 1, HEBREW_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
149 {{Script_Syriac, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
150 {LANG_SYRIAC, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 1, 0}},
151 {{Script_Persian, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
152 {LANG_PERSIAN, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
153 {{Script_Thaana, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
154 {LANG_DIVEHI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
155 {{Script_Greek, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
156 {LANG_GREEK, 0, 0, 0, 0, GREEK_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
157 {{Script_Cyrillic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
158 {LANG_RUSSIAN, 0, 0, 0, 0, RUSSIAN_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
159 {{Script_Armenian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
160 {LANG_ARMENIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0}},
161 {{Script_Georgian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
162 {LANG_GEORGIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0}},
163 {{Script_Sinhala, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
164 {LANG_SINHALESE, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
165 {{Script_Tibetan, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
166 {LANG_TIBETAN, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0}},
167 {{Script_Tibetan_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
168 {LANG_TIBETAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
169 {{Script_Phags_pa, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
170 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
171 {{Script_Thai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
172 {LANG_THAI, 0, 1, 1, 1, THAI_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 1}},
173 {{Script_Thai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
174 {LANG_THAI, 1, 1, 0, 0, THAI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
175 {{Script_Lao, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
176 {LANG_LAO, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0}},
177 {{Script_Lao_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
178 {LANG_LAO, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
181 static const SCRIPT_PROPERTIES *script_props[] =
183 &scriptInformation[0].props, &scriptInformation[1].props,
184 &scriptInformation[2].props, &scriptInformation[3].props,
185 &scriptInformation[4].props, &scriptInformation[5].props,
186 &scriptInformation[6].props, &scriptInformation[7].props,
187 &scriptInformation[8].props, &scriptInformation[9].props,
188 &scriptInformation[10].props, &scriptInformation[11].props,
189 &scriptInformation[12].props, &scriptInformation[13].props,
190 &scriptInformation[14].props, &scriptInformation[15].props,
191 &scriptInformation[16].props, &scriptInformation[17].props,
192 &scriptInformation[18].props, &scriptInformation[19].props,
193 &scriptInformation[20].props, &scriptInformation[21].props,
194 &scriptInformation[22].props, &scriptInformation[23].props
197 typedef struct {
198 int numGlyphs;
199 WORD* glyphs;
200 WORD* pwLogClust;
201 int* piAdvance;
202 SCRIPT_VISATTR* psva;
203 GOFFSET* pGoffset;
204 ABC* abc;
205 } StringGlyphs;
207 typedef struct {
208 HDC hdc;
209 BOOL invalid;
210 int clip_len;
211 ScriptCache *sc;
212 int cItems;
213 int cMaxGlyphs;
214 SCRIPT_ITEM* pItem;
215 int numItems;
216 StringGlyphs* glyphs;
217 SCRIPT_LOGATTR* logattrs;
218 SIZE* sz;
219 } StringAnalysis;
221 static inline void *heap_alloc(SIZE_T size)
223 return HeapAlloc(GetProcessHeap(), 0, size);
226 static inline void *heap_alloc_zero(SIZE_T size)
228 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
231 static inline void *heap_realloc_zero(LPVOID mem, SIZE_T size)
233 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
236 static inline BOOL heap_free(LPVOID mem)
238 return HeapFree(GetProcessHeap(), 0, mem);
241 static inline WCHAR get_cache_default_char(SCRIPT_CACHE *psc)
243 return ((ScriptCache *)*psc)->tm.tmDefaultChar;
246 static inline LONG get_cache_height(SCRIPT_CACHE *psc)
248 return ((ScriptCache *)*psc)->tm.tmHeight;
251 static inline BYTE get_cache_pitch_family(SCRIPT_CACHE *psc)
253 return ((ScriptCache *)*psc)->tm.tmPitchAndFamily;
256 static inline WORD get_cache_glyph(SCRIPT_CACHE *psc, WCHAR c)
258 WORD *block = ((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
260 if (!block) return 0;
261 return block[c & GLYPH_BLOCK_MASK];
264 static inline WORD set_cache_glyph(SCRIPT_CACHE *psc, WCHAR c, WORD glyph)
266 WORD **block = &((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
268 if (!*block && !(*block = heap_alloc_zero(sizeof(WORD) * GLYPH_BLOCK_SIZE))) return 0;
269 return ((*block)[c & GLYPH_BLOCK_MASK] = glyph);
272 static inline BOOL get_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
274 static const ABC nil;
275 ABC *block = ((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
277 if (!block || !memcmp(&block[glyph & GLYPH_BLOCK_MASK], &nil, sizeof(ABC))) return FALSE;
278 memcpy(abc, &block[glyph & GLYPH_BLOCK_MASK], sizeof(ABC));
279 return TRUE;
282 static inline BOOL set_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
284 ABC **block = &((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
286 if (!*block && !(*block = heap_alloc_zero(sizeof(ABC) * GLYPH_BLOCK_SIZE))) return FALSE;
287 memcpy(&(*block)[glyph & GLYPH_BLOCK_MASK], abc, sizeof(ABC));
288 return TRUE;
291 static HRESULT init_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
293 ScriptCache *sc;
295 if (!psc) return E_INVALIDARG;
296 if (*psc) return S_OK;
297 if (!hdc) return E_PENDING;
299 if (!(sc = heap_alloc_zero(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
300 if (!GetTextMetricsW(hdc, &sc->tm))
302 heap_free(sc);
303 return E_INVALIDARG;
305 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(LOGFONTW), &sc->lf))
307 heap_free(sc);
308 return E_INVALIDARG;
310 *psc = sc;
311 TRACE("<- %p\n", sc);
312 return S_OK;
315 static WCHAR mirror_char( WCHAR ch )
317 extern const WCHAR wine_mirror_map[];
318 return ch + wine_mirror_map[wine_mirror_map[ch >> 8] + (ch & 0xff)];
321 static WORD get_char_script( WCHAR ch)
323 WORD type = 0;
324 int i;
326 if (ch == 0xc || ch == 0x20 || ch == 0x202f)
327 return Script_CR;
329 GetStringTypeW(CT_CTYPE1, &ch, 1, &type);
331 if (type == 0)
332 return SCRIPT_UNDEFINED;
334 if (type & C1_CNTRL)
335 return Script_Control;
337 i = 0;
340 if (ch < scriptRanges[i].rangeFirst || scriptRanges[i].script == SCRIPT_UNDEFINED)
341 break;
343 if (ch >= scriptRanges[i].rangeFirst && ch <= scriptRanges[i].rangeLast)
345 if (scriptRanges[i].numericScript && type & C1_DIGIT)
346 return scriptRanges[i].numericScript;
347 if (scriptRanges[i].punctScript && type & C1_PUNCT)
348 return scriptRanges[i].punctScript;
349 return scriptRanges[i].script;
351 i++;
352 } while (1);
354 return SCRIPT_UNDEFINED;
357 /***********************************************************************
358 * DllMain
361 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
363 switch(fdwReason)
365 case DLL_PROCESS_ATTACH:
366 DisableThreadLibraryCalls(hInstDLL);
367 break;
368 case DLL_PROCESS_DETACH:
369 break;
371 return TRUE;
374 /***********************************************************************
375 * ScriptFreeCache (USP10.@)
377 * Free a script cache.
379 * PARAMS
380 * psc [I/O] Script cache.
382 * RETURNS
383 * Success: S_OK
384 * Failure: Non-zero HRESULT value.
386 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
388 TRACE("%p\n", psc);
390 if (psc && *psc)
392 unsigned int i;
393 for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++)
395 heap_free(((ScriptCache *)*psc)->glyphs[i]);
396 heap_free(((ScriptCache *)*psc)->widths[i]);
398 heap_free(((ScriptCache *)*psc)->GSUB_Table);
399 heap_free(((ScriptCache *)*psc)->features);
400 heap_free(*psc);
401 *psc = NULL;
403 return S_OK;
406 /***********************************************************************
407 * ScriptGetProperties (USP10.@)
409 * Retrieve a list of script properties.
411 * PARAMS
412 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
413 * num [I] Pointer to the number of scripts.
415 * RETURNS
416 * Success: S_OK
417 * Failure: Non-zero HRESULT value.
419 * NOTES
420 * Behaviour matches WinXP.
422 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
424 TRACE("(%p,%p)\n", props, num);
426 if (!props && !num) return E_INVALIDARG;
428 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
429 if (props) *props = script_props;
431 return S_OK;
434 /***********************************************************************
435 * ScriptGetFontProperties (USP10.@)
437 * Get information on special glyphs.
439 * PARAMS
440 * hdc [I] Device context.
441 * psc [I/O] Opaque pointer to a script cache.
442 * sfp [O] Font properties structure.
444 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
446 HRESULT hr;
448 TRACE("%p,%p,%p\n", hdc, psc, sfp);
450 if (!sfp) return E_INVALIDARG;
451 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
453 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
454 return E_INVALIDARG;
456 /* return something sensible? */
457 sfp->wgBlank = 0;
458 sfp->wgDefault = get_cache_default_char(psc);
459 sfp->wgInvalid = 0;
460 sfp->wgKashida = 0xffff;
461 sfp->iKashidaWidth = 0;
463 return S_OK;
466 /***********************************************************************
467 * ScriptRecordDigitSubstitution (USP10.@)
469 * Record digit substitution settings for a given locale.
471 * PARAMS
472 * locale [I] Locale identifier.
473 * sds [I] Structure to record substitution settings.
475 * RETURNS
476 * Success: S_OK
477 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
479 * SEE ALSO
480 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
482 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
484 DWORD plgid, sub;
486 TRACE("0x%x, %p\n", locale, sds);
488 /* This implementation appears to be correct for all languages, but it's
489 * not clear if sds->DigitSubstitute is ever set to anything except
490 * CONTEXT or NONE in reality */
492 if (!sds) return E_POINTER;
494 locale = ConvertDefaultLocale(locale);
496 if (!IsValidLocale(locale, LCID_INSTALLED))
497 return E_INVALIDARG;
499 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
500 sds->TraditionalDigitLanguage = plgid;
502 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
503 sds->NationalDigitLanguage = plgid;
504 else
505 sds->NationalDigitLanguage = LANG_ENGLISH;
507 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
508 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
510 switch (sub)
512 case 0:
513 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
514 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
515 else
516 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
517 break;
518 case 1:
519 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
520 break;
521 case 2:
522 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
523 break;
524 default:
525 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
526 break;
529 sds->dwReserved = 0;
530 return S_OK;
533 /***********************************************************************
534 * ScriptApplyDigitSubstitution (USP10.@)
536 * Apply digit substitution settings.
538 * PARAMS
539 * sds [I] Structure with recorded substitution settings.
540 * sc [I] Script control structure.
541 * ss [I] Script state structure.
543 * RETURNS
544 * Success: S_OK
545 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
547 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
548 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
550 SCRIPT_DIGITSUBSTITUTE psds;
552 TRACE("%p, %p, %p\n", sds, sc, ss);
554 if (!sc || !ss) return E_POINTER;
555 if (!sds)
557 sds = &psds;
558 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
559 return E_INVALIDARG;
562 sc->uDefaultLanguage = LANG_ENGLISH;
563 sc->fContextDigits = 0;
564 ss->fDigitSubstitute = 0;
566 switch (sds->DigitSubstitute) {
567 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
568 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
569 case SCRIPT_DIGITSUBSTITUTE_NONE:
570 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
571 return S_OK;
572 default:
573 return E_INVALIDARG;
577 /***********************************************************************
578 * ScriptItemize (USP10.@)
580 * Split a Unicode string into shapeable parts.
582 * PARAMS
583 * pwcInChars [I] String to split.
584 * cInChars [I] Number of characters in pwcInChars.
585 * cMaxItems [I] Maximum number of items to return.
586 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
587 * psState [I] Pointer to a SCRIPT_STATE structure.
588 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
589 * pcItems [O] Number of script items returned.
591 * RETURNS
592 * Success: S_OK
593 * Failure: Non-zero HRESULT value.
595 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
596 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
597 SCRIPT_ITEM *pItems, int *pcItems)
600 #define Numeric_space 0x0020
602 int cnt = 0, index = 0, str = 0;
603 int New_Script = SCRIPT_UNDEFINED;
604 WORD *levels = NULL;
605 WORD *strength = NULL;
606 WORD baselevel = 0;
608 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
609 psControl, psState, pItems, pcItems);
611 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
612 return E_INVALIDARG;
614 if (psState && psControl)
616 int i;
617 levels = heap_alloc_zero(cInChars * sizeof(WORD));
618 if (!levels)
619 return E_OUTOFMEMORY;
621 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels);
622 baselevel = levels[0];
623 for (i = 0; i < cInChars; i++)
624 if (levels[i]!=levels[0])
625 break;
626 if (i >= cInChars && !odd(baselevel))
628 heap_free(levels);
629 levels = NULL;
631 else
633 if (!psControl->fMergeNeutralItems)
635 strength = heap_alloc_zero(cInChars * sizeof(WORD));
636 BIDI_GetStrengths(pwcInChars, cInChars, psControl, strength);
641 while (pwcInChars[cnt] == Numeric_space && cnt < cInChars)
642 cnt++;
644 if (cnt == cInChars) /* All Spaces */
646 cnt = 0;
647 New_Script = get_char_script(pwcInChars[cnt]);
650 pItems[index].iCharPos = 0;
651 pItems[index].a = scriptInformation[get_char_script(pwcInChars[cnt])].a;
653 if (strength)
654 str = strength[cnt];
656 cnt = 0;
657 if (levels)
659 pItems[index].a.fRTL = odd(levels[cnt]);
660 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
661 pItems[index].a.s.uBidiLevel = levels[cnt];
663 else if (!pItems[index].a.s.uBidiLevel)
665 pItems[index].a.s.uBidiLevel = baselevel;
666 pItems[index].a.fLayoutRTL = odd(baselevel);
667 pItems[index].a.fRTL = odd(baselevel);
670 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
671 levels?levels[cnt]:-1, str, New_Script, pItems[index].a.eScript, index, cnt,
672 pItems[index].iCharPos);
674 for (cnt=1; cnt < cInChars; cnt++)
676 if (levels && (levels[cnt] == pItems[index].a.s.uBidiLevel && (!strength || (strength[cnt] == 0 || strength[cnt] == str))))
677 continue;
679 if(pwcInChars[cnt] != Numeric_space)
680 New_Script = get_char_script(pwcInChars[cnt]);
681 else if (levels)
683 int j = 1;
684 while (cnt + j < cInChars - 1 && pwcInChars[cnt+j] == Numeric_space)
685 j++;
686 New_Script = get_char_script(pwcInChars[cnt+j]);
689 if ((levels && (levels[cnt] != pItems[index].a.s.uBidiLevel || (strength && (strength[cnt] != str)))) || New_Script != pItems[index].a.eScript || New_Script == Script_Control)
691 TRACE("New_Level = %i, New_Strength = %i, New_Script=%d, eScript=%d\n", levels?levels[cnt]:-1, strength?strength[cnt]:str, New_Script, pItems[index].a.eScript);
693 if (strength && strength[cnt] != 0)
694 str = strength[cnt];
696 index++;
697 if (index+1 > cMaxItems)
698 return E_OUTOFMEMORY;
700 pItems[index].iCharPos = cnt;
701 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
703 pItems[index].a = scriptInformation[New_Script].a;
704 if (levels)
706 pItems[index].a.fRTL = odd(levels[cnt]);
707 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
708 pItems[index].a.s.uBidiLevel = levels[cnt];
710 else if (!pItems[index].a.s.uBidiLevel)
712 pItems[index].a.s.uBidiLevel = baselevel;
713 pItems[index].a.fLayoutRTL = odd(baselevel);
714 pItems[index].a.fRTL = odd(baselevel);
717 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
721 /* While not strictly necessary according to the spec, make sure the n+1
722 * item is set up to prevent random behaviour if the caller erroneously
723 * checks the n+1 structure */
724 index++;
725 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
727 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
729 /* Set one SCRIPT_STATE item being returned */
730 if (index + 1 > cMaxItems) return E_OUTOFMEMORY;
731 if (pcItems) *pcItems = index;
733 /* Set SCRIPT_ITEM */
734 pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */
735 heap_free(levels);
736 heap_free(strength);
737 return S_OK;
740 /***********************************************************************
741 * ScriptStringAnalyse (USP10.@)
744 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
745 int cGlyphs, int iCharset, DWORD dwFlags,
746 int iReqWidth, SCRIPT_CONTROL *psControl,
747 SCRIPT_STATE *psState, const int *piDx,
748 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
749 SCRIPT_STRING_ANALYSIS *pssa)
751 HRESULT hr = E_OUTOFMEMORY;
752 StringAnalysis *analysis = NULL;
753 int i, num_items = 255;
755 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
756 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
757 psControl, psState, piDx, pTabdef, pbInClass, pssa);
759 if (iCharset != -1)
761 FIXME("Only Unicode strings are supported\n");
762 return E_INVALIDARG;
764 if (cString < 1 || !pString) return E_INVALIDARG;
765 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
767 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
768 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
770 /* FIXME: handle clipping */
771 analysis->clip_len = cString;
772 analysis->hdc = hdc;
774 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
775 &analysis->numItems);
777 while (hr == E_OUTOFMEMORY)
779 SCRIPT_ITEM *tmp;
781 num_items *= 2;
782 if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
783 goto error;
785 analysis->pItem = tmp;
786 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
787 &analysis->numItems);
789 if (hr != S_OK) goto error;
791 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
792 ScriptBreak(pString, cString, (SCRIPT_STRING_ANALYSIS)analysis, analysis->logattrs);
793 else
794 goto error;
796 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
797 goto error;
799 for (i = 0; i < analysis->numItems; i++)
801 SCRIPT_CACHE *sc = (SCRIPT_CACHE *)&analysis->sc;
802 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
803 int numGlyphs = 1.5 * cChar + 16;
804 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
805 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
806 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
807 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * cChar);
808 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
809 ABC *abc = heap_alloc_zero(sizeof(ABC));
810 int numGlyphsReturned;
812 /* FIXME: non unicode strings */
813 const WCHAR* pStr = (const WCHAR*)pString;
814 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
815 cChar, numGlyphs, &analysis->pItem[i].a,
816 glyphs, pwLogClust, psva, &numGlyphsReturned);
817 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
818 piAdvance, pGoffset, abc);
820 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
821 analysis->glyphs[i].glyphs = glyphs;
822 analysis->glyphs[i].pwLogClust = pwLogClust;
823 analysis->glyphs[i].piAdvance = piAdvance;
824 analysis->glyphs[i].psva = psva;
825 analysis->glyphs[i].pGoffset = pGoffset;
826 analysis->glyphs[i].abc = abc;
829 *pssa = analysis;
830 return S_OK;
832 error:
833 heap_free(analysis->glyphs);
834 heap_free(analysis->logattrs);
835 heap_free(analysis->pItem);
836 heap_free(analysis->sc);
837 heap_free(analysis);
838 return hr;
841 /***********************************************************************
842 * ScriptStringOut (USP10.@)
844 * This function takes the output of ScriptStringAnalyse and joins the segments
845 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
846 * only processes glyphs.
848 * Parameters:
849 * ssa [I] buffer to hold the analysed string components
850 * iX [I] X axis displacement for output
851 * iY [I] Y axis displacement for output
852 * uOptions [I] flags controling output processing
853 * prc [I] rectangle coordinates
854 * iMinSel [I] starting pos for substringing output string
855 * iMaxSel [I] ending pos for substringing output string
856 * fDisabled [I] controls text highlighting
858 * RETURNS
859 * Success: S_OK
860 * Failure: is the value returned by ScriptTextOut
862 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
863 int iX,
864 int iY,
865 UINT uOptions,
866 const RECT *prc,
867 int iMinSel,
868 int iMaxSel,
869 BOOL fDisabled)
871 StringAnalysis *analysis;
872 WORD *glyphs;
873 int item, cnt, x;
874 HRESULT hr;
876 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
877 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
879 if (!(analysis = ssa)) return E_INVALIDARG;
882 * Get storage for the output buffer for the consolidated strings
884 cnt = 0;
885 for (item = 0; item < analysis->numItems; item++)
887 cnt += analysis->glyphs[item].numGlyphs;
889 if (!(glyphs = heap_alloc(sizeof(WCHAR) * cnt))) return E_OUTOFMEMORY;
892 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
894 uOptions |= ETO_GLYPH_INDEX;
895 analysis->pItem[0].a.fNoGlyphIndex = FALSE; /* say that we have glyphs */
898 * Copy the string items into the output buffer
901 TRACE("numItems %d\n", analysis->numItems);
903 cnt = 0;
904 for (item = 0; item < analysis->numItems; item++)
906 memcpy(&glyphs[cnt], analysis->glyphs[item].glyphs,
907 sizeof(WCHAR) * analysis->glyphs[item].numGlyphs);
909 TRACE("Item %d, Glyphs %d ", item, analysis->glyphs[item].numGlyphs);
910 for (x = cnt; x < analysis->glyphs[item].numGlyphs + cnt; x ++)
911 TRACE("%04x", glyphs[x]);
912 TRACE("\n");
914 cnt += analysis->glyphs[item].numGlyphs; /* point to the end of the copied text */
917 hr = ScriptTextOut(analysis->hdc, (SCRIPT_CACHE *)&analysis->sc, iX, iY,
918 uOptions, prc, &analysis->pItem->a, NULL, 0, glyphs, cnt,
919 analysis->glyphs->piAdvance, NULL, analysis->glyphs->pGoffset);
920 TRACE("ScriptTextOut hr=%08x\n", hr);
923 * Free the output buffer and script cache
925 heap_free(glyphs);
926 return hr;
929 /***********************************************************************
930 * ScriptStringCPtoX (USP10.@)
933 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
935 int i, j;
936 int runningX = 0;
937 int runningCp = 0;
938 StringAnalysis* analysis = ssa;
940 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
942 if (!ssa || !pX) return S_FALSE;
944 /* icp out of range */
945 if(icp < 0)
947 analysis->invalid = TRUE;
948 return E_INVALIDARG;
951 for(i=0; i<analysis->numItems; i++)
953 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
955 if(runningCp == icp && fTrailing == FALSE)
957 *pX = runningX;
958 return S_OK;
960 runningX += analysis->glyphs[i].piAdvance[j];
961 if(runningCp == icp && fTrailing == TRUE)
963 *pX = runningX;
964 return S_OK;
966 runningCp++;
970 /* icp out of range */
971 analysis->invalid = TRUE;
972 return E_INVALIDARG;
975 /***********************************************************************
976 * ScriptStringXtoCP (USP10.@)
979 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
981 StringAnalysis* analysis = ssa;
982 int i;
983 int j;
984 int runningX = 0;
985 int runningCp = 0;
986 int width;
988 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
990 if (!ssa || !piCh || !piTrailing) return S_FALSE;
992 /* out of range */
993 if(iX < 0)
995 *piCh = -1;
996 *piTrailing = TRUE;
997 return S_OK;
1000 for(i=0; i<analysis->numItems; i++)
1002 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
1004 width = analysis->glyphs[i].piAdvance[j];
1005 if(iX < (runningX + width))
1007 *piCh = runningCp;
1008 if((iX - runningX) > width/2)
1009 *piTrailing = TRUE;
1010 else
1011 *piTrailing = FALSE;
1012 return S_OK;
1014 runningX += width;
1015 runningCp++;
1019 /* out of range */
1020 *piCh = analysis->pItem[analysis->numItems].iCharPos;
1021 *piTrailing = FALSE;
1023 return S_OK;
1027 /***********************************************************************
1028 * ScriptStringFree (USP10.@)
1030 * Free a string analysis.
1032 * PARAMS
1033 * pssa [I] string analysis.
1035 * RETURNS
1036 * Success: S_OK
1037 * Failure: Non-zero HRESULT value.
1039 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
1041 StringAnalysis* analysis;
1042 BOOL invalid;
1043 int i;
1045 TRACE("(%p)\n", pssa);
1047 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
1049 invalid = analysis->invalid;
1050 ScriptFreeCache((SCRIPT_CACHE *)&analysis->sc);
1052 for (i = 0; i < analysis->numItems; i++)
1054 heap_free(analysis->glyphs[i].glyphs);
1055 heap_free(analysis->glyphs[i].pwLogClust);
1056 heap_free(analysis->glyphs[i].piAdvance);
1057 heap_free(analysis->glyphs[i].psva);
1058 heap_free(analysis->glyphs[i].pGoffset);
1059 heap_free(analysis->glyphs[i].abc);
1062 heap_free(analysis->glyphs);
1063 heap_free(analysis->pItem);
1064 heap_free(analysis->logattrs);
1065 heap_free(analysis->sz);
1066 heap_free(analysis->sc);
1067 heap_free(analysis);
1069 if (invalid) return E_INVALIDARG;
1070 return S_OK;
1073 /***********************************************************************
1074 * ScriptCPtoX (USP10.@)
1077 HRESULT WINAPI ScriptCPtoX(int iCP,
1078 BOOL fTrailing,
1079 int cChars,
1080 int cGlyphs,
1081 const WORD *pwLogClust,
1082 const SCRIPT_VISATTR *psva,
1083 const int *piAdvance,
1084 const SCRIPT_ANALYSIS *psa,
1085 int *piX)
1087 int item;
1088 int iPosX;
1089 float fMaxPosX = 0;
1090 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
1091 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1092 psa, piX);
1093 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1094 fMaxPosX += piAdvance[item];
1095 iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing);
1096 if (iPosX > fMaxPosX)
1097 iPosX = fMaxPosX;
1098 *piX = iPosX; /* Return something in range */
1100 TRACE("*piX=%d\n", *piX);
1101 return S_OK;
1104 /***********************************************************************
1105 * ScriptXtoCP (USP10.@)
1108 HRESULT WINAPI ScriptXtoCP(int iX,
1109 int cChars,
1110 int cGlyphs,
1111 const WORD *pwLogClust,
1112 const SCRIPT_VISATTR *psva,
1113 const int *piAdvance,
1114 const SCRIPT_ANALYSIS *psa,
1115 int *piCP,
1116 int *piTrailing)
1118 int item;
1119 int iPosX;
1120 float fMaxPosX = 1;
1121 float fAvePosX;
1122 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1123 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1124 psa, piCP, piTrailing);
1125 if (iX < 0) /* iX is before start of run */
1127 *piCP = -1;
1128 *piTrailing = TRUE;
1129 return S_OK;
1132 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1133 fMaxPosX += piAdvance[item];
1135 if (iX >= fMaxPosX) /* iX too large */
1137 *piCP = cChars;
1138 *piTrailing = FALSE;
1139 return S_OK;
1142 fAvePosX = fMaxPosX / cGlyphs;
1143 iPosX = fAvePosX;
1144 for (item = 1; item < cGlyphs && iPosX < iX; item++)
1145 iPosX += fAvePosX;
1146 if (iPosX - iX > fAvePosX/2)
1147 *piTrailing = 0;
1148 else
1149 *piTrailing = 1; /* yep we are over halfway */
1151 *piCP = item -1; /* Return character position */
1152 TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX);
1153 return S_OK;
1156 /***********************************************************************
1157 * ScriptBreak (USP10.@)
1159 * Retrieve line break information.
1161 * PARAMS
1162 * chars [I] Array of characters.
1163 * sa [I] String analysis.
1164 * la [I] Array of logical attribute structures.
1166 * RETURNS
1167 * Success: S_OK
1168 * Failure: S_FALSE
1170 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
1172 int i;
1174 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
1176 if (!la) return S_FALSE;
1178 for (i = 0; i < count; i++)
1180 memset(&la[i], 0, sizeof(SCRIPT_LOGATTR));
1182 /* FIXME: set the other flags */
1183 la[i].fWhiteSpace = (chars[i] == ' ');
1184 la[i].fCharStop = 1;
1186 if (i > 0 && la[i - 1].fWhiteSpace)
1188 la[i].fSoftBreak = 1;
1189 la[i].fWordStop = 1;
1192 return S_OK;
1195 /***********************************************************************
1196 * ScriptIsComplex (USP10.@)
1198 * Determine if a string is complex.
1200 * PARAMS
1201 * chars [I] Array of characters to test.
1202 * len [I] Length in characters.
1203 * flag [I] Flag.
1205 * RETURNS
1206 * Success: S_OK
1207 * Failure: S_FALSE
1210 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
1212 int i;
1214 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
1216 for (i = 0; i < len; i++)
1218 int script;
1220 if ((flag & SIC_ASCIIDIGIT) && chars[i] >= 0x30 && chars[i] <= 0x39)
1221 return S_OK;
1223 script = get_char_script(chars[i]);
1224 if ((scriptInformation[script].props.fComplex && (flag & SIC_COMPLEX))||
1225 (!scriptInformation[script].props.fComplex && (flag & SIC_NEUTRAL)))
1226 return S_OK;
1228 return S_FALSE;
1231 /***********************************************************************
1232 * ScriptShape (USP10.@)
1234 * Produce glyphs and visual attributes for a run.
1236 * PARAMS
1237 * hdc [I] Device context.
1238 * psc [I/O] Opaque pointer to a script cache.
1239 * pwcChars [I] Array of characters specifying the run.
1240 * cChars [I] Number of characters in pwcChars.
1241 * cMaxGlyphs [I] Length of pwOutGlyphs.
1242 * psa [I/O] Script analysis.
1243 * pwOutGlyphs [O] Array of glyphs.
1244 * pwLogClust [O] Array of logical cluster info.
1245 * psva [O] Array of visual attributes.
1246 * pcGlyphs [O] Number of glyphs returned.
1248 * RETURNS
1249 * Success: S_OK
1250 * Failure: Non-zero HRESULT value.
1252 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
1253 int cChars, int cMaxGlyphs,
1254 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
1255 SCRIPT_VISATTR *psva, int *pcGlyphs)
1257 HRESULT hr;
1258 unsigned int i;
1259 BOOL rtl;
1261 TRACE("(%p, %p, %s, %d, %d, %p, %p, %p, %p, %p)\n", hdc, psc, debugstr_wn(pwcChars, cChars),
1262 cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs);
1264 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
1265 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
1267 if (!psva || !pcGlyphs) return E_INVALIDARG;
1268 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
1269 rtl = (!psa->fLogicalOrder && psa->fRTL);
1271 *pcGlyphs = cChars;
1272 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1273 if (!pwLogClust) return E_FAIL;
1275 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
1276 for (i = 0; i < cChars; i++)
1278 int idx = i;
1279 if (rtl) idx = cChars - 1 - i;
1280 /* FIXME: set to better values */
1281 psva[i].uJustification = (pwcChars[idx] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER;
1282 psva[i].fClusterStart = 1;
1283 psva[i].fDiacritic = 0;
1284 psva[i].fZeroWidth = 0;
1285 psva[i].fReserved = 0;
1286 psva[i].fShapeReserved = 0;
1288 pwLogClust[i] = idx;
1291 if (!psa->fNoGlyphIndex)
1293 WCHAR *rChars;
1294 if ((hr = SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa)) != S_OK) return hr;
1296 rChars = heap_alloc(sizeof(WCHAR) * cChars);
1297 if (!rChars) return E_OUTOFMEMORY;
1298 for (i = 0; i < cChars; i++)
1300 int idx = i;
1301 WCHAR chInput;
1302 if (rtl) idx = cChars - 1 - i;
1303 if (psa->fRTL)
1304 chInput = mirror_char(pwcChars[idx]);
1305 else
1306 chInput = pwcChars[idx];
1307 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, chInput)))
1309 WORD glyph;
1310 if (!hdc) return E_PENDING;
1311 if (GetGlyphIndicesW(hdc, &chInput, 1, &glyph, 0) == GDI_ERROR) return S_FALSE;
1312 pwOutGlyphs[i] = set_cache_glyph(psc, chInput, glyph);
1314 rChars[i] = chInput;
1317 if (get_cache_pitch_family(psc) & TMPF_TRUETYPE)
1319 SHAPE_ContextualShaping(hdc, (ScriptCache *)*psc, psa, rChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
1320 SHAPE_ApplyDefaultOpentypeFeatures(hdc, (ScriptCache *)*psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, pwLogClust);
1322 heap_free(rChars);
1324 else
1326 TRACE("no glyph translation\n");
1327 for (i = 0; i < cChars; i++)
1329 int idx = i;
1330 /* No mirroring done here */
1331 if (rtl) idx = cChars - 1 - i;
1332 pwOutGlyphs[i] = pwcChars[idx];
1336 return S_OK;
1339 /***********************************************************************
1340 * ScriptPlace (USP10.@)
1342 * Produce advance widths for a run.
1344 * PARAMS
1345 * hdc [I] Device context.
1346 * psc [I/O] Opaque pointer to a script cache.
1347 * pwGlyphs [I] Array of glyphs.
1348 * cGlyphs [I] Number of glyphs in pwGlyphs.
1349 * psva [I] Array of visual attributes.
1350 * psa [I/O] String analysis.
1351 * piAdvance [O] Array of advance widths.
1352 * pGoffset [O] Glyph offsets.
1353 * pABC [O] Combined ABC width.
1355 * RETURNS
1356 * Success: S_OK
1357 * Failure: Non-zero HRESULT value.
1359 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
1360 int cGlyphs, const SCRIPT_VISATTR *psva,
1361 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
1363 HRESULT hr;
1364 int i;
1366 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa,
1367 piAdvance, pGoffset, pABC);
1369 if (!psva) return E_INVALIDARG;
1370 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1371 if (!pGoffset) return E_FAIL;
1373 if (pABC) memset(pABC, 0, sizeof(ABC));
1374 for (i = 0; i < cGlyphs; i++)
1376 ABC abc;
1377 if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc))
1379 if (!hdc) return E_PENDING;
1380 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
1382 if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE;
1384 else
1386 INT width;
1387 if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE;
1388 abc.abcB = width;
1389 abc.abcA = abc.abcC = 0;
1391 set_cache_glyph_widths(psc, pwGlyphs[i], &abc);
1393 if (pABC)
1395 pABC->abcA += abc.abcA;
1396 pABC->abcB += abc.abcB;
1397 pABC->abcC += abc.abcC;
1399 /* FIXME: set to more reasonable values */
1400 pGoffset[i].du = pGoffset[i].dv = 0;
1401 if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC;
1404 if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
1405 return S_OK;
1408 /***********************************************************************
1409 * ScriptGetCMap (USP10.@)
1411 * Retrieve glyph indices.
1413 * PARAMS
1414 * hdc [I] Device context.
1415 * psc [I/O] Opaque pointer to a script cache.
1416 * pwcInChars [I] Array of Unicode characters.
1417 * cChars [I] Number of characters in pwcInChars.
1418 * dwFlags [I] Flags.
1419 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1421 * RETURNS
1422 * Success: S_OK
1423 * Failure: Non-zero HRESULT value.
1425 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
1426 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
1428 HRESULT hr;
1429 int i;
1431 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
1432 cChars, dwFlags, pwOutGlyphs);
1434 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1436 hr = S_OK;
1438 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1440 for (i = 0; i < cChars; i++)
1442 WCHAR inChar;
1443 if (dwFlags == SGCM_RTL)
1444 inChar = mirror_char(pwcInChars[i]);
1445 else
1446 inChar = pwcInChars[i];
1447 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, inChar)))
1449 WORD glyph;
1450 if (!hdc) return E_PENDING;
1451 if (GetGlyphIndicesW(hdc, &inChar, 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE;
1452 if (glyph == 0xffff)
1454 hr = S_FALSE;
1455 glyph = 0x0;
1457 pwOutGlyphs[i] = set_cache_glyph(psc, inChar, glyph);
1461 else
1463 TRACE("no glyph translation\n");
1464 for (i = 0; i < cChars; i++)
1466 WCHAR inChar;
1467 if (dwFlags == SGCM_RTL)
1468 inChar = mirror_char(pwcInChars[i]);
1469 else
1470 inChar = pwcInChars[i];
1471 pwOutGlyphs[i] = inChar;
1474 return hr;
1477 /***********************************************************************
1478 * ScriptTextOut (USP10.@)
1481 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
1482 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
1483 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
1484 const int *piJustify, const GOFFSET *pGoffset)
1486 HRESULT hr = S_OK;
1488 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1489 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
1490 piAdvance, piJustify, pGoffset);
1492 if (!hdc || !psc) return E_INVALIDARG;
1493 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
1495 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
1496 fuOptions |= ETO_IGNORELANGUAGE;
1497 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
1498 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
1500 if (psa->fRTL && psa->fLogicalOrder)
1502 int i;
1503 WORD *rtlGlyphs;
1505 rtlGlyphs = heap_alloc(cGlyphs * sizeof(WORD));
1506 if (!rtlGlyphs)
1507 return E_OUTOFMEMORY;
1509 for (i = 0; i < cGlyphs; i++)
1510 rtlGlyphs[i] = pwGlyphs[cGlyphs-1-i];
1512 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, rtlGlyphs, cGlyphs, NULL))
1513 hr = S_FALSE;
1514 heap_free(rtlGlyphs);
1516 else
1517 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
1518 hr = S_FALSE;
1520 return hr;
1523 /***********************************************************************
1524 * ScriptCacheGetHeight (USP10.@)
1526 * Retrieve the height of the font in the cache.
1528 * PARAMS
1529 * hdc [I] Device context.
1530 * psc [I/O] Opaque pointer to a script cache.
1531 * height [O] Receives font height.
1533 * RETURNS
1534 * Success: S_OK
1535 * Failure: Non-zero HRESULT value.
1537 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
1539 HRESULT hr;
1541 TRACE("(%p, %p, %p)\n", hdc, psc, height);
1543 if (!height) return E_INVALIDARG;
1544 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1546 *height = get_cache_height(psc);
1547 return S_OK;
1550 /***********************************************************************
1551 * ScriptGetGlyphABCWidth (USP10.@)
1553 * Retrieve the width of a glyph.
1555 * PARAMS
1556 * hdc [I] Device context.
1557 * psc [I/O] Opaque pointer to a script cache.
1558 * glyph [I] Glyph to retrieve the width for.
1559 * abc [O] ABC widths of the glyph.
1561 * RETURNS
1562 * Success: S_OK
1563 * Failure: Non-zero HRESULT value.
1565 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
1567 HRESULT hr;
1569 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
1571 if (!abc) return E_INVALIDARG;
1572 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1574 if (!get_cache_glyph_widths(psc, glyph, abc))
1576 if (!hdc) return E_PENDING;
1577 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1579 if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE;
1581 else
1583 INT width;
1584 if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE;
1585 abc->abcB = width;
1586 abc->abcA = abc->abcC = 0;
1588 set_cache_glyph_widths(psc, glyph, abc);
1590 return S_OK;
1593 /***********************************************************************
1594 * ScriptLayout (USP10.@)
1596 * Map embedding levels to visual and/or logical order.
1598 * PARAMS
1599 * runs [I] Size of level array.
1600 * level [I] Array of embedding levels.
1601 * vistolog [O] Map of embedding levels from visual to logical order.
1602 * logtovis [O] Map of embedding levels from logical to visual order.
1604 * RETURNS
1605 * Success: S_OK
1606 * Failure: Non-zero HRESULT value.
1608 * BUGS
1609 * This stub works correctly for any sequence of a single
1610 * embedding level but not for sequences of different
1611 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1613 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
1615 int* indexs;
1616 int ich;
1618 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
1620 if (!level || (!vistolog && !logtovis))
1621 return E_INVALIDARG;
1623 indexs = heap_alloc(sizeof(int) * runs);
1624 if (!indexs)
1625 return E_OUTOFMEMORY;
1628 if (vistolog)
1630 for( ich = 0; ich < runs; ich++)
1631 indexs[ich] = ich;
1633 ich = 0;
1634 while (ich < runs)
1635 ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1636 for (ich = 0; ich < runs; ich++)
1637 vistolog[ich] = indexs[ich];
1641 if (logtovis)
1643 for( ich = 0; ich < runs; ich++)
1644 indexs[ich] = ich;
1646 ich = 0;
1647 while (ich < runs)
1648 ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1649 for (ich = 0; ich < runs; ich++)
1650 logtovis[ich] = indexs[ich];
1652 heap_free(indexs);
1654 return S_OK;
1657 /***********************************************************************
1658 * ScriptStringGetLogicalWidths (USP10.@)
1660 * Returns logical widths from a string analysis.
1662 * PARAMS
1663 * ssa [I] string analysis.
1664 * piDx [O] logical widths returned.
1666 * RETURNS
1667 * Success: S_OK
1668 * Failure: a non-zero HRESULT.
1670 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
1672 int i, j, next = 0;
1673 StringAnalysis *analysis = ssa;
1675 TRACE("%p, %p\n", ssa, piDx);
1677 if (!analysis) return S_FALSE;
1679 for (i = 0; i < analysis->numItems; i++)
1681 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1683 piDx[next] = analysis->glyphs[i].piAdvance[j];
1684 next++;
1687 return S_OK;
1690 /***********************************************************************
1691 * ScriptStringValidate (USP10.@)
1693 * Validate a string analysis.
1695 * PARAMS
1696 * ssa [I] string analysis.
1698 * RETURNS
1699 * Success: S_OK
1700 * Failure: S_FALSE if invalid sequences are found
1701 * or a non-zero HRESULT if it fails.
1703 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
1705 StringAnalysis *analysis = ssa;
1707 TRACE("(%p)\n", ssa);
1709 if (!analysis) return E_INVALIDARG;
1710 return (analysis->invalid) ? S_FALSE : S_OK;
1713 /***********************************************************************
1714 * ScriptString_pSize (USP10.@)
1716 * Retrieve width and height of an analysed string.
1718 * PARAMS
1719 * ssa [I] string analysis.
1721 * RETURNS
1722 * Success: Pointer to a SIZE structure.
1723 * Failure: NULL
1725 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
1727 int i, j;
1728 StringAnalysis *analysis = ssa;
1730 TRACE("(%p)\n", ssa);
1732 if (!analysis) return NULL;
1734 if (!analysis->sz)
1736 if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL;
1737 analysis->sz->cy = analysis->sc->tm.tmHeight;
1739 analysis->sz->cx = 0;
1740 for (i = 0; i < analysis->numItems; i++)
1741 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1742 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
1744 return analysis->sz;
1747 /***********************************************************************
1748 * ScriptString_pLogAttr (USP10.@)
1750 * Retrieve logical attributes of an analysed string.
1752 * PARAMS
1753 * ssa [I] string analysis.
1755 * RETURNS
1756 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
1757 * Failure: NULL
1759 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
1761 StringAnalysis *analysis = ssa;
1763 TRACE("(%p)\n", ssa);
1765 if (!analysis) return NULL;
1766 return analysis->logattrs;
1769 /***********************************************************************
1770 * ScriptString_pcOutChars (USP10.@)
1772 * Retrieve the length of a string after clipping.
1774 * PARAMS
1775 * ssa [I] String analysis.
1777 * RETURNS
1778 * Success: Pointer to the length.
1779 * Failure: NULL
1781 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
1783 StringAnalysis *analysis = ssa;
1785 TRACE("(%p)\n", ssa);
1787 if (!analysis) return NULL;
1788 return &analysis->clip_len;
1791 /***********************************************************************
1792 * ScriptStringGetOrder (USP10.@)
1794 * Retrieve a glyph order map.
1796 * PARAMS
1797 * ssa [I] String analysis.
1798 * order [I/O] Array of glyph positions.
1800 * RETURNS
1801 * Success: S_OK
1802 * Failure: a non-zero HRESULT.
1804 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
1806 int i, j;
1807 unsigned int k;
1808 StringAnalysis *analysis = ssa;
1810 TRACE("(%p)\n", ssa);
1812 if (!analysis) return S_FALSE;
1814 /* FIXME: handle RTL scripts */
1815 for (i = 0, k = 0; i < analysis->numItems; i++)
1816 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
1817 order[k] = k;
1819 return S_OK;
1822 /***********************************************************************
1823 * ScriptGetLogicalWidths (USP10.@)
1825 * Convert advance widths to logical widths.
1827 * PARAMS
1828 * sa [I] Script analysis.
1829 * nbchars [I] Number of characters.
1830 * nbglyphs [I] Number of glyphs.
1831 * glyph_width [I] Array of glyph widths.
1832 * log_clust [I] Array of logical clusters.
1833 * sva [I] Visual attributes.
1834 * widths [O] Array of logical widths.
1836 * RETURNS
1837 * Success: S_OK
1838 * Failure: a non-zero HRESULT.
1840 HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs,
1841 const int *glyph_width, const WORD *log_clust,
1842 const SCRIPT_VISATTR *sva, int *widths)
1844 int i;
1846 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
1847 sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths);
1849 /* FIXME */
1850 for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i];
1851 return S_OK;
1854 /***********************************************************************
1855 * ScriptApplyLogicalWidth (USP10.@)
1857 * Generate glyph advance widths.
1859 * PARAMS
1860 * dx [I] Array of logical advance widths.
1861 * num_chars [I] Number of characters.
1862 * num_glyphs [I] Number of glyphs.
1863 * log_clust [I] Array of logical clusters.
1864 * sva [I] Visual attributes.
1865 * advance [I] Array of glyph advance widths.
1866 * sa [I] Script analysis.
1867 * abc [I/O] Summed ABC widths.
1868 * justify [O] Array of glyph advance widths.
1870 * RETURNS
1871 * Success: S_OK
1872 * Failure: a non-zero HRESULT.
1874 HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs,
1875 const WORD *log_clust, const SCRIPT_VISATTR *sva,
1876 const int *advance, const SCRIPT_ANALYSIS *sa,
1877 ABC *abc, int *justify)
1879 int i;
1881 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
1882 dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify);
1884 for (i = 0; i < num_chars; i++) justify[i] = advance[i];
1885 return S_OK;
1888 HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance,
1889 int num_glyphs, int dx, int min_kashida, int *justify)
1891 int i;
1893 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify);
1895 for (i = 0; i < num_glyphs; i++) justify[i] = advance[i];
1896 return S_OK;