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