usp10: Add Vai script.
[wine.git] / dlls / usp10 / tests / usp10.c
blob932aaa739de5447c233a19ff0437adbf00e6058a
1 /*
2 * Tests for usp10 dll
4 * Copyright 2006 Jeff Latimer
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Notes:
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
27 #include <assert.h>
28 #include <stdio.h>
30 #include <wine/test.h>
31 #include <windows.h>
32 #include <usp10.h>
34 typedef struct _itemTest {
35 char todo_flag[5];
36 int iCharPos;
37 int fRTL;
38 int fLayoutRTL;
39 int uBidiLevel;
40 ULONG scriptTag;
41 BOOL isBroken;
42 int broken_value[5];
43 } itemTest;
45 typedef struct _shapeTest_char {
46 WORD wLogClust;
47 SCRIPT_CHARPROP CharProp;
48 } shapeTest_char;
50 typedef struct _shapeTest_glyph {
51 int Glyph;
52 SCRIPT_GLYPHPROP GlyphProp;
53 } shapeTest_glyph;
55 /* Uniscribe 1.6 calls */
56 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);
58 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);
60 static DWORD (WINAPI *pGetGlyphIndicesW)(HDC hdc, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags);
62 static inline void _test_items_ok(LPCWSTR string, DWORD cchString,
63 SCRIPT_CONTROL *Control, SCRIPT_STATE *State,
64 DWORD nItems, const itemTest* items, BOOL nItemsToDo,
65 const INT nItemsBroken[2])
67 HRESULT hr;
68 int x, outnItems;
69 SCRIPT_ITEM outpItems[15];
70 ULONG tags[15] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
72 if (pScriptItemizeOpenType)
73 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
74 else
75 hr = ScriptItemize(string, cchString, 15, Control, State, outpItems, &outnItems);
77 winetest_ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
78 if (nItemsBroken && (broken(nItemsBroken[0] == outnItems) || broken(nItemsBroken[1] == outnItems)))
80 winetest_win_skip("This test broken on this platform\n");
81 return;
83 if (nItemsToDo)
84 todo_wine winetest_ok(outnItems == nItems, "Wrong number of items\n");
85 else
86 winetest_ok(outnItems == nItems, "Wrong number of items\n");
87 for (x = 0; x <= outnItems; x++)
89 if (items[x].isBroken && broken(outpItems[x].iCharPos == items[x].broken_value[0]))
90 winetest_win_skip("This test broken on this platform\n");
91 else if (items[x].todo_flag[0])
92 todo_wine winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos\n",x);
93 else
94 winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos (%i)\n",x,outpItems[x].iCharPos);
96 if (items[x].isBroken && broken(outpItems[x].a.fRTL== items[x].broken_value[1]))
97 winetest_win_skip("This test broken on this platform\n");
98 else if (items[x].todo_flag[1])
99 todo_wine winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL\n",x);
100 else
101 winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL(%i)\n",x,outpItems[x].a.fRTL);
103 if (items[x].isBroken && broken(outpItems[x].a.fLayoutRTL == items[x].broken_value[2]))
104 winetest_win_skip("This test broken on this platform\n");
105 else if (items[x].todo_flag[2])
106 todo_wine winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL\n",x);
107 else
108 winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL(%i)\n",x,outpItems[x].a.fLayoutRTL);
110 if (items[x].isBroken && broken(outpItems[x].a.s.uBidiLevel == items[x].broken_value[3]))
111 winetest_win_skip("This test broken on this platform\n");
112 else if (items[x].todo_flag[3])
113 todo_wine winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel\n",x);
114 else
115 winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel(%i)\n",x,outpItems[x].a.s.uBidiLevel);
116 if (x != outnItems)
117 winetest_ok(outpItems[x].a.eScript != SCRIPT_UNDEFINED, "%i: Undefined script\n",x);
118 if (pScriptItemizeOpenType)
120 if (items[x].isBroken && broken(tags[x] == items[x].broken_value[4]))
121 winetest_win_skip("This test broken on this platform\n");
122 else if (items[x].todo_flag[4])
123 todo_wine winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
124 else
125 winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
130 #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)
132 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
133 ( ( (ULONG)_x4 << 24 ) | \
134 ( (ULONG)_x3 << 16 ) | \
135 ( (ULONG)_x2 << 8 ) | \
136 (ULONG)_x1 )
138 #define latn_tag MS_MAKE_TAG('l','a','t','n')
139 #define arab_tag MS_MAKE_TAG('a','r','a','b')
140 #define thai_tag MS_MAKE_TAG('t','h','a','i')
141 #define hebr_tag MS_MAKE_TAG('h','e','b','r')
142 #define syrc_tag MS_MAKE_TAG('s','y','r','c')
143 #define deva_tag MS_MAKE_TAG('d','e','v','a')
144 #define beng_tag MS_MAKE_TAG('b','e','n','g')
145 #define guru_tag MS_MAKE_TAG('g','u','r','u')
146 #define gujr_tag MS_MAKE_TAG('g','u','j','r')
147 #define orya_tag MS_MAKE_TAG('o','r','y','a')
148 #define taml_tag MS_MAKE_TAG('t','a','m','l')
149 #define telu_tag MS_MAKE_TAG('t','e','l','u')
150 #define knda_tag MS_MAKE_TAG('k','n','d','a')
151 #define mlym_tag MS_MAKE_TAG('m','l','y','m')
152 #define mymr_tag MS_MAKE_TAG('m','y','m','r')
153 #define tale_tag MS_MAKE_TAG('t','a','l','e')
154 #define talu_tag MS_MAKE_TAG('t','a','l','u')
155 #define khmr_tag MS_MAKE_TAG('k','h','m','r')
156 #define hani_tag MS_MAKE_TAG('h','a','n','i')
157 #define bopo_tag MS_MAKE_TAG('b','o','p','o')
158 #define kana_tag MS_MAKE_TAG('k','a','n','a')
159 #define hang_tag MS_MAKE_TAG('h','a','n','g')
160 #define yi_tag MS_MAKE_TAG('y','i',' ',' ')
161 #define ethi_tag MS_MAKE_TAG('e','t','h','i')
162 #define mong_tag MS_MAKE_TAG('m','o','n','g')
163 #define tfng_tag MS_MAKE_TAG('t','f','n','g')
164 #define nko_tag MS_MAKE_TAG('n','k','o',' ')
165 #define vai_tag MS_MAKE_TAG('v','a','i',' ')
167 static void test_ScriptItemize( void )
169 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
170 static const itemTest t11[2] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1}};
171 static const itemTest t12[2] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
173 static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
174 static const itemTest t1b1[2] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
175 static const itemTest t1b2[2] = {{{0,0,0,0,0},0,1,1,1,0,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
177 static const WCHAR test1c[] = {' ', ' ', ' ', '1', '2', ' ',0};
178 static const itemTest t1c1[2] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
179 static const itemTest t1c2[4] = {{{0,0,0,0,0},0,1,1,1,0,FALSE},{{0,0,0,0,0},3,0,1,2,0,FALSE},{{0,0,0,0,0},5,1,1,1,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
181 /* Arabic, English*/
182 static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
183 static const itemTest t21[7] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,0,0,0,FALSE},{{0,0,0,0,0},15,0,0,0,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
184 static const itemTest t22[5] = {{{0,0,0,0,0},0,0,0,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,1,2,0,FALSE},{{0,0,0,0,0},15,0,0,0,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
185 static const itemTest t23[5] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,1,2,0,FALSE},{{0,0,0,0,0},15,1,1,1,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
187 static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
188 static const itemTest t2b1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},8,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
189 static const itemTest t2b2[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,2,0,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
190 static const itemTest t2b3[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
191 static const int b2[2] = {4,4};
193 /* leading space */
194 static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
195 static const itemTest t2c1[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
196 static const itemTest t2c2[6] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},1,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
197 static const itemTest t2c3[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,2,0,FALSE},{{0,0,0,0,0},8,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
198 static const itemTest t2c4[3] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
200 /* trailing space */
201 static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
202 static const itemTest t2d1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
203 static const itemTest t2d2[6] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},10,0,0,0,0,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
204 static const itemTest t2d3[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,2,0,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
205 static const itemTest t2d4[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
207 /* Thai */
208 static const WCHAR test3[] =
209 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
210 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
211 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
212 0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
214 static const itemTest t31[2] = {{{0,0,0,0,0},0,0,0,0,thai_tag,FALSE},{{0,0,0,0,0},41,0,0,0,-1,FALSE}};
215 static const itemTest t32[2] = {{{0,0,0,0,0},0,0,0,2,thai_tag,FALSE},{{0,0,0,0,0},41,0,0,0,-1,FALSE}};
217 static const WCHAR test4[] = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
219 static const itemTest t41[6] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},10,0,0,0,0,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
220 static const itemTest t42[5] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,0,FALSE},{{0,0,0,0,0},7,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},10,0,0,2,0,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
221 static const itemTest t43[4] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,0,FALSE},{{0,0,0,0,0},7,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
222 static const int b43[2] = {4,4};
224 /* Arabic */
225 static const WCHAR test5[] =
226 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
227 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
228 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
229 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
230 static const itemTest t51[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},38,0,0,0,-1,FALSE}};
232 /* Hebrew */
233 static const WCHAR test6[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
234 static const itemTest t61[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
235 static const itemTest t62[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},4,1,1,1,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
236 static const itemTest t63[2] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
237 static const int b63[2] = {2,2};
238 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};
239 static const itemTest t71[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},9,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},19,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
240 static const itemTest t72[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},9,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},18,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
241 static const itemTest t73[4] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},8,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},19,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
242 static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
243 static const itemTest t81[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
245 /* Syriac (Like Arabic )*/
246 static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
247 static const itemTest t91[3] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
248 static const itemTest t92[3] = {{{0,0,0,0,0},0,1,1,1,syrc_tag},{{0,0,0,0,0},4,1,1,1,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
249 static const itemTest t93[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
250 static const int b93[2] = {2,2};
252 static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
253 static const itemTest t101[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
255 /* Devanagari */
256 static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
257 static const itemTest t111[2] = {{{0,0,0,0,0},0,0,0,0,deva_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
258 static const itemTest t112[2] = {{{0,0,0,0,0},0,0,0,2,deva_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
260 /* Bengali */
261 static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
262 static const itemTest t121[2] = {{{0,0,0,0,0},0,0,0,0,beng_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
263 static const itemTest t122[2] = {{{0,0,0,0,0},0,0,0,2,beng_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
265 /* Gurmukhi */
266 static const WCHAR test13[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
267 static const itemTest t131[2] = {{{0,0,0,0,0},0,0,0,0,guru_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
268 static const itemTest t132[2] = {{{0,0,0,0,0},0,0,0,2,guru_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
270 /* Gujarati */
271 static const WCHAR test14[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
272 static const itemTest t141[2] = {{{0,0,0,0,0},0,0,0,0,gujr_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
273 static const itemTest t142[2] = {{{0,0,0,0,0},0,0,0,2,gujr_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
275 /* Oriya */
276 static const WCHAR test15[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
277 static const itemTest t151[2] = {{{0,0,0,0,0},0,0,0,0,orya_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
278 static const itemTest t152[2] = {{{0,0,0,0,0},0,0,0,2,orya_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
280 /* Tamil */
281 static const WCHAR test16[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
282 static const itemTest t161[2] = {{{0,0,0,0,0},0,0,0,0,taml_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
283 static const itemTest t162[2] = {{{0,0,0,0,0},0,0,0,2,taml_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
285 /* Telugu */
286 static const WCHAR test17[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
287 static const itemTest t171[2] = {{{0,0,0,0,0},0,0,0,0,telu_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
288 static const itemTest t172[2] = {{{0,0,0,0,0},0,0,0,2,telu_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
290 /* Kannada */
291 static const WCHAR test18[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
292 static const itemTest t181[2] = {{{0,0,0,0,0},0,0,0,0,knda_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
293 static const itemTest t182[2] = {{{0,0,0,0,0},0,0,0,2,knda_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
295 /* Malayalam */
296 static const WCHAR test19[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
297 static const itemTest t191[2] = {{{0,0,0,0,0},0,0,0,0,mlym_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
298 static const itemTest t192[2] = {{{0,0,0,0,0},0,0,0,2,mlym_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
300 /* Diacritical */
301 static const WCHAR test20[] = {0x0309,'a','b','c','d',0};
302 static const itemTest t201[3] = {{{0,0,0,0,0},0,0,0,0,0x0,FALSE},{{0,0,0,0,0},1,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
303 static const itemTest t202[3] = {{{0,0,0,0,0},0,0,0,2,0,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},1,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
305 static const WCHAR test21[] = {0x0710, 0x0712, 0x0308, 0x0712, 0x0714,0};
306 static const itemTest t211[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
308 /* Latin Punctuation */
309 static const WCHAR test22[] = {'#','$',',','!','\"','*',0};
310 static const itemTest t221[3] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
311 static const itemTest t222[3] = {{{0,0,0,0,0},0,1,1,1,latn_tag,FALSE},{{0,0,0,0,0},3,1,1,1,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
312 static const itemTest t223[2] = {{{0,0,0,0,0},0,1,1,1,latn_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
313 static const int b222[2] = {1,1};
314 static const int b223[2] = {2,2};
316 /* Number 2*/
317 static const WCHAR test23[] = {'1','2','3',0x00b2,0x00b3,0x2070,0};
318 static const itemTest t231[3] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
319 static const itemTest t232[3] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},3,0,1,2,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
321 /* Myanmar */
322 static const WCHAR test24[] = {0x1019,0x103c,0x1014,0x103a,0x1019,0x102c,0x1021,0x1000,0x1039,0x1001,0x101b,0x102c};
323 static const itemTest t241[2] = {{{0,0,0,0,0},0,0,0,0,mymr_tag,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
324 static const itemTest t242[2] = {{{0,0,0,0,0},0,0,0,2,mymr_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
326 /* Tai Le */
327 static const WCHAR test25[] = {0x1956,0x196d,0x1970,0x1956,0x196c,0x1973,0x1951,0x1968,0x1952,0x1970};
328 static const itemTest t251[2] = {{{0,0,0,0,0},0,0,0,0,tale_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
329 static const itemTest t252[2] = {{{0,0,0,0,0},0,0,0,2,tale_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
331 /* New Tai Lue */
332 static const WCHAR test26[] = {0x1992,0x19c4};
333 static const itemTest t261[2] = {{{0,0,0,0,0},0,0,0,0,talu_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0},2,0,0,0,-1,FALSE}};
334 static const itemTest t262[2] = {{{0,0,0,0,0},0,0,0,2,talu_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0},2,0,0,0,-1,FALSE}};
336 /* Khmer */
337 static const WCHAR test27[] = {0x1781,0x17c1,0x1798,0x179a,0x1797,0x17b6,0x179f,0x17b6};
338 static const itemTest t271[2] = {{{0,0,0,0,0},0,0,0,0,khmr_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
339 static const itemTest t272[2] = {{{0,0,0,0,0},0,0,0,2,khmr_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
341 /* CJK Han */
342 static const WCHAR test28[] = {0x8bed,0x7d20,0x6587,0x5b57};
343 static const itemTest t281[2] = {{{0,0,0,0,0},0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
344 static const itemTest t282[2] = {{{0,0,0,0,0},0,0,0,2,hani_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
346 /* Ideographic */
347 static const WCHAR test29[] = {0x2ff0,0x2ff3,0x2ffb,0x2ff0,0x65e5,0x65e5,0x5de5,0x7f51,0x4e02,0x4e5e};
348 static const itemTest t291[3] = {{{0,0,0,0,0},0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0},4,0,0,0,hani_tag,FALSE},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
349 static const itemTest t292[3] = {{{0,0,0,0,0},0,1,1,1,hani_tag,FALSE},{{0,0,0,0,0},4,0,0,2,hani_tag,FALSE},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
351 /* Bopomofo */
352 static const WCHAR test30[] = {0x3113,0x3128,0x3127,0x3123,0x3108,0x3128,0x310f,0x3120};
353 static const itemTest t301[2] = {{{0,0,0,0,0},0,0,0,0,bopo_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
354 static const itemTest t302[2] = {{{0,0,0,0,0},0,0,0,2,bopo_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
356 /* Kana */
357 static const WCHAR test31[] = {0x3072,0x3089,0x304b,0x306a,0x30ab,0x30bf,0x30ab,0x30ca};
358 static const itemTest t311[2] = {{{0,0,0,0,0},0,0,0,0,kana_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
359 static const itemTest t312[2] = {{{0,0,0,0,0},0,0,0,2,kana_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
360 static const int b311[2] = {2,2};
361 static const int b312[2] = {2,2};
363 /* Hangul */
364 static const WCHAR test32[] = {0xd55c,0xad6d,0xc5b4};
365 static const itemTest t321[2] = {{{0,0,0,0,0},0,0,0,0,hang_tag,FALSE},{{0,0,0,0,0},3,0,0,0,-1,FALSE}};
366 static const itemTest t322[2] = {{{0,0,0,0,0},0,0,0,2,hang_tag,FALSE},{{0,0,0,0,0},3,0,0,0,-1,FALSE}};
368 /* Yi */
369 static const WCHAR test33[] = {0xa188,0xa320,0xa071,0xa0b7};
370 static const itemTest t331[2] = {{{0,0,0,0,0},0,0,0,0,yi_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
371 static const itemTest t332[2] = {{{0,0,0,0,0},0,0,0,2,yi_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
373 /* Ethiopic */
374 static const WCHAR test34[] = {0x130d,0x12d5,0x12dd};
375 static const itemTest t341[2] = {{{0,0,0,0,0},0,0,0,0,ethi_tag,FALSE},{{0,0,0,0,0},3,0,0,0,-1,FALSE}};
376 static const itemTest t342[2] = {{{0,0,0,0,0},0,0,0,2,ethi_tag,FALSE},{{0,0,0,0,0},3,0,0,0,-1,FALSE}};
377 static const int b342[2] = {2,2};
379 /* Mongolian */
380 static const WCHAR test35[] = {0x182e,0x1823,0x1829,0x182d,0x1823,0x182f,0x0020,0x182a,0x1822,0x1834,0x1822,0x182d,0x180c};
381 static const itemTest t351[2] = {{{0,0,0,0,0},0,0,0,0,mong_tag,FALSE},{{0,0,0,0,0},13,0,0,0,-1,FALSE}};
382 static const itemTest t352[2] = {{{0,0,0,0,0},0,0,0,2,mong_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},13,0,0,0,-1,FALSE}};
383 static const int b351[2] = {2,2};
384 static const int b352[2] = {2,3};
386 /* Tifinagh */
387 static const WCHAR test36[] = {0x2d5c,0x2d49,0x2d3c,0x2d49,0x2d4f,0x2d30,0x2d56};
388 static const itemTest t361[2] = {{{0,0,0,0,0},0,0,0,0,tfng_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
389 static const itemTest t362[2] = {{{0,0,0,0,0},0,0,0,2,tfng_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
391 /* N'Ko */
392 static const WCHAR test37[] = {0x07d2,0x07de,0x07cf};
393 static const itemTest t371[2] = {{{0,0,0,0,0},0,1,1,1,nko_tag,TRUE,{-1,0,0,0,arab_tag}},{{0,0,0,0,0},3,0,0,0,-1,FALSE}};
394 static const itemTest t372[2] = {{{0,0,0,0,0},0,1,1,1,nko_tag,TRUE,{-1,0,0,2,arab_tag}},{{0,0,0,0,0},3,0,0,0,-1,FALSE}};
396 /* Vai */
397 static const WCHAR test38[] = {0xa559,0xa524};
398 static const itemTest t381[2] = {{{0,0,0,0,0},0,0,0,0,vai_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0},2,0,0,0,-1,FALSE}};
399 static const itemTest t382[2] = {{{0,0,0,0,0},0,0,0,2,vai_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0},2,0,0,0,-1,FALSE}};
401 SCRIPT_ITEM items[15];
402 SCRIPT_CONTROL Control;
403 SCRIPT_STATE State;
404 HRESULT hr;
405 HMODULE usp10;
406 int nItems;
408 usp10 = LoadLibraryA("usp10.dll");
409 ok (usp10 != 0,"Unable to LoadLibrary on usp10.dll\n");
410 pScriptItemizeOpenType = (void*)GetProcAddress(usp10, "ScriptItemizeOpenType");
411 pScriptShapeOpenType = (void*)GetProcAddress(usp10, "ScriptShapeOpenType");
412 pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
414 memset(&Control, 0, sizeof(Control));
415 memset(&State, 0, sizeof(State));
417 hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
418 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
420 hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
421 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
423 hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
424 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
426 hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
427 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
429 test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
430 test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
431 test_items_ok(test1c,6,NULL,NULL,1,t1c1,FALSE,0);
432 test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
433 test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
434 test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
435 test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
436 test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
437 test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
438 test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
439 test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
440 test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
441 test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
442 test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
443 test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
444 test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
445 test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
446 test_items_ok(test13,7,NULL,NULL,1,t131,FALSE,0);
447 test_items_ok(test14,7,NULL,NULL,1,t141,FALSE,0);
448 test_items_ok(test15,5,NULL,NULL,1,t151,FALSE,0);
449 test_items_ok(test16,5,NULL,NULL,1,t161,FALSE,0);
450 test_items_ok(test17,6,NULL,NULL,1,t171,FALSE,0);
451 test_items_ok(test18,5,NULL,NULL,1,t181,FALSE,0);
452 test_items_ok(test19,6,NULL,NULL,1,t191,FALSE,0);
453 test_items_ok(test20,5,NULL,NULL,2,t201,FALSE,0);
454 test_items_ok(test21,5,NULL,NULL,1,t211,FALSE,0);
455 test_items_ok(test22,6,NULL,NULL,2,t221,FALSE,0);
456 test_items_ok(test23,6,NULL,NULL,2,t231,FALSE,0);
457 test_items_ok(test24,12,NULL,NULL,1,t241,FALSE,0);
458 test_items_ok(test25,10,NULL,NULL,1,t251,FALSE,0);
459 test_items_ok(test26,2,NULL,NULL,1,t261,FALSE,0);
460 test_items_ok(test27,8,NULL,NULL,1,t271,FALSE,0);
461 test_items_ok(test28,4,NULL,NULL,1,t281,FALSE,0);
462 test_items_ok(test29,10,NULL,NULL,2,t291,FALSE,0);
463 test_items_ok(test30,8,NULL,NULL,1,t301,FALSE,0);
464 test_items_ok(test31,8,NULL,NULL,1,t311,FALSE,b311);
465 test_items_ok(test32,3,NULL,NULL,1,t321,FALSE,0);
466 test_items_ok(test33,4,NULL,NULL,1,t331,FALSE,0);
467 test_items_ok(test34,3,NULL,NULL,1,t341,FALSE,0);
468 test_items_ok(test35,13,NULL,NULL,1,t351,FALSE,b351);
469 test_items_ok(test36,7,NULL,NULL,1,t361,FALSE,0);
470 test_items_ok(test37,3,NULL,NULL,1,t371,FALSE,0);
471 test_items_ok(test38,2,NULL,NULL,1,t381,FALSE,0);
473 State.uBidiLevel = 0;
474 test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
475 test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
476 test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
477 test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
478 test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
479 test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
480 test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
481 test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
482 test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
483 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
484 test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
485 test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
486 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
487 test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
488 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
489 test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
490 test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
491 test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
492 test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
493 test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
494 test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
495 test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
496 test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
497 test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
498 test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
499 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
500 test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
501 test_items_ok(test23,6,&Control,&State,2,t231,FALSE,0);
502 test_items_ok(test24,12,&Control,&State,1,t241,FALSE,0);
503 test_items_ok(test25,10,&Control,&State,1,t251,FALSE,0);
504 test_items_ok(test26,2,&Control,&State,1,t261,FALSE,0);
505 test_items_ok(test27,8,&Control,&State,1,t271,FALSE,0);
506 test_items_ok(test28,4,&Control,&State,1,t281,FALSE,0);
507 test_items_ok(test29,10,&Control,&State,2,t291,FALSE,0);
508 test_items_ok(test30,8,&Control,&State,1,t301,FALSE,0);
509 test_items_ok(test31,8,&Control,&State,1,t311,FALSE,b311);
510 test_items_ok(test32,3,&Control,&State,1,t321,FALSE,0);
511 test_items_ok(test33,4,&Control,&State,1,t331,FALSE,0);
512 test_items_ok(test34,3,&Control,&State,1,t341,FALSE,0);
513 test_items_ok(test35,13,&Control,&State,1,t351,FALSE,b351);
514 test_items_ok(test36,7,&Control,&State,1,t361,FALSE,0);
515 test_items_ok(test37,3,&Control,&State,1,t371,FALSE,0);
516 test_items_ok(test38,2,&Control,&State,1,t381,FALSE,0);
518 State.uBidiLevel = 1;
519 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
520 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
521 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
522 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
523 test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
524 test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
525 test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
526 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
527 test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
528 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
529 test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
530 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
531 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
532 test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
533 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
534 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
535 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
536 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
537 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
538 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
539 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
540 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
541 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
542 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
543 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
544 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
545 test_items_ok(test22,6,&Control,&State,2,t222,FALSE,b222);
546 test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
547 test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
548 test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
549 test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
550 test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
551 test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
552 test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
553 test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
554 test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
555 test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
556 test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
557 test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
558 test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
559 test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
560 test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
561 test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
563 State.uBidiLevel = 1;
564 Control.fMergeNeutralItems = TRUE;
565 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
566 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
567 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
568 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
569 test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,b2);
570 test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,b2);
571 test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,b2);
572 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
573 test_items_ok(test4,12,&Control,&State,3,t43,FALSE,b43);
574 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
575 test_items_ok(test6,5,&Control,&State,1,t63,FALSE,b63);
576 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
577 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
578 test_items_ok(test9,5,&Control,&State,1,t93,FALSE,b93);
579 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
580 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
581 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
582 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
583 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
584 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
585 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
586 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
587 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
588 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
589 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
590 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
591 test_items_ok(test22,6,&Control,&State,1,t223,FALSE,b223);
592 test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
593 test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
594 test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
595 test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
596 test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
597 test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
598 test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
599 test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
600 test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
601 test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
602 test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
603 test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
604 test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
605 test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
606 test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
607 test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
610 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
611 DWORD cchString, SCRIPT_CONTROL *Control,
612 SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
613 const shapeTest_char* charItems,
614 const shapeTest_glyph* glyphItems)
616 HRESULT hr;
617 int x, outnItems=0, outnGlyphs=0;
618 SCRIPT_ITEM outpItems[15];
619 SCRIPT_CACHE sc = NULL;
620 WORD *glyphs;
621 WORD *logclust;
622 int maxGlyphs = cchString * 1.5;
623 SCRIPT_GLYPHPROP *glyphProp;
624 SCRIPT_CHARPROP *charProp;
625 ULONG tags[15];
627 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
628 if (hr == USP_E_SCRIPT_NOT_IN_FONT)
630 if (valid > 0)
631 winetest_win_skip("Select font does not support script\n");
632 else
633 winetest_trace("Select font does not support script\n");
634 return;
636 if (valid > 0)
637 winetest_ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
638 else if (hr)
639 winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
642 if (outnItems <= item)
644 if (valid > 0)
645 winetest_win_skip("Did not get enough items\n");
646 else
647 winetest_trace("Did not get enough items\n");
648 return;
651 logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
652 memset(logclust,'a',sizeof(WORD) * cchString);
653 charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
654 memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
655 glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
656 memset(glyphs,'a',sizeof(WORD) * cchString);
657 glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
658 memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
660 hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
661 if (valid > 0)
662 winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
663 else if (hr != S_OK)
664 winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
665 if (FAILED(hr))
666 return;
668 for (x = 0; x < cchString; x++)
670 if (valid > 0)
671 winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
672 else if (logclust[x] != charItems[x].wLogClust)
673 winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
674 if (valid > 0)
675 winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
676 else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
677 winetest_trace("%i: invalid fCanGlyphAlone\n",x);
680 if (valid > 0)
681 winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
682 else if (nGlyphs != outnGlyphs)
683 winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
684 for (x = 0; x < outnGlyphs; x++)
686 if (glyphItems[x].Glyph)
688 if (valid > 0)
689 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
690 else if (glyphs[x]==0)
691 winetest_trace("%i: Glyph not present when it should be\n",x);
693 else
695 if (valid > 0)
696 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
697 else if (glyphs[x]!=0)
698 winetest_trace("%i: Glyph present when it should not be\n",x);
700 if (valid > 0)
701 winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification, "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
702 else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
703 winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
704 if (valid > 0)
705 winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart, "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
706 else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
707 winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
708 if (valid > 0)
709 winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic, "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
710 else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
711 winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
712 if (valid > 0)
713 winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth, "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
714 else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
715 winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
718 HeapFree(GetProcessHeap(),0,logclust);
719 HeapFree(GetProcessHeap(),0,charProp);
720 HeapFree(GetProcessHeap(),0,glyphs);
721 HeapFree(GetProcessHeap(),0,glyphProp);
722 ScriptFreeCache(&sc);
725 #define test_shape_ok(a,b,c,d,e,f,g,h,i) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(1,a,b,c,d,e,f,g,h,i)
727 #define test_shape_ok_valid(v,a,b,c,d,e,f,g,h,i) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(v,a,b,c,d,e,f,g,h,i)
729 typedef struct tagRangeP {
730 BYTE range;
731 LOGFONTA lf;
732 } fontEnumParam;
734 static int CALLBACK enumFontProc( const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
735 DWORD FontType, LPARAM lParam)
737 NEWTEXTMETRICEX *ntme = (NEWTEXTMETRICEX*)lpntme;
738 fontEnumParam *rp = (fontEnumParam*) lParam;
739 int idx = 0;
740 DWORD i;
741 DWORD mask = 0;
743 if (FontType != TRUETYPE_FONTTYPE)
744 return 1;
746 i = rp->range;
747 while (i > sizeof(DWORD)*8)
749 idx++;
750 i -= (sizeof(DWORD)*8);
752 if (idx > 3)
753 return 0;
755 mask = 1 << i;
757 if (ntme->ntmFontSig.fsUsb[idx] & mask)
759 memcpy(&(rp->lf),lpelfe,sizeof(LOGFONT));
760 return 0;
762 return 1;
765 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont)
767 int rc = 0;
768 fontEnumParam lParam;
770 lParam.range = range;
771 memset(&lParam.lf,0,sizeof(LOGFONT));
772 *hfont = NULL;
774 if (recommended)
776 lstrcpyA(lParam.lf.lfFaceName, recommended);
777 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
779 *hfont = CreateFontIndirectA(&lParam.lf);
780 if (*hfont)
782 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
783 rc = 1;
788 if (!*hfont)
790 memset(&lParam.lf,0,sizeof(LOGFONT));
791 lParam.lf.lfCharSet = DEFAULT_CHARSET;
793 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
795 *hfont = CreateFontIndirectA(&lParam.lf);
796 if (*hfont)
797 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
801 if (*hfont)
803 WORD glyph = 0;
805 *origFont = SelectObject(hdc,*hfont);
806 if (pGetGlyphIndicesW && (pGetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph ==0))
808 winetest_trace(" Font fails to contain required glyphs\n");
809 SelectObject(hdc,*origFont);
810 DeleteObject(*hfont);
811 *hfont=NULL;
812 rc = 0;
814 else if (!rc)
815 rc = -1;
817 else
818 winetest_trace("Failed to find usable font\n");
820 return rc;
823 #define find_font_for_range(a,b,c,d,e,f) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _find_font_for_range(a,b,c,d,e,f)
825 static void test_ScriptShapeOpenType(HDC hdc)
827 HRESULT hr;
828 SCRIPT_CACHE sc = NULL;
829 WORD glyphs[4], logclust[4];
830 SCRIPT_GLYPHPROP glyphProp[4];
831 SCRIPT_ITEM items[2];
832 ULONG tags[2];
833 SCRIPT_CONTROL Control;
834 SCRIPT_STATE State;
835 int nb, outnItems;
836 HFONT hfont, hfont_orig;
837 int test_valid;
839 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
840 static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
841 static const shapeTest_glyph t1_g[] = {
842 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
843 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
844 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
845 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
847 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
848 static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
849 static const shapeTest_glyph t2_g[] = {
850 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
851 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
852 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
853 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
855 /* Hebrew */
856 static const WCHAR test_hebrew[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
857 static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
858 static const shapeTest_glyph hebrew_g[] = {
859 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
860 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
861 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
862 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
864 /* Arabic */
865 static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
866 static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
867 static const shapeTest_glyph arabic_g[] = {
868 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
869 {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
870 {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
872 /* Thai */
873 static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
874 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}}};
875 static const shapeTest_glyph thai_g[] = {
876 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
877 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
878 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
879 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
880 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
881 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
882 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
883 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
884 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
885 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
887 /* Syriac */
888 static const WCHAR test_syriac[] = {0x0710, 0x0710, 0x0710, 0x0728, 0x0718, 0x0723,0};
889 static const shapeTest_char syriac_c[] = {{5,{0,0}},{4,{0,0}},{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
890 static const shapeTest_glyph syriac_g[] = {
891 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
892 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
893 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
894 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
895 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
896 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
898 /* Thaana */
899 static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
900 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}}};
901 static const shapeTest_glyph thaana_g[] = {
902 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
903 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
904 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
905 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
906 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
907 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
908 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
909 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
910 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
911 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
912 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
913 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
914 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
916 /* Phags-pa */
917 static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
918 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}}};
919 static const shapeTest_glyph phagspa_g[] = {
920 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
921 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
922 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
923 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
924 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
925 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
926 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
927 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
928 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
929 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
930 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
932 /* Lao */
933 static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
934 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}}};
935 static const shapeTest_glyph lao_g[] = {
936 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
937 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
938 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
939 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
940 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
941 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
942 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
943 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
944 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
946 /* Tibetan */
947 static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
948 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}}};
949 static const shapeTest_glyph tibetan_g[] = {
950 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
951 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
952 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
953 {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
954 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
955 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
956 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
957 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
958 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
959 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
960 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
961 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
962 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
963 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
964 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
965 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
966 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
968 /* Devanagari */
969 static const WCHAR test_devanagari[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
970 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}}};
971 static const shapeTest_glyph devanagari_g[] = {
972 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
973 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
974 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
975 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
976 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
977 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
978 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
979 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
981 /* Bengali */
982 static const WCHAR test_bengali[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
983 static const shapeTest_char bengali_c[] = {{0,{0,0}},{0,{0,0}},{0,{0,0}},{3,{0,0}},{3,{0,0}}};
984 static const shapeTest_glyph bengali_g[] = {
985 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
986 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
987 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
988 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
989 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
991 /* Gurmukhi */
992 static const WCHAR test_gurmukhi[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
993 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}}};
994 static const shapeTest_glyph gurmukhi_g[] = {
995 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
996 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
997 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
998 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
999 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1000 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1001 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1003 /* Gujarati */
1004 static const WCHAR test_gujarati[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
1005 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}}};
1006 static const shapeTest_glyph gujarati_g[] = {
1007 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1008 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1009 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1010 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1011 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1012 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1013 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1015 /* Oriya */
1016 static const WCHAR test_oriya[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
1017 static const shapeTest_char oriya_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1018 static const shapeTest_glyph oriya_g[] = {
1019 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1020 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1021 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1022 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1024 /* Tamil */
1025 static const WCHAR test_tamil[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
1026 static const shapeTest_char tamil_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}},{3,{0,0}}};
1027 static const shapeTest_glyph tamil_g[] = {
1028 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1029 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1030 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1031 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1033 /* Telugu */
1034 static const WCHAR test_telugu[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
1035 static const shapeTest_char telugu_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1036 static const shapeTest_glyph telugu_g[] = {
1037 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1038 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1039 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1040 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1041 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1042 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1044 /* Malayalam */
1045 static const WCHAR test_malayalam[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
1046 static const shapeTest_char malayalam_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1047 static const shapeTest_glyph malayalam_g[] = {
1048 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1049 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1050 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1051 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1052 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1053 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1055 /* Kannada */
1056 static const WCHAR test_kannada[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
1057 static const shapeTest_char kannada_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1058 static const shapeTest_glyph kannada_g[] = {
1059 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1060 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1061 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1062 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1063 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1065 if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
1067 win_skip("ScriptShapeOpenType not available on this platform\n");
1068 return;
1071 memset(&Control, 0 , sizeof(Control));
1072 memset(&State, 0 , sizeof(State));
1074 hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
1075 ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
1076 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1078 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
1079 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1081 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
1082 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1084 hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1085 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
1087 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1088 ok( hr == E_INVALIDARG,
1089 "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1090 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
1091 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1093 ScriptFreeCache(&sc);
1095 test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
1096 test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, t2_g);
1098 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig);
1099 if (hfont != NULL)
1101 test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
1102 SelectObject(hdc, hfont_orig);
1103 DeleteObject(hfont);
1106 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig);
1107 if (hfont != NULL)
1109 test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
1110 SelectObject(hdc, hfont_orig);
1111 DeleteObject(hfont);
1114 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig);
1115 if (hfont != NULL)
1117 test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
1118 SelectObject(hdc, hfont_orig);
1119 DeleteObject(hfont);
1122 test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig);
1123 if (hfont != NULL)
1125 test_shape_ok_valid(test_valid, hdc, test_syriac, 6, &Control, &State, 0, 6, syriac_c, syriac_g);
1126 SelectObject(hdc, hfont_orig);
1127 DeleteObject(hfont);
1130 test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig);
1131 if (hfont != NULL)
1133 test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
1134 SelectObject(hdc, hfont_orig);
1135 DeleteObject(hfont);
1138 test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig);
1139 if (hfont != NULL)
1141 test_shape_ok_valid(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11, phagspa_c, phagspa_g);
1142 SelectObject(hdc, hfont_orig);
1143 DeleteObject(hfont);
1146 test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig);
1147 if (hfont != NULL)
1149 test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
1150 SelectObject(hdc, hfont_orig);
1151 DeleteObject(hfont);
1154 test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig);
1155 if (hfont != NULL)
1157 test_shape_ok_valid(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17, tibetan_c, tibetan_g);
1158 SelectObject(hdc, hfont_orig);
1159 DeleteObject(hfont);
1162 test_valid = find_font_for_range(hdc, "Mangal", 15, test_devanagari[0], &hfont, &hfont_orig);
1163 if (hfont != NULL)
1165 test_shape_ok_valid(test_valid, hdc, test_devanagari, 8, &Control, &State, 0, 8, devanagari_c, devanagari_g);
1166 SelectObject(hdc, hfont_orig);
1167 DeleteObject(hfont);
1170 test_valid = find_font_for_range(hdc, "Vrinda", 16, test_bengali[0], &hfont, &hfont_orig);
1171 if (hfont != NULL)
1173 test_shape_ok_valid(test_valid, hdc, test_bengali, 5, &Control, &State, 0, 5, bengali_c, bengali_g);
1174 SelectObject(hdc, hfont_orig);
1175 DeleteObject(hfont);
1178 test_valid = find_font_for_range(hdc, "Raavi", 17, test_gurmukhi[0], &hfont, &hfont_orig);
1179 if (hfont != NULL)
1181 test_shape_ok_valid(test_valid, hdc, test_gurmukhi, 7, &Control, &State, 0, 7, gurmukhi_c, gurmukhi_g);
1182 SelectObject(hdc, hfont_orig);
1183 DeleteObject(hfont);
1186 test_valid = find_font_for_range(hdc, "Shruti", 18, test_gujarati[0], &hfont, &hfont_orig);
1187 if (hfont != NULL)
1189 test_shape_ok_valid(test_valid, hdc, test_gujarati, 7, &Control, &State, 0, 7, gujarati_c, gujarati_g);
1190 SelectObject(hdc, hfont_orig);
1191 DeleteObject(hfont);
1194 test_valid = find_font_for_range(hdc, "Kalinga", 19, test_oriya[0], &hfont, &hfont_orig);
1195 if (hfont != NULL)
1197 test_shape_ok_valid(test_valid, hdc, test_oriya, 5, &Control, &State, 0, 4, oriya_c, oriya_g);
1198 SelectObject(hdc, hfont_orig);
1199 DeleteObject(hfont);
1202 test_valid = find_font_for_range(hdc, "Latha", 20, test_tamil[0], &hfont, &hfont_orig);
1203 if (hfont != NULL)
1205 test_shape_ok_valid(test_valid, hdc, test_tamil, 5, &Control, &State, 0, 4, tamil_c, tamil_g);
1206 SelectObject(hdc, hfont_orig);
1207 DeleteObject(hfont);
1210 test_valid = find_font_for_range(hdc, "Gautami", 21, test_telugu[0], &hfont, &hfont_orig);
1211 if (hfont != NULL)
1213 test_shape_ok_valid(test_valid, hdc, test_telugu, 6, &Control, &State, 0, 6, telugu_c, telugu_g);
1214 SelectObject(hdc, hfont_orig);
1215 DeleteObject(hfont);
1218 test_valid = find_font_for_range(hdc, "Kartika", 23, test_malayalam[0], &hfont, &hfont_orig);
1219 if (hfont != NULL)
1221 test_shape_ok_valid(test_valid, hdc, test_malayalam, 6, &Control, &State, 0, 6, malayalam_c, malayalam_g);
1222 SelectObject(hdc, hfont_orig);
1223 DeleteObject(hfont);
1226 test_valid = find_font_for_range(hdc, "Tunga", 22, test_kannada[0], &hfont, &hfont_orig);
1227 if (hfont != NULL)
1229 test_shape_ok_valid(test_valid, hdc, test_kannada, 5, &Control, &State, 0, 4, kannada_c, kannada_g);
1230 SelectObject(hdc, hfont_orig);
1231 DeleteObject(hfont);
1235 static void test_ScriptShape(HDC hdc)
1237 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1238 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1239 HRESULT hr;
1240 SCRIPT_CACHE sc = NULL;
1241 WORD glyphs[4], glyphs2[4], logclust[4];
1242 SCRIPT_VISATTR attrs[4];
1243 SCRIPT_ITEM items[2];
1244 int nb;
1246 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1247 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1248 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1250 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
1251 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1253 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
1254 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1256 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1257 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
1259 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1260 ok(broken(hr == S_OK) ||
1261 hr == E_INVALIDARG || /* Vista, W2K8 */
1262 hr == E_FAIL, /* WIN7 */
1263 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1264 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1266 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1267 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1268 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1271 memset(glyphs,-1,sizeof(glyphs));
1272 memset(logclust,-1,sizeof(logclust));
1273 memset(attrs,-1,sizeof(attrs));
1274 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1275 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1276 ok(nb == 4, "Wrong number of items\n");
1277 ok(logclust[0] == 0, "clusters out of order\n");
1278 ok(logclust[1] == 1, "clusters out of order\n");
1279 ok(logclust[2] == 2, "clusters out of order\n");
1280 ok(logclust[3] == 3, "clusters out of order\n");
1281 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1282 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1283 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1284 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1285 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1286 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1287 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1288 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1289 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1290 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1291 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1292 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1293 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1294 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1295 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1296 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1298 ScriptFreeCache(&sc);
1299 sc = NULL;
1301 memset(glyphs2,-1,sizeof(glyphs2));
1302 memset(logclust,-1,sizeof(logclust));
1303 memset(attrs,-1,sizeof(attrs));
1304 hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1305 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1306 ok(nb == 4, "Wrong number of items\n");
1307 ok(glyphs2[0] == 0 || broken(glyphs2[0] == 0x80), "Incorrect glyph for 0x202B\n");
1308 ok(glyphs2[3] == 0 || broken(glyphs2[3] == 0x80), "Incorrect glyph for 0x202C\n");
1309 ok(logclust[0] == 0, "clusters out of order\n");
1310 ok(logclust[1] == 1, "clusters out of order\n");
1311 ok(logclust[2] == 2, "clusters out of order\n");
1312 ok(logclust[3] == 3, "clusters out of order\n");
1313 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1314 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1315 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1316 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1317 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1318 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1319 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1320 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1321 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1322 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1323 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1324 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1325 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1326 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1327 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1328 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1330 /* modify LTR to RTL */
1331 items[0].a.fRTL = 1;
1332 memset(glyphs2,-1,sizeof(glyphs2));
1333 memset(logclust,-1,sizeof(logclust));
1334 memset(attrs,-1,sizeof(attrs));
1335 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1336 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1337 ok(nb == 4, "Wrong number of items\n");
1338 ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
1339 ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
1340 ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
1341 ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
1342 ok(logclust[0] == 3, "clusters out of order\n");
1343 ok(logclust[1] == 2, "clusters out of order\n");
1344 ok(logclust[2] == 1, "clusters out of order\n");
1345 ok(logclust[3] == 0, "clusters out of order\n");
1346 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1347 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1348 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1349 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1350 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1351 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1352 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1353 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1354 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1355 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1356 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1357 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1358 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1359 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1360 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1361 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1363 ScriptFreeCache(&sc);
1366 static void test_ScriptPlace(HDC hdc)
1368 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
1369 BOOL ret;
1370 HRESULT hr;
1371 SCRIPT_CACHE sc = NULL;
1372 WORD glyphs[4], logclust[4];
1373 SCRIPT_VISATTR attrs[4];
1374 SCRIPT_ITEM items[2];
1375 int nb, widths[4];
1376 GOFFSET offset[4];
1377 ABC abc[4];
1379 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1380 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1381 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1383 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1384 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1385 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1387 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
1388 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
1390 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
1391 ok(broken(hr == E_PENDING) ||
1392 hr == E_INVALIDARG || /* Vista, W2K8 */
1393 hr == E_FAIL, /* WIN7 */
1394 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1396 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1397 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
1399 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
1400 ok(broken(hr == E_PENDING) ||
1401 hr == E_INVALIDARG || /* Vista, W2K8 */
1402 hr == E_FAIL, /* WIN7 */
1403 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1405 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1406 ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
1407 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1409 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
1410 ok(ret, "ExtTextOutW should return TRUE\n");
1412 ScriptFreeCache(&sc);
1415 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
1417 HRESULT hr;
1418 int iMaxProps;
1419 const SCRIPT_PROPERTIES **ppSp;
1421 int cInChars;
1422 int cMaxItems;
1423 SCRIPT_ITEM pItem[255];
1424 int pcItems;
1425 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1426 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
1427 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
1428 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
1429 WCHAR TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
1430 WCHAR TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
1432 SCRIPT_CACHE psc;
1433 int cChars;
1434 int cMaxGlyphs;
1435 unsigned short pwOutGlyphs1[256];
1436 unsigned short pwOutGlyphs2[256];
1437 unsigned short pwLogClust[256];
1438 SCRIPT_VISATTR psva[256];
1439 int pcGlyphs;
1440 int piAdvance[256];
1441 GOFFSET pGoffset[256];
1442 ABC pABC[256];
1443 int cnt;
1445 /* Start testing usp10 functions */
1446 /* This test determines that the pointer returned by ScriptGetProperties is valid
1447 * by checking a known value in the table */
1448 hr = ScriptGetProperties(&ppSp, &iMaxProps);
1449 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1450 trace("number of script properties %d\n", iMaxProps);
1451 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
1452 if (iMaxProps > 0)
1453 ok( ppSp[0]->langid == 0, "Langid[0] not = to 0\n"); /* Check a known value to ensure */
1454 /* ptrs work */
1456 /* This is a valid test that will cause parsing to take place */
1457 cInChars = 5;
1458 cMaxItems = 255;
1459 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1460 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1461 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1462 * returned. */
1463 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1464 if (pcItems > 0)
1465 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1466 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1467 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1469 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1470 * ie. ScriptItemize has succeeded and that pItem has been set */
1471 cInChars = 5;
1472 if (hr == 0) {
1473 psc = NULL; /* must be null on first call */
1474 cChars = cInChars;
1475 cMaxGlyphs = cInChars;
1476 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
1477 cMaxGlyphs, &pItem[0].a,
1478 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1479 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
1480 cMaxGlyphs = 4;
1481 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1482 cMaxGlyphs, &pItem[0].a,
1483 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1484 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
1485 "(%d) but not E_OUTOFMEMORY\n",
1486 cChars, cMaxGlyphs);
1487 cMaxGlyphs = 256;
1488 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1489 cMaxGlyphs, &pItem[0].a,
1490 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1491 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1492 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1493 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1494 if (hr ==0) {
1495 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1496 pGoffset, pABC);
1497 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1498 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1499 pGoffset, pABC);
1500 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1501 for (cnt=0; cnt < pcGlyphs; cnt++)
1502 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
1505 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
1506 * takes place if fNoGlyphIndex is set. */
1508 cInChars = 5;
1509 cMaxItems = 255;
1510 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1511 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1512 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1513 * returned. */
1514 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1515 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1516 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1517 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
1518 if (hr == 0) {
1519 cChars = cInChars;
1520 cMaxGlyphs = 256;
1521 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
1522 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
1523 cMaxGlyphs, &pItem[0].a,
1524 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
1525 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
1526 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1527 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1528 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1529 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
1530 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
1531 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
1532 if (hr ==0) {
1533 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
1534 pGoffset, pABC);
1535 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1538 ScriptFreeCache( &psc);
1539 ok (!psc, "psc is not null after ScriptFreeCache\n");
1543 /* This is a valid test that will cause parsing to take place and create 3 script_items */
1544 cInChars = (sizeof(TestItem3)/2)-1;
1545 cMaxItems = 255;
1546 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1547 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1548 if (hr == 0)
1550 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
1551 if (pcItems > 2)
1553 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1554 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1555 pItem[0].iCharPos, pItem[1].iCharPos);
1556 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1557 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1558 pItem[1].iCharPos, pItem[2].iCharPos);
1559 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
1560 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
1561 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
1565 /* This is a valid test that will cause parsing to take place and create 5 script_items */
1566 cInChars = (sizeof(TestItem4)/2)-1;
1567 cMaxItems = 255;
1568 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1569 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1570 if (hr == 0)
1572 ok (pcItems == 5, "The number of SCRIPT_ITEMS should be 5 not %d\n", pcItems);
1573 if (pcItems > 4)
1575 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1576 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1577 pItem[0].iCharPos, pItem[1].iCharPos);
1578 ok (pItem[0].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1579 pItem[0].a.s.uBidiLevel);
1580 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1581 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1582 pItem[1].iCharPos, pItem[2].iCharPos);
1583 ok (pItem[1].a.s.uBidiLevel == 1, "Should have been bidi=1 not %d\n",
1584 pItem[1].a.s.uBidiLevel);
1585 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == 12,
1586 "Start pos [2] not = 11 (%d) or end [3] pos not = 12 (%d)\n",
1587 pItem[2].iCharPos, pItem[3].iCharPos);
1588 ok (pItem[2].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1589 pItem[2].a.s.uBidiLevel);
1590 ok (pItem[3].iCharPos == 12 && pItem[4].iCharPos == 13,
1591 "Start pos [3] not = 12 (%d) or end [4] pos not = 13 (%d)\n",
1592 pItem[3].iCharPos, pItem[4].iCharPos);
1593 ok (pItem[3].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1594 pItem[3].a.s.uBidiLevel);
1595 ok (pItem[4].iCharPos == 13 && pItem[5].iCharPos == cInChars,
1596 "Start pos [4] not = 13 (%d) or end [5] pos not = 16 (%d), cInChars = %d\n",
1597 pItem[4].iCharPos, pItem[5].iCharPos, cInChars);
1602 * This test is for when the first unicode character requires bidi support
1604 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
1605 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1606 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1607 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
1608 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
1609 pItem[0].a.s.uBidiLevel);
1611 /* This test checks to make sure that the test to see if there are sufficient buffers to store *
1612 * the pointer to the last char works. Note that windows often needs a greater number of *
1613 * SCRIPT_ITEMS to process a string than is returned in pcItems. */
1614 cInChars = (sizeof(TestItem6)/2)-1;
1615 cMaxItems = 4;
1616 hr = ScriptItemize(TestItem6, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1617 ok (hr == E_OUTOFMEMORY, "ScriptItemize should return E_OUTOFMEMORY, returned %08x\n", hr);
1621 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
1623 HRESULT hr;
1624 SCRIPT_CACHE psc = NULL;
1625 int cInChars;
1626 int cChars;
1627 unsigned short pwOutGlyphs2[256];
1628 unsigned short pwOutGlyphs3[256];
1629 DWORD dwFlags;
1630 int cnt;
1632 static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1633 static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
1634 static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
1635 static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
1637 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
1638 dwFlags = 0;
1639 cInChars = cChars = 5;
1640 /* Some sanity checks for ScriptGetCMap */
1642 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
1643 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
1644 "expected E_INVALIDARG, got %08x\n", hr);
1646 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1647 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1648 "expected E_INVALIDARG, got %08x\n", hr);
1650 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1651 psc = NULL;
1652 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1653 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
1654 "got %08x\n", hr);
1655 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1657 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
1658 psc = NULL;
1659 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1660 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
1661 "got %08x\n", hr);
1662 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
1663 ScriptFreeCache( &psc);
1665 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1666 psc = NULL;
1667 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1668 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
1669 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1670 /* Check to see if the results are the same as those returned by ScriptShape */
1671 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1672 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
1673 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1674 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
1675 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
1676 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
1678 ScriptFreeCache( &psc);
1679 ok (!psc, "psc is not null after ScriptFreeCache\n");
1681 cInChars = cChars = 4;
1682 hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
1683 ok (hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
1684 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1685 ok(pwOutGlyphs3[0] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1686 ok(pwOutGlyphs3[3] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1689 cInChars = cChars = 9;
1690 hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
1691 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1692 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1694 cInChars = cChars = 9;
1695 dwFlags = SGCM_RTL;
1696 hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
1697 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1698 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1699 ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
1700 ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorreclty altered\n");
1701 ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorreclty altered\n");
1702 ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorreclty altered\n");
1703 ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
1704 ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
1705 ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
1706 ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
1707 ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
1709 ScriptFreeCache( &psc);
1710 ok (!psc, "psc is not null after ScriptFreeCache\n");
1713 static void test_ScriptGetFontProperties(HDC hdc)
1715 HRESULT hr;
1716 SCRIPT_CACHE psc,old_psc;
1717 SCRIPT_FONTPROPERTIES sfp;
1719 /* Some sanity checks for ScriptGetFontProperties */
1721 hr = ScriptGetFontProperties(NULL,NULL,NULL);
1722 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1724 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
1725 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1727 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1728 psc = NULL;
1729 hr = ScriptGetFontProperties(NULL,&psc,NULL);
1730 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1731 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1733 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1734 psc = NULL;
1735 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1736 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
1737 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1739 hr = ScriptGetFontProperties(hdc,NULL,NULL);
1740 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1742 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
1743 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1745 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1746 psc = NULL;
1747 hr = ScriptGetFontProperties(hdc,&psc,NULL);
1748 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1749 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1751 /* Pass an invalid sfp */
1752 psc = NULL;
1753 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
1754 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1755 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
1756 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1757 ScriptFreeCache(&psc);
1758 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1760 /* Give it the correct cBytes, we don't care about what's coming back */
1761 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
1762 psc = NULL;
1763 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1764 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
1765 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1767 /* Save the psc pointer */
1768 old_psc = psc;
1769 /* Now a NULL hdc again */
1770 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1771 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
1772 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
1773 ScriptFreeCache(&psc);
1774 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1777 static void test_ScriptTextOut(HDC hdc)
1779 HRESULT hr;
1781 int cInChars;
1782 int cMaxItems;
1783 SCRIPT_ITEM pItem[255];
1784 int pcItems;
1785 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1787 SCRIPT_CACHE psc;
1788 int cChars;
1789 int cMaxGlyphs;
1790 unsigned short pwOutGlyphs1[256];
1791 WORD pwLogClust[256];
1792 SCRIPT_VISATTR psva[256];
1793 int pcGlyphs;
1794 int piAdvance[256];
1795 GOFFSET pGoffset[256];
1796 ABC pABC[256];
1797 RECT rect;
1798 int piX;
1799 int iCP = 1;
1800 BOOL fTrailing = FALSE;
1801 SCRIPT_LOGATTR *psla;
1802 SCRIPT_LOGATTR sla[256];
1804 /* This is a valid test that will cause parsing to take place */
1805 cInChars = 5;
1806 cMaxItems = 255;
1807 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1808 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1809 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1810 * returned. */
1811 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1812 if (pcItems > 0)
1813 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1814 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1815 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1817 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1818 * ie. ScriptItemize has succeeded and that pItem has been set */
1819 cInChars = 5;
1820 if (hr == 0) {
1821 psc = NULL; /* must be null on first call */
1822 cChars = cInChars;
1823 cMaxGlyphs = 256;
1824 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1825 cMaxGlyphs, &pItem[0].a,
1826 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1827 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1828 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1829 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1830 if (hr ==0) {
1831 /* Note hdc is needed as glyph info is not yet in psc */
1832 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1833 pGoffset, pABC);
1834 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1835 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
1836 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1838 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
1839 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
1841 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1842 piAdvance, NULL, pGoffset);
1843 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1844 "expected E_INVALIDARG, got %08x\n", hr);
1846 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1847 psc = NULL;
1848 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
1849 NULL, NULL, NULL);
1850 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
1851 "got %08x\n", hr);
1852 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1854 /* hdc is required for this one rather than the usual optional */
1855 psc = NULL;
1856 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1857 piAdvance, NULL, pGoffset);
1858 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
1859 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1861 /* Set that it returns 0 status */
1862 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1863 piAdvance, NULL, pGoffset);
1864 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1866 /* Test Rect Rgn is acceptable */
1867 rect.top = 10;
1868 rect.bottom = 20;
1869 rect.left = 10;
1870 rect.right = 40;
1871 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1872 piAdvance, NULL, pGoffset);
1873 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1875 iCP = 1;
1876 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
1877 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
1878 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
1880 psla = (SCRIPT_LOGATTR *)&sla;
1881 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
1882 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
1884 /* Clean up and go */
1885 ScriptFreeCache(&psc);
1886 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1891 static void test_ScriptTextOut2(HDC hdc)
1893 /* Intent is to validate that the HDC passed into ScriptTextOut is
1894 * used instead of the (possibly) invalid cached one
1896 HRESULT hr;
1898 HDC hdc1, hdc2;
1899 int cInChars;
1900 int cMaxItems;
1901 SCRIPT_ITEM pItem[255];
1902 int pcItems;
1903 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1905 SCRIPT_CACHE psc;
1906 int cChars;
1907 int cMaxGlyphs;
1908 unsigned short pwOutGlyphs1[256];
1909 WORD pwLogClust[256];
1910 SCRIPT_VISATTR psva[256];
1911 int pcGlyphs;
1912 int piAdvance[256];
1913 GOFFSET pGoffset[256];
1914 ABC pABC[256];
1916 /* Create an extra DC that will be used until the ScriptTextOut */
1917 hdc1 = CreateCompatibleDC(hdc);
1918 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
1919 hdc2 = CreateCompatibleDC(hdc);
1920 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
1922 /* This is a valid test that will cause parsing to take place */
1923 cInChars = 5;
1924 cMaxItems = 255;
1925 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1926 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1927 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1928 * returned. */
1929 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1930 if (pcItems > 0)
1931 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1932 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1933 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1935 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1936 * ie. ScriptItemize has succeeded and that pItem has been set */
1937 cInChars = 5;
1938 if (hr == 0) {
1939 psc = NULL; /* must be null on first call */
1940 cChars = cInChars;
1941 cMaxGlyphs = 256;
1942 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
1943 cMaxGlyphs, &pItem[0].a,
1944 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1945 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1946 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1947 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1948 if (hr ==0) {
1949 /* Note hdc is needed as glyph info is not yet in psc */
1950 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1951 pGoffset, pABC);
1952 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1954 /* key part!!! cached dc is being deleted */
1955 hr = DeleteDC(hdc2);
1956 ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
1958 /* At this point the cached hdc (hdc2) has been destroyed,
1959 * however, we are passing in a *real* hdc (the original hdc).
1960 * The text should be written to that DC
1962 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1963 piAdvance, NULL, pGoffset);
1964 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1965 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1967 DeleteDC(hdc1);
1969 /* Clean up and go */
1970 ScriptFreeCache(&psc);
1971 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1976 static void test_ScriptTextOut3(HDC hdc)
1978 HRESULT hr;
1980 int cInChars;
1981 int cMaxItems;
1982 SCRIPT_ITEM pItem[255];
1983 int pcItems;
1984 WCHAR TestItem1[] = {' ','\r', 0};
1986 SCRIPT_CACHE psc;
1987 int cChars;
1988 int cMaxGlyphs;
1989 unsigned short pwOutGlyphs1[256];
1990 WORD pwLogClust[256];
1991 SCRIPT_VISATTR psva[256];
1992 int pcGlyphs;
1993 int piAdvance[256];
1994 GOFFSET pGoffset[256];
1995 ABC pABC[256];
1996 RECT rect;
1998 /* This is to ensure that nonexistent glyphs are translated into a valid glyph number */
1999 cInChars = 2;
2000 cMaxItems = 255;
2001 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
2002 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
2003 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
2004 * returned. */
2005 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
2006 if (pcItems > 0)
2007 ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
2008 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
2009 pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
2011 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
2012 * ie. ScriptItemize has succeeded and that pItem has been set */
2013 cInChars = 2;
2014 if (hr == 0) {
2015 psc = NULL; /* must be null on first call */
2016 cChars = cInChars;
2017 cMaxGlyphs = 256;
2018 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
2019 cMaxGlyphs, &pItem[0].a,
2020 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2021 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
2022 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2023 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
2024 if (hr ==0) {
2025 /* Note hdc is needed as glyph info is not yet in psc */
2026 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
2027 pGoffset, pABC);
2028 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
2030 /* Test Rect Rgn is acceptable */
2031 rect.top = 10;
2032 rect.bottom = 20;
2033 rect.left = 10;
2034 rect.right = 40;
2035 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2036 piAdvance, NULL, pGoffset);
2037 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
2040 /* Clean up and go */
2041 ScriptFreeCache(&psc);
2042 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2046 #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)
2048 static void _test_item_ScriptXtoX(SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
2050 int iX, iCP;
2051 int icChars, icGlyphs;
2052 int piCP, piX;
2053 HRESULT hr;
2054 SCRIPT_VISATTR psva[10];
2055 int piTrailing;
2056 BOOL fTrailing;
2057 int direction;
2059 memset(psva,0,sizeof(psva));
2060 direction = (psa->fRTL)?-1:+1;
2062 for(iCP = 0; iCP < cChars; iCP++)
2064 iX = offsets[iCP];
2065 icChars = cChars;
2066 icGlyphs = cGlyphs;
2067 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2068 winetest_ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
2069 winetest_ok(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2070 winetest_ok(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2073 for(iCP = 0; iCP < cChars; iCP++)
2075 iX = offsets[iCP]+direction;
2076 icChars = cChars;
2077 icGlyphs = cGlyphs;
2078 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2079 winetest_ok(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
2080 winetest_ok(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2081 winetest_ok(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2084 for(iCP = 0; iCP < cChars; iCP++)
2086 iX = offsets[iCP+1]-direction;
2087 icChars = cChars;
2088 icGlyphs = cGlyphs;
2089 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2090 winetest_ok(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
2091 winetest_ok(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2092 winetest_ok(piTrailing == 1, "ScriptXtoCP trailing: iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2095 for(iCP = 0; iCP <= cChars+1; iCP++)
2097 fTrailing = FALSE;
2098 icChars = cChars;
2099 icGlyphs = cGlyphs;
2100 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2101 winetest_ok(hr == S_OK, "ScriptCPtoX: should return S_OK not %08x\n", hr);
2102 winetest_ok(piX == offsets[iCP],
2103 "ScriptCPtoX: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
2106 for(iCP = 0; iCP <= cChars+1; iCP++)
2108 fTrailing = TRUE;
2109 icChars = cChars;
2110 icGlyphs = cGlyphs;
2111 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2112 winetest_ok(hr == S_OK, "ScriptCPtoX trailing: should return S_OK not %08x\n", hr);
2113 winetest_ok(piX == offsets[iCP+1],
2114 "ScriptCPtoX trailing: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
2118 static void test_ScriptXtoX(void)
2119 /****************************************************************************************
2120 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
2121 ****************************************************************************************/
2123 WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
2124 WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
2125 WORD pwLogClust_2[7] = {4, 3, 3, 2, 1, 0 ,0};
2126 int piAdvance[10] = {201, 190, 210, 180, 170, 204, 189, 195, 212, 203};
2127 int piAdvance_2[5] = {39, 26, 19, 17, 11};
2128 static const int offsets[13] = {0, 67, 134, 201, 296, 391, 496, 601, 1052, 1503, 1954, 1954, 1954};
2129 static const int offsets_RTL[13] = {781, 721, 661, 601, 496, 391, 296, 201, 134, 67, 0, 0, 0};
2130 static const int offsets_2[10] = {112, 101, 92, 84, 65, 39, 19, 0, 0, 0};
2131 SCRIPT_VISATTR psva[10];
2132 SCRIPT_ANALYSIS sa;
2133 int iX;
2134 int piCP;
2135 int piTrailing;
2136 HRESULT hr;
2138 memset(&sa, 0 , sizeof(SCRIPT_ANALYSIS));
2139 memset(psva, 0, sizeof(psva));
2141 sa.fRTL = FALSE;
2142 hr = ScriptXtoCP(-1, 10, 10, pwLogClust, psva, piAdvance, &sa, &piCP, &piTrailing);
2143 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2144 if (piTrailing)
2145 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2146 else /* win2k3 */
2147 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2149 for (iX = 0; iX <= 7; iX++)
2151 WORD clust = 0;
2152 INT advance = 16;
2153 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2154 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX, piCP,piTrailing);
2156 for (iX = 8; iX < 16; iX++)
2158 WORD clust = 0;
2159 INT advance = 16;
2160 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2161 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX, piCP,piTrailing);
2164 sa.fRTL = TRUE;
2165 hr = ScriptXtoCP(-1, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2166 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2167 if (piTrailing)
2168 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2169 else /* win2k3 */
2170 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2172 iX = 1954;
2173 hr = ScriptXtoCP(1954, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2174 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2175 ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
2176 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2178 for (iX = 1; iX <= 8; iX++)
2180 WORD clust = 0;
2181 INT advance = 16;
2182 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2183 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX,piCP,piTrailing);
2185 for (iX = 9; iX < 16; iX++)
2187 WORD clust = 0;
2188 INT advance = 16;
2189 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2190 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX,piCP,piTrailing);
2193 sa.fRTL = FALSE;
2194 test_item_ScriptXtoX(&sa, 10, 10, offsets, pwLogClust, piAdvance);
2195 sa.fRTL = TRUE;
2196 test_item_ScriptXtoX(&sa, 10, 10, offsets_RTL, pwLogClust_RTL, piAdvance);
2197 test_item_ScriptXtoX(&sa, 7, 5, offsets_2, pwLogClust_2, piAdvance_2);
2200 static void test_ScriptString(HDC hdc)
2202 /*******************************************************************************************
2204 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
2205 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
2206 * memory is freed by ScriptStringFree. There needs to be a valid hdc for this as
2207 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
2211 HRESULT hr;
2212 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
2213 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
2214 int Glyphs = len * 2 + 16;
2215 int Charset;
2216 DWORD Flags = SSA_GLYPHS;
2217 int ReqWidth = 100;
2218 const int Dx[5] = {10, 10, 10, 10, 10};
2219 const BYTE InClass = 0;
2220 SCRIPT_STRING_ANALYSIS ssa = NULL;
2222 int X = 10;
2223 int Y = 100;
2224 UINT Options = 0;
2225 const RECT rc = {0, 50, 100, 100};
2226 int MinSel = 0;
2227 int MaxSel = 0;
2228 BOOL Disabled = FALSE;
2229 const int *clip_len;
2230 int i;
2231 UINT *order;
2234 Charset = -1; /* this flag indicates unicode input */
2235 /* Test without hdc to get E_PENDING */
2236 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
2237 ReqWidth, NULL, NULL, Dx, NULL,
2238 &InClass, &ssa);
2239 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
2241 /* test with hdc, this should be a valid test */
2242 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2243 ReqWidth, NULL, NULL, Dx, NULL,
2244 &InClass, &ssa);
2245 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2246 ScriptStringFree(&ssa);
2248 /* test makes sure that a call with a valid pssa still works */
2249 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2250 ReqWidth, NULL, NULL, Dx, NULL,
2251 &InClass, &ssa);
2252 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2253 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
2255 if (hr == S_OK)
2257 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
2258 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
2261 clip_len = ScriptString_pcOutChars(ssa);
2262 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
2264 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
2265 hr = ScriptStringGetOrder(ssa, order);
2266 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
2268 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
2269 HeapFree(GetProcessHeap(), 0, order);
2271 hr = ScriptStringFree(&ssa);
2272 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2275 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
2277 /*****************************************************************************************
2279 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
2280 * nature of the fonts between Windows and Wine, the test is implemented by generating
2281 * values using one one function then checking the output of the second. In this way
2282 * the validity of the functions is established using Windows as a base and confirming
2283 * similar behaviour in wine.
2286 HRESULT hr;
2287 static const WCHAR teststr1[] = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
2288 static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
2289 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
2290 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
2291 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
2292 int Charset = -1; /* unicode */
2293 DWORD Flags = SSA_GLYPHS;
2294 int ReqWidth = 100;
2295 const BYTE InClass = 0;
2296 SCRIPT_STRING_ANALYSIS ssa = NULL;
2298 int Ch; /* Character position in string */
2299 int iTrailing;
2300 int Cp; /* Character position in string */
2301 int X;
2302 int trail,lead;
2303 BOOL fTrailing;
2305 /* Test with hdc, this should be a valid test
2306 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
2307 * following character positions to X and X to character position functions.
2310 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2311 ReqWidth, NULL, NULL, NULL, NULL,
2312 &InClass, &ssa);
2313 ok(hr == S_OK ||
2314 hr == E_INVALIDARG, /* NT */
2315 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
2317 if (hr == S_OK)
2319 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
2322 * Loop to generate character positions to provide starting positions for the
2323 * ScriptStringCPtoX and ScriptStringXtoCP functions
2325 for (Cp = 0; Cp < String_len; Cp++)
2327 /* The fTrailing flag is used to indicate whether the X being returned is at
2328 * the beginning or the end of the character. What happens here is that if
2329 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
2330 * returns the beginning of the next character and iTrailing is FALSE. So for this
2331 * loop iTrailing will be FALSE in both cases.
2333 hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
2334 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2335 hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
2336 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2337 if (rtl[Cp])
2338 ok(lead > trail, "Leading values should be after trailing for rtl characters(%i)\n",Cp);
2339 else
2340 ok(lead < trail, "Trailing values should be after leading for ltr characters(%i)\n",Cp);
2342 /* move by 1 pixel so that we are not inbetween 2 characters. That could result in being the lead of a rtl and
2343 at the same time the trail of an ltr */
2345 /* inside the leading edge */
2346 X = lead;
2347 if (rtl[Cp]) X--; else X++;
2348 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2349 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2350 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2351 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2352 iTrailing, X);
2354 /* inside the trailing edge */
2355 X = trail;
2356 if (rtl[Cp]) X++; else X--;
2357 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2358 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2359 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2360 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2361 iTrailing, X);
2363 /* outside the "trailing" edge */
2364 if (Cp < String_len-1)
2366 if (rtl[Cp]) X = lead; else X = trail;
2367 X++;
2368 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2369 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2370 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, trail);
2371 if (rtl[Cp+1])
2372 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2373 iTrailing, X);
2374 else
2375 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2376 iTrailing, X);
2379 /* outside the "leading" edge */
2380 if (Cp != 0)
2382 if (rtl[Cp]) X = trail; else X = lead;
2383 X--;
2384 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2385 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2386 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, trail);
2387 if (Cp != 0 && rtl[Cp-1])
2388 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2389 iTrailing, X);
2390 else
2391 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2392 iTrailing, X);
2396 /* Check beyond the leading boundary of the whole string */
2397 if (rtl[0])
2399 /* having a leading rtl character seems to confuse usp */
2400 /* this looks to be a windows bug we should emulate */
2401 hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
2402 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2403 X--;
2404 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2405 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2406 ok(Ch == 1, "ScriptStringXtoCP should return Ch = 1 not %d for X outside leading edge when rtl\n", Ch);
2407 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside leading edge when rtl\n",
2408 iTrailing);
2410 else
2412 hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
2413 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2414 X--;
2415 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2416 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2417 ok(Ch == -1, "ScriptStringXtoCP should return Ch = -1 not %d for X outside leading edge\n", Ch);
2418 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = outside leading edge\n",
2419 iTrailing);
2422 /* Check beyond the end boundary of the whole string */
2423 if (rtl[String_len-1])
2425 hr = ScriptStringCPtoX(ssa, String_len-1, FALSE, &X);
2426 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2428 else
2430 hr = ScriptStringCPtoX(ssa, String_len-1, TRUE, &X);
2431 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2433 X++;
2434 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2435 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2436 ok(Ch == String_len, "ScriptStringXtoCP should return Ch = %i not %d for X outside trailing edge\n", String_len, Ch);
2437 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside trailing edge\n",
2438 iTrailing);
2441 * Cleanup the SSA for the next round of tests
2443 hr = ScriptStringFree(&ssa);
2444 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2447 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
2448 * generate an SSA for the subsequent tests.
2450 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2451 ReqWidth, NULL, NULL, NULL, NULL,
2452 &InClass, &ssa);
2453 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2456 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
2457 * string length, return E_INVALIDARG. This also invalidates the ssa so a
2458 * ScriptStringFree should also fail.
2460 fTrailing = FALSE;
2461 Cp = String_len + 1;
2462 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
2463 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
2465 ScriptStringFree(&ssa);
2469 static void test_ScriptCacheGetHeight(HDC hdc)
2471 HRESULT hr;
2472 SCRIPT_CACHE sc = NULL;
2473 LONG height;
2475 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
2476 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2478 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
2479 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2481 hr = ScriptCacheGetHeight(NULL, &sc, &height);
2482 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2484 height = 0;
2486 hr = ScriptCacheGetHeight(hdc, &sc, &height);
2487 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2488 ok(height > 0, "expected height > 0\n");
2490 ScriptFreeCache(&sc);
2493 static void test_ScriptGetGlyphABCWidth(HDC hdc)
2495 HRESULT hr;
2496 SCRIPT_CACHE sc = NULL;
2497 ABC abc;
2499 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
2500 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2502 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
2503 ok(broken(hr == E_PENDING) ||
2504 hr == E_INVALIDARG, /* WIN7 */
2505 "expected E_INVALIDARG, got 0x%08x\n", hr);
2507 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
2508 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2510 if (0) { /* crashes on WinXP */
2511 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
2512 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2515 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
2516 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2518 ScriptFreeCache(&sc);
2521 static void test_ScriptLayout(void)
2523 HRESULT hr;
2524 static const BYTE levels[][10] =
2526 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2527 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
2528 { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2529 { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
2531 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
2532 { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
2533 { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
2534 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
2535 { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
2537 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
2538 { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
2540 static const int expect_l2v[][10] =
2542 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2543 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2544 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2545 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2547 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2548 /**/ { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
2549 /**/ { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
2550 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2551 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2553 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2554 /**/ { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
2556 static const int expect_v2l[][10] =
2558 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2559 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2560 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2561 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2563 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2564 { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
2565 { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
2566 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2567 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2569 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2570 { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
2573 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
2575 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
2576 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2578 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
2579 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2581 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
2583 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
2584 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2586 for (j = 0; j < sizeof(levels[i]); j++)
2588 ok(expect_v2l[i][j] == vistolog[j],
2589 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
2590 i, j, levels[i][j], j, vistolog[j] );
2593 for (j = 0; j < sizeof(levels[i]); j++)
2595 ok(expect_l2v[i][j] == logtovis[j],
2596 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
2597 i, j, levels[i][j], j, logtovis[j] );
2602 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
2604 HRESULT hr;
2605 SCRIPT_DIGITSUBSTITUTE sds;
2606 SCRIPT_CONTROL sc;
2607 SCRIPT_STATE ss;
2608 LCID lcid_old;
2610 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
2612 memset(&sds, 0, sizeof(sds));
2613 memset(&sc, 0, sizeof(sc));
2614 memset(&ss, 0, sizeof(ss));
2616 lcid_old = GetThreadLocale();
2617 if (!SetThreadLocale(lcid)) return TRUE;
2619 hr = ScriptRecordDigitSubstitution(lcid, &sds);
2620 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
2622 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
2623 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
2625 SetThreadLocale(lcid_old);
2626 return TRUE;
2629 static void test_digit_substitution(void)
2631 BOOL ret;
2632 unsigned int i;
2633 static const LGRPID groups[] =
2635 LGRPID_WESTERN_EUROPE,
2636 LGRPID_CENTRAL_EUROPE,
2637 LGRPID_BALTIC,
2638 LGRPID_GREEK,
2639 LGRPID_CYRILLIC,
2640 LGRPID_TURKISH,
2641 LGRPID_JAPANESE,
2642 LGRPID_KOREAN,
2643 LGRPID_TRADITIONAL_CHINESE,
2644 LGRPID_SIMPLIFIED_CHINESE,
2645 LGRPID_THAI,
2646 LGRPID_HEBREW,
2647 LGRPID_ARABIC,
2648 LGRPID_VIETNAMESE,
2649 LGRPID_INDIC,
2650 LGRPID_GEORGIAN,
2651 LGRPID_ARMENIAN
2653 HMODULE hKernel32;
2654 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
2656 hKernel32 = GetModuleHandleA("kernel32.dll");
2657 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
2659 if (!pEnumLanguageGroupLocalesA)
2661 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
2662 return;
2665 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
2667 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
2668 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2670 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
2671 break;
2674 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
2678 static void test_ScriptGetProperties(void)
2680 const SCRIPT_PROPERTIES **props;
2681 HRESULT hr;
2682 int num;
2684 hr = ScriptGetProperties(NULL, NULL);
2685 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
2687 hr = ScriptGetProperties(NULL, &num);
2688 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2690 hr = ScriptGetProperties(&props, NULL);
2691 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2693 hr = ScriptGetProperties(&props, &num);
2694 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2697 static void test_ScriptBreak(void)
2699 static const WCHAR test[] = {' ','\r','\n',0};
2700 SCRIPT_ITEM items[4];
2701 SCRIPT_LOGATTR la;
2702 HRESULT hr;
2704 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
2705 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
2707 memset(&la, 0, sizeof(la));
2708 hr = ScriptBreak(test, 1, &items[0].a, &la);
2709 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2711 ok(!la.fSoftBreak, "fSoftBreak set\n");
2712 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
2713 ok(la.fCharStop, "fCharStop not set\n");
2714 ok(!la.fWordStop, "fWordStop set\n");
2715 ok(!la.fInvalid, "fInvalid set\n");
2716 ok(!la.fReserved, "fReserved set\n");
2718 memset(&la, 0, sizeof(la));
2719 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
2720 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2722 ok(!la.fSoftBreak, "fSoftBreak set\n");
2723 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2724 ok(la.fCharStop, "fCharStop not set\n");
2725 ok(!la.fWordStop, "fWordStop set\n");
2726 ok(!la.fInvalid, "fInvalid set\n");
2727 ok(!la.fReserved, "fReserved set\n");
2729 memset(&la, 0, sizeof(la));
2730 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
2731 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2733 ok(!la.fSoftBreak, "fSoftBreak set\n");
2734 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2735 ok(la.fCharStop, "fCharStop not set\n");
2736 ok(!la.fWordStop, "fWordStop set\n");
2737 ok(!la.fInvalid, "fInvalid set\n");
2738 ok(!la.fReserved, "fReserved set\n");
2741 static void test_newlines(void)
2743 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
2744 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
2745 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
2746 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
2747 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
2748 SCRIPT_ITEM items[5];
2749 HRESULT hr;
2750 int count;
2752 count = 0;
2753 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
2754 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2755 ok(count == 3, "got %d expected 3\n", count);
2757 count = 0;
2758 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
2759 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2760 ok(count == 3, "got %d expected 3\n", count);
2762 count = 0;
2763 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
2764 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2765 ok(count == 4, "got %d expected 4\n", count);
2767 count = 0;
2768 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
2769 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2770 ok(count == 4, "got %d expected 4\n", count);
2772 count = 0;
2773 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
2774 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2775 ok(count == 4, "got %d expected 4\n", count);
2778 START_TEST(usp10)
2780 HWND hwnd;
2781 HDC hdc;
2782 LOGFONTA lf;
2783 HFONT hfont;
2785 unsigned short pwOutGlyphs[256];
2787 /* We need a valid HDC to drive a lot of Script functions which requires the following *
2788 * to set up for the tests. */
2789 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
2790 0, 0, 0, NULL);
2791 assert(hwnd != 0);
2792 ShowWindow(hwnd, SW_SHOW);
2793 UpdateWindow(hwnd);
2795 hdc = GetDC(hwnd); /* We now have a hdc */
2796 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
2798 memset(&lf, 0, sizeof(LOGFONTA));
2799 lstrcpyA(lf.lfFaceName, "Tahoma");
2800 lf.lfHeight = 10;
2801 lf.lfWeight = 3;
2802 lf.lfWidth = 10;
2804 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
2805 ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
2807 test_ScriptItemize();
2808 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
2809 test_ScriptGetCMap(hdc, pwOutGlyphs);
2810 test_ScriptCacheGetHeight(hdc);
2811 test_ScriptGetGlyphABCWidth(hdc);
2812 test_ScriptShape(hdc);
2813 test_ScriptShapeOpenType(hdc);
2814 test_ScriptPlace(hdc);
2816 test_ScriptGetFontProperties(hdc);
2817 test_ScriptTextOut(hdc);
2818 test_ScriptTextOut2(hdc);
2819 test_ScriptTextOut3(hdc);
2820 test_ScriptXtoX();
2821 test_ScriptString(hdc);
2822 test_ScriptStringXtoCP_CPtoX(hdc);
2824 test_ScriptLayout();
2825 test_digit_substitution();
2826 test_ScriptGetProperties();
2827 test_ScriptBreak();
2828 test_newlines();
2830 ReleaseDC(hwnd, hdc);
2831 DestroyWindow(hwnd);