1 /*
2  * Tests for usp10 dll
3  *
4  * Copyright 2006 Jeff Latimer
5  * Copyright 2006 Hans Leidekker
6  * Copyright 2010 CodeWeavers, Aric Stewart
7  *
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.
12  *
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.
17  *
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
21  *
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.
25  */
26 
27 #include <assert.h>
28 #include <stdio.h>
29 
30 #include <wine/test.h>
31 #include <windows.h>
32 #include <usp10.h>
33 
34 #ifndef ARRAY_SIZE
35 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
36 #endif
37 
38 typedef struct _itemTest {
39     char todo_flag[6];
40     int iCharPos;
41     int fRTL;
42     int fLayoutRTL;
43     int uBidiLevel;
44     int fOverrideDirection;
45     ULONG scriptTag;
46     BOOL isBroken;
47     int broken_value[6];
48 } itemTest;
49 
50 typedef struct _shapeTest_char {
51     WORD wLogClust;
52     SCRIPT_CHARPROP CharProp;
53 } shapeTest_char;
54 
55 typedef struct _shapeTest_glyph {
56     int Glyph;
57     SCRIPT_GLYPHPROP GlyphProp;
58 } shapeTest_glyph;
59 
60 typedef struct _font_fingerprint {
61     WCHAR check[10];
62     WORD result[10];
63 } font_fingerprint;
64 
65 /* Uniscribe 1.6 calls */
66 static HRESULT (WINAPI *pScriptItemizeOpenType)( const WCHAR *pwcInChars, int cInChars, int cMaxItems, const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState, SCRIPT_ITEM *pItems, ULONG *pScriptTags, int *pcItems);
67 
68 static HRESULT (WINAPI *pScriptShapeOpenType)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys, int *rcRangeChars, TEXTRANGE_PROPERTIES **rpRangeProperties, int cRanges, const WCHAR *pwcChars, int cChars, int cMaxGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProps, WORD *pwOutGlyphs, SCRIPT_GLYPHPROP *pOutGlyphProps, int *pcGlyphs);
69 
70 static HRESULT (WINAPI *pScriptGetFontScriptTags)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags);
71 static HRESULT (WINAPI *pScriptGetFontLanguageTags)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, int cMaxTags, OPENTYPE_TAG *pLangSysTags, int *pcTags);
72 static HRESULT (WINAPI *pScriptGetFontFeatureTags)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys, int cMaxTags, OPENTYPE_TAG *pFeatureTags, int *pcTags);
73 
74 static inline void _test_items_ok(LPCWSTR string, DWORD cchString,
75                          SCRIPT_CONTROL *Control, SCRIPT_STATE *State,
76                          DWORD nItems, const itemTest* items, BOOL nItemsToDo,
77                          const INT nItemsBroken[2])
78 {
79     HRESULT hr;
80     int x, outnItems;
81     SCRIPT_ITEM outpItems[15];
82     ULONG tags[15] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
83 
84     if (pScriptItemizeOpenType)
85         hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
86     else
87         hr = ScriptItemize(string, cchString, 15, Control, State, outpItems, &outnItems);
88 
89     winetest_ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
90     if (nItemsBroken && (broken(nItemsBroken[0] == outnItems) || broken(nItemsBroken[1] == outnItems)))
91     {
92         winetest_win_skip("This test broken on this platform: nitems %d\n", outnItems);
93         return;
94     }
95     todo_wine_if (nItemsToDo)
96         winetest_ok(outnItems == nItems, "Wrong number of items (%u)\n", outnItems);
97     outnItems = min(outnItems, nItems);
98     for (x = 0; x <= outnItems; x++)
99     {
100         if (items[x].isBroken && broken(outpItems[x].iCharPos == items[x].broken_value[0]))
101             winetest_win_skip("This test broken on this platform: item %d CharPos %d\n", x, outpItems[x].iCharPos);
102         else todo_wine_if (items[x].todo_flag[0])
103             winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos (%i)\n",x,outpItems[x].iCharPos);
104 
105         if (items[x].isBroken && broken(outpItems[x].a.fRTL== items[x].broken_value[1]))
106             winetest_win_skip("This test broken on this platform: item %d fRTL %d\n", x, outpItems[x].a.fRTL);
107         else todo_wine_if (items[x].todo_flag[1])
108             winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL(%i)\n",x,outpItems[x].a.fRTL);
109 
110         if (items[x].isBroken && broken(outpItems[x].a.fLayoutRTL == items[x].broken_value[2]))
111             winetest_win_skip("This test broken on this platform: item %d fLayoutRTL %d\n", x, outpItems[x].a.fLayoutRTL);
112         else todo_wine_if (items[x].todo_flag[2])
113             winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL(%i)\n",x,outpItems[x].a.fLayoutRTL);
114 
115         if (items[x].isBroken && broken(outpItems[x].a.s.uBidiLevel == items[x].broken_value[3]))
116             winetest_win_skip("This test broken on this platform: item %d BidiLevel %d\n", x, outpItems[x].a.s.uBidiLevel);
117         else todo_wine_if (items[x].todo_flag[3])
118             winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel(%i)\n",x,outpItems[x].a.s.uBidiLevel);
119 
120         if (items[x].isBroken && broken(outpItems[x].a.s.fOverrideDirection == items[x].broken_value[4]))
121             winetest_win_skip("This test broken on this platform: item %d fOverrideDirection %d\n", x, outpItems[x].a.s.fOverrideDirection);
122         else todo_wine_if (items[x].todo_flag[4])
123             winetest_ok(outpItems[x].a.s.fOverrideDirection == items[x].fOverrideDirection, "%i:Wrong fOverrideDirection(%i)\n",x,outpItems[x].a.s.fOverrideDirection);
124 
125         if (x != outnItems)
126             winetest_ok(outpItems[x].a.eScript != SCRIPT_UNDEFINED, "%i: Undefined script\n",x);
127         if (pScriptItemizeOpenType)
128         {
129             if (items[x].isBroken && broken(tags[x] == items[x].broken_value[5]))
130                 winetest_win_skip("This test broken on this platform: item %d Script Tag %x\n", x, tags[x]);
131             else todo_wine_if (items[x].todo_flag[5])
132                 winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
133         }
134 
135     }
136 }
137 
138 #define test_items_ok(a,b,c,d,e,f,g,h) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_items_ok(a,b,c,d,e,f,g,h)
139 
140 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
141           ( ( (ULONG)_x4 << 24 ) |     \
142             ( (ULONG)_x3 << 16 ) |     \
143             ( (ULONG)_x2 <<  8 ) |     \
144               (ULONG)_x1         )
145 
146 #define latn_tag MS_MAKE_TAG('l','a','t','n')
147 #define arab_tag MS_MAKE_TAG('a','r','a','b')
148 #define thai_tag MS_MAKE_TAG('t','h','a','i')
149 #define hebr_tag MS_MAKE_TAG('h','e','b','r')
150 #define syrc_tag MS_MAKE_TAG('s','y','r','c')
151 #define thaa_tag MS_MAKE_TAG('t','h','a','a')
152 #define deva_tag MS_MAKE_TAG('d','e','v','a')
153 #define beng_tag MS_MAKE_TAG('b','e','n','g')
154 #define guru_tag MS_MAKE_TAG('g','u','r','u')
155 #define gujr_tag MS_MAKE_TAG('g','u','j','r')
156 #define orya_tag MS_MAKE_TAG('o','r','y','a')
157 #define taml_tag MS_MAKE_TAG('t','a','m','l')
158 #define telu_tag MS_MAKE_TAG('t','e','l','u')
159 #define knda_tag MS_MAKE_TAG('k','n','d','a')
160 #define mlym_tag MS_MAKE_TAG('m','l','y','m')
161 #define mymr_tag MS_MAKE_TAG('m','y','m','r')
162 #define tale_tag MS_MAKE_TAG('t','a','l','e')
163 #define talu_tag MS_MAKE_TAG('t','a','l','u')
164 #define khmr_tag MS_MAKE_TAG('k','h','m','r')
165 #define hani_tag MS_MAKE_TAG('h','a','n','i')
166 #define bopo_tag MS_MAKE_TAG('b','o','p','o')
167 #define kana_tag MS_MAKE_TAG('k','a','n','a')
168 #define hang_tag MS_MAKE_TAG('h','a','n','g')
169 #define yi_tag MS_MAKE_TAG('y','i',' ',' ')
170 #define ethi_tag MS_MAKE_TAG('e','t','h','i')
171 #define mong_tag MS_MAKE_TAG('m','o','n','g')
172 #define tfng_tag MS_MAKE_TAG('t','f','n','g')
173 #define nko_tag MS_MAKE_TAG('n','k','o',' ')
174 #define vai_tag MS_MAKE_TAG('v','a','i',' ')
175 #define cher_tag MS_MAKE_TAG('c','h','e','r')
176 #define cans_tag MS_MAKE_TAG('c','a','n','s')
177 #define ogam_tag MS_MAKE_TAG('o','g','a','m')
178 #define runr_tag MS_MAKE_TAG('r','u','n','r')
179 #define brai_tag MS_MAKE_TAG('b','r','a','i')
180 #define dsrt_tag MS_MAKE_TAG('d','s','r','t')
181 #define osma_tag MS_MAKE_TAG('o','s','m','a')
182 #define math_tag MS_MAKE_TAG('m','a','t','h')
183 
184 static void test_ScriptItemize( void )
185 {
186     static const WCHAR test1[] = {'t', 'e', 's', 't',0};
187     static const itemTest t11[2] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1}};
188     static const itemTest t12[2] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
189 
190     static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
191     static const itemTest t1b1[2] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
192     static const itemTest t1b2[2] = {{{0,0,0,0,0,0},0,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
193 
194     static const WCHAR test1c[] = {' ', ' ', ' ', '1', '2', ' ',0};
195     static const itemTest t1c1[2] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
196     static const itemTest t1c2[4] = {{{0,0,0,0,0,0},0,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},3,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},5,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
197 
198     /* Arabic, English*/
199     static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
200     static const itemTest t21[7] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},15,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
201     static const itemTest t22[5] = {{{0,0,0,0,0,0},0,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},15,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
202     static const itemTest t23[5] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},15,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
203     static const itemTest t24[5] = {{{0,0,0,0,0,0},0,0,0,0,1,0,FALSE},
204                                 {{0,0,0,0,0,0},6,0,0,0,1,arab_tag,FALSE},
205                                 {{0,0,0,0,0,0},13,0,1,0,1,0,FALSE},
206                                 {{0,0,0,0,0,0},15,0,0,0,1,0,FALSE},
207                                 {{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
208 
209     static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
210     static const itemTest t2b1[5] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},8,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
211     static const itemTest t2b2[5] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
212     static const itemTest t2b3[3] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
213     static const itemTest t2b4[5] = {{{0,0,0,0,0,0},0,0,0,0,1,latn_tag,FALSE},
214                                     {{0,0,0,0,0,0},3,0,0,0,1,0,FALSE},
215                                     {{0,0,0,0,0,0},4,0,0,0,1,latn_tag,FALSE},
216                                     {{0,0,0,0,0,0},8,0,0,0,1,arab_tag,FALSE},
217                                     {{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
218     static const int b2[2] = {4,4};
219 
220     /* leading space */
221     static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
222     static const itemTest t2c1[5] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
223     static const itemTest t2c2[6] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},1,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
224     static const itemTest t2c3[5] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},8,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
225     static const itemTest t2c4[3] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
226     static const itemTest t2c5[5] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},
227                                     {{0,0,0,0,0,0},4,0,0,0,1,latn_tag,FALSE},
228                                     {{0,0,0,0,0,0},7,0,0,0,1,0,FALSE},
229                                     {{0,0,0,0,0,0},8,0,0,0,1,latn_tag,FALSE},
230                                     {{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
231 
232     /* trailing space */
233     static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
234     static const itemTest t2d1[5] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
235     static const itemTest t2d2[6] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
236     static const itemTest t2d3[5] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
237     static const itemTest t2d4[3] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
238     static const itemTest t2d5[5] = {{{0,0,0,0,0,0},0,0,0,0,1,latn_tag,FALSE},
239                                 {{0,0,0,0,0,0},3,0,0,0,1,0,FALSE},
240                                 {{0,0,0,0,0,0},4,0,0,0,1,latn_tag,FALSE},
241                                 {{0,0,0,0,0,0},7,0,0,0,1,arab_tag,FALSE},
242                                 {{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
243 
244     /* Thai */
245     static const WCHAR test3[] =
246 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
247 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
248 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
249  0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
250 
251     static const itemTest t31[2] = {{{0,0,0,0,0,0},0,0,0,0,0,thai_tag,FALSE},{{0,0,0,0,0,0},41,0,0,0,0,-1,FALSE}};
252     static const itemTest t32[2] = {{{0,0,0,0,0,0},0,0,0,2,0,thai_tag,FALSE},{{0,0,0,0,0,0},41,0,0,0,0,-1,FALSE}};
253 
254     static const WCHAR test4[]  = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
255 
256     static const itemTest t41[6] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
257     static const itemTest t42[5] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},7,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},10,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
258     static const itemTest t43[4] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},7,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
259     static const int b43[2] = {4,4};
260 
261     /* Arabic */
262     static const WCHAR test5[] = {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
263                                   0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
264                                   0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644,
265                                   0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
266     static const itemTest t51[2] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},38,0,0,0,0,-1,FALSE}};
267     static const itemTest t52[2] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},
268                                     {{0,0,0,0,0,0},38,0,0,0,0,-1,FALSE}};
269 
270 
271     /* Hebrew */
272     static const WCHAR test6[]  = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
273     static const itemTest t61[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,TRUE,{-1,0,0,0,-1,-1}},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
274     static const itemTest t62[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},4,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
275     static const itemTest t63[2] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
276     static const itemTest t64[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
277                                 {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
278                                 {{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
279 
280     static const int b63[2] = {2,2};
281     static const WCHAR test7[]  = {'p','a','r','t',' ','o','n','e',' ',0x05d7, 0x05dc, 0x05e7, ' ', 0x05e9, 0x05ea, 0x05d9, 0x05d9, 0x05dd, ' ','p','a','r','t',' ','t','h','r','e','e', 0};
282     static const itemTest t71[4] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},9,1,1,1,0,hebr_tag,TRUE,{-1,0,0,0,-1,-1}},{{0,0,0,0,0,0},19,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
283     static const itemTest t72[4] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},9,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},18,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
284     static const itemTest t73[4] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},8,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},19,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
285     static const itemTest t74[4] = {{{0,0,0,0,0,0},0,0,0,0,1,latn_tag,FALSE},
286                                 {{0,0,0,0,0,0},9,0,0,0,1,hebr_tag,FALSE},
287                                 {{0,0,0,0,0,0},19,0,0,0,1,latn_tag,FALSE},
288                                 {{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
289 
290     static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
291     static const itemTest t81[2] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
292     static const itemTest t82[2] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},
293                                     {{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
294 
295     /* Syriac  (Like Arabic )*/
296     static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
297     static const itemTest t91[3] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
298     static const itemTest t92[3] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag},{{0,0,0,0,0,0},4,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
299     static const itemTest t93[2] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
300     static const itemTest t94[3] = {{{0,0,0,0,0,0},0,0,0,0,1,syrc_tag,FALSE},
301                                     {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
302                                     {{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
303     static const int b93[2] = {2,2};
304 
305     static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
306     static const itemTest t101[2] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
307     static const itemTest t102[2] = {{{0,0,0,0,0,0},0,0,0,0,1,syrc_tag,FALSE},
308                                      {{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
309 
310     /* Devanagari */
311     static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
312     static const itemTest t111[2] = {{{0,0,0,0,0,0},0,0,0,0,0,deva_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
313     static const itemTest t112[2] = {{{0,0,0,0,0,0},0,0,0,2,0,deva_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
314 
315     /* Bengali */
316     static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
317     static const itemTest t121[2] = {{{0,0,0,0,0,0},0,0,0,0,0,beng_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
318     static const itemTest t122[2] = {{{0,0,0,0,0,0},0,0,0,2,0,beng_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
319 
320     /* Gurmukhi */
321     static const WCHAR test13[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
322     static const itemTest t131[2] = {{{0,0,0,0,0,0},0,0,0,0,0,guru_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
323     static const itemTest t132[2] = {{{0,0,0,0,0,0},0,0,0,2,0,guru_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
324 
325     /* Gujarati */
326     static const WCHAR test14[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
327     static const itemTest t141[2] = {{{0,0,0,0,0,0},0,0,0,0,0,gujr_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
328     static const itemTest t142[2] = {{{0,0,0,0,0,0},0,0,0,2,0,gujr_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
329 
330     /* Oriya */
331     static const WCHAR test15[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
332     static const itemTest t151[2] = {{{0,0,0,0,0,0},0,0,0,0,0,orya_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
333     static const itemTest t152[2] = {{{0,0,0,0,0,0},0,0,0,2,0,orya_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
334 
335     /* Tamil */
336     static const WCHAR test16[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
337     static const itemTest t161[2] = {{{0,0,0,0,0,0},0,0,0,0,0,taml_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
338     static const itemTest t162[2] = {{{0,0,0,0,0,0},0,0,0,2,0,taml_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
339 
340     /* Telugu */
341     static const WCHAR test17[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
342     static const itemTest t171[2] = {{{0,0,0,0,0,0},0,0,0,0,0,telu_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
343     static const itemTest t172[2] = {{{0,0,0,0,0,0},0,0,0,2,0,telu_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
344 
345     /* Kannada */
346     static const WCHAR test18[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
347     static const itemTest t181[2] = {{{0,0,0,0,0,0},0,0,0,0,0,knda_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
348     static const itemTest t182[2] = {{{0,0,0,0,0,0},0,0,0,2,0,knda_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
349 
350     /* Malayalam */
351     static const WCHAR test19[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
352     static const itemTest t191[2] = {{{0,0,0,0,0,0},0,0,0,0,0,mlym_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
353     static const itemTest t192[2] = {{{0,0,0,0,0,0},0,0,0,2,0,mlym_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
354 
355     /* Diacritical */
356     static const WCHAR test20[] = {0x0309,'a','b','c','d',0};
357     static const itemTest t201[3] = {{{0,0,0,0,0,0},0,0,0,0,0x0,0,FALSE},{{0,0,0,0,0,0},1,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
358     static const itemTest t202[3] = {{{0,0,0,0,0,0},0,0,0,2,0,0,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},1,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
359 
360     static const WCHAR test21[] = {0x0710, 0x0712, 0x0308, 0x0712, 0x0714,0};
361     static const itemTest t211[2] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
362     static const itemTest t212[2] = {{{0,0,0,0,0,0},0,0,0,0,1,syrc_tag,FALSE},
363                                      {{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
364 
365     /* Latin Punctuation */
366     static const WCHAR test22[] = {'#','$',',','!','\"','*',0};
367     static const itemTest t221[3] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
368     static const itemTest t222[3] = {{{0,0,0,0,0,0},0,1,1,1,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
369     static const itemTest t223[2] = {{{0,0,0,0,0,0},0,1,1,1,0,latn_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
370     static const int b222[2] = {1,1};
371     static const int b223[2] = {2,2};
372 
373     /* Number 2*/
374     static const WCHAR test23[] = {'1','2','3',0x00b2,0x00b3,0x2070,0};
375     static const itemTest t231[3] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
376     static const itemTest t232[3] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},3,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
377 
378     /* Myanmar */
379     static const WCHAR test24[] = {0x1019,0x103c,0x1014,0x103a,0x1019,0x102c,0x1021,0x1000,0x1039,0x1001,0x101b,0x102c};
380     static const itemTest t241[2] = {{{0,0,0,0,0,0},0,0,0,0,0,mymr_tag,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
381     static const itemTest t242[2] = {{{0,0,0,0,0,0},0,0,0,2,0,mymr_tag,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
382 
383     /* Tai Le */
384     static const WCHAR test25[] = {0x1956,0x196d,0x1970,0x1956,0x196c,0x1973,0x1951,0x1968,0x1952,0x1970};
385     static const itemTest t251[2] = {{{0,0,0,0,0,0},0,0,0,0,0,tale_tag,TRUE,{-1,-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
386     static const itemTest t252[2] = {{{0,0,0,0,0,0},0,0,0,2,0,tale_tag,TRUE,{-1,1,1,1,-1,latn_tag}},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
387 
388     /* New Tai Lue */
389     static const WCHAR test26[] = {0x1992,0x19c4};
390     static const itemTest t261[2] = {{{0,0,0,0,0,0},0,0,0,0,0,talu_tag,TRUE,{-1,-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
391     static const itemTest t262[2] = {{{0,0,0,0,0,0},0,0,0,2,0,talu_tag,TRUE,{-1,1,1,1,-1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
392 
393     /* Khmer */
394     static const WCHAR test27[] = {0x1781,0x17c1,0x1798,0x179a,0x1797,0x17b6,0x179f,0x17b6};
395     static const itemTest t271[2] = {{{0,0,0,0,0,0},0,0,0,0,0,khmr_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
396     static const itemTest t272[2] = {{{0,0,0,0,0,0},0,0,0,2,0,khmr_tag,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
397 
398     /* CJK Han */
399     static const WCHAR test28[] = {0x8bed,0x7d20,0x6587,0x5b57};
400     static const itemTest t281[2] = {{{0,0,0,0,0,0},0,0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
401     static const itemTest t282[2] = {{{0,0,0,0,0,0},0,0,0,2,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
402 
403     /* Ideographic */
404     static const WCHAR test29[] = {0x2ff0,0x2ff3,0x2ffb,0x2ff0,0x65e5,0x65e5,0x5de5,0x7f51,0x4e02,0x4e5e};
405     static const itemTest t291[3] = {{{0,0,0,0,0,0},0,0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
406     static const itemTest t292[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,hani_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
407 
408     /* Bopomofo */
409     static const WCHAR test30[] = {0x3113,0x3128,0x3127,0x3123,0x3108,0x3128,0x310f,0x3120};
410     static const itemTest t301[2] = {{{0,0,0,0,0,0},0,0,0,0,0,bopo_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
411     static const itemTest t302[2] = {{{0,0,0,0,0,0},0,0,0,2,0,bopo_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
412 
413     /* Kana */
414     static const WCHAR test31[] = {0x3072,0x3089,0x304b,0x306a,0x30ab,0x30bf,0x30ab,0x30ca};
415     static const itemTest t311[2] = {{{0,0,0,0,0,0},0,0,0,0,0,kana_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
416     static const itemTest t312[2] = {{{0,0,0,0,0,0},0,0,0,2,0,kana_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
417     static const int b311[2] = {2,2};
418     static const int b312[2] = {2,2};
419 
420     /* Hangul */
421     static const WCHAR test32[] = {0xd55c,0xad6d,0xc5b4};
422     static const itemTest t321[2] = {{{0,0,0,0,0,0},0,0,0,0,0,hang_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
423     static const itemTest t322[2] = {{{0,0,0,0,0,0},0,0,0,2,0,hang_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
424 
425     /* Yi */
426     static const WCHAR test33[] = {0xa188,0xa320,0xa071,0xa0b7};
427     static const itemTest t331[2] = {{{0,0,0,0,0,0},0,0,0,0,0,yi_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
428     static const itemTest t332[2] = {{{0,0,0,0,0,0},0,0,0,2,0,yi_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
429 
430     /* Ethiopic */
431     static const WCHAR test34[] = {0x130d,0x12d5,0x12dd};
432     static const itemTest t341[2] = {{{0,0,0,0,0,0},0,0,0,0,0,ethi_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
433     static const itemTest t342[2] = {{{0,0,0,0,0,0},0,0,0,2,0,ethi_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
434     static const int b342[2] = {2,2};
435 
436     /* Mongolian */
437     static const WCHAR test35[] = {0x182e,0x1823,0x1829,0x182d,0x1823,0x182f,0x0020,0x182a,0x1822,0x1834,0x1822,0x182d,0x180c};
438     static const itemTest t351[2] = {{{0,0,0,0,0,0},0,0,0,0,0,mong_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
439     static const int b351[2] = {2,2};
440     static const itemTest t352[2] = {{{0,0,0,0,0,0},0,0,0,2,0,mong_tag,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
441     static const int b352[2] = {2,3};
442     static const itemTest t353[2] = {{{0,0,0,0,1,0},0,0,0,0,1,mong_tag,TRUE,{-1,-1,-1,-1,0,0}},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
443 
444     /* Tifinagh */
445     static const WCHAR test36[] = {0x2d5c,0x2d49,0x2d3c,0x2d49,0x2d4f,0x2d30,0x2d56};
446     static const itemTest t361[2] = {{{0,0,0,0,0,0},0,0,0,0,0,tfng_tag,TRUE,{-1,-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
447     static const itemTest t362[2] = {{{0,0,0,0,0,0},0,0,0,2,0,tfng_tag,TRUE,{-1,1,1,1,-1,latn_tag}},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
448 
449     /* N'Ko */
450     static const WCHAR test37[] = {0x07d2,0x07de,0x07cf};
451     static const itemTest t371[2] = {{{0,0,0,0,0,0},0,1,1,1,0,nko_tag,TRUE,{-1,0,0,0,-1,arab_tag}},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
452     static const itemTest t372[2] = {{{0,0,0,0,0,0},0,1,1,1,0,nko_tag,TRUE,{-1,0,0,2,-1,arab_tag}},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
453     static const itemTest t373[2] = {{{0,0,0,0,0,0},0,0,0,0,1,nko_tag,TRUE,{-1,-1,-1,2,0,arab_tag}}, {{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
454 
455     /* Vai */
456     static const WCHAR test38[] = {0xa559,0xa524};
457     static const itemTest t381[2] = {{{0,0,0,0,0,0},0,0,0,0,0,vai_tag,TRUE,{-1,-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
458     static const itemTest t382[2] = {{{0,0,0,0,0,0},0,0,0,2,0,vai_tag,TRUE,{-1,1,1,1,-1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
459 
460     /* Cherokee */
461     static const WCHAR test39[] = {0x13e3,0x13b3,0x13a9,0x0020,0x13a6,0x13ec,0x13c2,0x13af,0x13cd,0x13d7};
462     static const itemTest t391[2] = {{{0,0,0,0,0,0},0,0,0,0,0,cher_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
463     static const itemTest t392[2] = {{{0,0,0,0,0,0},0,0,0,2,0,cher_tag,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
464 
465     /* Canadian Aboriginal Syllabics */
466     static const WCHAR test40[] = {0x1403,0x14c4,0x1483,0x144e,0x1450,0x1466};
467     static const itemTest t401[2] = {{{0,0,0,0,0,0},0,0,0,0,0,cans_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
468     static const itemTest t402[2] = {{{0,0,0,0,0,0},0,0,0,2,0,cans_tag,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
469 
470     /* Ogham */
471     static const WCHAR test41[] = {0x169b,0x1691,0x168c,0x1690,0x168b,0x169c};
472     static const itemTest t411[2] = {{{0,0,0,0,0,0},0,0,0,0,0,ogam_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
473     static const itemTest t412[4] = {{{0,0,0,0,0,0},0,1,1,1,0,ogam_tag,FALSE},{{0,0,0,0,0,0},1,0,0,2,0,ogam_tag,FALSE},{{0,0,0,0,0,0},5,1,1,1,0,ogam_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
474     static const int b412[2] = {1,1};
475 
476     /* Runic */
477     static const WCHAR test42[] = {0x16a0,0x16a1,0x16a2,0x16a3,0x16a4,0x16a5};
478     static const itemTest t421[2] = {{{0,0,0,0,0,0},0,0,0,0,0,runr_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
479     static const itemTest t422[4] = {{{0,0,0,0,0,0},0,0,0,2,0,runr_tag,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
480 
481     /* Braille */
482     static const WCHAR test43[] = {0x280f,0x2817,0x2811,0x280d,0x280a,0x2811,0x2817};
483     static const itemTest t431[2] = {{{0,0,0,0,0,0},0,0,0,0,0,brai_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
484     static const itemTest t432[4] = {{{0,0,0,0,0,0},0,0,0,2,0,brai_tag,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
485 
486     /* Private and Surrogates Area */
487     static const WCHAR test44[] = {0xe000, 0xe001, 0xd800, 0xd801};
488     static const itemTest t441[3] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},2,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
489     static const itemTest t442[4] = {{{0,0,0,0,0,0},0,0,0,2,0,0,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},2,0,0,2,0,0,TRUE,{-1,1,1,1,-1,-1}},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
490 
491     /* Deseret */
492     static const WCHAR test45[] = {0xd801,0xdc19,0xd801,0xdc32,0xd801,0xdc4c,0xd801,0xdc3c,0xd801,0xdc32,0xd801,0xdc4b,0xd801,0xdc2f,0xd801,0xdc4c,0xd801,0xdc3b,0xd801,0xdc32,0xd801,0xdc4a,0xd801,0xdc28};
493     static const itemTest t451[2] = {{{0,0,0,0,0,0},0,0,0,0,0,dsrt_tag,TRUE,{-1,-1,-1,-1,-1,0x0}},{{0,0,0,0,0,0},24,0,0,0,0,-1,FALSE}};
494     static const itemTest t452[2] = {{{0,0,0,0,0,0},0,0,0,2,0,dsrt_tag,TRUE,{-1,1,1,1,-1,0x0}},{{0,0,0,0,0,0},24,0,0,0,0,-1,FALSE}};
495 
496     /* Osmanya */
497     static const WCHAR test46[] = {0xd801,0xdc8b,0xd801,0xdc98,0xd801,0xdc88,0xd801,0xdc91,0xd801,0xdc9b,0xd801,0xdc92,0xd801,0xdc95,0xd801,0xdc80};
498     static const itemTest t461[2] = {{{0,0,0,0,0,0},0,0,0,0,0,osma_tag,TRUE,{-1,-1,-1,-1,-1,0x0}},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
499     static const itemTest t462[2] = {{{0,0,0,0,0,0},0,0,0,2,0,osma_tag,TRUE,{-1,1,1,1,-1,0x0}},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
500 
501     /* Mathematical Alphanumeric Symbols */
502     static const WCHAR test47[] = {0xd835,0xdc00,0xd835,0xdc35,0xd835,0xdc6a,0xd835,0xdc9f,0xd835,0xdcd4,0xd835,0xdd09,0xd835,0xdd3e,0xd835,0xdd73,0xd835,0xdda8,0xd835,0xdddd,0xd835,0xde12,0xd835,0xde47,0xd835,0xde7c};
503     static const itemTest t471[2] = {{{0,0,0,0,0,0},0,0,0,0,0,math_tag,TRUE,{-1,-1,-1,-1,-1,0x0}},{{0,0,0,0,0,0},26,0,0,0,0,-1,FALSE}};
504     static const itemTest t472[2] = {{{0,0,0,0,0,0},0,0,0,2,0,math_tag,TRUE,{-1,1,1,1,-1,0x0}},{{0,0,0,0,0,0},26,0,0,0,0,-1,FALSE}};
505 
506     /* Mathematical and Numeric combinations */
507     /* These have a leading hebrew character to force complicated itemization */
508     static const WCHAR test48[] = {0x05e9,' ','1','2','3','.'};
509     static const itemTest t481[4] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
510         {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,0,0,FALSE},
511         {{0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
512     static const itemTest t482[4] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
513                                     {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
514                                     {{0,0,0,0,0,0},5,0,0,0,1,0,FALSE},
515                                     {{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
516 
517     static const WCHAR test49[] = {0x05e9,' ','1','2','.','1','2'};
518     static const itemTest t491[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
519         {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
520     static const itemTest t492[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
521                                 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
522                                 {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
523 
524     static const WCHAR test50[] = {0x05e9,' ','.','1','2','3'};
525     static const itemTest t501[4] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
526         {{0,0,0,0,0},2,1,1,1,0,0,FALSE},{{0,0,0,0,0},3,0,1,2,0,0,FALSE},
527         {{0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
528     static const itemTest t502[4] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
529                                 {{0,0,0,0,0,0},2,0,0,0,1,0,FALSE},
530                                 {{0,0,0,0,0,0},3,0,1,0,1,0,FALSE},
531                                 {{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
532 
533     static const WCHAR test51[] = {0x05e9,' ','a','b','.','1','2'};
534     static const itemTest t511[5] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
535         {{0,0,0,0,0},1,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,0,FALSE},
536         {{0,0,0,0,0},5,0,0,2,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
537     static const itemTest t512[5] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
538                             {{0,0,0,0,0,0},2,0,0,0,1,latn_tag,FALSE},
539                             {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
540                             {{0,0,0,0,0,0},5,0,0,0,1,0,FALSE},
541                             {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
542 
543     static const WCHAR test52[] = {0x05e9,' ','1','2','.','a','b'};
544     static const itemTest t521[5] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
545         {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,0,FALSE},
546         {{0,0,0,0,0},5,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
547     static const itemTest t522[5] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
548                         {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
549                         {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
550                         {{0,0,0,0,0,0},5,0,0,0,1,latn_tag,FALSE},
551                         {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
552 
553     static const WCHAR test53[] = {0x05e9,' ','1','2','.','.','1','2'};
554     static const itemTest t531[5] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
555         {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},4,1,1,1,0,0,FALSE},
556         {{0,0,0,0,0},6,0,1,2,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
557     static const itemTest t532[5] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
558                             {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
559                             {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
560                             {{0,0,0,0,0,0},6,0,1,0,1,0,FALSE},
561                             {{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
562 
563     static const WCHAR test54[] = {0x05e9,' ','1','2','+','1','2'};
564     static const itemTest t541[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
565         {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
566     static const itemTest t542[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
567                                 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
568                                 {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
569     static const WCHAR test55[] = {0x05e9,' ','1','2','+','+','1','2'};
570     static const itemTest t551[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
571         {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
572     static const itemTest t552[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
573                                 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
574                                 {{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
575 
576     /* ZWNJ */
577     static const WCHAR test56[] = {0x0645, 0x06cc, 0x200c, 0x06a9, 0x0646, 0x0645}; /* می‌کنم */
578     static const itemTest t561[] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
579     static const itemTest t562[] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
580 
581     /* Persian numerals and punctuation. */
582     static const WCHAR test57[] = {0x06f1, 0x06f2, 0x066c, 0x06f3, 0x06f4, 0x06f5, 0x066c,  /* ۱۲٬۳۴۵٬ */
583                                    0x06f6, 0x06f7, 0x06f8, 0x066b, 0x06f9, 0x06f0};         /* ۶۷۸٫۹۰ */
584     static const itemTest t571[] = {{{0,0,0,0,0,0}, 0,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0}, 2,0,1,2,0,arab_tag,FALSE},
585                                     {{0,0,0,0,0,0}, 3,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0}, 6,0,1,2,0,arab_tag,FALSE},
586                                     {{0,0,0,0,0,0}, 7,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0},10,0,1,2,0,arab_tag,FALSE},
587                                     {{0,0,0,0,0,0},11,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
588     static const itemTest t572[] = {{{0,0,0,0,0,0}, 0,0,0,2,0,arab_tag,FALSE},{{0,0,1,0,0,0}, 2,0,1,2,0,arab_tag,FALSE},
589                                     {{0,0,0,0,0,0}, 3,0,0,2,0,arab_tag,FALSE},{{0,0,1,0,0,0}, 6,0,1,2,0,arab_tag,FALSE},
590                                     {{0,0,0,0,0,0}, 7,0,0,2,0,arab_tag,FALSE},{{0,0,1,0,0,0},10,0,1,2,0,arab_tag,FALSE},
591                                     {{0,0,0,0,0,0},11,0,0,2,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
592     static const itemTest t573[] = {{{0,0,0,0,0,0}, 0,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0}, 2,0,0,0,1,arab_tag,FALSE},
593                                     {{0,0,0,0,0,0}, 3,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0}, 6,0,0,0,1,arab_tag,FALSE},
594                                     {{0,0,0,0,0,0}, 7,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,1,arab_tag,FALSE},
595                                     {{0,0,0,0,0,0},11,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
596     /* Arabic numerals and punctuation. */
597     static const WCHAR test58[] = {0x0661, 0x0662, 0x066c, 0x0663, 0x0664, 0x0665, 0x066c,  /* ١٢٬٣٤٥٬ */
598                                    0x0666, 0x0667, 0x0668, 0x066b, 0x0669, 0x0660};         /* ٦٧٨٫٩٠ */
599     static const itemTest t581[] = {{{0,0,0,0,0,0}, 0,0,1,2,0,arab_tag,FALSE},
600                                     {{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
601     static const itemTest t582[] = {{{0,0,1,1,1,0}, 0,0,0,0,1,arab_tag,FALSE},
602                                     {{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
603 
604     SCRIPT_ITEM items[15];
605     SCRIPT_CONTROL  Control;
606     SCRIPT_STATE    State;
607     HRESULT hr;
608     int nItems;
609 
610     memset(&Control, 0, sizeof(Control));
611     memset(&State, 0, sizeof(State));
612 
613     hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
614     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
615 
616     hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
617     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
618 
619     hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
620     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
621 
622     hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
623     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
624 
625     test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
626     test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
627     test_items_ok(test1c,6,NULL,NULL,1,t1c1,FALSE,0);
628     test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
629     test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
630     test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
631     test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
632     test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
633     test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
634     test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
635     test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
636     test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
637     test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
638     test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
639     test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
640     test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
641     test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
642     test_items_ok(test13,7,NULL,NULL,1,t131,FALSE,0);
643     test_items_ok(test14,7,NULL,NULL,1,t141,FALSE,0);
644     test_items_ok(test15,5,NULL,NULL,1,t151,FALSE,0);
645     test_items_ok(test16,5,NULL,NULL,1,t161,FALSE,0);
646     test_items_ok(test17,6,NULL,NULL,1,t171,FALSE,0);
647     test_items_ok(test18,5,NULL,NULL,1,t181,FALSE,0);
648     test_items_ok(test19,6,NULL,NULL,1,t191,FALSE,0);
649     test_items_ok(test20,5,NULL,NULL,2,t201,FALSE,0);
650     test_items_ok(test21,5,NULL,NULL,1,t211,FALSE,0);
651     test_items_ok(test22,6,NULL,NULL,2,t221,FALSE,0);
652     test_items_ok(test23,6,NULL,NULL,2,t231,FALSE,0);
653     test_items_ok(test24,12,NULL,NULL,1,t241,FALSE,0);
654     test_items_ok(test25,10,NULL,NULL,1,t251,FALSE,0);
655     test_items_ok(test26,2,NULL,NULL,1,t261,FALSE,0);
656     test_items_ok(test27,8,NULL,NULL,1,t271,FALSE,0);
657     test_items_ok(test28,4,NULL,NULL,1,t281,FALSE,0);
658     test_items_ok(test29,10,NULL,NULL,2,t291,FALSE,0);
659     test_items_ok(test30,8,NULL,NULL,1,t301,FALSE,0);
660     test_items_ok(test31,8,NULL,NULL,1,t311,FALSE,b311);
661     test_items_ok(test32,3,NULL,NULL,1,t321,FALSE,0);
662     test_items_ok(test33,4,NULL,NULL,1,t331,FALSE,0);
663     test_items_ok(test34,3,NULL,NULL,1,t341,FALSE,0);
664     test_items_ok(test35,13,NULL,NULL,1,t351,FALSE,b351);
665     test_items_ok(test36,7,NULL,NULL,1,t361,FALSE,0);
666     test_items_ok(test37,3,NULL,NULL,1,t371,FALSE,0);
667     test_items_ok(test38,2,NULL,NULL,1,t381,FALSE,0);
668     test_items_ok(test39,10,NULL,NULL,1,t391,FALSE,0);
669     test_items_ok(test40,6,NULL,NULL,1,t401,FALSE,0);
670     test_items_ok(test41,6,NULL,NULL,1,t411,FALSE,0);
671     test_items_ok(test42,6,NULL,NULL,1,t421,FALSE,0);
672     test_items_ok(test43,7,NULL,NULL,1,t431,FALSE,0);
673     test_items_ok(test44,4,NULL,NULL,2,t441,FALSE,0);
674     test_items_ok(test45,24,NULL,NULL,1,t451,FALSE,0);
675     test_items_ok(test46,16,NULL,NULL,1,t461,FALSE,0);
676     test_items_ok(test47,26,NULL,NULL,1,t471,FALSE,0);
677     test_items_ok(test56,6,NULL,NULL,1,t561,FALSE,0);
678     test_items_ok(test57,13,NULL,NULL,7,t571,FALSE,0);
679     test_items_ok(test58,13,NULL,NULL,1,t581,FALSE,0);
680 
681     State.uBidiLevel = 0;
682     test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
683     test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
684     test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
685     test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
686     test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
687     test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
688     test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
689     test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
690     test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
691     test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
692     test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
693     test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
694     test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
695     test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
696     test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
697     test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
698     test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
699     test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
700     test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
701     test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
702     test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
703     test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
704     test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
705     test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
706     test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
707     test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
708     test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
709     test_items_ok(test23,6,&Control,&State,2,t231,FALSE,0);
710     test_items_ok(test24,12,&Control,&State,1,t241,FALSE,0);
711     test_items_ok(test25,10,&Control,&State,1,t251,FALSE,0);
712     test_items_ok(test26,2,&Control,&State,1,t261,FALSE,0);
713     test_items_ok(test27,8,&Control,&State,1,t271,FALSE,0);
714     test_items_ok(test28,4,&Control,&State,1,t281,FALSE,0);
715     test_items_ok(test29,10,&Control,&State,2,t291,FALSE,0);
716     test_items_ok(test30,8,&Control,&State,1,t301,FALSE,0);
717     test_items_ok(test31,8,&Control,&State,1,t311,FALSE,b311);
718     test_items_ok(test32,3,&Control,&State,1,t321,FALSE,0);
719     test_items_ok(test33,4,&Control,&State,1,t331,FALSE,0);
720     test_items_ok(test34,3,&Control,&State,1,t341,FALSE,0);
721     test_items_ok(test35,13,&Control,&State,1,t351,FALSE,b351);
722     test_items_ok(test36,7,&Control,&State,1,t361,FALSE,0);
723     test_items_ok(test37,3,&Control,&State,1,t371,FALSE,0);
724     test_items_ok(test38,2,&Control,&State,1,t381,FALSE,0);
725     test_items_ok(test39,10,&Control,&State,1,t391,FALSE,0);
726     test_items_ok(test40,6,&Control,&State,1,t401,FALSE,0);
727     test_items_ok(test41,6,&Control,&State,1,t411,FALSE,0);
728     test_items_ok(test42,6,&Control,&State,1,t421,FALSE,0);
729     test_items_ok(test43,7,&Control,&State,1,t431,FALSE,0);
730     test_items_ok(test44,4,&Control,&State,2,t441,FALSE,0);
731     test_items_ok(test45,24,&Control,&State,1,t451,FALSE,0);
732     test_items_ok(test46,16,&Control,&State,1,t461,FALSE,0);
733     test_items_ok(test47,26,&Control,&State,1,t471,FALSE,0);
734     test_items_ok(test48,6,&Control,&State,3,t481,FALSE,0);
735     test_items_ok(test49,7,&Control,&State,2,t491,FALSE,0);
736     test_items_ok(test50,6,&Control,&State,3,t501,FALSE,0);
737     test_items_ok(test51,7,&Control,&State,4,t511,FALSE,0);
738     test_items_ok(test52,7,&Control,&State,4,t521,FALSE,0);
739     test_items_ok(test53,8,&Control,&State,4,t531,FALSE,0);
740     test_items_ok(test54,7,&Control,&State,2,t541,FALSE,0);
741     test_items_ok(test55,8,&Control,&State,2,t551,FALSE,0);
742     test_items_ok(test56,6,&Control,&State,1,t561,FALSE,0);
743     test_items_ok(test57,13,&Control,&State,7,t572,FALSE,0);
744     test_items_ok(test58,13,&Control,&State,1,t581,FALSE,0);
745 
746     State.uBidiLevel = 1;
747     test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
748     test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
749     test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
750     test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
751     test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
752     test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
753     test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
754     test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
755     test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
756     test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
757     test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
758     test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
759     test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
760     test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
761     test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
762     test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
763     test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
764     test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
765     test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
766     test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
767     test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
768     test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
769     test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
770     test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
771     test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
772     test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
773     test_items_ok(test22,6,&Control,&State,2,t222,FALSE,b222);
774     test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
775     test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
776     test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
777     test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
778     test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
779     test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
780     test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
781     test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
782     test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
783     test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
784     test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
785     test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
786     test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
787     test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
788     test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
789     test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
790     test_items_ok(test39,10,&Control,&State,1,t392,FALSE,0);
791     test_items_ok(test40,6,&Control,&State,1,t402,FALSE,0);
792     test_items_ok(test41,6,&Control,&State,3,t412,FALSE,b412);
793     test_items_ok(test42,6,&Control,&State,1,t422,FALSE,0);
794     test_items_ok(test43,7,&Control,&State,1,t432,FALSE,0);
795     test_items_ok(test44,4,&Control,&State,2,t442,FALSE,0);
796     test_items_ok(test45,24,&Control,&State,1,t452,FALSE,0);
797     test_items_ok(test46,16,&Control,&State,1,t462,FALSE,0);
798     test_items_ok(test47,26,&Control,&State,1,t472,FALSE,0);
799     test_items_ok(test56,6,&Control,&State,1,t561,FALSE,0);
800     test_items_ok(test57,13,&Control,&State,7,t571,FALSE,0);
801     test_items_ok(test58,13,&Control,&State,1,t581,FALSE,0);
802 
803     State.uBidiLevel = 1;
804     Control.fMergeNeutralItems = TRUE;
805     test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
806     test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
807     test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
808     test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
809     test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,b2);
810     test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,b2);
811     test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,b2);
812     test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
813     test_items_ok(test4,12,&Control,&State,3,t43,FALSE,b43);
814     test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
815     test_items_ok(test6,5,&Control,&State,1,t63,FALSE,b63);
816     test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
817     test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
818     test_items_ok(test9,5,&Control,&State,1,t93,FALSE,b93);
819     test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
820     test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
821     test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
822     test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
823     test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
824     test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
825     test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
826     test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
827     test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
828     test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
829     test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
830     test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
831     test_items_ok(test22,6,&Control,&State,1,t223,FALSE,b223);
832     test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
833     test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
834     test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
835     test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
836     test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
837     test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
838     test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
839     test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
840     test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
841     test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
842     test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
843     test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
844     test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
845     test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
846     test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
847     test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
848     test_items_ok(test39,10,&Control,&State,1,t392,FALSE,0);
849     test_items_ok(test40,6,&Control,&State,1,t402,FALSE,0);
850     test_items_ok(test41,6,&Control,&State,3,t412,FALSE,b412);
851     test_items_ok(test42,6,&Control,&State,1,t422,FALSE,0);
852     test_items_ok(test43,7,&Control,&State,1,t432,FALSE,0);
853     test_items_ok(test44,4,&Control,&State,2,t442,FALSE,0);
854     test_items_ok(test45,24,&Control,&State,1,t452,FALSE,0);
855     test_items_ok(test46,16,&Control,&State,1,t462,FALSE,0);
856     test_items_ok(test47,26,&Control,&State,1,t472,FALSE,0);
857     test_items_ok(test56,6,&Control,&State,1,t561,FALSE,0);
858     test_items_ok(test57,13,&Control,&State,7,t571,FALSE,0);
859     test_items_ok(test58,13,&Control,&State,1,t581,FALSE,0);
860 
861     State.uBidiLevel = 0;
862     Control.fMergeNeutralItems = FALSE;
863     State.fOverrideDirection = 1;
864     test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
865     test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
866     test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
867     test_items_ok(test2,16,&Control,&State,4,t24,FALSE,0);
868     test_items_ok(test2b,11,&Control,&State,4,t2b4,FALSE,0);
869     test_items_ok(test2c,11,&Control,&State,4,t2c5,FALSE,0);
870     test_items_ok(test2d,11,&Control,&State,4,t2d5,FALSE,0);
871     test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
872     test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
873     test_items_ok(test5,38,&Control,&State,1,t52,FALSE,0);
874     test_items_ok(test6,5,&Control,&State,2,t64,FALSE,0);
875     test_items_ok(test7,29,&Control,&State,3,t74,FALSE,0);
876     test_items_ok(test8,4,&Control,&State,1,t82,FALSE,0);
877     test_items_ok(test9,5,&Control,&State,2,t94,FALSE,0);
878     test_items_ok(test10,4,&Control,&State,1,t102,FALSE,0);
879     test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
880     test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
881     test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
882     test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
883     test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
884     test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
885     test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
886     test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
887     test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
888     test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
889     test_items_ok(test21,5,&Control,&State,1,t212,FALSE,0);
890     test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
891     test_items_ok(test23,6,&Control,&State,2,t231,FALSE,0);
892     test_items_ok(test24,12,&Control,&State,1,t241,FALSE,0);
893     test_items_ok(test25,10,&Control,&State,1,t251,FALSE,0);
894     test_items_ok(test26,2,&Control,&State,1,t261,FALSE,0);
895     test_items_ok(test27,8,&Control,&State,1,t271,FALSE,0);
896     test_items_ok(test28,4,&Control,&State,1,t281,FALSE,0);
897     test_items_ok(test29,10,&Control,&State,2,t291,FALSE,0);
898     test_items_ok(test30,8,&Control,&State,1,t301,FALSE,0);
899     test_items_ok(test31,8,&Control,&State,1,t311,FALSE,b311);
900     test_items_ok(test32,3,&Control,&State,1,t321,FALSE,0);
901     test_items_ok(test33,4,&Control,&State,1,t331,FALSE,0);
902     test_items_ok(test34,3,&Control,&State,1,t341,FALSE,0);
903     test_items_ok(test35,13,&Control,&State,1,t353,FALSE,b351);
904     test_items_ok(test36,7,&Control,&State,1,t361,FALSE,0);
905     test_items_ok(test37,3,&Control,&State,1,t373,FALSE,0);
906     test_items_ok(test38,2,&Control,&State,1,t381,FALSE,0);
907     test_items_ok(test39,10,&Control,&State,1,t391,FALSE,0);
908     test_items_ok(test40,6,&Control,&State,1,t401,FALSE,0);
909     test_items_ok(test41,6,&Control,&State,1,t411,FALSE,0);
910     test_items_ok(test42,6,&Control,&State,1,t421,FALSE,0);
911     test_items_ok(test43,7,&Control,&State,1,t431,FALSE,0);
912     test_items_ok(test44,4,&Control,&State,2,t441,FALSE,0);
913     test_items_ok(test45,24,&Control,&State,1,t451,FALSE,0);
914     test_items_ok(test46,16,&Control,&State,1,t461,FALSE,0);
915     test_items_ok(test47,26,&Control,&State,1,t471,FALSE,0);
916     test_items_ok(test48,6,&Control,&State,3,t482,FALSE,0);
917     test_items_ok(test49,7,&Control,&State,2,t492,FALSE,0);
918     test_items_ok(test50,6,&Control,&State,3,t502,FALSE,0);
919     test_items_ok(test51,7,&Control,&State,4,t512,FALSE,0);
920     test_items_ok(test52,7,&Control,&State,4,t522,FALSE,0);
921     test_items_ok(test53,8,&Control,&State,4,t532,FALSE,0);
922     test_items_ok(test54,7,&Control,&State,2,t542,FALSE,0);
923     test_items_ok(test55,8,&Control,&State,2,t552,FALSE,0);
924     test_items_ok(test56,6,&Control,&State,1,t562,FALSE,0);
925     test_items_ok(test57,13,&Control,&State,7,t573,FALSE,0);
926     test_items_ok(test58,13,&Control,&State,1,t582,FALSE,0);
927 }
928 
929 static void make_surrogate(DWORD i, WORD out[2])
930 {
931     static const DWORD mask = (1 << 10) - 1;
932 
933     if (i <= 0xffff)
934     {
935         out[0] = i;
936         out[1] = 0;
937     }
938     else
939     {
940         i -= 0x010000;
941         out[0] = ((i >> 10) & mask) + 0xd800;
942         out[1] = (i & mask) + 0xdc00;
943     }
944 }
945 
946 static void test_ScriptItemize_surrogates(void)
947 {
948     HRESULT hr;
949     WCHAR surrogate[2];
950     WORD Script_Surrogates;
951     SCRIPT_ITEM items[2];
952     int num;
953 
954     /* Find Script_Surrogates */
955     surrogate[0] = 0xd800;
956     hr = ScriptItemize( surrogate, 1, 2, NULL, NULL, items, &num );
957     ok( hr == S_OK, "got %08x\n", hr );
958     ok( num == 1, "got %d\n", num );
959     ok( items[0].a.eScript != SCRIPT_UNDEFINED, "got script %x\n", items[0].a.eScript );
960     Script_Surrogates = items[0].a.eScript;
961 
962     /* Show that an invalid character has script Script_Surrogates */
963     make_surrogate( 0x01ffff, surrogate );
964     hr = ScriptItemize( surrogate, 2, 2, NULL, NULL, items, &num );
965     ok( hr == S_OK, "got %08x\n", hr );
966     ok( num == 1, "got %d\n", num );
967     ok( items[0].a.eScript == Script_Surrogates, "got script %x\n", items[0].a.eScript );
968 }
969 
970 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
971                          DWORD cchString, SCRIPT_CONTROL *Control,
972                          SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
973                          const shapeTest_char *charItems,
974                          const shapeTest_glyph *glyphItems,
975                          const SCRIPT_GLYPHPROP *props2)
976 {
977     HRESULT hr;
978     int x, outnItems = 0, outnGlyphs = 0, outnGlyphs2 = 0;
979     const SCRIPT_PROPERTIES **script_properties;
980     SCRIPT_ITEM outpItems[15];
981     SCRIPT_CACHE sc = NULL;
982     WORD *glyphs, *glyphs2;
983     WORD *logclust, *logclust2;
984     int maxGlyphs = cchString * 1.5;
985     SCRIPT_GLYPHPROP *glyphProp, *glyphProp2;
986     SCRIPT_CHARPROP  *charProp, *charProp2;
987     int script_count;
988     WCHAR *string2;
989     ULONG tags[15];
990 
991     hr = ScriptGetProperties(&script_properties, &script_count);
992     winetest_ok(SUCCEEDED(hr), "Failed to get script properties, hr %#x.\n", hr);
993 
994     hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
995     if (valid > 0)
996         winetest_ok(hr == S_OK, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
997     else if (hr != S_OK)
998         winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
999 
1000     if (outnItems <= item)
1001     {
1002         if (valid > 0)
1003             winetest_win_skip("Did not get enough items\n");
1004         else
1005             winetest_trace("Did not get enough items\n");
1006         return;
1007     }
1008 
1009     logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
1010     memset(logclust,'a',sizeof(WORD) * cchString);
1011     charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
1012     memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
1013     glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
1014     memset(glyphs,'a',sizeof(WORD) * cchString);
1015     glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
1016     memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
1017 
1018     string2 = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(*string2));
1019     logclust2 = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(*logclust2));
1020     memset(logclust2, 'a', cchString * sizeof(*logclust2));
1021     charProp2 = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(*charProp2));
1022     memset(charProp2, 'a', cchString * sizeof(*charProp2));
1023     glyphs2 = HeapAlloc(GetProcessHeap(), 0, maxGlyphs * sizeof(*glyphs2));
1024     memset(glyphs2, 'a', maxGlyphs * sizeof(*glyphs2));
1025     glyphProp2 = HeapAlloc(GetProcessHeap(), 0, maxGlyphs * sizeof(*glyphProp2));
1026     memset(glyphProp2, 'a', maxGlyphs * sizeof(*glyphProp2));
1027 
1028     winetest_ok(!outpItems[item].a.fLogicalOrder, "Got unexpected fLogicalOrder %#x.\n",
1029             outpItems[item].a.fLogicalOrder);
1030     hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
1031     if (valid > 0)
1032         winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
1033     else if (hr != S_OK)
1034         winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
1035     if (FAILED(hr))
1036         goto cleanup;
1037 
1038     for (x = 0; x < cchString; x++)
1039     {
1040         if (valid > 0)
1041             winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
1042         else if (logclust[x] != charItems[x].wLogClust)
1043             winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
1044         if (valid > 0)
1045             winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
1046         else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
1047             winetest_trace("%i: invalid fCanGlyphAlone\n",x);
1048     }
1049 
1050     if (valid > 0)
1051         winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
1052     else if (nGlyphs != outnGlyphs)
1053         winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
1054     for (x = 0; x < outnGlyphs; x++)
1055     {
1056         if (glyphItems[x].Glyph)
1057         {
1058             if (valid > 0)
1059                 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
1060             else if (glyphs[x]==0)
1061                 winetest_trace("%i: Glyph not present when it should be\n",x);
1062         }
1063         else
1064         {
1065             if (valid > 0)
1066                 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
1067             else if (glyphs[x]!=0)
1068                 winetest_trace("%i: Glyph present when it should not be\n",x);
1069         }
1070         if (valid > 0)
1071         {
1072             todo_wine_if(tags[item] == syrc_tag && !x)
1073                 winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification ||
1074                             (props2 && glyphProp[x].sva.uJustification == props2[x].sva.uJustification),
1075                              "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
1076         }
1077         else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
1078         {
1079             winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
1080         }
1081         if (valid > 0)
1082             winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart ||
1083                         (props2 && glyphProp[x].sva.fClusterStart == props2[x].sva.fClusterStart),
1084                         "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
1085         else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
1086             winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
1087         if (valid > 0)
1088             winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic ||
1089                         (props2 && glyphProp[x].sva.fDiacritic == props2[x].sva.fDiacritic),
1090                         "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
1091         else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
1092             winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
1093         if (valid > 0)
1094             winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth ||
1095                         (props2 && glyphProp[x].sva.fZeroWidth == props2[x].sva.fZeroWidth),
1096                         "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
1097         else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
1098             winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
1099     }
1100 
1101     outpItems[item].a.fLogicalOrder = 1;
1102     hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0,
1103             string, cchString, maxGlyphs, logclust2, charProp2, glyphs2, glyphProp2, &outnGlyphs2);
1104     winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
1105     /* Cluster maps are hard. */
1106     if (tags[item] != thaa_tag && tags[item] != syrc_tag)
1107     {
1108         for (x = 0; x < cchString; ++x)
1109         {
1110             unsigned int compare_idx = outpItems[item].a.fRTL ? cchString - x - 1 : x;
1111             winetest_ok(logclust2[x] == logclust[compare_idx],
1112                     "Got unexpected logclust2[%u] %#x, expected %#x.\n",
1113                     x, logclust2[x], logclust[compare_idx]);
1114             winetest_ok(charProp2[x].fCanGlyphAlone == charProp[compare_idx].fCanGlyphAlone,
1115                     "Got unexpected charProp2[%u].fCanGlyphAlone %#x, expected %#x.\n",
1116                     x, charProp2[x].fCanGlyphAlone, charProp[compare_idx].fCanGlyphAlone);
1117         }
1118     }
1119     winetest_ok(outnGlyphs2 == outnGlyphs, "Got unexpected glyph count %u.\n", outnGlyphs2);
1120     for (x = 0; x < outnGlyphs2; ++x)
1121     {
1122         unsigned int compare_idx = outpItems[item].a.fRTL ? outnGlyphs2 - x - 1 : x;
1123         winetest_ok(glyphs2[x] == glyphs[compare_idx], "Got unexpected glyphs2[%u] %#x, expected %#x.\n",
1124                 x, glyphs2[x], glyphs[compare_idx]);
1125         winetest_ok(glyphProp2[x].sva.uJustification == glyphProp[compare_idx].sva.uJustification,
1126                 "Got unexpected glyphProp2[%u].sva.uJustification %#x, expected %#x.\n",
1127                 x, glyphProp2[x].sva.uJustification, glyphProp[compare_idx].sva.uJustification);
1128         winetest_ok(glyphProp2[x].sva.fClusterStart == glyphProp[compare_idx].sva.fClusterStart,
1129                 "Got unexpected glyphProp2[%u].sva.fClusterStart %#x, expected %#x.\n",
1130                 x, glyphProp2[x].sva.fClusterStart, glyphProp[compare_idx].sva.fClusterStart);
1131         winetest_ok(glyphProp2[x].sva.fDiacritic == glyphProp[compare_idx].sva.fDiacritic,
1132                 "Got unexpected glyphProp2[%u].sva.fDiacritic %#x, expected %#x.\n",
1133                 x, glyphProp2[x].sva.fDiacritic, glyphProp[compare_idx].sva.fDiacritic);
1134         winetest_ok(glyphProp2[x].sva.fZeroWidth == glyphProp[compare_idx].sva.fZeroWidth,
1135                 "Got unexpected glyphProp2[%u].sva.fZeroWidth %#x, expected %#x.\n",
1136                 x, glyphProp2[x].sva.fZeroWidth, glyphProp[compare_idx].sva.fZeroWidth);
1137     }
1138 
1139     /* Most scripts get this wrong. For example, when the font has the
1140      * appropriate ligatures, "ttfffi" get rendered as "<ttf><ffi>", but
1141      * "<RLO>iffftt" gets rendered as "t<ft><ff>i". Arabic gets it right,
1142      * and there exist applications that depend on that. */
1143     if (tags[item] == arab_tag && broken(script_count <= 75))
1144     {
1145         winetest_win_skip("Test broken on this platform, skipping.\n");
1146     }
1147     else if (tags[item] == arab_tag)
1148     {
1149         for (x = 0; x < cchString; ++x)
1150         {
1151             string2[x] = string[cchString - x - 1];
1152         }
1153         outpItems[item].a.fLogicalOrder = 0;
1154         outpItems[item].a.fRTL = !outpItems[item].a.fRTL;
1155         hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0,
1156                 string2, cchString, maxGlyphs, logclust2, charProp2, glyphs2, glyphProp2, &outnGlyphs2);
1157         winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
1158         for (x = 0; x < cchString; ++x)
1159         {
1160             unsigned int compare_idx = cchString - x - 1;
1161             winetest_ok(logclust2[x] == logclust[compare_idx],
1162                     "Got unexpected logclust2[%u] %#x, expected %#x.\n",
1163                     x, logclust2[x], logclust[compare_idx]);
1164             winetest_ok(charProp2[x].fCanGlyphAlone == charProp[compare_idx].fCanGlyphAlone,
1165                     "Got unexpected charProp2[%u].fCanGlyphAlone %#x, expected %#x.\n",
1166                     x, charProp2[x].fCanGlyphAlone, charProp[compare_idx].fCanGlyphAlone);
1167         }
1168         winetest_ok(outnGlyphs2 == outnGlyphs, "Got unexpected glyph count %u.\n", outnGlyphs2);
1169         for (x = 0; x < outnGlyphs2; ++x)
1170         {
1171             winetest_ok(glyphs2[x] == glyphs[x], "Got unexpected glyphs2[%u] %#x, expected %#x.\n",
1172                     x, glyphs2[x], glyphs[x]);
1173             winetest_ok(glyphProp2[x].sva.uJustification == glyphProp[x].sva.uJustification,
1174                     "Got unexpected glyphProp2[%u].sva.uJustification %#x, expected %#x.\n",
1175                     x, glyphProp2[x].sva.uJustification, glyphProp[x].sva.uJustification);
1176             winetest_ok(glyphProp2[x].sva.fClusterStart == glyphProp[x].sva.fClusterStart,
1177                     "Got unexpected glyphProp2[%u].sva.fClusterStart %#x, expected %#x.\n",
1178                     x, glyphProp2[x].sva.fClusterStart, glyphProp[x].sva.fClusterStart);
1179             winetest_ok(glyphProp2[x].sva.fDiacritic == glyphProp[x].sva.fDiacritic,
1180                     "Got unexpected glyphProp2[%u].sva.fDiacritic %#x, expected %#x.\n",
1181                     x, glyphProp2[x].sva.fDiacritic, glyphProp[x].sva.fDiacritic);
1182             winetest_ok(glyphProp2[x].sva.fZeroWidth == glyphProp[x].sva.fZeroWidth,
1183                     "Got unexpected glyphProp2[%u].sva.fZeroWidth %#x, expected %#x.\n",
1184                     x, glyphProp2[x].sva.fZeroWidth, glyphProp[x].sva.fZeroWidth);
1185         }
1186         outpItems[item].a.fLogicalOrder = 1;
1187         hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0,
1188                 string2, cchString, maxGlyphs, logclust2, charProp2, glyphs2, glyphProp2, &outnGlyphs2);
1189         winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
1190         for (x = 0; x < cchString; ++x)
1191         {
1192             unsigned int compare_idx = outpItems[item].a.fRTL ? x : cchString - x - 1;
1193             winetest_ok(logclust2[x] == logclust[compare_idx], "Got unexpected logclust2[%u] %#x, expected %#x.\n",
1194                     x, logclust2[x], logclust[compare_idx]);
1195             winetest_ok(charProp2[x].fCanGlyphAlone == charProp[compare_idx].fCanGlyphAlone,
1196                     "Got unexpected charProp2[%u].fCanGlyphAlone %#x, expected %#x.\n",
1197                     x, charProp2[x].fCanGlyphAlone, charProp[compare_idx].fCanGlyphAlone);
1198         }
1199         winetest_ok(outnGlyphs2 == outnGlyphs, "Got unexpected glyph count %u.\n", outnGlyphs2);
1200         for (x = 0; x < outnGlyphs2; ++x)
1201         {
1202             unsigned int compare_idx = outpItems[item].a.fRTL ? outnGlyphs2 - x - 1 : x;
1203             winetest_ok(glyphs2[x] == glyphs[compare_idx], "Got unexpected glyphs2[%u] %#x, expected %#x.\n",
1204                     x, glyphs2[x], glyphs[compare_idx]);
1205             winetest_ok(glyphProp2[x].sva.uJustification == glyphProp[compare_idx].sva.uJustification,
1206                     "Got unexpected glyphProp2[%u].sva.uJustification %#x, expected %#x.\n",
1207                     x, glyphProp2[x].sva.uJustification, glyphProp[compare_idx].sva.uJustification);
1208             winetest_ok(glyphProp2[x].sva.fClusterStart == glyphProp[compare_idx].sva.fClusterStart,
1209                     "Got unexpected glyphProp2[%u].sva.fClusterStart %#x, expected %#x.\n",
1210                     x, glyphProp2[x].sva.fClusterStart, glyphProp[compare_idx].sva.fClusterStart);
1211             winetest_ok(glyphProp2[x].sva.fDiacritic == glyphProp[compare_idx].sva.fDiacritic,
1212                     "Got unexpected glyphProp2[%u].sva.fDiacritic %#x, expected %#x.\n",
1213                     x, glyphProp2[x].sva.fDiacritic, glyphProp[compare_idx].sva.fDiacritic);
1214             winetest_ok(glyphProp2[x].sva.fZeroWidth == glyphProp[compare_idx].sva.fZeroWidth,
1215                     "Got unexpected glyphProp2[%u].sva.fZeroWidth %#x, expected %#x.\n",
1216                     x, glyphProp2[x].sva.fZeroWidth, glyphProp[compare_idx].sva.fZeroWidth);
1217         }
1218     }
1219 
1220 cleanup:
1221     HeapFree(GetProcessHeap(),0,string2);
1222     HeapFree(GetProcessHeap(),0,logclust2);
1223     HeapFree(GetProcessHeap(),0,charProp2);
1224     HeapFree(GetProcessHeap(),0,glyphs2);
1225     HeapFree(GetProcessHeap(),0,glyphProp2);
1226 
1227     HeapFree(GetProcessHeap(),0,logclust);
1228     HeapFree(GetProcessHeap(),0,charProp);
1229     HeapFree(GetProcessHeap(),0,glyphs);
1230     HeapFree(GetProcessHeap(),0,glyphProp);
1231     ScriptFreeCache(&sc);
1232 }
1233 
1234 #define test_shape_ok(a,b,c,d,e,f,g,h,i) \
1235     (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(1,a,b,c,d,e,f,g,h,i,NULL)
1236 
1237 #define test_shape_ok_valid(v,a,b,c,d,e,f,g,h,i) \
1238     (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(v,a,b,c,d,e,f,g,h,i,NULL)
1239 
1240 #define test_shape_ok_valid_props2(v,a,b,c,d,e,f,g,h,i,j) \
1241     (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(v,a,b,c,d,e,f,g,h,i,j)
1242 
1243 typedef struct tagRangeP {
1244     BYTE range;
1245     LOGFONTA lf;
1246 } fontEnumParam;
1247 
1248 static int CALLBACK enumFontProc( const LOGFONTA *lpelfe, const TEXTMETRICA *lpntme, DWORD FontType, LPARAM lParam )
1249 {
1250     NEWTEXTMETRICEXA *ntme = (NEWTEXTMETRICEXA*)lpntme;
1251     fontEnumParam *rp = (fontEnumParam*) lParam;
1252     int idx = 0;
1253     DWORD i;
1254     DWORD mask = 0;
1255 
1256     if (FontType != TRUETYPE_FONTTYPE)
1257         return 1;
1258 
1259     i = rp->range;
1260     while (i >= sizeof(DWORD)*8)
1261     {
1262         idx++;
1263         i -= (sizeof(DWORD)*8);
1264     }
1265     if (idx > 3)
1266         return 0;
1267 
1268     mask = 1 << i;
1269 
1270     if (ntme->ntmFontSig.fsUsb[idx] & mask)
1271     {
1272         memcpy(&(rp->lf),lpelfe,sizeof(LOGFONTA));
1273         return 0;
1274     }
1275     return 1;
1276 }
1277 
1278 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont, const font_fingerprint *fingerprint)
1279 {
1280     int rc = 0;
1281     fontEnumParam lParam;
1282 
1283     lParam.range = range;
1284     memset(&lParam.lf,0,sizeof(LOGFONTA));
1285     *hfont = NULL;
1286 
1287     if (recommended)
1288     {
1289         lstrcpyA(lParam.lf.lfFaceName, recommended);
1290         if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
1291         {
1292             *hfont = CreateFontIndirectA(&lParam.lf);
1293             if (*hfont)
1294             {
1295                 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
1296                 if (fingerprint)
1297                 {
1298                     WORD output[10];
1299                     int i;
1300 
1301                     *origFont = SelectObject(hdc,*hfont);
1302                     if (GetGlyphIndicesW(hdc, fingerprint->check, 10, output, 0) != GDI_ERROR)
1303                     {
1304                         for (i=0; i < 10; i++)
1305                             if (output[i] != fingerprint->result[i])
1306                             {
1307                                 winetest_trace("found font does not match fingerprint\n");
1308                                 SelectObject(hdc,*origFont);
1309                                 DeleteObject(*hfont);
1310                                 *hfont = NULL;
1311                                 break;
1312                             }
1313                         if (i == 10) rc = 1;
1314                     }
1315                     SelectObject(hdc, *origFont);
1316                 }
1317                 else rc = 1;
1318             }
1319         }
1320         if (!rc)
1321             winetest_skip("Font %s is not available.\n", recommended);
1322     }
1323 
1324     if (!*hfont)
1325     {
1326         memset(&lParam.lf,0,sizeof(LOGFONTA));
1327         lParam.lf.lfCharSet = DEFAULT_CHARSET;
1328 
1329         if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
1330         {
1331             *hfont = CreateFontIndirectA(&lParam.lf);
1332             if (*hfont)
1333                 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
1334         }
1335     }
1336 
1337     if (*hfont)
1338     {
1339         WORD glyph = 0;
1340 
1341         *origFont = SelectObject(hdc,*hfont);
1342         if (GetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph == 0)
1343         {
1344             winetest_trace("    Font fails to contain required glyphs\n");
1345             SelectObject(hdc,*origFont);
1346             DeleteObject(*hfont);
1347             *hfont=NULL;
1348             rc = 0;
1349         }
1350         else if (!rc)
1351             rc = -1;
1352     }
1353     else
1354         winetest_trace("Failed to find usable font\n");
1355 
1356     return rc;
1357 }
1358 
1359 #define find_font_for_range(a,b,c,d,e,f,g) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _find_font_for_range(a,b,c,d,e,f,g)
1360 
1361 static void test_ScriptShapeOpenType(HDC hdc)
1362 {
1363     HRESULT hr;
1364     SCRIPT_CACHE sc = NULL;
1365     WORD glyphs[4], logclust[4];
1366     SCRIPT_GLYPHPROP glyphProp[4];
1367     SCRIPT_ITEM items[2];
1368     ULONG tags[2];
1369     SCRIPT_CONTROL  Control;
1370     SCRIPT_STATE    State;
1371     int nb, outnItems;
1372     HFONT hfont, hfont_orig;
1373     int test_valid;
1374     shapeTest_glyph glyph_test[4];
1375 
1376     static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1377     static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
1378     static const shapeTest_glyph t1_g[] = {
1379                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1380                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1381                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1382                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
1383 
1384     static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1385     static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
1386     static const shapeTest_glyph t2_g[] = {
1387                             {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1388                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1389                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1390                             {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
1391 
1392     static const WCHAR test3[] = {'t', 't', 'f', 'f', 'f', 'i', 0};
1393     static const shapeTest_char t3_c[] = {{0, {0, 0}}, {0, {0, 0}}, {0, {0, 0}},
1394             {1, {0, 0}}, {1, {0, 0}}, {1, {0, 0}}};
1395     static const shapeTest_glyph t3_g[] = {
1396                             {1, {{SCRIPT_JUSTIFY_CHARACTER, 1, 0, 0, 0, 0}, 0}},
1397                             {1, {{SCRIPT_JUSTIFY_CHARACTER, 1, 0, 0, 0, 0}, 0}}};
1398 
1399     /* Hebrew */
1400     static const WCHAR test_hebrew[]  = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
1401     static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
1402     static const shapeTest_glyph hebrew_g[] = {
1403                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1404                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1405                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1406                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
1407 
1408     /* Arabic */
1409     static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
1410     static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
1411     static const shapeTest_glyph arabic_g[] = {
1412                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1413                             {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
1414                             {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
1415 
1416     /* Thai */
1417     static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
1418     static const shapeTest_char thai_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{5,{0,0}},{5,{0,0}},{7,{0,0}},{8,{0,0}},{9,{0,0}}};
1419     static const shapeTest_glyph thai_g[] = {
1420                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1421                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1422                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1423                             {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
1424                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1425                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1426                             {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
1427                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1428                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1429                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
1430 
1431     /* Syriac */
1432     static const WCHAR test_syriac[] = {0x0710, 0x072c, 0x0728, 0x0742, 0x0718, 0x0723, 0x0720, 0x0710, 0};
1433     static const shapeTest_char syriac_c[] = {{6, {0, 0}}, {5, {0, 0}}, {4, {0, 0}},
1434             {4, {0, 0}}, {2, {0, 0}}, {1, {0, 0}}, {0, {0, 0}}, {0, {0, 0}}};
1435     static const shapeTest_glyph syriac_g[] = {
1436                             {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
1437                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1438                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1439                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1440                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1441                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1442                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1443 
1444     /* Thaana */
1445     static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
1446     static const shapeTest_char thaana_c[] = {{12,{0,0}},{12,{0,0}},{10,{0,0}},{10,{0,0}},{8,{1,0}},{7,{0,0}},{7,{0,0}},{5,{0,0}},{5,{0,0}},{3,{0,0}},{3,{0,0}},{1,{0,0}},{1,{0,0}}};
1447     static const shapeTest_glyph thaana_g[] = {
1448                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1449                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1450                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1451                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1452                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1453                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1454                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1455                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1456                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1457                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1458                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1459                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1460                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1461 
1462     /* Phags-pa */
1463     static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
1464     static const shapeTest_char phagspa_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{1,0}},{4,{0,0}},{5,{0,0}},{6,{0,0}},{7,{1,0}},{8,{0,0}},{9,{0,0}},{10,{0,0}}};
1465     static const shapeTest_glyph phagspa_g[] = {
1466                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1467                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1468                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1469                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1470                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1471                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1472                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1473                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1474                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1475                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1476                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1477     static const SCRIPT_GLYPHPROP phagspa_win10_props[] = {
1478                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1479                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1480                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1481                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1482                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1483                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1484                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1485                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1486                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1487                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1488                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0} };
1489 
1490     /* Lao */
1491     static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
1492     static const shapeTest_char lao_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{4,{0,0}},{5,{0,0}},{6,{0,0}},{7,{0,0}},{8,{0,0}}};
1493     static const shapeTest_glyph lao_g[] = {
1494                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1495                             {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
1496                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1497                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1498                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1499                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1500                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1501                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1502                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1503 
1504     /* Tibetan */
1505     static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
1506     static const shapeTest_char tibetan_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{1,0}},{4,{0,0}},{4,{0,0}},{6,{0,0}},{7,{0,0}},{8,{0,0}},{9,{0,0}},{10,{0,0}},{11,{0,0}},{12,{0,0}},{13,{0,0}},{14,{0,0}},{14,{0,0}},{16,{0,0}}};
1507     static const shapeTest_glyph tibetan_g[] = {
1508                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1509                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1510                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1511                             {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
1512                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1513                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1514                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1515                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1516                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1517                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1518                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1519                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1520                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1521                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1522                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1523                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1524                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1525     static const SCRIPT_GLYPHPROP tibetan_win10_props[] = {
1526                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1527                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1528                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1529                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1530                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1531                             {{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0},
1532                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1533                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1534                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1535                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1536                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1537                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1538                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1539                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1540                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0},
1541                             {{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0},
1542                             {{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0} };
1543 
1544     /* Devanagari */
1545     static const WCHAR test_devanagari[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
1546     static const shapeTest_char devanagari_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{6,{0,0}},{6,{0,0}}};
1547     static const shapeTest_glyph devanagari_g[] = {
1548                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1549                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1550                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1551                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1552                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1553                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1554                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1555                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1556 
1557     /* Bengali */
1558     static const WCHAR test_bengali[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
1559     static const shapeTest_char bengali_c[] = {{0,{0,0}},{0,{0,0}},{0,{0,0}},{3,{0,0}},{3,{0,0}}};
1560     static const shapeTest_glyph bengali_g[] = {
1561                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1562                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1563                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1564                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1565                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1566 
1567     /* Gurmukhi */
1568     static const WCHAR test_gurmukhi[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
1569     static const shapeTest_char gurmukhi_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
1570     static const shapeTest_glyph gurmukhi_g[] = {
1571                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1572                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1573                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1574                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1575                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1576                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1577                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1578 
1579     /* Gujarati */
1580     static const WCHAR test_gujarati[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
1581     static const shapeTest_char gujarati_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
1582     static const shapeTest_glyph gujarati_g[] = {
1583                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1584                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1585                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1586                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1587                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1588                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1589                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1590 
1591     /* Oriya */
1592     static const WCHAR test_oriya[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
1593     static const shapeTest_char oriya_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1594     static const shapeTest_glyph oriya_g[] = {
1595                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1596                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1597                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1598                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1599 
1600     /* Tamil */
1601     static const WCHAR test_tamil[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
1602     static const shapeTest_char tamil_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}},{3,{0,0}}};
1603     static const shapeTest_glyph tamil_g[] = {
1604                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1605                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1606                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1607                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1608 
1609     /* Telugu */
1610     static const WCHAR test_telugu[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
1611     static const shapeTest_char telugu_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1612     static const shapeTest_glyph telugu_g[] = {
1613                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1614                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1615                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1616                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1617                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1618                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1619 
1620     /* Malayalam */
1621     static const WCHAR test_malayalam[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
1622     static const shapeTest_char malayalam_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1623     static const shapeTest_glyph malayalam_g[] = {
1624                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1625                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1626                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1627                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1628                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1629                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1630 
1631     /* Kannada */
1632     static const WCHAR test_kannada[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
1633     static const shapeTest_char kannada_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1634     static const shapeTest_glyph kannada_g[] = {
1635                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1636                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1637                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1638                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1639                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1640 
1641     static const font_fingerprint fingerprint_estrangelo = {
1642         {'A','a','B','b','C','c','D','d',0,0},
1643         {284,310,285,311,286,312,287,313,0,0}};
1644 
1645 
1646     if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
1647     {
1648         win_skip("ScriptShapeOpenType not available on this platform\n");
1649         return;
1650     }
1651 
1652     memset(&Control, 0 , sizeof(Control));
1653     memset(&State, 0 , sizeof(State));
1654 
1655     hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
1656     ok(hr == S_OK, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
1657     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1658 
1659     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
1660     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1661 
1662     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
1663     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1664 
1665     hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1666     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
1667 
1668     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1669     ok( hr == E_INVALIDARG,
1670        "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1671     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
1672     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1673 
1674     ScriptFreeCache(&sc);
1675 
1676     test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
1677 
1678     /* newer Tahoma has zerowidth space glyphs for 0x202b and 0x202c */
1679     memcpy(glyph_test, t2_g, sizeof(glyph_test));
1680     GetGlyphIndicesW(hdc, test2, 4, glyphs, 0);
1681     if (glyphs[0] != 0)
1682         glyph_test[0].Glyph = 1;
1683     if (glyphs[3] != 0)
1684         glyph_test[3].Glyph = 1;
1685 
1686     test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, glyph_test);
1687 
1688     test_valid = find_font_for_range(hdc, "Calibri", 0, test3[0], &hfont, &hfont_orig, NULL);
1689     if (hfont != NULL)
1690     {
1691         test_shape_ok_valid(test_valid, hdc, test3, 6, &Control, &State, 0, 2, t3_c, t3_g);
1692         SelectObject(hdc, hfont_orig);
1693         DeleteObject(hfont);
1694     }
1695 
1696     test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig, NULL);
1697     if (hfont != NULL)
1698     {
1699         test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
1700         SelectObject(hdc, hfont_orig);
1701         DeleteObject(hfont);
1702     }
1703 
1704     test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig, NULL);
1705     if (hfont != NULL)
1706     {
1707         test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
1708         SelectObject(hdc, hfont_orig);
1709         DeleteObject(hfont);
1710     }
1711 
1712     test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig, NULL);
1713     if (hfont != NULL)
1714     {
1715         test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
1716         SelectObject(hdc, hfont_orig);
1717         DeleteObject(hfont);
1718     }
1719 
1720     test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig, &fingerprint_estrangelo);
1721     if (hfont != NULL)
1722     {
1723         test_shape_ok_valid(test_valid, hdc, test_syriac, 8, &Control, &State, 0, 7, syriac_c, syriac_g);
1724         SelectObject(hdc, hfont_orig);
1725         DeleteObject(hfont);
1726     }
1727 
1728     test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig, NULL);
1729     if (hfont != NULL)
1730     {
1731         test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
1732         SelectObject(hdc, hfont_orig);
1733         DeleteObject(hfont);
1734     }
1735 
1736     test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig, NULL);
1737     if (hfont != NULL)
1738     {
1739         test_shape_ok_valid_props2(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11,
1740                                    phagspa_c, phagspa_g, phagspa_win10_props);
1741         SelectObject(hdc, hfont_orig);
1742         DeleteObject(hfont);
1743     }
1744 
1745     test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig, NULL);
1746     if (hfont != NULL)
1747     {
1748         test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
1749         SelectObject(hdc, hfont_orig);
1750         DeleteObject(hfont);
1751     }
1752 
1753     test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig, NULL);
1754     if (hfont != NULL)
1755     {
1756         test_shape_ok_valid_props2(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17,
1757                                    tibetan_c, tibetan_g, tibetan_win10_props);
1758         SelectObject(hdc, hfont_orig);
1759         DeleteObject(hfont);
1760     }
1761 
1762     test_valid = find_font_for_range(hdc, "Mangal", 15, test_devanagari[0], &hfont, &hfont_orig, NULL);
1763     if (hfont != NULL)
1764     {
1765         test_shape_ok_valid(test_valid, hdc, test_devanagari, 8, &Control, &State, 0, 8, devanagari_c, devanagari_g);
1766         SelectObject(hdc, hfont_orig);
1767         DeleteObject(hfont);
1768     }
1769 
1770     test_valid = find_font_for_range(hdc, "Vrinda", 16, test_bengali[0], &hfont, &hfont_orig, NULL);
1771     if (hfont != NULL)
1772     {
1773         test_shape_ok_valid(test_valid, hdc, test_bengali, 5, &Control, &State, 0, 5, bengali_c, bengali_g);
1774         SelectObject(hdc, hfont_orig);
1775         DeleteObject(hfont);
1776     }
1777 
1778     test_valid = find_font_for_range(hdc, "Raavi", 17, test_gurmukhi[0], &hfont, &hfont_orig, NULL);
1779     if (hfont != NULL)
1780     {
1781         test_shape_ok_valid(test_valid, hdc, test_gurmukhi, 7, &Control, &State, 0, 7, gurmukhi_c, gurmukhi_g);
1782         SelectObject(hdc, hfont_orig);
1783         DeleteObject(hfont);
1784     }
1785 
1786     test_valid = find_font_for_range(hdc, "Shruti", 18, test_gujarati[0], &hfont, &hfont_orig, NULL);
1787     if (hfont != NULL)
1788     {
1789         test_shape_ok_valid(test_valid, hdc, test_gujarati, 7, &Control, &State, 0, 7, gujarati_c, gujarati_g);
1790         SelectObject(hdc, hfont_orig);
1791         DeleteObject(hfont);
1792     }
1793 
1794     test_valid = find_font_for_range(hdc, "Kalinga", 19, test_oriya[0], &hfont, &hfont_orig, NULL);
1795     if (hfont != NULL)
1796     {
1797         test_shape_ok_valid(test_valid, hdc, test_oriya, 5, &Control, &State, 0, 4, oriya_c, oriya_g);
1798         SelectObject(hdc, hfont_orig);
1799         DeleteObject(hfont);
1800     }
1801 
1802     test_valid = find_font_for_range(hdc, "Latha", 20, test_tamil[0], &hfont, &hfont_orig, NULL);
1803     if (hfont != NULL)
1804     {
1805         test_shape_ok_valid(test_valid, hdc, test_tamil, 5, &Control, &State, 0, 4, tamil_c, tamil_g);
1806         SelectObject(hdc, hfont_orig);
1807         DeleteObject(hfont);
1808     }
1809 
1810     test_valid = find_font_for_range(hdc, "Gautami", 21, test_telugu[0], &hfont, &hfont_orig, NULL);
1811     if (hfont != NULL)
1812     {
1813         test_shape_ok_valid(test_valid, hdc, test_telugu, 6, &Control, &State, 0, 6, telugu_c, telugu_g);
1814         SelectObject(hdc, hfont_orig);
1815         DeleteObject(hfont);
1816     }
1817 
1818     test_valid = find_font_for_range(hdc, "Kartika", 23, test_malayalam[0], &hfont, &hfont_orig, NULL);
1819     if (hfont != NULL)
1820     {
1821         test_shape_ok_valid(test_valid, hdc, test_malayalam, 6, &Control, &State, 0, 6, malayalam_c, malayalam_g);
1822         SelectObject(hdc, hfont_orig);
1823         DeleteObject(hfont);
1824     }
1825 
1826     test_valid = find_font_for_range(hdc, "Tunga", 22, test_kannada[0], &hfont, &hfont_orig, NULL);
1827     if (hfont != NULL)
1828     {
1829         test_shape_ok_valid(test_valid, hdc, test_kannada, 5, &Control, &State, 0, 4, kannada_c, kannada_g);
1830         SelectObject(hdc, hfont_orig);
1831         DeleteObject(hfont);
1832     }
1833 }
1834 
1835 static void test_ScriptShape(HDC hdc)
1836 {
1837     static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1838     static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1839     static const WCHAR test3[] = {0x30b7};
1840     HRESULT hr;
1841     SCRIPT_CACHE sc = NULL;
1842     SCRIPT_CACHE sc2 = NULL;
1843     WORD glyphs[4], glyphs2[4], logclust[4], glyphs3[4];
1844     SCRIPT_VISATTR attrs[4];
1845     SCRIPT_ITEM items[4];
1846     int nb, i, j;
1847 
1848     hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1849     ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
1850     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1851 
1852     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
1853     ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1854 
1855     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
1856     ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1857 
1858     hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1859     ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
1860 
1861     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1862     ok(broken(hr == S_OK) ||
1863        hr == E_INVALIDARG || /* Vista, W2K8 */
1864        hr == E_FAIL, /* WIN7 */
1865        "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1866     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1867 
1868     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1869     ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1870     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1871 
1872     hr = ScriptShape(hdc, &sc2, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1873     ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1874     ok(sc2 == sc, "caches %p, %p not identical\n", sc, sc2);
1875     ScriptFreeCache(&sc2);
1876 
1877     memset(glyphs,-1,sizeof(glyphs));
1878     memset(logclust,-1,sizeof(logclust));
1879     memset(attrs,-1,sizeof(attrs));
1880     hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1881     ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1882     ok(nb == 4, "Wrong number of items\n");
1883     ok(logclust[0] == 0, "clusters out of order\n");
1884     ok(logclust[1] == 1, "clusters out of order\n");
1885     ok(logclust[2] == 2, "clusters out of order\n");
1886     ok(logclust[3] == 3, "clusters out of order\n");
1887     ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1888     ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1889     ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1890     ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1891     ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1892     ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1893     ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1894     ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1895     ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1896     ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1897     ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1898     ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1899     ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1900     ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1901     ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1902     ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1903 
1904     ScriptFreeCache(&sc);
1905     sc = NULL;
1906 
1907     memset(glyphs2,-1,sizeof(glyphs2));
1908     memset(glyphs3,-1,sizeof(glyphs3));
1909     memset(logclust,-1,sizeof(logclust));
1910     memset(attrs,-1,sizeof(attrs));
1911 
1912     GetGlyphIndicesW(hdc, test2, 4, glyphs3, 0);
1913 
1914     hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1915     ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1916     ok(nb == 4, "Wrong number of items\n");
1917     ok(glyphs2[0] == glyphs3[0], "Incorrect glyph for 0x202B\n");
1918     ok(glyphs2[3] == glyphs3[3], "Incorrect glyph for 0x202C\n");
1919     ok(logclust[0] == 0, "clusters out of order\n");
1920     ok(logclust[1] == 1, "clusters out of order\n");
1921     ok(logclust[2] == 2, "clusters out of order\n");
1922     ok(logclust[3] == 3, "clusters out of order\n");
1923     ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1924     ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1925     ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1926     ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1927     ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1928     ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1929     ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1930     ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1931     ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1932     ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1933     ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1934     ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1935     ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1936     ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1937     ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1938     ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1939 
1940     /* modify LTR to RTL */
1941     items[0].a.fRTL = 1;
1942     memset(glyphs2,-1,sizeof(glyphs2));
1943     memset(logclust,-1,sizeof(logclust));
1944     memset(attrs,-1,sizeof(attrs));
1945     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1946     ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1947     ok(nb == 4, "Wrong number of items\n");
1948     ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
1949     ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
1950     ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
1951     ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
1952     ok(logclust[0] == 3, "clusters out of order\n");
1953     ok(logclust[1] == 2, "clusters out of order\n");
1954     ok(logclust[2] == 1, "clusters out of order\n");
1955     ok(logclust[3] == 0, "clusters out of order\n");
1956     ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1957     ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1958     ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1959     ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1960     ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1961     ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1962     ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1963     ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1964     ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1965     ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1966     ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1967     ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1968     ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1969     ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1970     ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1971     ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1972 
1973     ScriptFreeCache(&sc);
1974 
1975     /* some control characters are shown as blank */
1976     for (i = 0; i < 2; i++)
1977     {
1978         static const WCHAR space[]  = {' ', 0};
1979         static const struct
1980         {
1981             WCHAR c;
1982             unsigned int item_count;
1983             unsigned int item;
1984         }
1985         test_data[] =
1986         {
1987             {0x0009, 3, 1}, /* \t   */
1988             {0x000a, 3, 1}, /* \n   */
1989             {0x000d, 3, 1}, /* \r   */
1990             {0x001c, 3, 1}, /* FS   */
1991             {0x001d, 3, 1}, /* GS   */
1992             {0x001e, 3, 1}, /* RS   */
1993             {0x001f, 3, 1}, /* US   */
1994             {0x200b, 1, 0}, /* ZWSP */
1995             {0x200c, 1, 0}, /* ZWNJ */
1996             {0x200d, 1, 0}, /* ZWJ  */
1997             {0x200e, 3, 1}, /* LRM  */
1998             {0x200f, 3, 1}, /* RLM  */
1999             {0x202a, 3, 1}, /* LRE  */
2000             {0x202b, 3, 1}, /* RLE  */
2001             {0x202c, 3, 1}, /* PDF  */
2002             {0x202d, 3, 1}, /* LRO  */
2003             {0x202e, 3, 1}, /* RLO  */
2004         };
2005         WCHAR chars[3];
2006         HFONT font, oldfont = NULL;
2007         LOGFONTA lf;
2008 
2009         font = GetCurrentObject(hdc, OBJ_FONT);
2010         GetObjectA(font, sizeof(lf), &lf);
2011         if (i == 1) {
2012             lstrcpyA(lf.lfFaceName, "MS Sans Serif");
2013             font = CreateFontIndirectA(&lf);
2014             oldfont = SelectObject(hdc, font);
2015         }
2016 
2017         hr = ScriptItemize(space, 1, 2, NULL, NULL, items, NULL);
2018         ok(hr == S_OK, "%s: expected S_OK, got %08x\n", lf.lfFaceName, hr);
2019 
2020         hr = ScriptShape(hdc, &sc, space, 1, 1, &items[0].a, glyphs, logclust, attrs, &nb);
2021         ok(hr == S_OK, "%s: expected S_OK, got %08x\n", lf.lfFaceName, hr);
2022         ok(nb == 1, "%s: expected 1, got %d\n", lf.lfFaceName, nb);
2023 
2024         chars[0] = 'A';
2025         chars[2] = 'A';
2026         for (j = 0; j < ARRAY_SIZE(test_data); ++j)
2027         {
2028             WCHAR c = test_data[j].c;
2029             SCRIPT_ITEM *item;
2030 
2031             chars[1] = c;
2032             hr = ScriptItemize(chars, 3, 4, NULL, NULL, items, &nb);
2033             ok(hr == S_OK, "%s: [%02x] expected S_OK, got %08x\n", lf.lfFaceName, c, hr);
2034             ok(nb == test_data[j].item_count, "%s: [%02x] Got unexpected item count %d.\n",
2035                lf.lfFaceName, c, nb);
2036             item = &items[test_data[j].item];
2037 
2038             ok(!item->a.fNoGlyphIndex, "%s: [%02x] got unexpected fNoGlyphIndex %#x.\n",
2039                lf.lfFaceName, c, item->a.fNoGlyphIndex);
2040             hr = ScriptShape(hdc, &sc, chars, 3, 3, &item->a, glyphs2, logclust, attrs, &nb);
2041             ok(hr == S_OK, "%s: [%02x] expected S_OK, got %08x\n", lf.lfFaceName, c, hr);
2042             ok(nb == 3, "%s: [%02x] expected 3, got %d\n", lf.lfFaceName, c, nb);
2043             ok(!item->a.fNoGlyphIndex, "%s: [%02x] got unexpected fNoGlyphIndex %#x.\n",
2044                lf.lfFaceName, c, item->a.fNoGlyphIndex);
2045 
2046             ok(glyphs[0] == glyphs2[1] ||
2047                broken(glyphs2[1] == c && (c < 0x10)),
2048                "%s: [%02x] expected %04x, got %04x\n", lf.lfFaceName, c, glyphs[0], glyphs2[1]);
2049             ok(attrs[1].fZeroWidth || broken(!attrs[1].fZeroWidth && (c < 0x10) /* Vista */),
2050                "%s: [%02x] got unexpected fZeroWidth %#x.\n", lf.lfFaceName, c, attrs[1].fZeroWidth);
2051 
2052             item->a.fNoGlyphIndex = 1;
2053             hr = ScriptShape(hdc, &sc, chars, 3, 3, &item->a, glyphs2, logclust, attrs, &nb);
2054             ok(hr == S_OK, "%s: [%02x] expected S_OK, got %08x\n", lf.lfFaceName, c, hr);
2055             ok(nb == 3, "%s: [%02x] expected 1, got %d\n", lf.lfFaceName, c, nb);
2056 
2057             if (c == 0x200b || c == 0x200c || c == 0x200d)
2058             {
2059                 ok(glyphs2[1] == 0x0020,
2060                    "%s: [%02x] got unexpected %04x.\n", lf.lfFaceName, c, glyphs2[1]);
2061                 ok(attrs[1].fZeroWidth, "%s: [%02x] got unexpected fZeroWidth %#x.\n",
2062                    lf.lfFaceName, c, attrs[1].fZeroWidth);
2063             }
2064             else
2065             {
2066                 ok(glyphs2[1] == c,
2067                    "%s: [%02x] got unexpected %04x.\n", lf.lfFaceName, c, glyphs2[1]);
2068                 ok(!attrs[1].fZeroWidth, "%s: [%02x] got unexpected fZeroWidth %#x.\n",
2069                    lf.lfFaceName, c, attrs[1].fZeroWidth);
2070             }
2071         }
2072         if (oldfont)
2073             DeleteObject(SelectObject(hdc, oldfont));
2074         ScriptFreeCache(&sc);
2075     }
2076 
2077     /* Text does not support this range. */
2078     memset(items, 0, sizeof(items));
2079     nb = 0;
2080     hr = ScriptItemize(test3, ARRAY_SIZE(test3), ARRAY_SIZE(items), NULL, NULL, items, &nb);
2081     ok(hr == S_OK, "ScriptItemize failed, hr %#x.\n", hr);
2082     ok(items[0].a.eScript > 0, "Expected script id.\n");
2083     ok(nb == 1, "Unexpected number of items.\n");
2084 
2085     memset(glyphs, 0xff, sizeof(glyphs));
2086     nb = 0;
2087     hr = ScriptShape(hdc, &sc, test3, ARRAY_SIZE(test3), ARRAY_SIZE(glyphs),
2088             &items[0].a, glyphs, logclust, attrs, &nb);
2089     ok(hr == S_OK, "ScriptShape failed, hr %#x.\n", hr);
2090     ok(nb == 1, "Unexpected glyph count %u\n", nb);
2091     ok(glyphs[0] == 0, "Unexpected glyph id\n");
2092     ScriptFreeCache(&sc);
2093 }
2094 
2095 static void test_ScriptPlace(HDC hdc)
2096 {
2097     static const WCHAR test1[] = {'t', 'e', 's', 't',0};
2098     BOOL ret;
2099     HRESULT hr;
2100     SCRIPT_CACHE sc = NULL;
2101     SCRIPT_CACHE sc2 = NULL;
2102     WORD glyphs[4], logclust[4];
2103     SCRIPT_VISATTR attrs[4];
2104     SCRIPT_ITEM items[2];
2105     int nb, widths[4];
2106     GOFFSET offset[4];
2107     ABC abc[4];
2108 
2109     hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
2110     ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
2111     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
2112 
2113     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
2114     ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
2115     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
2116 
2117     hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
2118     ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
2119 
2120     hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
2121     ok(broken(hr == E_PENDING) ||
2122        hr == E_INVALIDARG || /* Vista, W2K8 */
2123        hr == E_FAIL, /* WIN7 */
2124        "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
2125 
2126     hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
2127     ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
2128 
2129     hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
2130     ok(broken(hr == E_PENDING) ||
2131        hr == E_INVALIDARG || /* Vista, W2K8 */
2132        hr == E_FAIL, /* WIN7 */
2133        "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
2134 
2135     hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
2136     ok(hr == S_OK, "ScriptPlace should return S_OK not %08x\n", hr);
2137     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
2138 
2139     hr = ScriptPlace(hdc, &sc2, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
2140     ok(hr == S_OK, "ScriptPlace should return S_OK not %08x\n", hr);
2141     ok(sc2 == sc, "caches %p, %p not identical\n", sc, sc2);
2142     ScriptFreeCache(&sc2);
2143 
2144     if (widths[0] != 0)
2145     {
2146         int old_width = widths[0];
2147         attrs[0].fZeroWidth = 1;
2148 
2149         hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
2150         ok(hr == S_OK, "ScriptPlace should return S_OK not %08x\n", hr);
2151         ok(widths[0] == 0, "got width %d\n", widths[0]);
2152         widths[0] = old_width;
2153     }
2154     else
2155         skip("Glyph already has zero-width - skipping fZeroWidth test\n");
2156 
2157     ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
2158     ok(ret, "ExtTextOutW should return TRUE\n");
2159 
2160     ScriptFreeCache(&sc);
2161 }
2162 
2163 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
2164 {
2165     HRESULT         hr;
2166     int             iMaxProps;
2167     const SCRIPT_PROPERTIES **ppSp;
2168 
2169     int             cInChars;
2170     SCRIPT_ITEM     pItem[255];
2171     int             pcItems;
2172     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
2173     WCHAR           TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
2174     WCHAR           TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
2175     WCHAR           TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
2176     WCHAR           TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
2177     WCHAR           TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
2178 
2179     SCRIPT_CACHE    psc;
2180     unsigned short  pwOutGlyphs1[256];
2181     unsigned short  pwLogClust[256];
2182     SCRIPT_VISATTR  psva[256];
2183     int             pcGlyphs;
2184     int             piAdvance[256];
2185     GOFFSET         pGoffset[256];
2186     ABC             pABC[256];
2187     unsigned int i;
2188 
2189     /* Verify we get a valid pointer from ScriptGetProperties(). */
2190     hr = ScriptGetProperties(&ppSp, &iMaxProps);
2191     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2192     trace("number of script properties %d\n", iMaxProps);
2193     ok(iMaxProps > 0, "Got unexpected script count %d.\n", iMaxProps);
2194     ok(ppSp[0]->langid == 0, "Got unexpected langid %#x.\n", ppSp[0]->langid);
2195 
2196     /* This is a valid test that will cause parsing to take place. */
2197     cInChars = lstrlenW(TestItem1);
2198     hr = ScriptItemize(TestItem1, cInChars, ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2199     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2200     /* This test is for the interim operation of ScriptItemize() where only
2201      * one SCRIPT_ITEM is returned. */
2202     ok(pcItems == 1, "Got unexpected item count %d.\n", pcItems);
2203     ok(pItem[0].iCharPos == 0, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2204     ok(pItem[1].iCharPos == cInChars, "Got unexpected character position %d, expected %d.\n",
2205             pItem[1].iCharPos, cInChars);
2206 
2207     psc = NULL;
2208     hr = ScriptShape(NULL, &psc, TestItem1, cInChars, cInChars,
2209             &pItem[0].a, pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2210     ok(hr == E_PENDING, "Got unexpected hr %#x.\n", hr);
2211 
2212     hr = ScriptShape(hdc, &psc, TestItem1, cInChars, cInChars - 1,
2213             &pItem[0].a, pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2214     ok(hr == E_OUTOFMEMORY, "Got unexpected hr %#x.\n", hr);
2215 
2216     hr = ScriptShape(hdc, &psc, TestItem1, cInChars, ARRAY_SIZE(pwOutGlyphs1),
2217             &pItem[0].a, pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2218     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2219     ok(!!psc, "Got unexpected psc %p.\n", psc);
2220     ok(pcGlyphs == cInChars, "Got unexpected glyph count %d, expected %d.\n", pcGlyphs, cInChars);
2221 
2222     /* Send to next test. */
2223     memcpy(pwOutGlyphs, pwOutGlyphs1, pcGlyphs * sizeof(*pwOutGlyphs));
2224 
2225     hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs,
2226             psva, &pItem[0].a, piAdvance, pGoffset, pABC);
2227     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2228     hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs,
2229             psva, &pItem[0].a, piAdvance, pGoffset, pABC);
2230     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2231 
2232     /* This test verifies that SCRIPT_CACHE is reused and that no translation
2233      * takes place if fNoGlyphIndex is set. */
2234     cInChars = lstrlenW(TestItem2);
2235     hr = ScriptItemize(TestItem2, cInChars, ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2236     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2237     /* This test is for the interim operation of ScriptItemize() where only
2238      * one SCRIPT_ITEM is returned. */
2239     ok(pcItems == 1, "Got unexpected item count %d.\n", pcItems);
2240     ok(pItem[0].iCharPos == 0, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2241     ok(pItem[1].iCharPos == cInChars, "Got unexpected character position %d, expected %d.\n",
2242             pItem[1].iCharPos, cInChars);
2243 
2244     pItem[0].a.fNoGlyphIndex = 1; /* No translation. */
2245     hr = ScriptShape(NULL, &psc, TestItem2, cInChars, ARRAY_SIZE(pwOutGlyphs1),
2246            &pItem[0].a, pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2247     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2248     ok(!!psc, "Got unexpected psc %p.\n", psc);
2249     ok(pcGlyphs == cInChars, "Got unexpected glyph count %d, expected %d.\n", pcGlyphs, cInChars);
2250 
2251     for (i = 0; i < cInChars; ++i)
2252     {
2253         ok(pwOutGlyphs1[i] == TestItem2[i],
2254                 "Got unexpected pwOutGlyphs1[%u] %#x, expected %#x.\n",
2255                 i, pwOutGlyphs1[i], TestItem2[i]);
2256     }
2257 
2258     hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs,
2259             psva, &pItem[0].a, piAdvance, pGoffset, pABC);
2260     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2261     ScriptFreeCache(&psc);
2262     ok(!psc, "Got unexpected psc %p.\n", psc);
2263 
2264     /* This is a valid test that will cause parsing to take place and create 3
2265      * script_items. */
2266     cInChars = lstrlenW(TestItem3);
2267     hr = ScriptItemize(TestItem3, cInChars, ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2268     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2269     ok(pcItems == 3, "Got unexpected item count %d.\n", pcItems);
2270     ok(pItem[0].iCharPos == 0, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2271     ok(pItem[1].iCharPos == 6, "Got unexpected character position %d.\n", pItem[1].iCharPos);
2272     ok(pItem[2].iCharPos == 11, "Got unexpected character position %d.\n", pItem[2].iCharPos);
2273     ok(pItem[3].iCharPos == cInChars, "Got unexpected character position %d, expected %d.\n",
2274             pItem[3].iCharPos, cInChars);
2275 
2276     /* This is a valid test that will cause parsing to take place and create 5
2277      * script_items. */
2278     cInChars = lstrlenW(TestItem4);
2279     hr = ScriptItemize(TestItem4, cInChars, ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2280     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2281     ok(pcItems == 5, "Got unexpected item count %d.\n", pcItems);
2282 
2283     ok(pItem[0].iCharPos == 0, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2284     ok(pItem[1].iCharPos == 6, "Got unexpected character position %d.\n", pItem[1].iCharPos);
2285     ok(pItem[2].iCharPos == 11, "Got unexpected character position %d.\n", pItem[2].iCharPos);
2286     ok(pItem[3].iCharPos == 12, "Got unexpected character position %d.\n", pItem[3].iCharPos);
2287     ok(pItem[4].iCharPos == 13, "Got unexpected character position %d.\n", pItem[4].iCharPos);
2288     ok(pItem[5].iCharPos == cInChars, "Got unexpected character position %d, expected %d.\n",
2289             pItem[5].iCharPos, cInChars);
2290 
2291     ok(pItem[0].a.s.uBidiLevel == 0, "Got unexpected bidi level %u.\n", pItem[0].a.s.uBidiLevel);
2292     ok(pItem[1].a.s.uBidiLevel == 1, "Got unexpected bidi level %u.\n", pItem[1].a.s.uBidiLevel);
2293     ok(pItem[2].a.s.uBidiLevel == 0, "Got unexpected bidi level %u.\n", pItem[2].a.s.uBidiLevel);
2294     ok(pItem[3].a.s.uBidiLevel == 0, "Got unexpected bidi level %u.\n", pItem[3].a.s.uBidiLevel);
2295     ok(pItem[4].a.s.uBidiLevel == 0, "Got unexpected bidi level %u.\n", pItem[3].a.s.uBidiLevel);
2296 
2297     /* This test is for when the first Unicode character requires BiDi support. */
2298     hr = ScriptItemize(TestItem5, lstrlenW(TestItem5), ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2299     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2300     ok(pcItems == 4, "Got unexpected item count %d.\n", pcItems);
2301     ok(pItem[0].a.s.uBidiLevel == 1, "Got unexpected bidi level %u.\n", pItem[0].a.s.uBidiLevel);
2302 
2303     /* This test verifies that the test to see if there are sufficient buffers
2304      * to store the pointer to the last character works. Note that Windows
2305      * often needs a greater number of SCRIPT_ITEMS to process a string than
2306      * is returned in pcItems. */
2307     hr = ScriptItemize(TestItem6, lstrlenW(TestItem6), 4, NULL, NULL, pItem, &pcItems);
2308     ok(hr == E_OUTOFMEMORY, "Got unexpected hr %#x.\n", hr);
2309 }
2310 
2311 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
2312 {
2313     HRESULT         hr;
2314     SCRIPT_CACHE    psc = NULL;
2315     int             cInChars;
2316     int             cChars;
2317     unsigned short  pwOutGlyphs2[256];
2318     unsigned short  pwOutGlyphs3[256];
2319     DWORD           dwFlags;
2320     int             cnt;
2321 
2322     static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
2323     static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
2324     static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
2325     static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
2326 
2327     /*  Check to make sure that SCRIPT_CACHE gets allocated ok                     */
2328     dwFlags = 0;
2329     cInChars = cChars = 5;
2330     /* Some sanity checks for ScriptGetCMap */
2331 
2332     hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
2333     ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
2334                             "expected E_INVALIDARG, got %08x\n", hr);
2335 
2336     hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
2337     ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
2338                             "expected E_INVALIDARG, got %08x\n", hr);
2339 
2340     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2341     psc = NULL;
2342     hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
2343     ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
2344                          "got %08x\n", hr);
2345     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2346 
2347     /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
2348     psc = NULL;
2349     hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
2350     ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
2351                     "got %08x\n", hr);
2352     ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
2353     ScriptFreeCache( &psc);
2354 
2355     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2356     psc = NULL;
2357     hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
2358     ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
2359     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2360     /*  Check to see if the results are the same as those returned by ScriptShape  */
2361     hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
2362     ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2363     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2364     for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
2365     ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
2366                          cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
2367 
2368     ScriptFreeCache( &psc);
2369     ok (!psc, "psc is not null after ScriptFreeCache\n");
2370 
2371     /* ScriptGetCMap returns whatever font defines, no special treatment for control chars */
2372     cInChars = cChars = 4;
2373     GetGlyphIndicesW(hdc, TestItem2, cInChars, pwOutGlyphs2, 0);
2374 
2375     hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
2376     if (pwOutGlyphs3[0] == 0 || pwOutGlyphs3[3] == 0)
2377         ok(hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
2378     else
2379         ok(hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2380 
2381     ok(psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2382     ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "expected glyph %d, got %d\n", pwOutGlyphs2[0], pwOutGlyphs3[0]);
2383     ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "expected glyph %d, got %d\n", pwOutGlyphs2[3], pwOutGlyphs3[3]);
2384 
2385     cInChars = cChars = 9;
2386     hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
2387     ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2388     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2389 
2390     cInChars = cChars = 9;
2391     dwFlags = SGCM_RTL;
2392     hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
2393     ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2394     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2395     ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
2396     ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorrectly altered\n");
2397     ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorrectly altered\n");
2398     ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorrectly altered\n");
2399     ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
2400     ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
2401     ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
2402     ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
2403     ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
2404 
2405     ScriptFreeCache( &psc);
2406     ok (!psc, "psc is not null after ScriptFreeCache\n");
2407 }
2408 
2409 #define MAX_ENUM_FONTS 4096
2410 
2411 struct enum_font_data
2412 {
2413     int total;
2414     ENUMLOGFONTA elf[MAX_ENUM_FONTS];
2415 };
2416 
2417 static INT CALLBACK enum_bitmap_font_proc(const LOGFONTA *lf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)
2418 {
2419     struct enum_font_data *efnd = (struct enum_font_data *)lParam;
2420 
2421     if (type & (TRUETYPE_FONTTYPE | DEVICE_FONTTYPE)) return 1;
2422 
2423     if (efnd->total < MAX_ENUM_FONTS)
2424     {
2425         efnd->elf[efnd->total++] = *(ENUMLOGFONTA*)lf;
2426     }
2427     else
2428         trace("enum tests invalid; you have more than %d fonts\n", MAX_ENUM_FONTS);
2429 
2430     return 1;
2431 }
2432 
2433 static INT CALLBACK enum_truetype_proc(const LOGFONTA *lf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)
2434 {
2435     struct enum_font_data *efnd = (struct enum_font_data *)lParam;
2436 
2437     if (!(type & (TRUETYPE_FONTTYPE | DEVICE_FONTTYPE))) return 1;
2438 
2439     if (efnd->total < MAX_ENUM_FONTS)
2440     {
2441         efnd->elf[efnd->total++] = *(ENUMLOGFONTA*)lf;
2442     }
2443     else
2444         trace("enum tests invalid; you have more than %d fonts\n", MAX_ENUM_FONTS);
2445 
2446     return 1;
2447 }
2448 
2449 static void test_ScriptGetFontProperties(HDC hdc)
2450 {
2451     HRESULT         hr;
2452     SCRIPT_CACHE    psc,old_psc;
2453     SCRIPT_FONTPROPERTIES sfp;
2454     HFONT font, oldfont;
2455     LOGFONTA lf;
2456     struct enum_font_data efnd;
2457     TEXTMETRICA tmA;
2458     WORD gi[3];
2459     WCHAR str[3];
2460     DWORD  i, ret;
2461     WORD system_lang_id = PRIMARYLANGID(GetSystemDefaultLangID());
2462     static const WCHAR invalids[] = {0x0020, 0x200B, 0xF71B};
2463     /* U+0020: numeric space
2464        U+200B: zero width space
2465        U+F71B: unknown, found by black box testing */
2466     BOOL is_arial, is_times_new_roman, is_arabic = (system_lang_id == LANG_ARABIC);
2467 
2468     /* Some sanity checks for ScriptGetFontProperties */
2469 
2470     hr = ScriptGetFontProperties(NULL,NULL,NULL);
2471     ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
2472 
2473     hr = ScriptGetFontProperties(NULL,NULL,&sfp);
2474     ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
2475 
2476     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2477     psc = NULL;
2478     hr = ScriptGetFontProperties(NULL,&psc,NULL);
2479     ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
2480     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2481 
2482     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2483     psc = NULL;
2484     hr = ScriptGetFontProperties(NULL,&psc,&sfp);
2485     ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
2486     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2487 
2488     hr = ScriptGetFontProperties(hdc,NULL,NULL);
2489     ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
2490 
2491     hr = ScriptGetFontProperties(hdc,NULL,&sfp);
2492     ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
2493 
2494     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2495     psc = NULL;
2496     hr = ScriptGetFontProperties(hdc,&psc,NULL);
2497     ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
2498     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2499 
2500     /* Pass an invalid sfp */
2501     psc = NULL;
2502     sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
2503     hr = ScriptGetFontProperties(hdc,&psc,&sfp);
2504     ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
2505     ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
2506     ok( sfp.cBytes == sizeof(SCRIPT_FONTPROPERTIES) - 1, "Unexpected cBytes.\n");
2507     ScriptFreeCache(&psc);
2508     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2509 
2510     /* Give it the correct cBytes, we don't care about what's coming back */
2511     sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
2512     psc = NULL;
2513     hr = ScriptGetFontProperties(hdc,&psc,&sfp);
2514     ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
2515     ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
2516 
2517     /* Save the psc pointer */
2518     old_psc = psc;
2519     /* Now a NULL hdc again */
2520     hr = ScriptGetFontProperties(NULL,&psc,&sfp);
2521     ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
2522     ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
2523     ScriptFreeCache(&psc);
2524     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2525 
2526     memset(&lf, 0, sizeof(lf));
2527     lf.lfCharSet = DEFAULT_CHARSET;
2528     efnd.total = 0;
2529     EnumFontFamiliesA(hdc, NULL, enum_bitmap_font_proc, (LPARAM)&efnd);
2530 
2531     for (i = 0; i < efnd.total; i++)
2532     {
2533         if (strlen((char *)efnd.elf[i].elfFullName) >= LF_FACESIZE)
2534         {
2535             trace("Font name to long to test: %s\n",(char *)efnd.elf[i].elfFullName);
2536             continue;
2537         }
2538         lstrcpyA(lf.lfFaceName, (char *)efnd.elf[i].elfFullName);
2539         font = CreateFontIndirectA(&lf);
2540         oldfont = SelectObject(hdc, font);
2541 
2542         sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
2543         psc = NULL;
2544         hr = ScriptGetFontProperties(hdc, &psc, &sfp);
2545         ok(hr == S_OK, "ScriptGetFontProperties expected S_OK, got %08x\n", hr);
2546         if (winetest_interactive)
2547         {
2548             trace("bitmap font %s\n", lf.lfFaceName);
2549             trace("wgBlank %04x\n", sfp.wgBlank);
2550             trace("wgDefault %04x\n", sfp.wgDefault);
2551             trace("wgInvalid %04x\n", sfp.wgInvalid);
2552             trace("wgKashida %04x\n", sfp.wgKashida);
2553             trace("iKashidaWidth %d\n", sfp.iKashidaWidth);
2554         }
2555 
2556         ret = GetTextMetricsA(hdc, &tmA);
2557         ok(ret != 0, "GetTextMetricsA failed!\n");
2558 
2559         ret = GetGlyphIndicesW(hdc, invalids, 1, gi, GGI_MARK_NONEXISTING_GLYPHS);
2560         ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2561 
2562         ok(sfp.wgBlank == tmA.tmBreakChar || sfp.wgBlank == gi[0], "bitmap font %s wgBlank %04x tmBreakChar %04x Space %04x\n", lf.lfFaceName, sfp.wgBlank, tmA.tmBreakChar, gi[0]);
2563 
2564         ok(sfp.wgDefault == 0 || sfp.wgDefault == tmA.tmDefaultChar || broken(sfp.wgDefault == (0x100 | tmA.tmDefaultChar)), "bitmap font %s wgDefault %04x, tmDefaultChar %04x\n", lf.lfFaceName, sfp.wgDefault, tmA.tmDefaultChar);
2565 
2566         ok(sfp.wgInvalid == sfp.wgBlank || broken(is_arabic), "bitmap font %s wgInvalid %02x wgBlank %02x\n", lf.lfFaceName, sfp.wgInvalid, sfp.wgBlank);
2567 
2568         ok(sfp.wgKashida == 0xFFFF || broken(is_arabic), "bitmap font %s wgKashida %02x\n", lf.lfFaceName, sfp.wgKashida);
2569 
2570         ScriptFreeCache(&psc);
2571 
2572         SelectObject(hdc, oldfont);
2573         DeleteObject(font);
2574     }
2575 
2576     efnd.total = 0;
2577     EnumFontFamiliesA(hdc, NULL, enum_truetype_proc, (LPARAM)&efnd);
2578 
2579     for (i = 0; i < efnd.total; i++)
2580     {
2581         if (strlen((char *)efnd.elf[i].elfFullName) >= LF_FACESIZE)
2582         {
2583             trace("Font name to long to test: %s\n",(char *)efnd.elf[i].elfFullName);
2584             continue;
2585         }
2586         lstrcpyA(lf.lfFaceName, (char *)efnd.elf[i].elfFullName);
2587         font = CreateFontIndirectA(&lf);
2588         oldfont = SelectObject(hdc, font);
2589 
2590         sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
2591         psc = NULL;
2592         hr = ScriptGetFontProperties(hdc, &psc, &sfp);
2593         ok(hr == S_OK, "ScriptGetFontProperties expected S_OK, got %08x\n", hr);
2594         if (winetest_interactive)
2595         {
2596             trace("truetype font %s\n", lf.lfFaceName);
2597             trace("wgBlank %04x\n", sfp.wgBlank);
2598             trace("wgDefault %04x\n", sfp.wgDefault);
2599             trace("wgInvalid %04x\n", sfp.wgInvalid);
2600             trace("wgKashida %04x\n", sfp.wgKashida);
2601             trace("iKashidaWidth %d\n", sfp.iKashidaWidth);
2602         }
2603 
2604         str[0] = 0x0020; /* U+0020: numeric space */
2605         ret = GetGlyphIndicesW(hdc, str, 1, gi, 0);
2606         ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2607         ok(sfp.wgBlank == gi[0], "truetype font %s wgBlank %04x gi[0] %04x\n", lf.lfFaceName, sfp.wgBlank, gi[0]);
2608 
2609         ok(sfp.wgDefault == 0 || broken(is_arabic), "truetype font %s wgDefault %04x\n", lf.lfFaceName, sfp.wgDefault);
2610 
2611         ret = GetGlyphIndicesW(hdc, invalids, 3, gi, GGI_MARK_NONEXISTING_GLYPHS);
2612         ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2613         if (gi[2] != 0xFFFF) /* index of default non exist char */
2614             ok(sfp.wgInvalid == gi[2], "truetype font %s wgInvalid %04x gi[2] %04x\n", lf.lfFaceName, sfp.wgInvalid, gi[2]);
2615         else if (gi[1] != 0xFFFF)
2616             ok(sfp.wgInvalid == gi[1], "truetype font %s wgInvalid %04x gi[1] %04x\n", lf.lfFaceName, sfp.wgInvalid, gi[1]);
2617         else if (gi[0] != 0xFFFF)
2618             ok(sfp.wgInvalid == gi[0], "truetype font %s wgInvalid %04x gi[0] %04x\n", lf.lfFaceName, sfp.wgInvalid, gi[0]);
2619         else
2620             ok(sfp.wgInvalid == 0, "truetype font %s wgInvalid %04x expect 0\n", lf.lfFaceName, sfp.wgInvalid);
2621 
2622         str[0] = 0x0640; /* U+0640: kashida */
2623         ret = GetGlyphIndicesW(hdc, str, 1, gi, GGI_MARK_NONEXISTING_GLYPHS);
2624         ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2625         is_arial = !lstrcmpA(lf.lfFaceName, "Arial");
2626         is_times_new_roman= !lstrcmpA(lf.lfFaceName, "Times New Roman");
2627         ok(sfp.wgKashida == gi[0] || broken(is_arial || is_times_new_roman) || broken(is_arabic), "truetype font %s wgKashida %04x gi[0] %04x\n", lf.lfFaceName, sfp.wgKashida, gi[0]);
2628 
2629         ScriptFreeCache(&psc);
2630 
2631         SelectObject(hdc, oldfont);
2632         DeleteObject(font);
2633     }
2634 }
2635 
2636 static void test_ScriptTextOut(HDC hdc)
2637 {
2638     HRESULT         hr;
2639 
2640     int             cInChars;
2641     SCRIPT_ITEM     pItem[255];
2642     int             pcItems;
2643     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
2644 
2645     SCRIPT_CACHE    psc;
2646     unsigned short  pwOutGlyphs1[256];
2647     WORD            pwLogClust[256];
2648     SCRIPT_VISATTR  psva[256];
2649     int             pcGlyphs;
2650     int             piAdvance[256];
2651     GOFFSET         pGoffset[256];
2652     ABC             pABC[256];
2653     RECT            rect;
2654     int             piX;
2655     SCRIPT_LOGATTR  sla[256];
2656 
2657     /* This is a valid test that will cause parsing to take place. */
2658     cInChars = lstrlenW(TestItem1);
2659     hr = ScriptItemize(TestItem1, cInChars, ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2660     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2661     /* This test is for the interim operation of ScriptItemize() where only
2662      * one SCRIPT_ITEM is returned. */
2663     ok(pcItems == 1, "Got unexpected item count %d.\n", pcItems);
2664     ok(pItem[0].iCharPos == 0, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2665     ok(pItem[1].iCharPos == cInChars, "Got unexpected character position %d, expected %d.\n",
2666             pItem[1].iCharPos, cInChars);
2667 
2668     psc = NULL;
2669     cInChars = 5;
2670     hr = ScriptShape(hdc, &psc, TestItem1, cInChars, ARRAY_SIZE(pwOutGlyphs1),
2671             &pItem[0].a, pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2672     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2673     ok(!!psc, "Got unexpected psc %p.\n", psc);
2674     ok(pcGlyphs == cInChars, "Got unexpected glyph count %d, expected %d.\n", pcGlyphs, cInChars);
2675 
2676     /* Note hdc is needed as glyph info is not yet in psc. */
2677     hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs,
2678             psva, &pItem[0].a, piAdvance, pGoffset, pABC);
2679     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2680     /* Get rid of psc for next test set. */
2681     ScriptFreeCache(&psc);
2682     ok(!psc, "Got unexpected psc %p.\n", psc);
2683 
2684     hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
2685     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2686 
2687     hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0,
2688             pwOutGlyphs1, pcGlyphs, piAdvance, NULL, pGoffset);
2689     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2690 
2691     hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
2692     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2693     ok(!psc, "Got unexpected psc %p.\n", psc);
2694 
2695     /* hdc is required. */
2696     hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0,
2697             pwOutGlyphs1, pcGlyphs, piAdvance, NULL, pGoffset);
2698     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2699     ok(!psc, "Got unexpected psc %p.\n", psc);
2700     hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0,
2701             pwOutGlyphs1, pcGlyphs, piAdvance, NULL, pGoffset);
2702     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2703 
2704     /* Test Rect Rgn is acceptable. */
2705     SetRect(&rect, 10, 10, 40, 20);
2706     hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0,
2707             pwOutGlyphs1, pcGlyphs, piAdvance, NULL, pGoffset);
2708     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2709 
2710     hr = ScriptCPtoX(1, FALSE, cInChars, pcGlyphs, pwLogClust, psva, piAdvance, &pItem[0].a, &piX);
2711     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2712 
2713     hr = ScriptBreak(TestItem1, cInChars, &pItem[0].a, sla);
2714     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2715 
2716     ScriptFreeCache(&psc);
2717     ok(!psc, "Got unexpected psc %p.\n", psc);
2718 }
2719 
2720 /* The intent is to validate that the DC passed into ScriptTextOut() is used
2721  * instead of the (possibly) invalid cached one. */
2722 static void test_ScriptTextOut2(HDC hdc)
2723 {
2724     HRESULT         hr;
2725 
2726     HDC             hdc1, hdc2;
2727     int             cInChars;
2728     SCRIPT_ITEM     pItem[255];
2729     int             pcItems;
2730     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
2731 
2732     SCRIPT_CACHE    psc;
2733     unsigned short  pwOutGlyphs1[256];
2734     WORD            pwLogClust[256];
2735     SCRIPT_VISATTR  psva[256];
2736     int             pcGlyphs;
2737     int             piAdvance[256];
2738     GOFFSET         pGoffset[256];
2739     ABC             pABC[256];
2740     BOOL ret;
2741 
2742     /* Create an extra DC that will be used until the ScriptTextOut() call. */
2743     hdc1 = CreateCompatibleDC(hdc);
2744     ok(!!hdc1, "Failed to create a DC.\n");
2745     hdc2 = CreateCompatibleDC(hdc);
2746     ok(!!hdc2, "Failed to create a DC.\n");
2747 
2748     /* This is a valid test that will cause parsing to take place. */
2749     cInChars = lstrlenW(TestItem1);
2750     hr = ScriptItemize(TestItem1, cInChars, ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2751     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2752     /* This test is for the interim operation of ScriptItemize() where only
2753      * one SCRIPT_ITEM is returned. */
2754     ok(pcItems == 1, "Got unexpected item count %d.\n", pcItems);
2755     ok(pItem[0].iCharPos == 0, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2756     ok(pItem[1].iCharPos == cInChars, "Got unexpected character position %d, expected %d.\n",
2757             pItem[1].iCharPos, cInChars);
2758 
2759     psc = NULL;
2760     hr = ScriptShape(hdc2, &psc, TestItem1, cInChars, ARRAY_SIZE(pwOutGlyphs1),
2761             &pItem[0].a, pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2762     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2763     ok(!!psc, "Got unexpected psc %p.\n", psc);
2764     ok(pcGlyphs == cInChars, "Got unexpected glyph count %d, expected %d.\n", pcGlyphs, cInChars);
2765 
2766     /* Note hdc is needed as glyph info is not yet in psc. */
2767     hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs,
2768             psva, &pItem[0].a, piAdvance, pGoffset, pABC);
2769     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2770 
2771     /* Key part! Cached DC is being deleted. */
2772     ret = DeleteDC(hdc2);
2773     ok(ret, "Got unexpected ret %#x.\n", ret);
2774 
2775     /* At this point the cached DC (hdc2) has been destroyed. However, we are
2776      * passing in a *real* DC (the original DC). The text should be written to
2777      * that DC. */
2778     hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0,
2779             pwOutGlyphs1, pcGlyphs, piAdvance, NULL, pGoffset);
2780     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2781     ok(!!psc, "Got unexpected psc %p.\n", psc);
2782 
2783     DeleteDC(hdc1);
2784 
2785     ScriptFreeCache(&psc);
2786     ok(!psc, "Got unexpected psc %p.\n", psc);
2787 }
2788 
2789 static void test_ScriptTextOut3(HDC hdc)
2790 {
2791     HRESULT         hr;
2792 
2793     int             cInChars;
2794     SCRIPT_ITEM     pItem[255];
2795     int             pcItems;
2796     WCHAR           TestItem1[] = {' ','\r', 0};
2797 
2798     SCRIPT_CACHE    psc;
2799     unsigned short  pwOutGlyphs1[256];
2800     WORD            pwLogClust[256];
2801     SCRIPT_VISATTR  psva[256];
2802     int             pcGlyphs;
2803     int             piAdvance[256];
2804     GOFFSET         pGoffset[256];
2805     ABC             pABC[256];
2806     RECT            rect;
2807 
2808     /* This is to ensure that non-existent glyphs are translated into a valid
2809      * glyph number. */
2810     cInChars = lstrlenW(TestItem1);
2811     hr = ScriptItemize(TestItem1, cInChars, ARRAY_SIZE(pItem), NULL, NULL, pItem, &pcItems);
2812     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2813     /* This test is for the interim operation of ScriptItemize() where only
2814      * one SCRIPT_ITEM is returned. */
2815     ok(pcItems == 2, "Got unexpected item count %d.\n", pcItems);
2816     ok(pItem[0].iCharPos == 0, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2817     ok(pItem[1].iCharPos == 1, "Got unexpected character position %d.\n", pItem[0].iCharPos);
2818     ok(pItem[2].iCharPos == cInChars, "Got unexpected character position %d, expected %d.\n",
2819             pItem[2].iCharPos, cInChars);
2820 
2821     psc = NULL;
2822     hr = ScriptShape(hdc, &psc, TestItem1, cInChars, ARRAY_SIZE(pwOutGlyphs1),
2823             &pItem[0].a, pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2824     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2825     ok(!!psc, "Got unexpected psc %p.\n", psc);
2826     ok(pcGlyphs == cInChars, "Got unexpected glyph count %d, expected %d.\n", pcGlyphs, cInChars);
2827 
2828     /* Note hdc is needed as glyph info is not yet in psc. */
2829     hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs,
2830             psva, &pItem[0].a, piAdvance, pGoffset, pABC);
2831     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2832 
2833     /* Test Rect Rgn is acceptable. */
2834     SetRect(&rect, 10, 10, 40, 20);
2835     hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0,
2836             pwOutGlyphs1, pcGlyphs, piAdvance, NULL, pGoffset);
2837     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2838 
2839     ScriptFreeCache(&psc);
2840     ok(!psc, "Got unexpected psc %p.\n", psc);
2841 }
2842 
2843 #define test_item_ScriptXtoX(a,b,c,d,e,f) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_item_ScriptXtoX(a,b,c,d,e,f)
2844 
2845 static void _test_item_ScriptXtoX(SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
2846 {
2847     int iX, iCP;
2848     int icChars, icGlyphs;
2849     int piCP, piX;
2850     HRESULT hr;
2851     SCRIPT_VISATTR psva[10];
2852     int piTrailing;
2853     BOOL fTrailing;
2854     int direction;
2855 
2856     memset(psva,0,sizeof(psva));
2857     direction = (psa->fRTL)?-1:+1;
2858 
2859     for(iCP = 0; iCP < cChars; iCP++)
2860     {
2861         iX = offsets[iCP];
2862         icChars = cChars;
2863         icGlyphs = cGlyphs;
2864         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2865         winetest_ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
2866         winetest_ok(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2867         winetest_ok(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2868     }
2869 
2870     for(iCP = 0; iCP < cChars; iCP++)
2871     {
2872         iX = offsets[iCP]+direction;
2873         icChars = cChars;
2874         icGlyphs = cGlyphs;
2875         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2876         winetest_ok(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
2877         winetest_ok(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2878         winetest_ok(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2879     }
2880 
2881     for(iCP = 0; iCP < cChars; iCP++)
2882     {
2883         iX = offsets[iCP+1]-direction;
2884         icChars = cChars;
2885         icGlyphs = cGlyphs;
2886         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2887         winetest_ok(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
2888         winetest_ok(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2889         winetest_ok(piTrailing == 1, "ScriptXtoCP trailing: iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2890     }
2891 
2892     for(iCP = 0; iCP <= cChars+1; iCP++)
2893     {
2894         fTrailing = FALSE;
2895         icChars = cChars;
2896         icGlyphs = cGlyphs;
2897         hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2898         winetest_ok(hr == S_OK, "ScriptCPtoX: should return S_OK not %08x\n", hr);
2899         winetest_ok(piX == offsets[iCP],
2900            "ScriptCPtoX: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
2901     }
2902 
2903     for(iCP = 0; iCP <= cChars+1; iCP++)
2904     {
2905         fTrailing = TRUE;
2906         icChars = cChars;
2907         icGlyphs = cGlyphs;
2908         hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2909         winetest_ok(hr == S_OK, "ScriptCPtoX trailing: should return S_OK not %08x\n", hr);
2910         winetest_ok(piX == offsets[iCP+1],
2911            "ScriptCPtoX trailing: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
2912     }
2913 }
2914 
2915 #define test_caret_item_ScriptXtoCP(a,b,c,d,e,f) _test_caret_item_ScriptXtoCP(__LINE__,a,b,c,d,e,f)
2916 
2917 static void _test_caret_item_ScriptXtoCP(int line, SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
2918 {
2919     int iX, iCP, i;
2920     int icChars, icGlyphs;
2921     int piCP;
2922     int clusterSize;
2923     HRESULT hr;
2924     SCRIPT_VISATTR psva[10];
2925     int piTrailing;
2926     int direction;
2927 
2928     memset(psva,0,sizeof(psva));
2929     direction = (psa->fRTL)?-1:+1;
2930 
2931     for(iX = -1, i = iCP = 0; i < cChars; i++)
2932     {
2933         if (offsets[i] != iX)
2934         {
2935             iX = offsets[i];
2936             iCP = i;
2937         }
2938         icChars = cChars;
2939         icGlyphs = cGlyphs;
2940         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2941         ok_(__FILE__,line)(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
2942         ok_(__FILE__,line)(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2943         ok_(__FILE__,line)(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2944     }
2945 
2946     for(iX = -2, i = 0; i < cChars; i++)
2947     {
2948         if (offsets[i]+direction != iX)
2949         {
2950             iX = offsets[i] + direction;
2951             iCP = i;
2952         }
2953         icChars = cChars;
2954         icGlyphs = cGlyphs;
2955         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2956         ok_(__FILE__,line)(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
2957         ok_(__FILE__,line)(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2958         ok_(__FILE__,line)(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2959     }
2960 
2961     for(clusterSize = 0, iCP = 0, iX = -2, i = 0; i < cChars; i++)
2962     {
2963         clusterSize++;
2964         if (offsets[i] != offsets[i+1])
2965         {
2966             iX = offsets[i+1]-direction;
2967             icChars = cChars;
2968             icGlyphs = cGlyphs;
2969             hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2970             ok_(__FILE__,line)(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
2971             ok_(__FILE__,line)(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2972             ok_(__FILE__,line)(piTrailing == clusterSize, "ScriptXtoCP trailing: iX=%d should return piTrailing=%d not %d\n", iX, clusterSize, piTrailing);
2973             iCP = i+1;
2974             clusterSize = 0;
2975         }
2976     }
2977 }
2978 
2979 static void test_ScriptXtoX(void)
2980 /****************************************************************************************
2981  *  This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
2982  ****************************************************************************************/
2983 {
2984     WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
2985     WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
2986     WORD pwLogClust_2[7] = {4, 3, 3, 2, 1, 0 ,0};
2987     WORD pwLogClust_3[17] = {0, 1, 1, 1, 1, 4, 5, 6, 6, 8, 8, 8, 8, 11, 11, 13, 13};
2988     WORD pwLogClust_3_RTL[17] = {13, 13, 11, 11, 8, 8, 8, 8, 6, 6, 5, 4, 1, 1, 1, 1, 0};
2989     int piAdvance[10] = {201, 190, 210, 180, 170, 204, 189, 195, 212, 203};
2990     int piAdvance_2[5] = {39, 26, 19, 17, 11};
2991     int piAdvance_3[15] = {6, 6, 0, 0, 10, 5, 10, 0, 12, 0, 0, 9, 0, 10, 0};
2992     static const int offsets[13] = {0, 67, 134, 201, 296, 391, 496, 601, 1052, 1503, 1954, 1954, 1954};
2993     static const int offsets_RTL[13] = {781, 721, 661, 601, 496, 391, 296, 201, 134, 67, 0, 0, 0};
2994     static const int offsets_2[10] = {112, 101, 92, 84, 65, 39, 19, 0, 0, 0};
2995 
2996     static const int offsets_3[19] = {0, 6, 6, 6, 6, 12, 22, 27, 27, 37, 37, 37, 37, 49, 49, 58, 58, 68, 68};
2997     static const int offsets_3_RTL[19] = {68, 68, 58, 58, 49, 49, 49, 49, 37, 37, 27, 22, 12, 12, 12, 12, 6, 6};
2998 
2999     SCRIPT_VISATTR psva[15];
3000     SCRIPT_ANALYSIS sa;
3001     SCRIPT_ITEM items[2];
3002     int iX, i;
3003     int piCP;
3004     int piTrailing;
3005     HRESULT hr;
3006     static const WCHAR hebrW[] = { 0x5be, 0};
3007     static const WCHAR thaiW[] = { 0xe2a, 0};
3008     const SCRIPT_PROPERTIES **ppScriptProperties;
3009 
3010     memset(&sa, 0 , sizeof(SCRIPT_ANALYSIS));
3011     memset(psva, 0, sizeof(psva));
3012 
3013     sa.fRTL = FALSE;
3014     hr = ScriptXtoCP(-1, 10, 10, pwLogClust, psva, piAdvance, &sa, &piCP, &piTrailing);
3015     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
3016     if (piTrailing)
3017         ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
3018     else /* win2k3 */
3019         ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
3020 
3021     for (iX = 0; iX <= 7; iX++)
3022     {
3023         WORD clust = 0;
3024         INT advance = 16;
3025         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
3026         ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX, piCP,piTrailing);
3027     }
3028     for (iX = 8; iX < 16; iX++)
3029     {
3030         WORD clust = 0;
3031         INT advance = 16;
3032         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
3033         ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX, piCP,piTrailing);
3034     }
3035 
3036     sa.fRTL = TRUE;
3037     hr = ScriptXtoCP(-1, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
3038     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
3039     if (piTrailing)
3040         ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
3041     else /* win2k3 */
3042         ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
3043 
3044     iX = 1954;
3045     hr = ScriptXtoCP(1954, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
3046     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
3047     ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
3048     ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
3049 
3050     for (iX = 1; iX <= 8; iX++)
3051     {
3052         WORD clust = 0;
3053         INT advance = 16;
3054         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
3055         ok(hr == S_OK, "ScriptXtoCP() failed, hr %#x.\n", hr);
3056         ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX,piCP,piTrailing);
3057     }
3058     for (iX = 9; iX < 16; iX++)
3059     {
3060         WORD clust = 0;
3061         INT advance = 16;
3062         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
3063         ok(hr == S_OK, "ScriptXtoCP() failed, hr %#x.\n", hr);
3064         ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX,piCP,piTrailing);
3065     }
3066 
3067     sa.fRTL = FALSE;
3068     test_item_ScriptXtoX(&sa, 10, 10, offsets, pwLogClust, piAdvance);
3069     sa.fRTL = TRUE;
3070     test_item_ScriptXtoX(&sa, 10, 10, offsets_RTL, pwLogClust_RTL, piAdvance);
3071     test_item_ScriptXtoX(&sa, 7, 5, offsets_2, pwLogClust_2, piAdvance_2);
3072 
3073     /* Get thai eScript, This will do LTR and fNeedsCaretInfo */
3074     hr = ScriptItemize(thaiW, 1, 2, NULL, NULL, items, &i);
3075     ok(hr == S_OK, "got %08x\n", hr);
3076     ok(i == 1, "got %d\n", i);
3077     sa = items[0].a;
3078 
3079     test_caret_item_ScriptXtoCP(&sa, 17, 15, offsets_3, pwLogClust_3, piAdvance_3);
3080 
3081     /* Get hebrew eScript, This will do RTL and fNeedsCaretInfo */
3082     hr = ScriptItemize(hebrW, 1, 2, NULL, NULL, items, &i);
3083     ok(hr == S_OK, "got %08x\n", hr);
3084     ok(i == 1, "got %d\n", i);
3085     sa = items[0].a;
3086 
3087     /* Note: This behavior CHANGED in uniscribe versions...
3088      *       so we only want to test if fNeedsCaretInfo is set */
3089     hr = ScriptGetProperties(&ppScriptProperties, &i);
3090     if (ppScriptProperties[sa.eScript]->fNeedsCaretInfo)
3091     {
3092         test_caret_item_ScriptXtoCP(&sa, 17, 15, offsets_3_RTL, pwLogClust_3_RTL, piAdvance_3);
3093         hr = ScriptXtoCP(0, 17, 15, pwLogClust_3_RTL, psva, piAdvance_3, &sa, &piCP, &piTrailing);
3094         ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
3095         ok(piCP == 16, "ScriptXtoCP: iX=0 should return piCP=16 not %d\n", piCP);
3096         ok(piTrailing == 1, "ScriptXtoCP: iX=0 should return piTrailing=1 not %d\n", piTrailing);
3097     }
3098     else
3099         win_skip("Uniscribe version too old to test Hebrew clusters\n");
3100 }
3101 
3102 /* This set of tests is for the string functions of Uniscribe. The
3103  * ScriptStringAnalyse() function allocates memory pointed to by the
3104  * SCRIPT_STRING_ANALYSIS ssa pointer. This memory is freed by
3105  * ScriptStringFree(). There needs to be a valid hdc for this as
3106  * ScriptStringAnalyse() calls ScriptItemize(), ScriptShape() and
3107  * ScriptPlace() which require it. */
3108 static void test_ScriptString(HDC hdc)
3109 {
3110 
3111     HRESULT         hr;
3112     WCHAR           teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
3113     int             len = ARRAY_SIZE(teststr) - 1;
3114     int             Glyphs = len * 2 + 16;
3115     DWORD           Flags = SSA_GLYPHS;
3116     int             ReqWidth = 100;
3117     static const int Dx[ARRAY_SIZE(teststr) - 1];
3118     static const BYTE InClass[ARRAY_SIZE(teststr) - 1];
3119     SCRIPT_STRING_ANALYSIS ssa = NULL;
3120 
3121     int             X = 10;
3122     int             Y = 100;
3123     UINT            Options = 0;
3124     const RECT      rc = {0, 50, 100, 100};
3125     int             MinSel = 0;
3126     int             MaxSel = 0;
3127     BOOL            Disabled = FALSE;
3128     const int      *clip_len;
3129     UINT           *order;
3130     unsigned int i;
3131 
3132     /* Test without hdc to get E_PENDING. */
3133     hr = ScriptStringAnalyse(NULL, teststr, len, Glyphs, -1,
3134             Flags, ReqWidth, NULL, NULL, Dx, NULL, InClass, &ssa);
3135     ok(hr == E_PENDING, "Got unexpected hr %#x.\n", hr);
3136 
3137     /* Test that 0 length string returns E_INVALIDARG. */
3138     hr = ScriptStringAnalyse(hdc, teststr, 0, Glyphs, -1,
3139             Flags, ReqWidth, NULL, NULL, Dx, NULL, InClass, &ssa);
3140     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3141 
3142     /* Test with hdc, this should be a valid test. */
3143     hr = ScriptStringAnalyse(hdc, teststr, len, Glyphs, -1,
3144             Flags, ReqWidth, NULL, NULL, Dx, NULL, InClass, &ssa);
3145     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3146     ScriptStringFree(&ssa);
3147 
3148     /* Test makes sure that a call with a valid pssa still works. */
3149     hr = ScriptStringAnalyse(hdc, teststr, len, Glyphs, -1,
3150             Flags, ReqWidth, NULL, NULL, Dx, NULL, InClass, &ssa);
3151     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3152     ok(!!ssa, "Got unexpected ssa %p.\n", ssa);
3153 
3154     hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
3155     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3156 
3157     clip_len = ScriptString_pcOutChars(ssa);
3158     ok(*clip_len == len, "Got unexpected *clip_len %d, expected %d.\n", *clip_len, len);
3159 
3160     order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(*order));
3161     hr = ScriptStringGetOrder(ssa, order);
3162     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3163 
3164     for (i = 0; i < *clip_len; ++i)
3165     {
3166         ok(order[i] == i, "Got unexpected order[%u] %u.\n", i, order[i]);
3167     }
3168     HeapFree(GetProcessHeap(), 0, order);
3169 
3170     hr = ScriptStringFree(&ssa);
3171     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3172 }
3173 
3174 /* Test ScriptStringXtoCP() and ScriptStringCPtoX(). Since fonts may differ
3175  * between Windows and Wine, the test generates values using one function, and
3176  * then verifies the output is consistent with the output of the other. */
3177 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
3178 {
3179     HRESULT         hr;
3180     static const WCHAR teststr1[]  = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
3181     static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
3182     unsigned int String_len = ARRAY_SIZE(teststr1) - 1;
3183     int             Glyphs = String_len * 2 + 16;       /* size of buffer as recommended  */
3184     static const BYTE InClass[ARRAY_SIZE(teststr1) - 1];
3185     SCRIPT_STRING_ANALYSIS ssa = NULL;
3186 
3187     int             Ch;                                  /* Character position in string */
3188     int             iTrailing;
3189     int             Cp;                                  /* Character position in string */
3190     int             X;
3191     int             trail,lead;
3192 
3193     /* Test with hdc, this should be a valid test. Here we generate a
3194      * SCRIPT_STRING_ANALYSIS that will be used as input to the following
3195      * character-positions-to-X and X-to-character-position functions. */
3196     hr = ScriptStringAnalyse(hdc, &teststr1, String_len, Glyphs, -1,
3197             SSA_GLYPHS, 100, NULL, NULL, NULL, NULL, InClass, &ssa);
3198     ok(hr == S_OK || broken(hr == E_INVALIDARG) /* NT */,
3199             "Got unexpected hr %08x.\n", hr);
3200     if (hr != S_OK)
3201         return;
3202     ok(!!ssa, "Got unexpected ssa %p.\n", ssa);
3203 
3204     /* Loop to generate character positions to provide starting positions for
3205      * the ScriptStringCPtoX() and ScriptStringXtoCP() functions. */
3206     for (Cp = 0; Cp < String_len; ++Cp)
3207     {
3208         /* The fTrailing flag is used to indicate whether the X being returned
3209          * is at the beginning or the end of the character. What happens here
3210          * is that if fTrailing indicates the end of the character, i.e. FALSE,
3211          * then ScriptStringXtoCP() returns the beginning of the next
3212          * character and iTrailing is FALSE. So for this loop iTrailing will
3213          * be FALSE in both cases. */
3214         hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
3215         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3216         hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
3217         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3218         ok(rtl[Cp] ? lead > trail : lead < trail,
3219                 "Got unexpected lead %d, trail %d, for rtl[%u] %u.\n",
3220                 lead, trail, Cp, rtl[Cp]);
3221 
3222         /* Move by 1 pixel so that we are not between 2 characters. That could
3223          * result in being the lead of a RTL and at the same time the trail of
3224          * an LTR. */
3225 
3226         /* Inside the leading edge. */
3227         X = rtl[Cp] ? lead - 1 : lead + 1;
3228         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3229         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3230         ok(Ch == Cp, "Got unexpected Ch %d for X %d, expected %d.\n", Ch, X, Cp);
3231         ok(!iTrailing, "Got unexpected iTrailing %#x for X %d.\n", iTrailing, X);
3232 
3233         /* Inside the trailing edge. */
3234         X = rtl[Cp] ? trail + 1 : trail - 1;
3235         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3236         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3237         ok(Ch == Cp, "Got unexpected Ch %d for X %d, expected %d.\n", Ch, X, Cp);
3238         ok(iTrailing, "Got unexpected iTrailing %#x for X %d.\n", iTrailing, X);
3239 
3240         /* Outside the trailing edge. */
3241         if (Cp < String_len - 1)
3242         {
3243             X = rtl[Cp] ? lead + 1 : trail + 1;
3244             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3245             ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3246             ok(Ch == Cp + 1, "Got unexpected Ch %d for X %d, expected %d.\n", Ch, X, Cp + 1);
3247             ok(iTrailing == !!rtl[Cp + 1], "Got unexpected iTrailing %#x for X %d, expected %#x.\n",
3248                     iTrailing, X, !!rtl[Cp + 1]);
3249         }
3250 
3251         /* Outside the leading edge. */
3252         if (Cp)
3253         {
3254             X = rtl[Cp] ? trail - 1 : lead - 1;
3255             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3256             ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3257             ok(Ch == Cp - 1, "Got unexpected Ch %d for X %d, expected %d.\n", Ch, X, Cp - 1);
3258             ok(iTrailing == !rtl[Cp - 1], "Got unexpected iTrailing %#x for X %d, expected %#x.\n",
3259                     iTrailing, X, !rtl[Cp - 1]);
3260         }
3261     }
3262 
3263     /* Check beyond the leading boundary of the whole string. */
3264     if (rtl[0])
3265     {
3266         /* Having a leading RTL character seems to confuse usp. This looks to
3267          * be a Windows bug we should emulate. */
3268         hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
3269         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3270         --X;
3271         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3272         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3273         ok(Ch == 1, "Got unexpected Ch %d.\n", Ch);
3274         ok(!iTrailing, "Got unexpected iTrailing %#x.\n", iTrailing);
3275     }
3276     else
3277     {
3278         hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
3279         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3280         --X;
3281         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3282         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3283         ok(Ch == -1, "Got unexpected Ch %d.\n", Ch);
3284         ok(iTrailing, "Got unexpected iTrailing %#x.\n", iTrailing);
3285     }
3286 
3287     /* Check beyond the end boundary of the whole string. */
3288     if (rtl[String_len - 1])
3289     {
3290         hr = ScriptStringCPtoX(ssa, String_len - 1, FALSE, &X);
3291         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3292     }
3293     else
3294     {
3295         hr = ScriptStringCPtoX(ssa, String_len - 1, TRUE, &X);
3296         ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3297     }
3298     ++X;
3299     hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3300     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3301     ok(Ch == String_len, "Got unexpected Ch %d, expected %d.\n", Ch, String_len);
3302     ok(!iTrailing, "Got unexpected iTrailing %#x.\n", iTrailing);
3303 
3304     /* Cleanup the SSA for the next round of tests. */
3305     hr = ScriptStringFree(&ssa);
3306     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3307 
3308     /* Test to see that exceeding the number of characters returns
3309      * E_INVALIDARG. First generate an SSA for the subsequent tests. */
3310     hr = ScriptStringAnalyse(hdc, &teststr1, String_len, Glyphs, -1,
3311             SSA_GLYPHS, 100, NULL, NULL, NULL, NULL, InClass, &ssa);
3312     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3313 
3314     /* When ScriptStringCPtoX() is called with a character position that
3315      * exceeds the string length, return E_INVALIDARG. This also invalidates
3316      * the ssa so a ScriptStringFree() should also fail. */
3317     hr = ScriptStringCPtoX(ssa, String_len + 1, FALSE, &X);
3318     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3319 
3320     ScriptStringFree(&ssa);
3321 }
3322 
3323 static HWND create_test_window(void)
3324 {
3325     HWND hwnd = CreateWindowExA(0, "Static", "", WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
3326     ok(hwnd != NULL, "Failed to create test window.\n");
3327 
3328     ShowWindow(hwnd, SW_SHOW);
3329     UpdateWindow(hwnd);
3330 
3331     return hwnd;
3332 }
3333 
3334 static void test_ScriptCacheGetHeight(HDC hdc)
3335 {
3336     HFONT hfont, prev_hfont;
3337     SCRIPT_CACHE sc = NULL;
3338     LONG height, height2;
3339     TEXTMETRICW tm;
3340     LOGFONTA lf;
3341     HRESULT hr;
3342     HWND hwnd;
3343     HDC hdc2;
3344 
3345     hr = ScriptCacheGetHeight(NULL, NULL, NULL);
3346     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3347 
3348     hr = ScriptCacheGetHeight(NULL, &sc, NULL);
3349     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3350 
3351     hr = ScriptCacheGetHeight(NULL, &sc, &height);
3352     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
3353 
3354     height = 123;
3355     hr = ScriptCacheGetHeight(hdc, NULL, &height);
3356     ok(hr == E_INVALIDARG, "Uexpected hr %#x.\n", hr);
3357     ok(height == 123, "Unexpected height.\n");
3358 
3359     memset(&tm, 0, sizeof(tm));
3360     GetTextMetricsW(hdc, &tm);
3361     ok(tm.tmHeight > 0, "Unexpected tmHeight %u.\n", tm.tmHeight);
3362 
3363     height = 0;
3364     hr = ScriptCacheGetHeight(hdc, &sc, &height);
3365     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
3366     ok(height == tm.tmHeight, "expected height > 0\n");
3367 
3368     /* Try again with NULL dc. */
3369     height2 = 0;
3370     hr = ScriptCacheGetHeight(NULL, &sc, &height2);
3371     ok(hr == S_OK, "Failed to get cached height, hr %#x.\n", hr);
3372     ok(height2 == height, "Unexpected height %u.\n", height2);
3373 
3374     hwnd = create_test_window();
3375 
3376     hdc2 = GetDC(hwnd);
3377     ok(hdc2 != NULL, "Failed to get window dc.\n");
3378 
3379     memset(&lf, 0, sizeof(LOGFONTA));
3380     lstrcpyA(lf.lfFaceName, "Tahoma");
3381     lf.lfHeight = -32;
3382 
3383     hfont = CreateFontIndirectA(&lf);
3384     ok(hfont != NULL, "Failed to create font.\n");
3385 
3386     prev_hfont = SelectObject(hdc2, hfont);
3387 
3388     memset(&tm, 0, sizeof(tm));
3389     GetTextMetricsW(hdc2, &tm);
3390     ok(tm.tmHeight > height, "Unexpected tmHeight %u.\n", tm.tmHeight);
3391 
3392     height2 = 0;
3393     hr = ScriptCacheGetHeight(hdc2, &sc, &height2);
3394     ok(hr == S_OK, "Failed to get cached height, hr %#x.\n", hr);
3395     ok(height2 == height, "Unexpected height.\n");
3396 
3397     SelectObject(hdc2, prev_hfont);
3398     DeleteObject(hfont);
3399 
3400     ReleaseDC(hwnd, hdc2);
3401     DestroyWindow(hwnd);
3402 
3403     ScriptFreeCache(&sc);
3404 }
3405 
3406 static void test_ScriptGetGlyphABCWidth(HDC hdc)
3407 {
3408     HRESULT hr;
3409     SCRIPT_CACHE sc = NULL;
3410     ABC abc;
3411 
3412     hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
3413     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3414 
3415     hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
3416     ok(broken(hr == E_PENDING) ||
3417        hr == E_INVALIDARG, /* WIN7 */
3418        "expected E_INVALIDARG, got 0x%08x\n", hr);
3419 
3420     hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
3421     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
3422 
3423     if (0) {    /* crashes on WinXP */
3424     hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
3425     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3426     }
3427 
3428     hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
3429     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
3430 
3431     ScriptFreeCache(&sc);
3432 }
3433 
3434 static void test_ScriptLayout(void)
3435 {
3436     HRESULT hr;
3437     static const BYTE levels[][10] =
3438     {
3439         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3440         { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
3441         { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
3442         { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
3443 
3444         { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
3445         { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
3446         { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
3447         { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
3448         { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
3449 
3450         { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
3451         { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
3452 
3453         { 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 },
3454         { 2, 2, 2, 0, 0, 0, 0, 0, 0, 0 },
3455         { 2, 2, 2, 4, 4, 4, 1, 1, 0, 0 },
3456         { 1, 2, 3, 0, 3, 2, 1, 0, 0, 0 }
3457     };
3458     static const int expect_l2v[][10] =
3459     {
3460         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3461         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3462         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3463         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3464 
3465         { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
3466 /**/    { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
3467 /**/    { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
3468         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3469         { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
3470 
3471         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3472 /**/    { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
3473 
3474         { 1, 0, 2, 3, 4, 5, 6, 7, 8, 9},
3475         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
3476         { 2, 3, 4, 5, 6, 7, 1, 0, 8, 9},
3477         { 2, 0, 1, 3, 5, 6, 4, 7, 8, 9}
3478     };
3479     static const int expect_v2l[][10] =
3480     {
3481         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3482         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3483         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3484         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3485 
3486         { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
3487         { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
3488         { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
3489         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3490         { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
3491 
3492         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3493         { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
3494 
3495         { 1, 0, 2, 3, 4, 5, 6, 7, 8, 9},
3496         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
3497         { 7, 6, 0, 1, 2, 3, 4, 5, 8, 9},
3498         { 1, 2, 0, 3, 6, 4, 5, 7, 8, 9}
3499     };
3500 
3501     int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
3502 
3503     hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
3504     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3505 
3506     hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
3507     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3508 
3509     for (i = 0; i < ARRAY_SIZE(levels); ++i)
3510     {
3511         hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
3512         ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
3513 
3514         for (j = 0; j < sizeof(levels[i]); j++)
3515         {
3516             ok(expect_v2l[i][j] == vistolog[j],
3517                "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
3518                i, j, levels[i][j], j, vistolog[j] );
3519         }
3520 
3521         for (j = 0; j < sizeof(levels[i]); j++)
3522         {
3523             ok(expect_l2v[i][j] == logtovis[j],
3524                "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
3525                i, j, levels[i][j], j, logtovis[j] );
3526         }
3527     }
3528 }
3529 
3530 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
3531 {
3532     HRESULT hr;
3533     SCRIPT_DIGITSUBSTITUTE sds;
3534     SCRIPT_CONTROL sc;
3535     SCRIPT_STATE ss;
3536     LCID lcid_old;
3537 
3538     if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
3539 
3540     memset(&sds, 0, sizeof(sds));
3541     memset(&sc, 0, sizeof(sc));
3542     memset(&ss, 0, sizeof(ss));
3543 
3544     lcid_old = GetThreadLocale();
3545     if (!SetThreadLocale(lcid)) return TRUE;
3546 
3547     hr = ScriptRecordDigitSubstitution(lcid, &sds);
3548     ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
3549 
3550     hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
3551     ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
3552 
3553     SetThreadLocale(lcid_old);
3554     return TRUE;
3555 }
3556 
3557 static void test_digit_substitution(void)
3558 {
3559     BOOL ret;
3560     unsigned int i;
3561     static const LGRPID groups[] =
3562     {
3563         LGRPID_WESTERN_EUROPE,
3564         LGRPID_CENTRAL_EUROPE,
3565         LGRPID_BALTIC,
3566         LGRPID_GREEK,
3567         LGRPID_CYRILLIC,
3568         LGRPID_TURKISH,
3569         LGRPID_JAPANESE,
3570         LGRPID_KOREAN,
3571         LGRPID_TRADITIONAL_CHINESE,
3572         LGRPID_SIMPLIFIED_CHINESE,
3573         LGRPID_THAI,
3574         LGRPID_HEBREW,
3575         LGRPID_ARABIC,
3576         LGRPID_VIETNAMESE,
3577         LGRPID_INDIC,
3578         LGRPID_GEORGIAN,
3579         LGRPID_ARMENIAN
3580     };
3581 
3582     for (i = 0; i < ARRAY_SIZE(groups); ++i)
3583     {
3584         ret = EnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
3585         ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
3586     }
3587 }
3588 
3589 static void test_ScriptGetProperties(void)
3590 {
3591     const SCRIPT_PROPERTIES **props;
3592     HRESULT hr;
3593     int num;
3594 
3595     hr = ScriptGetProperties(NULL, NULL);
3596     ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
3597 
3598     hr = ScriptGetProperties(NULL, &num);
3599     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
3600 
3601     hr = ScriptGetProperties(&props, NULL);
3602     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
3603 
3604     hr = ScriptGetProperties(&props, &num);
3605     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
3606 }
3607 
3608 static void test_ScriptBreak(void)
3609 {
3610     static const WCHAR test[] = {' ','\r','\n',0};
3611     SCRIPT_ITEM items[4];
3612     SCRIPT_LOGATTR la;
3613     HRESULT hr;
3614 
3615     hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
3616     ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
3617 
3618     /*
3619      * This Test crashes pre Vista.
3620 
3621     hr = ScriptBreak(test, 1, &items[0].a, NULL);
3622     ok(hr == E_INVALIDARG, "ScriptBreak should return E_INVALIDARG not %08x\n", hr);
3623     */
3624 
3625     hr = ScriptBreak(test, 0, &items[0].a, &la);
3626     ok(hr == E_FAIL || broken(hr == S_OK), "ScriptBreak should return E_FAIL not %08x\n", hr);
3627 
3628     hr = ScriptBreak(test, -1, &items[0].a, &la);
3629     ok(hr == E_INVALIDARG || broken(hr == S_OK), "ScriptBreak should return E_INVALIDARG not %08x\n", hr);
3630 
3631     memset(&la, 0, sizeof(la));
3632     hr = ScriptBreak(test, 1, &items[0].a, &la);
3633     ok(hr == S_OK, "ScriptBreak should return S_OK not %08x\n", hr);
3634 
3635     ok(!la.fSoftBreak, "fSoftBreak set\n");
3636     ok(la.fWhiteSpace, "fWhiteSpace not set\n");
3637     ok(la.fCharStop, "fCharStop not set\n");
3638     ok(!la.fWordStop, "fWordStop set\n");
3639     ok(!la.fInvalid, "fInvalid set\n");
3640     ok(!la.fReserved, "fReserved set\n");
3641 
3642     memset(&la, 0, sizeof(la));
3643     hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
3644     ok(hr == S_OK, "ScriptBreak should return S_OK not %08x\n", hr);
3645 
3646     ok(!la.fSoftBreak, "fSoftBreak set\n");
3647     ok(!la.fWhiteSpace, "fWhiteSpace set\n");
3648     ok(la.fCharStop, "fCharStop not set\n");
3649     ok(!la.fWordStop, "fWordStop set\n");
3650     ok(!la.fInvalid, "fInvalid set\n");
3651     ok(!la.fReserved, "fReserved set\n");
3652 
3653     memset(&la, 0, sizeof(la));
3654     hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
3655     ok(hr == S_OK, "ScriptBreak should return S_OK not %08x\n", hr);
3656 
3657     ok(!la.fSoftBreak, "fSoftBreak set\n");
3658     ok(!la.fWhiteSpace, "fWhiteSpace set\n");
3659     ok(la.fCharStop, "fCharStop not set\n");
3660     ok(!la.fWordStop, "fWordStop set\n");
3661     ok(!la.fInvalid, "fInvalid set\n");
3662     ok(!la.fReserved, "fReserved set\n");
3663 }
3664 
3665 static void test_newlines(void)
3666 {
3667     static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
3668     static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
3669     static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
3670     static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
3671     static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
3672     SCRIPT_ITEM items[5];
3673     HRESULT hr;
3674     int count;
3675 
3676     count = 0;
3677     hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
3678     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3679     ok(count == 3, "got %d expected 3\n", count);
3680 
3681     count = 0;
3682     hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
3683     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3684     ok(count == 3, "got %d expected 3\n", count);
3685 
3686     count = 0;
3687     hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
3688     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3689     ok(count == 4, "got %d expected 4\n", count);
3690 
3691     count = 0;
3692     hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
3693     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3694     ok(count == 4, "got %d expected 4\n", count);
3695 
3696     count = 0;
3697     hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
3698     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3699     ok(count == 4, "got %d expected 4\n", count);
3700 }
3701 
3702 static void test_ScriptGetFontFunctions(HDC hdc)
3703 {
3704     static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859,
3705             0x0020, 0xa850, 0xa85c, 0xa85e};
3706     SCRIPT_CONTROL control;
3707     SCRIPT_CACHE sc = NULL;
3708     SCRIPT_ITEM items[15];
3709     OPENTYPE_TAG tags[5];
3710     SCRIPT_STATE state;
3711     int count = 0;
3712     HRESULT hr;
3713 
3714     if (!pScriptGetFontScriptTags || !pScriptGetFontLanguageTags || !pScriptGetFontFeatureTags)
3715     {
3716         win_skip("ScriptGetFontScriptTags, ScriptGetFontLanguageTags or "
3717                 "ScriptGetFontFeatureTags not available on this platform.\n");
3718         return;
3719     }
3720 
3721     hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 0, NULL, NULL);
3722     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3723     ok(!sc, "Got unexpected script cache %p.\n", sc);
3724     hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 0, NULL, &count);
3725     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3726     ok(!sc, "Got unexpected script cache %p.\n", sc);
3727     hr = pScriptGetFontScriptTags(hdc, &sc, NULL, ARRAY_SIZE(tags), tags, NULL);
3728     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3729     ok(!sc, "Got unexpected script cache %p.\n", sc);
3730     hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 0, tags, &count);
3731     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3732     ok(!sc, "Got unexpected script cache %p.\n", sc);
3733     hr = pScriptGetFontScriptTags(NULL, &sc, NULL, ARRAY_SIZE(tags), tags, &count);
3734     ok(hr == E_PENDING, "Got unexpected hr %#x.\n", hr);
3735     ok(!sc, "Got unexpected script cache %p.\n", sc);
3736     hr = pScriptGetFontScriptTags(hdc, &sc, NULL, ARRAY_SIZE(tags), tags, &count);
3737     ok(hr == S_OK || hr == E_OUTOFMEMORY, "Got unexpected hr %#x.\n", hr);
3738     if (hr == S_OK)
3739         ok(count <= 5, "Got unexpected count %d.\n", count);
3740     else
3741         ok(!count, "Got unexpected count %d.\n", count);
3742     ok(!!sc, "Got unexpected script cache %p.\n", sc);
3743 
3744     ScriptFreeCache(&sc);
3745     sc = NULL;
3746 
3747     hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 0, NULL, NULL);
3748     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3749     ok(!sc, "Got unexpected script cache %p.\n", sc);
3750     hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 0, NULL, &count);
3751     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3752     ok(!sc, "Got unexpected script cache %p.\n", sc);
3753     hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, ARRAY_SIZE(tags), tags, NULL);
3754     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3755     ok(!sc, "Got unexpected script cache %p.\n", sc);
3756     hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 0, tags, &count);
3757     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3758     ok(!sc, "Got unexpected script cache %p.\n", sc);
3759     hr = pScriptGetFontLanguageTags(NULL, &sc, NULL, latn_tag, ARRAY_SIZE(tags), tags, &count);
3760     ok(hr == E_PENDING, "Got unexpected hr %#x.\n", hr);
3761     ok(!sc, "Got unexpected script cache %p.\n", sc);
3762     hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, ARRAY_SIZE(tags), tags, &count);
3763     ok(hr == S_OK || hr == E_OUTOFMEMORY, "Got unexpected hr %#x.\n", hr);
3764     if (hr == S_OK)
3765         ok(count <= 5, "Got unexpected count %d.\n", count);
3766     else
3767         ok(!count, "Got unexpected count %d.\n", count);
3768 
3769     ScriptFreeCache(&sc);
3770     sc = NULL;
3771 
3772     hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 0, NULL, NULL);
3773     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3774     ok(!sc, "Got unexpected script cache %p.\n", sc);
3775     hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 0, NULL, &count);
3776     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3777     ok(!sc, "Got unexpected script cache %p.\n", sc);
3778     hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, ARRAY_SIZE(tags), tags, NULL);
3779     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3780     ok(!sc, "Got unexpected script cache %p.\n", sc);
3781     hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 0, tags, &count);
3782     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3783     ok(!sc, "Got unexpected script cache %p.\n", sc);
3784     hr = pScriptGetFontFeatureTags(NULL, &sc, NULL, latn_tag, 0x0, ARRAY_SIZE(tags), tags, &count);
3785     ok(hr == E_PENDING, "Got unexpected hr %#x.\n", hr);
3786     ok(!sc, "Got unexpected script cache %p.\n", sc);
3787     hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, ARRAY_SIZE(tags), tags, &count);
3788     ok(hr == S_OK || hr == E_OUTOFMEMORY, "Got unexpected hr %#x.\n", hr);
3789     if (hr == S_OK)
3790         ok(count <= 5, "Got unexpected count %d.\n", count);
3791     else
3792         ok(!count, "Got unexpected count %d.\n", count);
3793 
3794     memset(&control, 0, sizeof(control));
3795     memset(&state, 0, sizeof(state));
3796 
3797     hr = ScriptItemize(test_phagspa, ARRAY_SIZE(test_phagspa), ARRAY_SIZE(items),
3798             &control, &state, items, &count);
3799     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3800     memset(tags, 0, sizeof(tags));
3801     hr = pScriptGetFontScriptTags(hdc, &sc, &items[0].a, ARRAY_SIZE(tags), tags, &count);
3802     ok(hr == USP_E_SCRIPT_NOT_IN_FONT || broken(hr == S_OK), "Got unexpected hr %#x.\n", hr);
3803 
3804     hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, dsrt_tag, ARRAY_SIZE(tags), tags, &count);
3805     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3806     hr = pScriptGetFontLanguageTags(hdc, &sc, &items[0].a, dsrt_tag, ARRAY_SIZE(tags), tags, &count);
3807     ok(hr == E_INVALIDARG || broken(hr == S_OK), "Got unexpected hr %#x.\n", hr);
3808 
3809     hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, dsrt_tag, 0x0, ARRAY_SIZE(tags), tags, &count);
3810     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3811     hr = pScriptGetFontFeatureTags(hdc, &sc, &items[0].a, dsrt_tag, 0x0, ARRAY_SIZE(tags), tags, &count);
3812     ok(hr == E_INVALIDARG || broken(hr == S_OK), "Got unexpected hr %#x.\n", hr);
3813 
3814     ScriptFreeCache(&sc);
3815 }
3816 
3817 struct logical_width_test
3818 {
3819     int char_count;
3820     int glyph_count;
3821     int advances[3];
3822     WORD map[3];
3823     int widths[3];
3824     BOOL clusterstart[3];
3825     BOOL diacritic[3];
3826     BOOL zerowidth[3];
3827     BOOL todo;
3828 };
3829 
3830 static const struct logical_width_test logical_width_tests[] =
3831 {
3832     { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, {  6,  9, 12 }, { 1, 1, 1 } },
3833     { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, {  6,  9, 12 }, { 1, 1, 1 }, { 1, 0, 0 } },
3834     { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, {  6,  9, 12 }, { 1, 1, 1 }, { 0 }, { 1, 1, 1 } },
3835     { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, { 27, 21, 12 }, { 0, 0, 0 }, { 0 }, { 0 }, TRUE },
3836     { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, {  6, 21, 12 }, { 0, 1, 0 }, { 0 }, { 0 }, TRUE },
3837     { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, {  6, 21, 12 }, { 1, 1, 0 }, { 0 }, { 0 }, TRUE },
3838     { 3, 3, { 6, 9, 12 }, { 0, 2, 2 }, { 15,  6,  6 }, { 1, 0, 1 } },
3839 };
3840 
3841 static void test_ScriptGetLogicalWidths(void)
3842 {
3843     SCRIPT_ANALYSIS sa = { 0 };
3844     unsigned int i, j;
3845 
3846     for (i = 0; i < ARRAY_SIZE(logical_width_tests); ++i)
3847     {
3848         const struct logical_width_test *ptr = logical_width_tests + i;
3849         SCRIPT_VISATTR attrs[3];
3850         int widths[3];
3851         HRESULT hr;
3852 
3853         memset(attrs, 0, sizeof(attrs));
3854         for (j = 0; j < ptr->glyph_count; j++)
3855         {
3856             attrs[j].fClusterStart = ptr->clusterstart[j];
3857             attrs[j].fDiacritic = ptr->diacritic[j];
3858             attrs[j].fZeroWidth = ptr->zerowidth[j];
3859         }
3860 
3861         hr = ScriptGetLogicalWidths(&sa, ptr->char_count, ptr->glyph_count, ptr->advances, ptr->map, attrs, widths);
3862         ok(hr == S_OK, "got 0x%08x\n", hr);
3863 
3864         todo_wine_if(ptr->todo)
3865             ok(!memcmp(ptr->widths, widths, sizeof(widths)), "test %u: got wrong widths\n", i);
3866     }
3867 }
3868 
3869 static void test_ScriptIsComplex(void)
3870 {
3871     static const WCHAR testW[] = {0x202a,'1',0x202c,0};
3872     static const WCHAR test2W[] = {'1',0};
3873     static const struct complex_test
3874     {
3875         const WCHAR *text;
3876         DWORD flags;
3877         HRESULT hr;
3878         BOOL todo;
3879     } complex_tests[] =
3880     {
3881         { test2W, SIC_ASCIIDIGIT, S_OK },
3882         { test2W, SIC_COMPLEX, S_FALSE },
3883         { test2W, SIC_COMPLEX | SIC_ASCIIDIGIT, S_OK },
3884         { testW, SIC_NEUTRAL | SIC_COMPLEX, S_OK },
3885         { testW, SIC_NEUTRAL, S_FALSE, TRUE },
3886         { testW, SIC_COMPLEX, S_OK },
3887         { testW, 0, S_FALSE },
3888     };
3889     unsigned int i;
3890     HRESULT hr;
3891 
3892     hr = ScriptIsComplex(NULL, 0, 0);
3893     ok(hr == E_INVALIDARG || broken(hr == S_FALSE) /* winxp/vista */, "got 0x%08x\n", hr);
3894 
3895     if (hr == E_INVALIDARG)
3896     {
3897         hr = ScriptIsComplex(NULL, 1, 0);
3898         ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3899     }
3900 
3901     hr = ScriptIsComplex(test2W, -1, SIC_ASCIIDIGIT);
3902     ok(hr == E_INVALIDARG || broken(hr == S_FALSE) /* winxp/vista */, "got 0x%08x\n", hr);
3903 
3904     hr = ScriptIsComplex(test2W, 0, SIC_ASCIIDIGIT);
3905     ok(hr == S_FALSE, "got 0x%08x\n", hr);
3906 
3907     for (i = 0; i < ARRAY_SIZE(complex_tests); ++i)
3908     {
3909         hr = ScriptIsComplex(complex_tests[i].text, lstrlenW(complex_tests[i].text), complex_tests[i].flags);
3910     todo_wine_if(complex_tests[i].todo)
3911         ok(hr == complex_tests[i].hr, "%u: got %#x, expected %#x, flags %#x\n", i, hr, complex_tests[i].hr,
3912             complex_tests[i].flags);
3913     }
3914 
3915     hr = ScriptIsComplex(test2W, 1, ~0u);
3916     ok(hr == S_OK, "got 0x%08x\n", hr);
3917 
3918     hr = ScriptIsComplex(testW, 3, 0);
3919     ok(hr == S_FALSE, "got 0x%08x\n", hr);
3920 
3921     hr = ScriptIsComplex(testW, 3, SIC_NEUTRAL | SIC_COMPLEX);
3922     ok(hr == S_OK, "got 0x%08x\n", hr);
3923 
3924     hr = ScriptIsComplex(testW, 3, SIC_COMPLEX);
3925     ok(hr == S_OK, "got 0x%08x\n", hr);
3926 
3927     hr = ScriptIsComplex(test2W, 1, SIC_COMPLEX);
3928     ok(hr == S_FALSE, "got 0x%08x\n", hr);
3929 }
3930 
3931 static void test_ScriptString_pSize(HDC hdc)
3932 {
3933     static const WCHAR textW[] = {'A',0};
3934     SCRIPT_STRING_ANALYSIS ssa;
3935     const SIZE *size;
3936     TEXTMETRICW tm;
3937     HRESULT hr;
3938     ABC abc;
3939 
3940     hr = ScriptStringAnalyse(hdc, textW, 1, 16, -1, SSA_GLYPHS, 0, NULL, NULL, NULL, NULL, NULL, &ssa);
3941     ok(hr == S_OK, "ScriptStringAnalyse failed, hr %#x.\n", hr);
3942 
3943     size = ScriptString_pSize(NULL);
3944     ok(size == NULL || broken(size != NULL) /* <win7 */, "Unexpected size pointer.\n");
3945 
3946     GetCharABCWidthsW(hdc, textW[0], textW[0], &abc);
3947 
3948     memset(&tm, 0, sizeof(tm));
3949     GetTextMetricsW(hdc, &tm);
3950     ok(tm.tmHeight > 0, "Unexpected tmHeight.\n");
3951 
3952     size = ScriptString_pSize(ssa);
3953     ok(size != NULL, "Unexpected size pointer.\n");
3954     ok(size->cx == abc.abcA + abc.abcB + abc.abcC, "Unexpected cx size %d.\n", size->cx);
3955     ok(size->cy == tm.tmHeight, "Unexpected cy size %d.\n", size->cy);
3956 
3957     hr = ScriptStringFree(&ssa);
3958     ok(hr == S_OK, "Failed to free ssa, hr %#x.\n", hr);
3959 }
3960 
3961 static void test_script_cache_reuse(void)
3962 {
3963     HRESULT hr;
3964     HWND hwnd1, hwnd2;
3965     HDC hdc1, hdc2;
3966     LOGFONTA lf;
3967     HFONT hfont1, hfont2;
3968     HFONT prev_hfont1, prev_hfont2;
3969     SCRIPT_CACHE sc = NULL;
3970     SCRIPT_CACHE sc2;
3971     LONG height;
3972 
3973     hwnd1 = create_test_window();
3974     hwnd2 = create_test_window();
3975 
3976     hdc1 = GetDC(hwnd1);
3977     hdc2 = GetDC(hwnd2);
3978     ok(hdc1 != NULL && hdc2 != NULL, "Failed to get window dc.\n");
3979 
3980     memset(&lf, 0, sizeof(LOGFONTA));
3981     lstrcpyA(lf.lfFaceName, "Tahoma");
3982 
3983     lf.lfHeight = 10;
3984     hfont1 = CreateFontIndirectA(&lf);
3985     ok(hfont1 != NULL, "CreateFontIndirectA failed\n");
3986     hfont2 = CreateFontIndirectA(&lf);
3987     ok(hfont2 != NULL, "CreateFontIndirectA failed\n");
3988     ok(hfont1 != hfont2, "Expected fonts %p and %p to differ\n", hfont1, hfont2);
3989 
3990     prev_hfont1 = SelectObject(hdc1, hfont1);
3991     ok(prev_hfont1 != NULL, "SelectObject failed: %p\n", prev_hfont1);
3992     prev_hfont2 = SelectObject(hdc2, hfont1);
3993     ok(prev_hfont2 != NULL, "SelectObject failed: %p\n", prev_hfont2);
3994 
3995     /* Get a script cache */
3996     hr = ScriptCacheGetHeight(hdc1, &sc, &height);
3997     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
3998     ok(sc != NULL, "Script cache is NULL\n");
3999 
4000     /* Same font, same DC -> same SCRIPT_CACHE */
4001     sc2 = NULL;
4002     hr = ScriptCacheGetHeight(hdc1, &sc2, &height);
4003     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
4004     ok(sc2 != NULL, "Script cache is NULL\n");
4005     ok(sc == sc2, "Expected caches %p, %p to be identical\n", sc, sc2);
4006     ScriptFreeCache(&sc2);
4007 
4008     /* Same font in different DC -> same SCRIPT_CACHE */
4009     sc2 = NULL;
4010     hr = ScriptCacheGetHeight(hdc2, &sc2, &height);
4011     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
4012     ok(sc2 != NULL, "Script cache is NULL\n");
4013     ok(sc == sc2, "Expected caches %p, %p to be identical\n", sc, sc2);
4014     ScriptFreeCache(&sc2);
4015 
4016     /* Same font face & size, but different font handle */
4017     ok(SelectObject(hdc1, hfont2) != NULL, "SelectObject failed\n");
4018     ok(SelectObject(hdc2, hfont2) != NULL, "SelectObject failed\n");
4019 
4020     sc2 = NULL;
4021     hr = ScriptCacheGetHeight(hdc1, &sc2, &height);
4022     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
4023     ok(sc2 != NULL, "Script cache is NULL\n");
4024     ok(sc == sc2, "Expected caches %p, %p to be identical\n", sc, sc2);
4025     ScriptFreeCache(&sc2);
4026 
4027     sc2 = NULL;
4028     hr = ScriptCacheGetHeight(hdc2, &sc2, &height);
4029     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
4030     ok(sc2 != NULL, "Script cache is NULL\n");
4031     ok(sc == sc2, "Expected caches %p, %p to be identical\n", sc, sc2);
4032     ScriptFreeCache(&sc2);
4033 
4034     /* Different font size -- now we get a different SCRIPT_CACHE */
4035     SelectObject(hdc1, prev_hfont1);
4036     SelectObject(hdc2, prev_hfont2);
4037     DeleteObject(hfont2);
4038     lf.lfHeight = 20;
4039     hfont2 = CreateFontIndirectA(&lf);
4040     ok(hfont2 != NULL, "CreateFontIndirectA failed\n");
4041     ok(SelectObject(hdc1, hfont2) != NULL, "SelectObject failed\n");
4042     ok(SelectObject(hdc2, hfont2) != NULL, "SelectObject failed\n");
4043 
4044     sc2 = NULL;
4045     hr = ScriptCacheGetHeight(hdc1, &sc2, &height);
4046     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
4047     ok(sc2 != NULL, "Script cache is NULL\n");
4048     ok(sc != sc2, "Expected caches %p, %p to be different\n", sc, sc2);
4049     ScriptFreeCache(&sc2);
4050 
4051     sc2 = NULL;
4052     hr = ScriptCacheGetHeight(hdc2, &sc2, &height);
4053     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
4054     ok(sc2 != NULL, "Script cache is NULL\n");
4055     ok(sc != sc2, "Expected caches %p, %p to be different\n", sc, sc2);
4056     ScriptFreeCache(&sc2);
4057 
4058     ScriptFreeCache(&sc);
4059     SelectObject(hdc1, prev_hfont1);
4060     SelectObject(hdc2, prev_hfont2);
4061     DeleteObject(hfont1);
4062     DeleteObject(hfont2);
4063     DestroyWindow(hwnd1);
4064     DestroyWindow(hwnd2);
4065 }
4066 
4067 static void init_tests(void)
4068 {
4069     HMODULE module = GetModuleHandleA("usp10.dll");
4070 
4071     ok(module != 0, "Expected usp10.dll to be loaded.\n");
4072 
4073     pScriptItemizeOpenType = (void *)GetProcAddress(module, "ScriptItemizeOpenType");
4074     pScriptShapeOpenType = (void *)GetProcAddress(module, "ScriptShapeOpenType");
4075     pScriptGetFontScriptTags = (void *)GetProcAddress(module, "ScriptGetFontScriptTags");
4076     pScriptGetFontLanguageTags = (void *)GetProcAddress(module, "ScriptGetFontLanguageTags");
4077     pScriptGetFontFeatureTags = (void *)GetProcAddress(module, "ScriptGetFontFeatureTags");
4078 }
4079 
4080 START_TEST(usp10)
4081 {
4082     HWND            hwnd;
4083     HDC             hdc;
4084     LOGFONTA        lf;
4085     HFONT           hfont;
4086 
4087     unsigned short  pwOutGlyphs[256];
4088 
4089     /* We need a valid HDC to drive a lot of Script functions which requires the following    *
4090      * to set up for the tests.                                                               */
4091     hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
4092                            0, 0, 0, NULL);
4093     assert(hwnd != 0);
4094     ShowWindow(hwnd, SW_SHOW);
4095     UpdateWindow(hwnd);
4096 
4097     hdc = GetDC(hwnd);                                      /* We now have a hdc             */
4098     ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
4099 
4100     memset(&lf, 0, sizeof(LOGFONTA));
4101     lstrcpyA(lf.lfFaceName, "Tahoma");
4102     lf.lfHeight = 10;
4103     lf.lfWeight = 3;
4104     lf.lfWidth = 10;
4105 
4106     hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
4107     ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
4108 
4109     init_tests();
4110 
4111     test_ScriptItemize();
4112     test_ScriptItemize_surrogates();
4113     test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
4114     test_ScriptGetCMap(hdc, pwOutGlyphs);
4115     test_ScriptCacheGetHeight(hdc);
4116     test_ScriptGetGlyphABCWidth(hdc);
4117     test_ScriptShape(hdc);
4118     test_ScriptShapeOpenType(hdc);
4119     test_ScriptPlace(hdc);
4120 
4121     test_ScriptGetFontProperties(hdc);
4122     test_ScriptTextOut(hdc);
4123     test_ScriptTextOut2(hdc);
4124     test_ScriptTextOut3(hdc);
4125     test_ScriptXtoX();
4126     test_ScriptString(hdc);
4127     test_ScriptStringXtoCP_CPtoX(hdc);
4128     test_ScriptString_pSize(hdc);
4129 
4130     test_ScriptLayout();
4131     test_digit_substitution();
4132     test_ScriptGetProperties();
4133     test_ScriptBreak();
4134     test_newlines();
4135 
4136     test_ScriptGetFontFunctions(hdc);
4137     test_ScriptGetLogicalWidths();
4138 
4139     test_ScriptIsComplex();
4140     test_script_cache_reuse();
4141 
4142     ReleaseDC(hwnd, hdc);
4143     DestroyWindow(hwnd);
4144 }
4145