usp10: Add Ogham script.
[wine.git] / dlls / usp10 / tests / usp10.c
blob0439d5f2a2ae15eb11c85522fbfa4ab6ba58b765
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',' ')
166 #define cher_tag MS_MAKE_TAG('c','h','e','r')
167 #define cans_tag MS_MAKE_TAG('c','a','n','s')
168 #define ogam_tag MS_MAKE_TAG('o','g','a','m')
170 static void test_ScriptItemize( void )
172 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
173 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}};
174 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}};
176 static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
177 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}};
178 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}};
180 static const WCHAR test1c[] = {' ', ' ', ' ', '1', '2', ' ',0};
181 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}};
182 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}};
184 /* Arabic, English*/
185 static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
186 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}};
187 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}};
188 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}};
190 static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
191 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}};
192 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}};
193 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}};
194 static const int b2[2] = {4,4};
196 /* leading space */
197 static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
198 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}};
199 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}};
200 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}};
201 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}};
203 /* trailing space */
204 static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
205 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}};
206 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}};
207 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}};
208 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}};
210 /* Thai */
211 static const WCHAR test3[] =
212 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
213 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
214 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
215 0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
217 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}};
218 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}};
220 static const WCHAR test4[] = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
222 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}};
223 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}};
224 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}};
225 static const int b43[2] = {4,4};
227 /* Arabic */
228 static const WCHAR test5[] =
229 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
230 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
231 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
232 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
233 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}};
235 /* Hebrew */
236 static const WCHAR test6[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
237 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}};
238 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}};
239 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}};
240 static const int b63[2] = {2,2};
241 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};
242 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}};
243 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}};
244 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}};
245 static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
246 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}};
248 /* Syriac (Like Arabic )*/
249 static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
250 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}};
251 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}};
252 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}};
253 static const int b93[2] = {2,2};
255 static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
256 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}};
258 /* Devanagari */
259 static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
260 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}};
261 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}};
263 /* Bengali */
264 static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
265 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}};
266 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}};
268 /* Gurmukhi */
269 static const WCHAR test13[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
270 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}};
271 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}};
273 /* Gujarati */
274 static const WCHAR test14[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
275 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}};
276 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}};
278 /* Oriya */
279 static const WCHAR test15[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
280 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}};
281 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}};
283 /* Tamil */
284 static const WCHAR test16[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
285 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}};
286 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}};
288 /* Telugu */
289 static const WCHAR test17[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
290 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}};
291 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}};
293 /* Kannada */
294 static const WCHAR test18[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
295 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}};
296 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}};
298 /* Malayalam */
299 static const WCHAR test19[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
300 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}};
301 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}};
303 /* Diacritical */
304 static const WCHAR test20[] = {0x0309,'a','b','c','d',0};
305 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}};
306 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}};
308 static const WCHAR test21[] = {0x0710, 0x0712, 0x0308, 0x0712, 0x0714,0};
309 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}};
311 /* Latin Punctuation */
312 static const WCHAR test22[] = {'#','$',',','!','\"','*',0};
313 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}};
314 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}};
315 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}};
316 static const int b222[2] = {1,1};
317 static const int b223[2] = {2,2};
319 /* Number 2*/
320 static const WCHAR test23[] = {'1','2','3',0x00b2,0x00b3,0x2070,0};
321 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}};
322 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}};
324 /* Myanmar */
325 static const WCHAR test24[] = {0x1019,0x103c,0x1014,0x103a,0x1019,0x102c,0x1021,0x1000,0x1039,0x1001,0x101b,0x102c};
326 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}};
327 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}};
329 /* Tai Le */
330 static const WCHAR test25[] = {0x1956,0x196d,0x1970,0x1956,0x196c,0x1973,0x1951,0x1968,0x1952,0x1970};
331 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}};
332 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}};
334 /* New Tai Lue */
335 static const WCHAR test26[] = {0x1992,0x19c4};
336 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}};
337 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}};
339 /* Khmer */
340 static const WCHAR test27[] = {0x1781,0x17c1,0x1798,0x179a,0x1797,0x17b6,0x179f,0x17b6};
341 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}};
342 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}};
344 /* CJK Han */
345 static const WCHAR test28[] = {0x8bed,0x7d20,0x6587,0x5b57};
346 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}};
347 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}};
349 /* Ideographic */
350 static const WCHAR test29[] = {0x2ff0,0x2ff3,0x2ffb,0x2ff0,0x65e5,0x65e5,0x5de5,0x7f51,0x4e02,0x4e5e};
351 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}};
352 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}};
354 /* Bopomofo */
355 static const WCHAR test30[] = {0x3113,0x3128,0x3127,0x3123,0x3108,0x3128,0x310f,0x3120};
356 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}};
357 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}};
359 /* Kana */
360 static const WCHAR test31[] = {0x3072,0x3089,0x304b,0x306a,0x30ab,0x30bf,0x30ab,0x30ca};
361 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}};
362 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}};
363 static const int b311[2] = {2,2};
364 static const int b312[2] = {2,2};
366 /* Hangul */
367 static const WCHAR test32[] = {0xd55c,0xad6d,0xc5b4};
368 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}};
369 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}};
371 /* Yi */
372 static const WCHAR test33[] = {0xa188,0xa320,0xa071,0xa0b7};
373 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}};
374 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}};
376 /* Ethiopic */
377 static const WCHAR test34[] = {0x130d,0x12d5,0x12dd};
378 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}};
379 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}};
380 static const int b342[2] = {2,2};
382 /* Mongolian */
383 static const WCHAR test35[] = {0x182e,0x1823,0x1829,0x182d,0x1823,0x182f,0x0020,0x182a,0x1822,0x1834,0x1822,0x182d,0x180c};
384 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}};
385 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}};
386 static const int b351[2] = {2,2};
387 static const int b352[2] = {2,3};
389 /* Tifinagh */
390 static const WCHAR test36[] = {0x2d5c,0x2d49,0x2d3c,0x2d49,0x2d4f,0x2d30,0x2d56};
391 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}};
392 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}};
394 /* N'Ko */
395 static const WCHAR test37[] = {0x07d2,0x07de,0x07cf};
396 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}};
397 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}};
399 /* Vai */
400 static const WCHAR test38[] = {0xa559,0xa524};
401 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}};
402 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}};
404 /* Cherokee */
405 static const WCHAR test39[] = {0x13e3,0x13b3,0x13a9,0x0020,0x13a6,0x13ec,0x13c2,0x13af,0x13cd,0x13d7};
406 static const itemTest t391[2] = {{{0,0,0,0,0},0,0,0,0,cher_tag,FALSE},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
407 static const itemTest t392[2] = {{{0,0,0,0,0},0,0,0,2,cher_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
409 /* Canadian Aboriginal Syllabics */
410 static const WCHAR test40[] = {0x1403,0x14c4,0x1483,0x144e,0x1450,0x1466};
411 static const itemTest t401[2] = {{{0,0,0,0,0},0,0,0,0,cans_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
412 static const itemTest t402[2] = {{{0,0,0,0,0},0,0,0,2,cans_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
414 /* Ogham */
415 static const WCHAR test41[] = {0x169b,0x1691,0x168c,0x1690,0x168b,0x169c};
416 static const itemTest t411[2] = {{{0,0,0,0,0},0,0,0,0,ogam_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
417 static const itemTest t412[4] = {{{0,0,0,0,0},0,1,1,1,ogam_tag,FALSE},{{0,0,0,0,0},1,0,0,2,ogam_tag,FALSE},{{0,0,0,0,0},5,1,1,1,ogam_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
418 static const int b412[2] = {1,1};
420 SCRIPT_ITEM items[15];
421 SCRIPT_CONTROL Control;
422 SCRIPT_STATE State;
423 HRESULT hr;
424 HMODULE usp10;
425 int nItems;
427 usp10 = LoadLibraryA("usp10.dll");
428 ok (usp10 != 0,"Unable to LoadLibrary on usp10.dll\n");
429 pScriptItemizeOpenType = (void*)GetProcAddress(usp10, "ScriptItemizeOpenType");
430 pScriptShapeOpenType = (void*)GetProcAddress(usp10, "ScriptShapeOpenType");
431 pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
433 memset(&Control, 0, sizeof(Control));
434 memset(&State, 0, sizeof(State));
436 hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
437 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
439 hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
440 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
442 hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
443 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
445 hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
446 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
448 test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
449 test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
450 test_items_ok(test1c,6,NULL,NULL,1,t1c1,FALSE,0);
451 test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
452 test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
453 test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
454 test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
455 test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
456 test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
457 test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
458 test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
459 test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
460 test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
461 test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
462 test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
463 test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
464 test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
465 test_items_ok(test13,7,NULL,NULL,1,t131,FALSE,0);
466 test_items_ok(test14,7,NULL,NULL,1,t141,FALSE,0);
467 test_items_ok(test15,5,NULL,NULL,1,t151,FALSE,0);
468 test_items_ok(test16,5,NULL,NULL,1,t161,FALSE,0);
469 test_items_ok(test17,6,NULL,NULL,1,t171,FALSE,0);
470 test_items_ok(test18,5,NULL,NULL,1,t181,FALSE,0);
471 test_items_ok(test19,6,NULL,NULL,1,t191,FALSE,0);
472 test_items_ok(test20,5,NULL,NULL,2,t201,FALSE,0);
473 test_items_ok(test21,5,NULL,NULL,1,t211,FALSE,0);
474 test_items_ok(test22,6,NULL,NULL,2,t221,FALSE,0);
475 test_items_ok(test23,6,NULL,NULL,2,t231,FALSE,0);
476 test_items_ok(test24,12,NULL,NULL,1,t241,FALSE,0);
477 test_items_ok(test25,10,NULL,NULL,1,t251,FALSE,0);
478 test_items_ok(test26,2,NULL,NULL,1,t261,FALSE,0);
479 test_items_ok(test27,8,NULL,NULL,1,t271,FALSE,0);
480 test_items_ok(test28,4,NULL,NULL,1,t281,FALSE,0);
481 test_items_ok(test29,10,NULL,NULL,2,t291,FALSE,0);
482 test_items_ok(test30,8,NULL,NULL,1,t301,FALSE,0);
483 test_items_ok(test31,8,NULL,NULL,1,t311,FALSE,b311);
484 test_items_ok(test32,3,NULL,NULL,1,t321,FALSE,0);
485 test_items_ok(test33,4,NULL,NULL,1,t331,FALSE,0);
486 test_items_ok(test34,3,NULL,NULL,1,t341,FALSE,0);
487 test_items_ok(test35,13,NULL,NULL,1,t351,FALSE,b351);
488 test_items_ok(test36,7,NULL,NULL,1,t361,FALSE,0);
489 test_items_ok(test37,3,NULL,NULL,1,t371,FALSE,0);
490 test_items_ok(test38,2,NULL,NULL,1,t381,FALSE,0);
491 test_items_ok(test39,10,NULL,NULL,1,t391,FALSE,0);
492 test_items_ok(test40,6,NULL,NULL,1,t401,FALSE,0);
493 test_items_ok(test41,6,NULL,NULL,1,t411,FALSE,0);
495 State.uBidiLevel = 0;
496 test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
497 test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
498 test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
499 test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
500 test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
501 test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
502 test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
503 test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
504 test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
505 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
506 test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
507 test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
508 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
509 test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
510 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
511 test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
512 test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
513 test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
514 test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
515 test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
516 test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
517 test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
518 test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
519 test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
520 test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
521 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
522 test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
523 test_items_ok(test23,6,&Control,&State,2,t231,FALSE,0);
524 test_items_ok(test24,12,&Control,&State,1,t241,FALSE,0);
525 test_items_ok(test25,10,&Control,&State,1,t251,FALSE,0);
526 test_items_ok(test26,2,&Control,&State,1,t261,FALSE,0);
527 test_items_ok(test27,8,&Control,&State,1,t271,FALSE,0);
528 test_items_ok(test28,4,&Control,&State,1,t281,FALSE,0);
529 test_items_ok(test29,10,&Control,&State,2,t291,FALSE,0);
530 test_items_ok(test30,8,&Control,&State,1,t301,FALSE,0);
531 test_items_ok(test31,8,&Control,&State,1,t311,FALSE,b311);
532 test_items_ok(test32,3,&Control,&State,1,t321,FALSE,0);
533 test_items_ok(test33,4,&Control,&State,1,t331,FALSE,0);
534 test_items_ok(test34,3,&Control,&State,1,t341,FALSE,0);
535 test_items_ok(test35,13,&Control,&State,1,t351,FALSE,b351);
536 test_items_ok(test36,7,&Control,&State,1,t361,FALSE,0);
537 test_items_ok(test37,3,&Control,&State,1,t371,FALSE,0);
538 test_items_ok(test38,2,&Control,&State,1,t381,FALSE,0);
539 test_items_ok(test39,10,&Control,&State,1,t391,FALSE,0);
540 test_items_ok(test40,6,&Control,&State,1,t401,FALSE,0);
541 test_items_ok(test41,6,&Control,&State,1,t411,FALSE,0);
543 State.uBidiLevel = 1;
544 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
545 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
546 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
547 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
548 test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
549 test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
550 test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
551 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
552 test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
553 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
554 test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
555 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
556 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
557 test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
558 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
559 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
560 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
561 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
562 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
563 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
564 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
565 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
566 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
567 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
568 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
569 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
570 test_items_ok(test22,6,&Control,&State,2,t222,FALSE,b222);
571 test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
572 test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
573 test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
574 test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
575 test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
576 test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
577 test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
578 test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
579 test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
580 test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
581 test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
582 test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
583 test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
584 test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
585 test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
586 test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
587 test_items_ok(test39,10,&Control,&State,1,t392,FALSE,0);
588 test_items_ok(test40,6,&Control,&State,1,t402,FALSE,0);
589 test_items_ok(test41,6,&Control,&State,3,t412,FALSE,b412);
591 State.uBidiLevel = 1;
592 Control.fMergeNeutralItems = TRUE;
593 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
594 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
595 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
596 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
597 test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,b2);
598 test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,b2);
599 test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,b2);
600 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
601 test_items_ok(test4,12,&Control,&State,3,t43,FALSE,b43);
602 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
603 test_items_ok(test6,5,&Control,&State,1,t63,FALSE,b63);
604 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
605 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
606 test_items_ok(test9,5,&Control,&State,1,t93,FALSE,b93);
607 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
608 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
609 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
610 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
611 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
612 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
613 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
614 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
615 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
616 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
617 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
618 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
619 test_items_ok(test22,6,&Control,&State,1,t223,FALSE,b223);
620 test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
621 test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
622 test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
623 test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
624 test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
625 test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
626 test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
627 test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
628 test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
629 test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
630 test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
631 test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
632 test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
633 test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
634 test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
635 test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
636 test_items_ok(test39,10,&Control,&State,1,t392,FALSE,0);
637 test_items_ok(test40,6,&Control,&State,1,t402,FALSE,0);
638 test_items_ok(test41,6,&Control,&State,3,t412,FALSE,b412);
641 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
642 DWORD cchString, SCRIPT_CONTROL *Control,
643 SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
644 const shapeTest_char* charItems,
645 const shapeTest_glyph* glyphItems)
647 HRESULT hr;
648 int x, outnItems=0, outnGlyphs=0;
649 SCRIPT_ITEM outpItems[15];
650 SCRIPT_CACHE sc = NULL;
651 WORD *glyphs;
652 WORD *logclust;
653 int maxGlyphs = cchString * 1.5;
654 SCRIPT_GLYPHPROP *glyphProp;
655 SCRIPT_CHARPROP *charProp;
656 ULONG tags[15];
658 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
659 if (hr == USP_E_SCRIPT_NOT_IN_FONT)
661 if (valid > 0)
662 winetest_win_skip("Select font does not support script\n");
663 else
664 winetest_trace("Select font does not support script\n");
665 return;
667 if (valid > 0)
668 winetest_ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
669 else if (hr)
670 winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
673 if (outnItems <= item)
675 if (valid > 0)
676 winetest_win_skip("Did not get enough items\n");
677 else
678 winetest_trace("Did not get enough items\n");
679 return;
682 logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
683 memset(logclust,'a',sizeof(WORD) * cchString);
684 charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
685 memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
686 glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
687 memset(glyphs,'a',sizeof(WORD) * cchString);
688 glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
689 memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
691 hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
692 if (valid > 0)
693 winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
694 else if (hr != S_OK)
695 winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
696 if (FAILED(hr))
697 return;
699 for (x = 0; x < cchString; x++)
701 if (valid > 0)
702 winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
703 else if (logclust[x] != charItems[x].wLogClust)
704 winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
705 if (valid > 0)
706 winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
707 else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
708 winetest_trace("%i: invalid fCanGlyphAlone\n",x);
711 if (valid > 0)
712 winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
713 else if (nGlyphs != outnGlyphs)
714 winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
715 for (x = 0; x < outnGlyphs; x++)
717 if (glyphItems[x].Glyph)
719 if (valid > 0)
720 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
721 else if (glyphs[x]==0)
722 winetest_trace("%i: Glyph not present when it should be\n",x);
724 else
726 if (valid > 0)
727 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
728 else if (glyphs[x]!=0)
729 winetest_trace("%i: Glyph present when it should not be\n",x);
731 if (valid > 0)
732 winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification, "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
733 else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
734 winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
735 if (valid > 0)
736 winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart, "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
737 else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
738 winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
739 if (valid > 0)
740 winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic, "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
741 else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
742 winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
743 if (valid > 0)
744 winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth, "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
745 else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
746 winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
749 HeapFree(GetProcessHeap(),0,logclust);
750 HeapFree(GetProcessHeap(),0,charProp);
751 HeapFree(GetProcessHeap(),0,glyphs);
752 HeapFree(GetProcessHeap(),0,glyphProp);
753 ScriptFreeCache(&sc);
756 #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)
758 #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)
760 typedef struct tagRangeP {
761 BYTE range;
762 LOGFONTA lf;
763 } fontEnumParam;
765 static int CALLBACK enumFontProc( const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
766 DWORD FontType, LPARAM lParam)
768 NEWTEXTMETRICEX *ntme = (NEWTEXTMETRICEX*)lpntme;
769 fontEnumParam *rp = (fontEnumParam*) lParam;
770 int idx = 0;
771 DWORD i;
772 DWORD mask = 0;
774 if (FontType != TRUETYPE_FONTTYPE)
775 return 1;
777 i = rp->range;
778 while (i > sizeof(DWORD)*8)
780 idx++;
781 i -= (sizeof(DWORD)*8);
783 if (idx > 3)
784 return 0;
786 mask = 1 << i;
788 if (ntme->ntmFontSig.fsUsb[idx] & mask)
790 memcpy(&(rp->lf),lpelfe,sizeof(LOGFONT));
791 return 0;
793 return 1;
796 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont)
798 int rc = 0;
799 fontEnumParam lParam;
801 lParam.range = range;
802 memset(&lParam.lf,0,sizeof(LOGFONT));
803 *hfont = NULL;
805 if (recommended)
807 lstrcpyA(lParam.lf.lfFaceName, recommended);
808 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
810 *hfont = CreateFontIndirectA(&lParam.lf);
811 if (*hfont)
813 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
814 rc = 1;
819 if (!*hfont)
821 memset(&lParam.lf,0,sizeof(LOGFONT));
822 lParam.lf.lfCharSet = DEFAULT_CHARSET;
824 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
826 *hfont = CreateFontIndirectA(&lParam.lf);
827 if (*hfont)
828 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
832 if (*hfont)
834 WORD glyph = 0;
836 *origFont = SelectObject(hdc,*hfont);
837 if (pGetGlyphIndicesW && (pGetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph ==0))
839 winetest_trace(" Font fails to contain required glyphs\n");
840 SelectObject(hdc,*origFont);
841 DeleteObject(*hfont);
842 *hfont=NULL;
843 rc = 0;
845 else if (!rc)
846 rc = -1;
848 else
849 winetest_trace("Failed to find usable font\n");
851 return rc;
854 #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)
856 static void test_ScriptShapeOpenType(HDC hdc)
858 HRESULT hr;
859 SCRIPT_CACHE sc = NULL;
860 WORD glyphs[4], logclust[4];
861 SCRIPT_GLYPHPROP glyphProp[4];
862 SCRIPT_ITEM items[2];
863 ULONG tags[2];
864 SCRIPT_CONTROL Control;
865 SCRIPT_STATE State;
866 int nb, outnItems;
867 HFONT hfont, hfont_orig;
868 int test_valid;
870 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
871 static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
872 static const shapeTest_glyph t1_g[] = {
873 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
874 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
875 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
876 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
878 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
879 static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
880 static const shapeTest_glyph t2_g[] = {
881 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
882 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
883 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
884 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
886 /* Hebrew */
887 static const WCHAR test_hebrew[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
888 static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
889 static const shapeTest_glyph hebrew_g[] = {
890 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
891 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
892 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
893 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
895 /* Arabic */
896 static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
897 static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
898 static const shapeTest_glyph arabic_g[] = {
899 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
900 {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
901 {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
903 /* Thai */
904 static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
905 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}}};
906 static const shapeTest_glyph thai_g[] = {
907 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
908 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
909 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
910 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
911 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
912 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
913 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
914 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
915 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
916 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
918 /* Syriac */
919 static const WCHAR test_syriac[] = {0x0710, 0x0710, 0x0710, 0x0728, 0x0718, 0x0723,0};
920 static const shapeTest_char syriac_c[] = {{5,{0,0}},{4,{0,0}},{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
921 static const shapeTest_glyph syriac_g[] = {
922 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
923 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
924 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
925 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
926 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
927 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
929 /* Thaana */
930 static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
931 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}}};
932 static const shapeTest_glyph thaana_g[] = {
933 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
934 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
935 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
936 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
937 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
938 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
939 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
940 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
941 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
942 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
943 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
944 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
945 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
947 /* Phags-pa */
948 static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
949 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}}};
950 static const shapeTest_glyph phagspa_g[] = {
951 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
952 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
953 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
954 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
955 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
956 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
957 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
958 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
959 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
960 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
961 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
963 /* Lao */
964 static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
965 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}}};
966 static const shapeTest_glyph lao_g[] = {
967 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
968 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
969 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
970 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
971 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
972 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
973 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
974 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
975 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
977 /* Tibetan */
978 static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
979 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}}};
980 static const shapeTest_glyph tibetan_g[] = {
981 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
982 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
983 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
984 {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
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,1,0,0,0,0},0}},
988 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
989 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
990 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
991 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
992 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
993 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
994 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
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}} };
999 /* Devanagari */
1000 static const WCHAR test_devanagari[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
1001 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}}};
1002 static const shapeTest_glyph devanagari_g[] = {
1003 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1004 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1005 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1006 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1007 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1008 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1009 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1010 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1012 /* Bengali */
1013 static const WCHAR test_bengali[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
1014 static const shapeTest_char bengali_c[] = {{0,{0,0}},{0,{0,0}},{0,{0,0}},{3,{0,0}},{3,{0,0}}};
1015 static const shapeTest_glyph bengali_g[] = {
1016 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1017 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1018 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1019 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1020 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1022 /* Gurmukhi */
1023 static const WCHAR test_gurmukhi[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
1024 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}}};
1025 static const shapeTest_glyph gurmukhi_g[] = {
1026 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1027 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
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}},
1032 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1034 /* Gujarati */
1035 static const WCHAR test_gujarati[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
1036 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}}};
1037 static const shapeTest_glyph gujarati_g[] = {
1038 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1039 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1040 {1,{{SCRIPT_JUSTIFY_NONE,1,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}},
1043 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1044 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1046 /* Oriya */
1047 static const WCHAR test_oriya[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
1048 static const shapeTest_char oriya_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1049 static const shapeTest_glyph oriya_g[] = {
1050 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1051 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1052 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1053 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1055 /* Tamil */
1056 static const WCHAR test_tamil[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
1057 static const shapeTest_char tamil_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}},{3,{0,0}}};
1058 static const shapeTest_glyph tamil_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}} };
1064 /* Telugu */
1065 static const WCHAR test_telugu[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
1066 static const shapeTest_char telugu_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1067 static const shapeTest_glyph telugu_g[] = {
1068 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1069 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1070 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1071 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1072 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1073 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1075 /* Malayalam */
1076 static const WCHAR test_malayalam[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
1077 static const shapeTest_char malayalam_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1078 static const shapeTest_glyph malayalam_g[] = {
1079 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1080 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1081 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1082 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1083 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1084 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1086 /* Kannada */
1087 static const WCHAR test_kannada[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
1088 static const shapeTest_char kannada_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1089 static const shapeTest_glyph kannada_g[] = {
1090 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1091 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1092 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1093 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1094 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1096 if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
1098 win_skip("ScriptShapeOpenType not available on this platform\n");
1099 return;
1102 memset(&Control, 0 , sizeof(Control));
1103 memset(&State, 0 , sizeof(State));
1105 hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
1106 ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
1107 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1109 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
1110 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1112 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
1113 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1115 hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1116 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
1118 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1119 ok( hr == E_INVALIDARG,
1120 "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1121 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
1122 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1124 ScriptFreeCache(&sc);
1126 test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
1127 test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, t2_g);
1129 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig);
1130 if (hfont != NULL)
1132 test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
1133 SelectObject(hdc, hfont_orig);
1134 DeleteObject(hfont);
1137 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig);
1138 if (hfont != NULL)
1140 test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
1141 SelectObject(hdc, hfont_orig);
1142 DeleteObject(hfont);
1145 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig);
1146 if (hfont != NULL)
1148 test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
1149 SelectObject(hdc, hfont_orig);
1150 DeleteObject(hfont);
1153 test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig);
1154 if (hfont != NULL)
1156 test_shape_ok_valid(test_valid, hdc, test_syriac, 6, &Control, &State, 0, 6, syriac_c, syriac_g);
1157 SelectObject(hdc, hfont_orig);
1158 DeleteObject(hfont);
1161 test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig);
1162 if (hfont != NULL)
1164 test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
1165 SelectObject(hdc, hfont_orig);
1166 DeleteObject(hfont);
1169 test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig);
1170 if (hfont != NULL)
1172 test_shape_ok_valid(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11, phagspa_c, phagspa_g);
1173 SelectObject(hdc, hfont_orig);
1174 DeleteObject(hfont);
1177 test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig);
1178 if (hfont != NULL)
1180 test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
1181 SelectObject(hdc, hfont_orig);
1182 DeleteObject(hfont);
1185 test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig);
1186 if (hfont != NULL)
1188 test_shape_ok_valid(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17, tibetan_c, tibetan_g);
1189 SelectObject(hdc, hfont_orig);
1190 DeleteObject(hfont);
1193 test_valid = find_font_for_range(hdc, "Mangal", 15, test_devanagari[0], &hfont, &hfont_orig);
1194 if (hfont != NULL)
1196 test_shape_ok_valid(test_valid, hdc, test_devanagari, 8, &Control, &State, 0, 8, devanagari_c, devanagari_g);
1197 SelectObject(hdc, hfont_orig);
1198 DeleteObject(hfont);
1201 test_valid = find_font_for_range(hdc, "Vrinda", 16, test_bengali[0], &hfont, &hfont_orig);
1202 if (hfont != NULL)
1204 test_shape_ok_valid(test_valid, hdc, test_bengali, 5, &Control, &State, 0, 5, bengali_c, bengali_g);
1205 SelectObject(hdc, hfont_orig);
1206 DeleteObject(hfont);
1209 test_valid = find_font_for_range(hdc, "Raavi", 17, test_gurmukhi[0], &hfont, &hfont_orig);
1210 if (hfont != NULL)
1212 test_shape_ok_valid(test_valid, hdc, test_gurmukhi, 7, &Control, &State, 0, 7, gurmukhi_c, gurmukhi_g);
1213 SelectObject(hdc, hfont_orig);
1214 DeleteObject(hfont);
1217 test_valid = find_font_for_range(hdc, "Shruti", 18, test_gujarati[0], &hfont, &hfont_orig);
1218 if (hfont != NULL)
1220 test_shape_ok_valid(test_valid, hdc, test_gujarati, 7, &Control, &State, 0, 7, gujarati_c, gujarati_g);
1221 SelectObject(hdc, hfont_orig);
1222 DeleteObject(hfont);
1225 test_valid = find_font_for_range(hdc, "Kalinga", 19, test_oriya[0], &hfont, &hfont_orig);
1226 if (hfont != NULL)
1228 test_shape_ok_valid(test_valid, hdc, test_oriya, 5, &Control, &State, 0, 4, oriya_c, oriya_g);
1229 SelectObject(hdc, hfont_orig);
1230 DeleteObject(hfont);
1233 test_valid = find_font_for_range(hdc, "Latha", 20, test_tamil[0], &hfont, &hfont_orig);
1234 if (hfont != NULL)
1236 test_shape_ok_valid(test_valid, hdc, test_tamil, 5, &Control, &State, 0, 4, tamil_c, tamil_g);
1237 SelectObject(hdc, hfont_orig);
1238 DeleteObject(hfont);
1241 test_valid = find_font_for_range(hdc, "Gautami", 21, test_telugu[0], &hfont, &hfont_orig);
1242 if (hfont != NULL)
1244 test_shape_ok_valid(test_valid, hdc, test_telugu, 6, &Control, &State, 0, 6, telugu_c, telugu_g);
1245 SelectObject(hdc, hfont_orig);
1246 DeleteObject(hfont);
1249 test_valid = find_font_for_range(hdc, "Kartika", 23, test_malayalam[0], &hfont, &hfont_orig);
1250 if (hfont != NULL)
1252 test_shape_ok_valid(test_valid, hdc, test_malayalam, 6, &Control, &State, 0, 6, malayalam_c, malayalam_g);
1253 SelectObject(hdc, hfont_orig);
1254 DeleteObject(hfont);
1257 test_valid = find_font_for_range(hdc, "Tunga", 22, test_kannada[0], &hfont, &hfont_orig);
1258 if (hfont != NULL)
1260 test_shape_ok_valid(test_valid, hdc, test_kannada, 5, &Control, &State, 0, 4, kannada_c, kannada_g);
1261 SelectObject(hdc, hfont_orig);
1262 DeleteObject(hfont);
1266 static void test_ScriptShape(HDC hdc)
1268 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1269 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1270 HRESULT hr;
1271 SCRIPT_CACHE sc = NULL;
1272 WORD glyphs[4], glyphs2[4], logclust[4];
1273 SCRIPT_VISATTR attrs[4];
1274 SCRIPT_ITEM items[2];
1275 int nb;
1277 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1278 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1279 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1281 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
1282 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1284 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
1285 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1287 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1288 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
1290 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1291 ok(broken(hr == S_OK) ||
1292 hr == E_INVALIDARG || /* Vista, W2K8 */
1293 hr == E_FAIL, /* WIN7 */
1294 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1295 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1297 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1298 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1299 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1302 memset(glyphs,-1,sizeof(glyphs));
1303 memset(logclust,-1,sizeof(logclust));
1304 memset(attrs,-1,sizeof(attrs));
1305 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1306 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1307 ok(nb == 4, "Wrong number of items\n");
1308 ok(logclust[0] == 0, "clusters out of order\n");
1309 ok(logclust[1] == 1, "clusters out of order\n");
1310 ok(logclust[2] == 2, "clusters out of order\n");
1311 ok(logclust[3] == 3, "clusters out of order\n");
1312 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1313 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1314 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1315 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1316 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1317 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1318 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1319 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1320 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1321 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1322 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1323 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1324 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1325 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1326 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1327 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1329 ScriptFreeCache(&sc);
1330 sc = NULL;
1332 memset(glyphs2,-1,sizeof(glyphs2));
1333 memset(logclust,-1,sizeof(logclust));
1334 memset(attrs,-1,sizeof(attrs));
1335 hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1336 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1337 ok(nb == 4, "Wrong number of items\n");
1338 ok(glyphs2[0] == 0 || broken(glyphs2[0] == 0x80), "Incorrect glyph for 0x202B\n");
1339 ok(glyphs2[3] == 0 || broken(glyphs2[3] == 0x80), "Incorrect glyph for 0x202C\n");
1340 ok(logclust[0] == 0, "clusters out of order\n");
1341 ok(logclust[1] == 1, "clusters out of order\n");
1342 ok(logclust[2] == 2, "clusters out of order\n");
1343 ok(logclust[3] == 3, "clusters out of order\n");
1344 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1345 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1346 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1347 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1348 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1349 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1350 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1351 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1352 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1353 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1354 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1355 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1356 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1357 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1358 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1359 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1361 /* modify LTR to RTL */
1362 items[0].a.fRTL = 1;
1363 memset(glyphs2,-1,sizeof(glyphs2));
1364 memset(logclust,-1,sizeof(logclust));
1365 memset(attrs,-1,sizeof(attrs));
1366 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1367 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1368 ok(nb == 4, "Wrong number of items\n");
1369 ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
1370 ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
1371 ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
1372 ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
1373 ok(logclust[0] == 3, "clusters out of order\n");
1374 ok(logclust[1] == 2, "clusters out of order\n");
1375 ok(logclust[2] == 1, "clusters out of order\n");
1376 ok(logclust[3] == 0, "clusters out of order\n");
1377 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1378 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1379 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1380 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1381 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1382 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1383 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1384 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1385 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1386 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1387 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1388 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1389 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1390 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1391 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1392 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1394 ScriptFreeCache(&sc);
1397 static void test_ScriptPlace(HDC hdc)
1399 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
1400 BOOL ret;
1401 HRESULT hr;
1402 SCRIPT_CACHE sc = NULL;
1403 WORD glyphs[4], logclust[4];
1404 SCRIPT_VISATTR attrs[4];
1405 SCRIPT_ITEM items[2];
1406 int nb, widths[4];
1407 GOFFSET offset[4];
1408 ABC abc[4];
1410 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1411 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1412 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1414 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1415 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1416 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1418 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
1419 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
1421 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
1422 ok(broken(hr == E_PENDING) ||
1423 hr == E_INVALIDARG || /* Vista, W2K8 */
1424 hr == E_FAIL, /* WIN7 */
1425 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1427 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1428 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
1430 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
1431 ok(broken(hr == E_PENDING) ||
1432 hr == E_INVALIDARG || /* Vista, W2K8 */
1433 hr == E_FAIL, /* WIN7 */
1434 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1436 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1437 ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
1438 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1440 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
1441 ok(ret, "ExtTextOutW should return TRUE\n");
1443 ScriptFreeCache(&sc);
1446 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
1448 HRESULT hr;
1449 int iMaxProps;
1450 const SCRIPT_PROPERTIES **ppSp;
1452 int cInChars;
1453 int cMaxItems;
1454 SCRIPT_ITEM pItem[255];
1455 int pcItems;
1456 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1457 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
1458 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
1459 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
1460 WCHAR TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
1461 WCHAR TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
1463 SCRIPT_CACHE psc;
1464 int cChars;
1465 int cMaxGlyphs;
1466 unsigned short pwOutGlyphs1[256];
1467 unsigned short pwOutGlyphs2[256];
1468 unsigned short pwLogClust[256];
1469 SCRIPT_VISATTR psva[256];
1470 int pcGlyphs;
1471 int piAdvance[256];
1472 GOFFSET pGoffset[256];
1473 ABC pABC[256];
1474 int cnt;
1476 /* Start testing usp10 functions */
1477 /* This test determines that the pointer returned by ScriptGetProperties is valid
1478 * by checking a known value in the table */
1479 hr = ScriptGetProperties(&ppSp, &iMaxProps);
1480 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1481 trace("number of script properties %d\n", iMaxProps);
1482 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
1483 if (iMaxProps > 0)
1484 ok( ppSp[0]->langid == 0, "Langid[0] not = to 0\n"); /* Check a known value to ensure */
1485 /* ptrs work */
1487 /* This is a valid test that will cause parsing to take place */
1488 cInChars = 5;
1489 cMaxItems = 255;
1490 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1491 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1492 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1493 * returned. */
1494 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1495 if (pcItems > 0)
1496 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1497 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1498 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1500 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1501 * ie. ScriptItemize has succeeded and that pItem has been set */
1502 cInChars = 5;
1503 if (hr == 0) {
1504 psc = NULL; /* must be null on first call */
1505 cChars = cInChars;
1506 cMaxGlyphs = cInChars;
1507 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
1508 cMaxGlyphs, &pItem[0].a,
1509 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1510 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
1511 cMaxGlyphs = 4;
1512 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1513 cMaxGlyphs, &pItem[0].a,
1514 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1515 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
1516 "(%d) but not E_OUTOFMEMORY\n",
1517 cChars, cMaxGlyphs);
1518 cMaxGlyphs = 256;
1519 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1520 cMaxGlyphs, &pItem[0].a,
1521 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1522 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1523 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1524 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1525 if (hr ==0) {
1526 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1527 pGoffset, pABC);
1528 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1529 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1530 pGoffset, pABC);
1531 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1532 for (cnt=0; cnt < pcGlyphs; cnt++)
1533 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
1536 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
1537 * takes place if fNoGlyphIndex is set. */
1539 cInChars = 5;
1540 cMaxItems = 255;
1541 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1542 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1543 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1544 * returned. */
1545 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1546 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1547 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1548 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
1549 if (hr == 0) {
1550 cChars = cInChars;
1551 cMaxGlyphs = 256;
1552 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
1553 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
1554 cMaxGlyphs, &pItem[0].a,
1555 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
1556 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
1557 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1558 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1559 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1560 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
1561 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
1562 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
1563 if (hr ==0) {
1564 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
1565 pGoffset, pABC);
1566 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1569 ScriptFreeCache( &psc);
1570 ok (!psc, "psc is not null after ScriptFreeCache\n");
1574 /* This is a valid test that will cause parsing to take place and create 3 script_items */
1575 cInChars = (sizeof(TestItem3)/2)-1;
1576 cMaxItems = 255;
1577 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1578 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1579 if (hr == 0)
1581 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
1582 if (pcItems > 2)
1584 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1585 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1586 pItem[0].iCharPos, pItem[1].iCharPos);
1587 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1588 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1589 pItem[1].iCharPos, pItem[2].iCharPos);
1590 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
1591 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
1592 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
1596 /* This is a valid test that will cause parsing to take place and create 5 script_items */
1597 cInChars = (sizeof(TestItem4)/2)-1;
1598 cMaxItems = 255;
1599 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1600 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1601 if (hr == 0)
1603 ok (pcItems == 5, "The number of SCRIPT_ITEMS should be 5 not %d\n", pcItems);
1604 if (pcItems > 4)
1606 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1607 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1608 pItem[0].iCharPos, pItem[1].iCharPos);
1609 ok (pItem[0].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1610 pItem[0].a.s.uBidiLevel);
1611 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1612 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1613 pItem[1].iCharPos, pItem[2].iCharPos);
1614 ok (pItem[1].a.s.uBidiLevel == 1, "Should have been bidi=1 not %d\n",
1615 pItem[1].a.s.uBidiLevel);
1616 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == 12,
1617 "Start pos [2] not = 11 (%d) or end [3] pos not = 12 (%d)\n",
1618 pItem[2].iCharPos, pItem[3].iCharPos);
1619 ok (pItem[2].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1620 pItem[2].a.s.uBidiLevel);
1621 ok (pItem[3].iCharPos == 12 && pItem[4].iCharPos == 13,
1622 "Start pos [3] not = 12 (%d) or end [4] pos not = 13 (%d)\n",
1623 pItem[3].iCharPos, pItem[4].iCharPos);
1624 ok (pItem[3].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1625 pItem[3].a.s.uBidiLevel);
1626 ok (pItem[4].iCharPos == 13 && pItem[5].iCharPos == cInChars,
1627 "Start pos [4] not = 13 (%d) or end [5] pos not = 16 (%d), cInChars = %d\n",
1628 pItem[4].iCharPos, pItem[5].iCharPos, cInChars);
1633 * This test is for when the first unicode character requires bidi support
1635 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
1636 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1637 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1638 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
1639 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
1640 pItem[0].a.s.uBidiLevel);
1642 /* This test checks to make sure that the test to see if there are sufficient buffers to store *
1643 * the pointer to the last char works. Note that windows often needs a greater number of *
1644 * SCRIPT_ITEMS to process a string than is returned in pcItems. */
1645 cInChars = (sizeof(TestItem6)/2)-1;
1646 cMaxItems = 4;
1647 hr = ScriptItemize(TestItem6, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1648 ok (hr == E_OUTOFMEMORY, "ScriptItemize should return E_OUTOFMEMORY, returned %08x\n", hr);
1652 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
1654 HRESULT hr;
1655 SCRIPT_CACHE psc = NULL;
1656 int cInChars;
1657 int cChars;
1658 unsigned short pwOutGlyphs2[256];
1659 unsigned short pwOutGlyphs3[256];
1660 DWORD dwFlags;
1661 int cnt;
1663 static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1664 static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
1665 static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
1666 static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
1668 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
1669 dwFlags = 0;
1670 cInChars = cChars = 5;
1671 /* Some sanity checks for ScriptGetCMap */
1673 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
1674 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
1675 "expected E_INVALIDARG, got %08x\n", hr);
1677 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1678 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1679 "expected E_INVALIDARG, got %08x\n", hr);
1681 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1682 psc = NULL;
1683 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1684 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
1685 "got %08x\n", hr);
1686 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1688 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
1689 psc = NULL;
1690 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1691 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
1692 "got %08x\n", hr);
1693 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
1694 ScriptFreeCache( &psc);
1696 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1697 psc = NULL;
1698 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1699 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
1700 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1701 /* Check to see if the results are the same as those returned by ScriptShape */
1702 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1703 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
1704 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1705 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
1706 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
1707 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
1709 ScriptFreeCache( &psc);
1710 ok (!psc, "psc is not null after ScriptFreeCache\n");
1712 cInChars = cChars = 4;
1713 hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
1714 ok (hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
1715 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1716 ok(pwOutGlyphs3[0] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1717 ok(pwOutGlyphs3[3] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1720 cInChars = cChars = 9;
1721 hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
1722 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1723 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1725 cInChars = cChars = 9;
1726 dwFlags = SGCM_RTL;
1727 hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
1728 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1729 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1730 ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
1731 ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorreclty altered\n");
1732 ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorreclty altered\n");
1733 ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorreclty altered\n");
1734 ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
1735 ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
1736 ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
1737 ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
1738 ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
1740 ScriptFreeCache( &psc);
1741 ok (!psc, "psc is not null after ScriptFreeCache\n");
1744 static void test_ScriptGetFontProperties(HDC hdc)
1746 HRESULT hr;
1747 SCRIPT_CACHE psc,old_psc;
1748 SCRIPT_FONTPROPERTIES sfp;
1750 /* Some sanity checks for ScriptGetFontProperties */
1752 hr = ScriptGetFontProperties(NULL,NULL,NULL);
1753 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1755 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
1756 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1758 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1759 psc = NULL;
1760 hr = ScriptGetFontProperties(NULL,&psc,NULL);
1761 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1762 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1764 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1765 psc = NULL;
1766 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1767 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
1768 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1770 hr = ScriptGetFontProperties(hdc,NULL,NULL);
1771 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1773 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
1774 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1776 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1777 psc = NULL;
1778 hr = ScriptGetFontProperties(hdc,&psc,NULL);
1779 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1780 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1782 /* Pass an invalid sfp */
1783 psc = NULL;
1784 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
1785 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1786 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
1787 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1788 ScriptFreeCache(&psc);
1789 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1791 /* Give it the correct cBytes, we don't care about what's coming back */
1792 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
1793 psc = NULL;
1794 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1795 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
1796 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1798 /* Save the psc pointer */
1799 old_psc = psc;
1800 /* Now a NULL hdc again */
1801 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1802 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
1803 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
1804 ScriptFreeCache(&psc);
1805 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1808 static void test_ScriptTextOut(HDC hdc)
1810 HRESULT hr;
1812 int cInChars;
1813 int cMaxItems;
1814 SCRIPT_ITEM pItem[255];
1815 int pcItems;
1816 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1818 SCRIPT_CACHE psc;
1819 int cChars;
1820 int cMaxGlyphs;
1821 unsigned short pwOutGlyphs1[256];
1822 WORD pwLogClust[256];
1823 SCRIPT_VISATTR psva[256];
1824 int pcGlyphs;
1825 int piAdvance[256];
1826 GOFFSET pGoffset[256];
1827 ABC pABC[256];
1828 RECT rect;
1829 int piX;
1830 int iCP = 1;
1831 BOOL fTrailing = FALSE;
1832 SCRIPT_LOGATTR *psla;
1833 SCRIPT_LOGATTR sla[256];
1835 /* This is a valid test that will cause parsing to take place */
1836 cInChars = 5;
1837 cMaxItems = 255;
1838 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1839 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1840 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1841 * returned. */
1842 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1843 if (pcItems > 0)
1844 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1845 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1846 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1848 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1849 * ie. ScriptItemize has succeeded and that pItem has been set */
1850 cInChars = 5;
1851 if (hr == 0) {
1852 psc = NULL; /* must be null on first call */
1853 cChars = cInChars;
1854 cMaxGlyphs = 256;
1855 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1856 cMaxGlyphs, &pItem[0].a,
1857 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1858 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1859 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1860 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1861 if (hr ==0) {
1862 /* Note hdc is needed as glyph info is not yet in psc */
1863 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1864 pGoffset, pABC);
1865 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1866 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
1867 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1869 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
1870 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
1872 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1873 piAdvance, NULL, pGoffset);
1874 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1875 "expected E_INVALIDARG, got %08x\n", hr);
1877 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1878 psc = NULL;
1879 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
1880 NULL, NULL, NULL);
1881 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
1882 "got %08x\n", hr);
1883 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1885 /* hdc is required for this one rather than the usual optional */
1886 psc = NULL;
1887 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1888 piAdvance, NULL, pGoffset);
1889 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
1890 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1892 /* Set that it returns 0 status */
1893 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1894 piAdvance, NULL, pGoffset);
1895 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1897 /* Test Rect Rgn is acceptable */
1898 rect.top = 10;
1899 rect.bottom = 20;
1900 rect.left = 10;
1901 rect.right = 40;
1902 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1903 piAdvance, NULL, pGoffset);
1904 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1906 iCP = 1;
1907 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
1908 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
1909 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
1911 psla = (SCRIPT_LOGATTR *)&sla;
1912 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
1913 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
1915 /* Clean up and go */
1916 ScriptFreeCache(&psc);
1917 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1922 static void test_ScriptTextOut2(HDC hdc)
1924 /* Intent is to validate that the HDC passed into ScriptTextOut is
1925 * used instead of the (possibly) invalid cached one
1927 HRESULT hr;
1929 HDC hdc1, hdc2;
1930 int cInChars;
1931 int cMaxItems;
1932 SCRIPT_ITEM pItem[255];
1933 int pcItems;
1934 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1936 SCRIPT_CACHE psc;
1937 int cChars;
1938 int cMaxGlyphs;
1939 unsigned short pwOutGlyphs1[256];
1940 WORD pwLogClust[256];
1941 SCRIPT_VISATTR psva[256];
1942 int pcGlyphs;
1943 int piAdvance[256];
1944 GOFFSET pGoffset[256];
1945 ABC pABC[256];
1947 /* Create an extra DC that will be used until the ScriptTextOut */
1948 hdc1 = CreateCompatibleDC(hdc);
1949 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
1950 hdc2 = CreateCompatibleDC(hdc);
1951 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
1953 /* This is a valid test that will cause parsing to take place */
1954 cInChars = 5;
1955 cMaxItems = 255;
1956 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1957 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1958 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1959 * returned. */
1960 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1961 if (pcItems > 0)
1962 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1963 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1964 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1966 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1967 * ie. ScriptItemize has succeeded and that pItem has been set */
1968 cInChars = 5;
1969 if (hr == 0) {
1970 psc = NULL; /* must be null on first call */
1971 cChars = cInChars;
1972 cMaxGlyphs = 256;
1973 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
1974 cMaxGlyphs, &pItem[0].a,
1975 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1976 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1977 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1978 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1979 if (hr ==0) {
1980 /* Note hdc is needed as glyph info is not yet in psc */
1981 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1982 pGoffset, pABC);
1983 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1985 /* key part!!! cached dc is being deleted */
1986 hr = DeleteDC(hdc2);
1987 ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
1989 /* At this point the cached hdc (hdc2) has been destroyed,
1990 * however, we are passing in a *real* hdc (the original hdc).
1991 * The text should be written to that DC
1993 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1994 piAdvance, NULL, pGoffset);
1995 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1996 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1998 DeleteDC(hdc1);
2000 /* Clean up and go */
2001 ScriptFreeCache(&psc);
2002 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2007 static void test_ScriptTextOut3(HDC hdc)
2009 HRESULT hr;
2011 int cInChars;
2012 int cMaxItems;
2013 SCRIPT_ITEM pItem[255];
2014 int pcItems;
2015 WCHAR TestItem1[] = {' ','\r', 0};
2017 SCRIPT_CACHE psc;
2018 int cChars;
2019 int cMaxGlyphs;
2020 unsigned short pwOutGlyphs1[256];
2021 WORD pwLogClust[256];
2022 SCRIPT_VISATTR psva[256];
2023 int pcGlyphs;
2024 int piAdvance[256];
2025 GOFFSET pGoffset[256];
2026 ABC pABC[256];
2027 RECT rect;
2029 /* This is to ensure that nonexistent glyphs are translated into a valid glyph number */
2030 cInChars = 2;
2031 cMaxItems = 255;
2032 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
2033 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
2034 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
2035 * returned. */
2036 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
2037 if (pcItems > 0)
2038 ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
2039 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
2040 pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
2042 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
2043 * ie. ScriptItemize has succeeded and that pItem has been set */
2044 cInChars = 2;
2045 if (hr == 0) {
2046 psc = NULL; /* must be null on first call */
2047 cChars = cInChars;
2048 cMaxGlyphs = 256;
2049 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
2050 cMaxGlyphs, &pItem[0].a,
2051 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2052 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
2053 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2054 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
2055 if (hr ==0) {
2056 /* Note hdc is needed as glyph info is not yet in psc */
2057 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
2058 pGoffset, pABC);
2059 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
2061 /* Test Rect Rgn is acceptable */
2062 rect.top = 10;
2063 rect.bottom = 20;
2064 rect.left = 10;
2065 rect.right = 40;
2066 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2067 piAdvance, NULL, pGoffset);
2068 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
2071 /* Clean up and go */
2072 ScriptFreeCache(&psc);
2073 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2077 #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)
2079 static void _test_item_ScriptXtoX(SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
2081 int iX, iCP;
2082 int icChars, icGlyphs;
2083 int piCP, piX;
2084 HRESULT hr;
2085 SCRIPT_VISATTR psva[10];
2086 int piTrailing;
2087 BOOL fTrailing;
2088 int direction;
2090 memset(psva,0,sizeof(psva));
2091 direction = (psa->fRTL)?-1:+1;
2093 for(iCP = 0; iCP < cChars; iCP++)
2095 iX = offsets[iCP];
2096 icChars = cChars;
2097 icGlyphs = cGlyphs;
2098 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2099 winetest_ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
2100 winetest_ok(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2101 winetest_ok(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2104 for(iCP = 0; iCP < cChars; iCP++)
2106 iX = offsets[iCP]+direction;
2107 icChars = cChars;
2108 icGlyphs = cGlyphs;
2109 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2110 winetest_ok(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
2111 winetest_ok(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2112 winetest_ok(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2115 for(iCP = 0; iCP < cChars; iCP++)
2117 iX = offsets[iCP+1]-direction;
2118 icChars = cChars;
2119 icGlyphs = cGlyphs;
2120 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2121 winetest_ok(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
2122 winetest_ok(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2123 winetest_ok(piTrailing == 1, "ScriptXtoCP trailing: iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2126 for(iCP = 0; iCP <= cChars+1; iCP++)
2128 fTrailing = FALSE;
2129 icChars = cChars;
2130 icGlyphs = cGlyphs;
2131 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2132 winetest_ok(hr == S_OK, "ScriptCPtoX: should return S_OK not %08x\n", hr);
2133 winetest_ok(piX == offsets[iCP],
2134 "ScriptCPtoX: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
2137 for(iCP = 0; iCP <= cChars+1; iCP++)
2139 fTrailing = TRUE;
2140 icChars = cChars;
2141 icGlyphs = cGlyphs;
2142 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2143 winetest_ok(hr == S_OK, "ScriptCPtoX trailing: should return S_OK not %08x\n", hr);
2144 winetest_ok(piX == offsets[iCP+1],
2145 "ScriptCPtoX trailing: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
2149 static void test_ScriptXtoX(void)
2150 /****************************************************************************************
2151 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
2152 ****************************************************************************************/
2154 WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
2155 WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
2156 WORD pwLogClust_2[7] = {4, 3, 3, 2, 1, 0 ,0};
2157 int piAdvance[10] = {201, 190, 210, 180, 170, 204, 189, 195, 212, 203};
2158 int piAdvance_2[5] = {39, 26, 19, 17, 11};
2159 static const int offsets[13] = {0, 67, 134, 201, 296, 391, 496, 601, 1052, 1503, 1954, 1954, 1954};
2160 static const int offsets_RTL[13] = {781, 721, 661, 601, 496, 391, 296, 201, 134, 67, 0, 0, 0};
2161 static const int offsets_2[10] = {112, 101, 92, 84, 65, 39, 19, 0, 0, 0};
2162 SCRIPT_VISATTR psva[10];
2163 SCRIPT_ANALYSIS sa;
2164 int iX;
2165 int piCP;
2166 int piTrailing;
2167 HRESULT hr;
2169 memset(&sa, 0 , sizeof(SCRIPT_ANALYSIS));
2170 memset(psva, 0, sizeof(psva));
2172 sa.fRTL = FALSE;
2173 hr = ScriptXtoCP(-1, 10, 10, pwLogClust, psva, piAdvance, &sa, &piCP, &piTrailing);
2174 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2175 if (piTrailing)
2176 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2177 else /* win2k3 */
2178 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2180 for (iX = 0; iX <= 7; iX++)
2182 WORD clust = 0;
2183 INT advance = 16;
2184 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2185 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX, piCP,piTrailing);
2187 for (iX = 8; iX < 16; iX++)
2189 WORD clust = 0;
2190 INT advance = 16;
2191 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2192 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX, piCP,piTrailing);
2195 sa.fRTL = TRUE;
2196 hr = ScriptXtoCP(-1, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2197 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2198 if (piTrailing)
2199 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2200 else /* win2k3 */
2201 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2203 iX = 1954;
2204 hr = ScriptXtoCP(1954, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2205 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2206 ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
2207 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2209 for (iX = 1; iX <= 8; iX++)
2211 WORD clust = 0;
2212 INT advance = 16;
2213 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2214 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX,piCP,piTrailing);
2216 for (iX = 9; iX < 16; iX++)
2218 WORD clust = 0;
2219 INT advance = 16;
2220 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2221 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX,piCP,piTrailing);
2224 sa.fRTL = FALSE;
2225 test_item_ScriptXtoX(&sa, 10, 10, offsets, pwLogClust, piAdvance);
2226 sa.fRTL = TRUE;
2227 test_item_ScriptXtoX(&sa, 10, 10, offsets_RTL, pwLogClust_RTL, piAdvance);
2228 test_item_ScriptXtoX(&sa, 7, 5, offsets_2, pwLogClust_2, piAdvance_2);
2231 static void test_ScriptString(HDC hdc)
2233 /*******************************************************************************************
2235 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
2236 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
2237 * memory is freed by ScriptStringFree. There needs to be a valid hdc for this as
2238 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
2242 HRESULT hr;
2243 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
2244 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
2245 int Glyphs = len * 2 + 16;
2246 int Charset;
2247 DWORD Flags = SSA_GLYPHS;
2248 int ReqWidth = 100;
2249 const int Dx[5] = {10, 10, 10, 10, 10};
2250 const BYTE InClass = 0;
2251 SCRIPT_STRING_ANALYSIS ssa = NULL;
2253 int X = 10;
2254 int Y = 100;
2255 UINT Options = 0;
2256 const RECT rc = {0, 50, 100, 100};
2257 int MinSel = 0;
2258 int MaxSel = 0;
2259 BOOL Disabled = FALSE;
2260 const int *clip_len;
2261 int i;
2262 UINT *order;
2265 Charset = -1; /* this flag indicates unicode input */
2266 /* Test without hdc to get E_PENDING */
2267 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
2268 ReqWidth, NULL, NULL, Dx, NULL,
2269 &InClass, &ssa);
2270 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
2272 /* test with hdc, this should be a valid test */
2273 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2274 ReqWidth, NULL, NULL, Dx, NULL,
2275 &InClass, &ssa);
2276 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2277 ScriptStringFree(&ssa);
2279 /* test makes sure that a call with a valid pssa still works */
2280 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2281 ReqWidth, NULL, NULL, Dx, NULL,
2282 &InClass, &ssa);
2283 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2284 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
2286 if (hr == S_OK)
2288 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
2289 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
2292 clip_len = ScriptString_pcOutChars(ssa);
2293 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
2295 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
2296 hr = ScriptStringGetOrder(ssa, order);
2297 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
2299 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
2300 HeapFree(GetProcessHeap(), 0, order);
2302 hr = ScriptStringFree(&ssa);
2303 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2306 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
2308 /*****************************************************************************************
2310 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
2311 * nature of the fonts between Windows and Wine, the test is implemented by generating
2312 * values using one one function then checking the output of the second. In this way
2313 * the validity of the functions is established using Windows as a base and confirming
2314 * similar behaviour in wine.
2317 HRESULT hr;
2318 static const WCHAR teststr1[] = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
2319 static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
2320 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
2321 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
2322 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
2323 int Charset = -1; /* unicode */
2324 DWORD Flags = SSA_GLYPHS;
2325 int ReqWidth = 100;
2326 const BYTE InClass = 0;
2327 SCRIPT_STRING_ANALYSIS ssa = NULL;
2329 int Ch; /* Character position in string */
2330 int iTrailing;
2331 int Cp; /* Character position in string */
2332 int X;
2333 int trail,lead;
2334 BOOL fTrailing;
2336 /* Test with hdc, this should be a valid test
2337 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
2338 * following character positions to X and X to character position functions.
2341 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2342 ReqWidth, NULL, NULL, NULL, NULL,
2343 &InClass, &ssa);
2344 ok(hr == S_OK ||
2345 hr == E_INVALIDARG, /* NT */
2346 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
2348 if (hr == S_OK)
2350 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
2353 * Loop to generate character positions to provide starting positions for the
2354 * ScriptStringCPtoX and ScriptStringXtoCP functions
2356 for (Cp = 0; Cp < String_len; Cp++)
2358 /* The fTrailing flag is used to indicate whether the X being returned is at
2359 * the beginning or the end of the character. What happens here is that if
2360 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
2361 * returns the beginning of the next character and iTrailing is FALSE. So for this
2362 * loop iTrailing will be FALSE in both cases.
2364 hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
2365 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2366 hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
2367 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2368 if (rtl[Cp])
2369 ok(lead > trail, "Leading values should be after trailing for rtl characters(%i)\n",Cp);
2370 else
2371 ok(lead < trail, "Trailing values should be after leading for ltr characters(%i)\n",Cp);
2373 /* move by 1 pixel so that we are not inbetween 2 characters. That could result in being the lead of a rtl and
2374 at the same time the trail of an ltr */
2376 /* inside the leading edge */
2377 X = lead;
2378 if (rtl[Cp]) X--; else X++;
2379 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2380 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2381 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2382 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2383 iTrailing, X);
2385 /* inside the trailing edge */
2386 X = trail;
2387 if (rtl[Cp]) X++; else X--;
2388 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2389 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2390 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2391 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2392 iTrailing, X);
2394 /* outside the "trailing" edge */
2395 if (Cp < String_len-1)
2397 if (rtl[Cp]) X = lead; else X = trail;
2398 X++;
2399 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2400 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2401 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, trail);
2402 if (rtl[Cp+1])
2403 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2404 iTrailing, X);
2405 else
2406 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2407 iTrailing, X);
2410 /* outside the "leading" edge */
2411 if (Cp != 0)
2413 if (rtl[Cp]) X = trail; else X = lead;
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(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, trail);
2418 if (Cp != 0 && rtl[Cp-1])
2419 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2420 iTrailing, X);
2421 else
2422 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2423 iTrailing, X);
2427 /* Check beyond the leading boundary of the whole string */
2428 if (rtl[0])
2430 /* having a leading rtl character seems to confuse usp */
2431 /* this looks to be a windows bug we should emulate */
2432 hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
2433 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2434 X--;
2435 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2436 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2437 ok(Ch == 1, "ScriptStringXtoCP should return Ch = 1 not %d for X outside leading edge when rtl\n", Ch);
2438 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside leading edge when rtl\n",
2439 iTrailing);
2441 else
2443 hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
2444 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2445 X--;
2446 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2447 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2448 ok(Ch == -1, "ScriptStringXtoCP should return Ch = -1 not %d for X outside leading edge\n", Ch);
2449 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = outside leading edge\n",
2450 iTrailing);
2453 /* Check beyond the end boundary of the whole string */
2454 if (rtl[String_len-1])
2456 hr = ScriptStringCPtoX(ssa, String_len-1, FALSE, &X);
2457 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2459 else
2461 hr = ScriptStringCPtoX(ssa, String_len-1, TRUE, &X);
2462 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2464 X++;
2465 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2466 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2467 ok(Ch == String_len, "ScriptStringXtoCP should return Ch = %i not %d for X outside trailing edge\n", String_len, Ch);
2468 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside trailing edge\n",
2469 iTrailing);
2472 * Cleanup the SSA for the next round of tests
2474 hr = ScriptStringFree(&ssa);
2475 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2478 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
2479 * generate an SSA for the subsequent tests.
2481 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2482 ReqWidth, NULL, NULL, NULL, NULL,
2483 &InClass, &ssa);
2484 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2487 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
2488 * string length, return E_INVALIDARG. This also invalidates the ssa so a
2489 * ScriptStringFree should also fail.
2491 fTrailing = FALSE;
2492 Cp = String_len + 1;
2493 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
2494 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
2496 ScriptStringFree(&ssa);
2500 static void test_ScriptCacheGetHeight(HDC hdc)
2502 HRESULT hr;
2503 SCRIPT_CACHE sc = NULL;
2504 LONG height;
2506 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
2507 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2509 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
2510 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2512 hr = ScriptCacheGetHeight(NULL, &sc, &height);
2513 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2515 height = 0;
2517 hr = ScriptCacheGetHeight(hdc, &sc, &height);
2518 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2519 ok(height > 0, "expected height > 0\n");
2521 ScriptFreeCache(&sc);
2524 static void test_ScriptGetGlyphABCWidth(HDC hdc)
2526 HRESULT hr;
2527 SCRIPT_CACHE sc = NULL;
2528 ABC abc;
2530 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
2531 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2533 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
2534 ok(broken(hr == E_PENDING) ||
2535 hr == E_INVALIDARG, /* WIN7 */
2536 "expected E_INVALIDARG, got 0x%08x\n", hr);
2538 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
2539 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2541 if (0) { /* crashes on WinXP */
2542 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
2543 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2546 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
2547 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2549 ScriptFreeCache(&sc);
2552 static void test_ScriptLayout(void)
2554 HRESULT hr;
2555 static const BYTE levels[][10] =
2557 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2558 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
2559 { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2560 { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
2562 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
2563 { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
2564 { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
2565 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
2566 { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
2568 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
2569 { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
2571 static const int expect_l2v[][10] =
2573 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2574 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2575 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2576 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2578 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2579 /**/ { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
2580 /**/ { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
2581 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2582 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2584 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2585 /**/ { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
2587 static const int expect_v2l[][10] =
2589 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2590 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2591 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2592 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2594 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2595 { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
2596 { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
2597 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2598 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2600 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2601 { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
2604 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
2606 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
2607 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2609 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
2610 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2612 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
2614 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
2615 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2617 for (j = 0; j < sizeof(levels[i]); j++)
2619 ok(expect_v2l[i][j] == vistolog[j],
2620 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
2621 i, j, levels[i][j], j, vistolog[j] );
2624 for (j = 0; j < sizeof(levels[i]); j++)
2626 ok(expect_l2v[i][j] == logtovis[j],
2627 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
2628 i, j, levels[i][j], j, logtovis[j] );
2633 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
2635 HRESULT hr;
2636 SCRIPT_DIGITSUBSTITUTE sds;
2637 SCRIPT_CONTROL sc;
2638 SCRIPT_STATE ss;
2639 LCID lcid_old;
2641 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
2643 memset(&sds, 0, sizeof(sds));
2644 memset(&sc, 0, sizeof(sc));
2645 memset(&ss, 0, sizeof(ss));
2647 lcid_old = GetThreadLocale();
2648 if (!SetThreadLocale(lcid)) return TRUE;
2650 hr = ScriptRecordDigitSubstitution(lcid, &sds);
2651 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
2653 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
2654 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
2656 SetThreadLocale(lcid_old);
2657 return TRUE;
2660 static void test_digit_substitution(void)
2662 BOOL ret;
2663 unsigned int i;
2664 static const LGRPID groups[] =
2666 LGRPID_WESTERN_EUROPE,
2667 LGRPID_CENTRAL_EUROPE,
2668 LGRPID_BALTIC,
2669 LGRPID_GREEK,
2670 LGRPID_CYRILLIC,
2671 LGRPID_TURKISH,
2672 LGRPID_JAPANESE,
2673 LGRPID_KOREAN,
2674 LGRPID_TRADITIONAL_CHINESE,
2675 LGRPID_SIMPLIFIED_CHINESE,
2676 LGRPID_THAI,
2677 LGRPID_HEBREW,
2678 LGRPID_ARABIC,
2679 LGRPID_VIETNAMESE,
2680 LGRPID_INDIC,
2681 LGRPID_GEORGIAN,
2682 LGRPID_ARMENIAN
2684 HMODULE hKernel32;
2685 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
2687 hKernel32 = GetModuleHandleA("kernel32.dll");
2688 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
2690 if (!pEnumLanguageGroupLocalesA)
2692 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
2693 return;
2696 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
2698 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
2699 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2701 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
2702 break;
2705 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
2709 static void test_ScriptGetProperties(void)
2711 const SCRIPT_PROPERTIES **props;
2712 HRESULT hr;
2713 int num;
2715 hr = ScriptGetProperties(NULL, NULL);
2716 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
2718 hr = ScriptGetProperties(NULL, &num);
2719 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2721 hr = ScriptGetProperties(&props, NULL);
2722 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2724 hr = ScriptGetProperties(&props, &num);
2725 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2728 static void test_ScriptBreak(void)
2730 static const WCHAR test[] = {' ','\r','\n',0};
2731 SCRIPT_ITEM items[4];
2732 SCRIPT_LOGATTR la;
2733 HRESULT hr;
2735 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
2736 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
2738 memset(&la, 0, sizeof(la));
2739 hr = ScriptBreak(test, 1, &items[0].a, &la);
2740 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2742 ok(!la.fSoftBreak, "fSoftBreak set\n");
2743 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
2744 ok(la.fCharStop, "fCharStop not set\n");
2745 ok(!la.fWordStop, "fWordStop set\n");
2746 ok(!la.fInvalid, "fInvalid set\n");
2747 ok(!la.fReserved, "fReserved set\n");
2749 memset(&la, 0, sizeof(la));
2750 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
2751 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2753 ok(!la.fSoftBreak, "fSoftBreak set\n");
2754 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2755 ok(la.fCharStop, "fCharStop not set\n");
2756 ok(!la.fWordStop, "fWordStop set\n");
2757 ok(!la.fInvalid, "fInvalid set\n");
2758 ok(!la.fReserved, "fReserved set\n");
2760 memset(&la, 0, sizeof(la));
2761 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
2762 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2764 ok(!la.fSoftBreak, "fSoftBreak set\n");
2765 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2766 ok(la.fCharStop, "fCharStop not set\n");
2767 ok(!la.fWordStop, "fWordStop set\n");
2768 ok(!la.fInvalid, "fInvalid set\n");
2769 ok(!la.fReserved, "fReserved set\n");
2772 static void test_newlines(void)
2774 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
2775 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
2776 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
2777 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
2778 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
2779 SCRIPT_ITEM items[5];
2780 HRESULT hr;
2781 int count;
2783 count = 0;
2784 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
2785 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2786 ok(count == 3, "got %d expected 3\n", count);
2788 count = 0;
2789 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
2790 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2791 ok(count == 3, "got %d expected 3\n", count);
2793 count = 0;
2794 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
2795 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2796 ok(count == 4, "got %d expected 4\n", count);
2798 count = 0;
2799 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
2800 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2801 ok(count == 4, "got %d expected 4\n", count);
2803 count = 0;
2804 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
2805 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2806 ok(count == 4, "got %d expected 4\n", count);
2809 START_TEST(usp10)
2811 HWND hwnd;
2812 HDC hdc;
2813 LOGFONTA lf;
2814 HFONT hfont;
2816 unsigned short pwOutGlyphs[256];
2818 /* We need a valid HDC to drive a lot of Script functions which requires the following *
2819 * to set up for the tests. */
2820 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
2821 0, 0, 0, NULL);
2822 assert(hwnd != 0);
2823 ShowWindow(hwnd, SW_SHOW);
2824 UpdateWindow(hwnd);
2826 hdc = GetDC(hwnd); /* We now have a hdc */
2827 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
2829 memset(&lf, 0, sizeof(LOGFONTA));
2830 lstrcpyA(lf.lfFaceName, "Tahoma");
2831 lf.lfHeight = 10;
2832 lf.lfWeight = 3;
2833 lf.lfWidth = 10;
2835 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
2836 ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
2838 test_ScriptItemize();
2839 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
2840 test_ScriptGetCMap(hdc, pwOutGlyphs);
2841 test_ScriptCacheGetHeight(hdc);
2842 test_ScriptGetGlyphABCWidth(hdc);
2843 test_ScriptShape(hdc);
2844 test_ScriptShapeOpenType(hdc);
2845 test_ScriptPlace(hdc);
2847 test_ScriptGetFontProperties(hdc);
2848 test_ScriptTextOut(hdc);
2849 test_ScriptTextOut2(hdc);
2850 test_ScriptTextOut3(hdc);
2851 test_ScriptXtoX();
2852 test_ScriptString(hdc);
2853 test_ScriptStringXtoCP_CPtoX(hdc);
2855 test_ScriptLayout();
2856 test_digit_substitution();
2857 test_ScriptGetProperties();
2858 test_ScriptBreak();
2859 test_newlines();
2861 ReleaseDC(hwnd, hdc);
2862 DestroyWindow(hwnd);