usp10: Add Vai script.
[wine.git] / dlls / usp10 / usp10.c
bloba73d8e995fcdd353b15ff1d5ea243b7e06378a75
1 /*
2 * Implementation of Uniscribe Script Processor (usp10.dll)
4 * Copyright 2005 Steven Edwards for CodeWeavers
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Notes:
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
27 #include <stdarg.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "winreg.h"
35 #include "usp10.h"
37 #include "usp10_internal.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
44 typedef struct _scriptRange
46 WORD script;
47 WORD rangeFirst;
48 WORD rangeLast;
49 WORD numericScript;
50 WORD punctScript;
51 } scriptRange;
53 static const scriptRange scriptRanges[] = {
54 /* Basic Latin: U+0000–U+007A */
55 { Script_Latin, 0x00, 0x07a , Script_Numeric, Script_Punctuation},
56 /* Latin-1 Supplement: U+0080–U+00FF */
57 /* Latin Extended-A: U+0100–U+017F */
58 /* Latin Extended-B: U+0180–U+024F */
59 /* IPA Extensions: U+0250–U+02AF */
60 { Script_Latin, 0x80, 0x2af , Script_Numeric2, Script_Punctuation},
61 /* Combining Diacritical Marks : U+0300–U+036F */
62 { Script_Diacritical,0x300, 0x36f, 0, 0},
63 /* Greek: U+0370–U+03FF */
64 { Script_Greek, 0x370, 0x3ff, 0, 0},
65 /* Cyrillic: U+0400–U+04FF */
66 /* Cyrillic Supplement: U+0500–U+052F */
67 { Script_Cyrillic, 0x400, 0x52f, 0, 0},
68 /* Armenian: U+0530–U+058F */
69 { Script_Armenian, 0x530, 0x58f, 0, 0},
70 /* Hebrew: U+0590–U+05FF */
71 { Script_Hebrew, 0x590, 0x5ff, 0, 0},
72 /* Arabic: U+0600–U+06FF */
73 { Script_Arabic, 0x600, 0x6ef, Script_Arabic_Numeric, 0},
74 /* Defined by Windows */
75 { Script_Persian, 0x6f0, 0x6f9, 0, 0},
76 /* Continue Arabic: U+0600–U+06FF */
77 { Script_Arabic, 0x6fa, 0x6ff, 0, 0},
78 /* Syriac: U+0700–U+074F*/
79 { Script_Syriac, 0x700, 0x74f, 0, 0},
80 /* Arabic Supplement: U+0750–U+077F */
81 { Script_Arabic, 0x750, 0x77f, 0, 0},
82 /* Thaana: U+0780–U+07BF */
83 { Script_Thaana, 0x780, 0x7bf, 0, 0},
84 /* N’Ko: U+07C0–U+07FF */
85 { Script_NKo, 0x7c0, 0x7ff, 0, 0},
86 /* Devanagari: U+0900–U+097F */
87 { Script_Devanagari, 0x900, 0x97f, Script_Devanagari_Numeric, 0},
88 /* Bengali: U+0980–U+09FF */
89 { Script_Bengali, 0x980, 0x9ff, Script_Bengali_Numeric, 0},
90 /* Gurmukhi: U+0A00–U+0A7F*/
91 { Script_Gurmukhi, 0xa00, 0xa7f, Script_Gurmukhi_Numeric, 0},
92 /* Gujarati: U+0A80–U+0AFF*/
93 { Script_Gujarati, 0xa80, 0xaff, Script_Gujarati_Numeric, 0},
94 /* Oriya: U+0B00–U+0B7F */
95 { Script_Oriya, 0xb00, 0xb7f, Script_Oriya_Numeric, 0},
96 /* Tamil: U+0B80–U+0BFF */
97 { Script_Tamil, 0xb80, 0xbff, Script_Tamil_Numeric, 0},
98 /* Telugu: U+0C00–U+0C7F */
99 { Script_Telugu, 0xc00, 0xc7f, Script_Telugu_Numeric, 0},
100 /* Kannada: U+0C80–U+0CFF */
101 { Script_Kannada, 0xc80, 0xcff, Script_Kannada_Numeric, 0},
102 /* Malayalam: U+0D00–U+0D7F */
103 { Script_Malayalam, 0xd00, 0xd7f, Script_Malayalam_Numeric, 0},
104 /* Sinhala: U+0D80–U+0DFF */
105 { Script_Sinhala, 0xd80, 0xdff, 0, 0},
106 /* Thai: U+0E00–U+0E7F */
107 { Script_Thai, 0xe00, 0xe7f, Script_Thai_Numeric, 0},
108 /* Lao: U+0E80–U+0EFF */
109 { Script_Lao, 0xe80, 0xeff, Script_Lao_Numeric, 0},
110 /* Tibetan: U+0F00–U+0FFF */
111 { Script_Tibetan, 0xf00, 0xfff, 0, 0},
112 /* Myanmar: U+1000–U+109F */
113 { Script_Myanmar, 0x1000, 0x109f, Script_Myanmar_Numeric, 0},
114 /* Georgian: U+10A0–U+10FF */
115 { Script_Georgian, 0x10a0, 0x10ff, 0, 0},
116 /* Hangul Jamo: U+1100–U+11FF */
117 { Script_Hangul, 0x1100, 0x11ff, 0, 0},
118 /* Ethiopic: U+1200–U+137F */
119 /* Ethiopic Extensions: U+1380–U+139F */
120 { Script_Ethiopic, 0x1200, 0x139f, 0, 0},
121 /* Khmer: U+1780–U+17FF */
122 { Script_Khmer, 0x1780, 0x17ff, Script_Khmer_Numeric, 0},
123 /* Mongolian: U+1800–U+18AF */
124 { Script_Mongolian, 0x1800, 0x18af, Script_Mongolian_Numeric, 0},
125 /* Tai Le: U+1950–U+197F */
126 { Script_Tai_Le, 0x1950, 0x197f, 0, 0},
127 /* New Tai Lue: U+1980–U+19DF */
128 { Script_New_Tai_Lue,0x1980, 0x19df, Script_New_Tai_Lue_Numeric, 0},
129 /* Khmer Symbols: U+19E0–U+19FF */
130 { Script_Khmer, 0x19e0, 0x19ff, Script_Khmer_Numeric, 0},
131 /* Vedic Extensions: U+1CD0-U+1CFF */
132 { Script_Devanagari, 0x1cd0, 0x1cff, Script_Devanagari_Numeric, 0},
133 /* Phonetic Extensions: U+1D00–U+1DBF */
134 { Script_Latin, 0x1d00, 0x1dbf, 0, 0},
135 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
136 { Script_Diacritical,0x1dc0, 0x1dff, 0, 0},
137 /* Latin Extended Additional: U+1E00–U+1EFF */
138 { Script_Latin, 0x1e00, 0x1eff, 0, 0},
139 /* Greek Extended: U+1F00–U+1FFF */
140 { Script_Greek, 0x1f00, 0x1fff, 0, 0},
141 /* General Punctuation: U+2000 –U+206f */
142 { Script_Latin, 0x2000, 0x206f, 0, 0},
143 /* Superscripts and Subscripts : U+2070 –U+209f */
144 /* Currency Symbols : U+20a0 –U+20cf */
145 { Script_Numeric2, 0x2070, 0x2070, 0, 0},
146 { Script_Latin, 0x2071, 0x2073, 0, 0},
147 { Script_Numeric2, 0x2074, 0x2079, 0, 0},
148 { Script_Latin, 0x207a, 0x207f, 0, 0},
149 { Script_Numeric2, 0x2080, 0x2089, 0, 0},
150 { Script_Latin, 0x208a, 0x20cf, 0, 0},
151 /* Letterlike Symbols : U+2100 –U+214f */
152 /* Number Forms : U+2150 –U+218f */
153 /* Arrows : U+2190 –U+21ff */
154 /* Mathematical Operators : U+2200 –U+22ff */
155 /* Miscellaneous Technical : U+2300 –U+23ff */
156 /* Control Pictures : U+2400 –U+243f */
157 /* Optical Character Recognition : U+2440 –U+245f */
158 /* Enclosed Alphanumerics : U+2460 –U+24ff */
159 /* Box Drawing : U+2500 –U+25ff */
160 /* Block Elements : U+2580 –U+259f */
161 /* Geometric Shapes : U+25a0 –U+25ff */
162 /* Miscellaneous Symbols : U+2600 –U+26ff */
163 /* Dingbats : U+2700 –U+27bf */
164 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
165 /* Supplemental Arrows-A : U+27f0 –U+27ff */
166 { Script_Latin, 0x2100, 0x27ff, 0, 0},
167 /* Supplemental Arrows-B : U+2900 –U+297f */
168 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
169 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
170 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
171 { Script_Latin, 0x2900, 0x2bff, 0, 0},
172 /* Latin Extended-C: U+2C60–U+2C7F */
173 { Script_Latin, 0x2c60, 0x2c7f, 0, 0},
174 /* Georgian: U+2D00–U+2D2F */
175 { Script_Georgian, 0x2d00, 0x2d2f, 0, 0},
176 /* Tifinagh: U+2D30–U+2D7F */
177 { Script_Tifinagh, 0x2d30, 0x2d7f, 0, 0},
178 /* Ethiopic Extensions: U+2D80–U+2DDF */
179 { Script_Ethiopic, 0x2d80, 0x2ddf, 0, 0},
180 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
181 { Script_Cyrillic, 0x2de0, 0x2dff, 0, 0},
182 /* CJK Radicals Supplement: U+2E80–U+2EFF */
183 /* Kangxi Radicals: U+2F00–U+2FDF */
184 { Script_CJK_Han, 0x2e80, 0x2fdf, 0, 0},
185 /* Ideographic Description Characters: U+2FF0–U+2FFF */
186 { Script_Ideograph ,0x2ff0, 0x2fff, 0, 0},
187 /* CJK Symbols and Punctuation: U+3000–U+303F */
188 { Script_Ideograph ,0x3000, 0x3004, 0, 0},
189 { Script_CJK_Han ,0x3005, 0x3005, 0, 0},
190 { Script_Ideograph ,0x3006, 0x3006, 0, 0},
191 { Script_CJK_Han ,0x3007, 0x3007, 0, 0},
192 { Script_Ideograph ,0x3008, 0x3020, 0, 0},
193 { Script_CJK_Han ,0x3021, 0x3029, 0, 0},
194 { Script_Ideograph ,0x302a, 0x3030, 0, 0},
195 /* Kana Marks: */
196 { Script_Kana ,0x3031, 0x3035, 0, 0},
197 { Script_Ideograph ,0x3036, 0x3037, 0, 0},
198 { Script_CJK_Han ,0x3038, 0x303b, 0, 0},
199 { Script_Ideograph ,0x303c, 0x303f, 0, 0},
200 /* Hiragana: U+3040–U+309F */
201 /* Katakana: U+30A0–U+30FF */
202 { Script_Kana ,0x3040, 0x30ff, 0, 0},
203 /* Bopomofo: U+3100–U+312F */
204 { Script_Bopomofo ,0x3100, 0x312f, 0, 0},
205 /* Hangul Compatibility Jamo: U+3130–U+318F */
206 { Script_Hangul ,0x3130, 0x318f, 0, 0},
207 /* Kanbun: U+3190–U+319F */
208 { Script_Ideograph ,0x3190, 0x319f, 0, 0},
209 /* Bopomofo Extended: U+31A0–U+31BF */
210 { Script_Bopomofo ,0x31a0, 0x31bf, 0, 0},
211 /* CJK Strokes: U+31C0–U+31EF */
212 { Script_Ideograph ,0x31c0, 0x31ef, 0, 0},
213 /* Katakana Phonetic Extensions: U+31F0–U+31FF */
214 { Script_Kana ,0x31f0, 0x31ff, 0, 0},
215 /* Enclosed CJK Letters and Months: U+3200–U+32FF */
216 { Script_Hangul ,0x3200, 0x321f, 0, 0},
217 { Script_Ideograph ,0x3220, 0x325f, 0, 0},
218 { Script_Hangul ,0x3260, 0x327f, 0, 0},
219 { Script_Ideograph ,0x3280, 0x32ef, 0, 0},
220 { Script_Kana ,0x32d0, 0x31ff, 0, 0},
221 /* CJK Compatibility: U+3300–U+33FF*/
222 { Script_Kana ,0x3300, 0x3357, 0, 0},
223 { Script_Ideograph ,0x3358, 0x33ff, 0, 0},
224 /* CJK Unified Ideographs Extension A: U+3400–U+4DBF */
225 { Script_CJK_Han ,0x3400, 0x4dbf, 0, 0},
226 /* CJK Unified Ideographs: U+4E00–U+9FFF */
227 { Script_CJK_Han ,0x4e00, 0x9fff, 0, 0},
228 /* Yi: U+A000–U+A4CF */
229 { Script_Yi ,0xa000, 0xa4cf, 0, 0},
230 /* Vai: U+A500–U+A63F */
231 { Script_Vai ,0xa500, 0xa63f, Script_Vai_Numeric, 0},
232 /* Cyrillic Extended-B: U+A640–U+A69F */
233 { Script_Cyrillic, 0xa640, 0xa69f, 0, 0},
234 /* Modifier Tone Letters: U+A700–U+A71F */
235 /* Latin Extended-D: U+A720–U+A7FF */
236 { Script_Latin, 0xa700, 0xa7ff, 0, 0},
237 /* Phags-pa: U+A840–U+A87F */
238 { Script_Phags_pa, 0xa840, 0xa87f, 0, 0},
239 /* Devanagari Extended: U+A8E0-U+A8FF */
240 { Script_Devanagari, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric, 0},
241 /* Myanmar Extended-A: U+AA60–U+AA7F */
242 { Script_Myanmar, 0xaa60, 0xaa7f, Script_Myanmar_Numeric, 0},
243 /* Hangul Jamo Extended-A: U+A960–U+A97F */
244 { Script_Hangul, 0xa960, 0xa97f, 0, 0},
245 /* Hangul Syllables: U+AC00–U+D7A3 */
246 { Script_Hangul, 0xac00, 0xd7a3, 0, 0},
247 /* Hangul Jamo Extended-B: U+D7B0–U+D7FF */
248 { Script_Hangul, 0xd7b0, 0xd7ff, 0, 0},
249 /* CJK Compatibility Ideographs: U+F900–U+FAFF */
250 { Script_CJK_Han ,0xf900, 0xfaff, 0, 0},
251 /* Latin Ligatures: U+FB00–U+FB06 */
252 { Script_Latin, 0xfb00, 0xfb06, 0, 0},
253 /* Armenian ligatures U+FB13..U+FB17 */
254 { Script_Armenian, 0xfb13, 0xfb17, 0, 0},
255 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
256 { Script_Hebrew, 0xfb1d, 0xfb4f, 0, 0},
257 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
258 { Script_Arabic, 0xfb50, 0xfdff, 0, 0},
259 /* Vertical Forms: U+FE10–U+FE1F */
260 /* Combining Half Marks: U+FE20–U+FE2F */
261 /* CJK Compatibility Forms: U+FE30–U+FE4F */
262 /* Small Form Variants: U+FE50–U+FE6F */
263 { Script_Ideograph ,0xfe10, 0xfe6f, 0, 0},
264 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
265 { Script_Arabic, 0xfe70, 0xfeff, 0, 0},
266 /* Halfwidth and Fullwidth Forms: U+FF00–FFEF */
267 { Script_Ideograph ,0xff00, 0xff64, Script_Numeric2, 0},
268 { Script_Kana ,0xff65, 0xff9f, 0, 0},
269 { Script_Hangul ,0xffa0, 0xffdf, 0, 0},
270 { Script_Ideograph ,0xffe0, 0xffef, 0, 0},
271 /* END */
272 { SCRIPT_UNDEFINED, 0, 0, 0}
275 typedef struct _scriptData
277 SCRIPT_ANALYSIS a;
278 SCRIPT_PROPERTIES props;
279 OPENTYPE_TAG scriptTag;
280 WCHAR fallbackFont[LF_FACESIZE];
281 } scriptData;
283 /* the must be in order so that the index matches the Script value */
284 static const scriptData scriptInformation[] = {
285 {{SCRIPT_UNDEFINED, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
286 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
287 0x00000000,
288 {0}},
289 {{Script_Latin, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
290 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
291 MS_MAKE_TAG('l','a','t','n'),
292 {0}},
293 {{Script_CR, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
294 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
295 0x00000000,
296 {0}},
297 {{Script_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
298 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
299 0x00000000,
300 {0}},
301 {{Script_Control, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
302 {LANG_ENGLISH, 0, 1, 0, 0, ANSI_CHARSET, 1, 0, 0, 0, 0, 0, 1, 0, 0},
303 0x00000000,
304 {0}},
305 {{Script_Punctuation, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
306 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
307 0x00000000,
308 {0}},
309 {{Script_Arabic, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
310 {LANG_ARABIC, 0, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 1, 0},
311 MS_MAKE_TAG('a','r','a','b'),
312 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
313 {{Script_Arabic_Numeric, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
314 {LANG_ARABIC, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
315 MS_MAKE_TAG('a','r','a','b'),
316 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
317 {{Script_Hebrew, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
318 {LANG_HEBREW, 0, 1, 0, 1, HEBREW_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
319 MS_MAKE_TAG('h','e','b','r'),
320 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
321 {{Script_Syriac, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
322 {LANG_SYRIAC, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 1, 0},
323 MS_MAKE_TAG('s','y','r','c'),
324 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
325 {{Script_Persian, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
326 {LANG_PERSIAN, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
327 MS_MAKE_TAG('s','y','r','c'),
328 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
329 {{Script_Thaana, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
330 {LANG_DIVEHI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
331 MS_MAKE_TAG('t','h','a','a'),
332 {'M','V',' ','B','o','l','i',0}},
333 {{Script_Greek, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
334 {LANG_GREEK, 0, 0, 0, 0, GREEK_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
335 MS_MAKE_TAG('g','r','e','k'),
336 {0}},
337 {{Script_Cyrillic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
338 {LANG_RUSSIAN, 0, 0, 0, 0, RUSSIAN_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
339 MS_MAKE_TAG('c','y','r','l'),
340 {0}},
341 {{Script_Armenian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
342 {LANG_ARMENIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
343 MS_MAKE_TAG('a','r','m','n'),
344 {'S','y','l','f','a','e','n',0}},
345 {{Script_Georgian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
346 {LANG_GEORGIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
347 MS_MAKE_TAG('g','e','o','r'),
348 {'S','y','l','f','a','e','n',0}},
349 {{Script_Sinhala, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
350 {LANG_SINHALESE, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
351 MS_MAKE_TAG('s','i','n','h'),
352 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
353 {{Script_Tibetan, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
354 {LANG_TIBETAN, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
355 MS_MAKE_TAG('t','i','b','t'),
356 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
357 {{Script_Tibetan_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
358 {LANG_TIBETAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
359 MS_MAKE_TAG('t','i','b','t'),
360 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
361 {{Script_Phags_pa, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
362 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
363 MS_MAKE_TAG('p','h','a','g'),
364 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
365 {{Script_Thai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
366 {LANG_THAI, 0, 1, 1, 1, THAI_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 1},
367 MS_MAKE_TAG('t','h','a','i'),
368 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
369 {{Script_Thai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
370 {LANG_THAI, 1, 1, 0, 0, THAI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
371 MS_MAKE_TAG('t','h','a','i'),
372 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
373 {{Script_Lao, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
374 {LANG_LAO, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
375 MS_MAKE_TAG('l','a','o',' '),
376 {'D','o','k','C','h','a','m','p','a',0}},
377 {{Script_Lao_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
378 {LANG_LAO, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
379 MS_MAKE_TAG('l','a','o',' '),
380 {'D','o','k','C','h','a','m','p','a',0}},
381 {{Script_Devanagari, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
382 {LANG_HINDI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
383 MS_MAKE_TAG('d','e','v','a'),
384 {'M','a','n','g','a','l',0}},
385 {{Script_Devanagari_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
386 {LANG_HINDI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
387 MS_MAKE_TAG('d','e','v','a'),
388 {'M','a','n','g','a','l',0}},
389 {{Script_Bengali, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
390 {LANG_BENGALI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
391 MS_MAKE_TAG('b','e','n','g'),
392 {'V','r','i','n','d','a',0}},
393 {{Script_Bengali_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
394 {LANG_BENGALI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
395 MS_MAKE_TAG('b','e','n','g'),
396 {'V','r','i','n','d','a',0}},
397 {{Script_Bengali_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
398 {LANG_BENGALI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
399 MS_MAKE_TAG('b','e','n','g'),
400 {'V','r','i','n','d','a',0}},
401 {{Script_Gurmukhi, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
402 {LANG_PUNJABI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
403 MS_MAKE_TAG('g','u','r','u'),
404 {'R','a','a','v','i',0}},
405 {{Script_Gurmukhi_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
406 {LANG_PUNJABI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
407 MS_MAKE_TAG('g','u','r','u'),
408 {'R','a','a','v','i',0}},
409 {{Script_Gujarati, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
410 {LANG_GUJARATI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
411 MS_MAKE_TAG('g','u','j','r'),
412 {'S','h','r','u','t','i',0}},
413 {{Script_Gujarati_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
414 {LANG_GUJARATI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
415 MS_MAKE_TAG('g','u','j','r'),
416 {'S','h','r','u','t','i',0}},
417 {{Script_Gujarati_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
418 {LANG_GUJARATI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
419 MS_MAKE_TAG('g','u','j','r'),
420 {'S','h','r','u','t','i',0}},
421 {{Script_Oriya, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
422 {LANG_ORIYA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
423 MS_MAKE_TAG('o','r','y','a'),
424 {'K','a','l','i','n','g','a',0}},
425 {{Script_Oriya_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
426 {LANG_ORIYA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
427 MS_MAKE_TAG('o','r','y','a'),
428 {'K','a','l','i','n','g','a',0}},
429 {{Script_Tamil, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
430 {LANG_TAMIL, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
431 MS_MAKE_TAG('t','a','m','l'),
432 {'L','a','t','h','a',0}},
433 {{Script_Tamil_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
434 {LANG_TAMIL, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
435 MS_MAKE_TAG('t','a','m','l'),
436 {'L','a','t','h','a',0}},
437 {{Script_Telugu, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
438 {LANG_TELUGU, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
439 MS_MAKE_TAG('t','e','l','u'),
440 {'G','a','u','t','a','m','i',0}},
441 {{Script_Telugu_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
442 {LANG_TELUGU, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
443 MS_MAKE_TAG('t','e','l','u'),
444 {'G','a','u','t','a','m','i',0}},
445 {{Script_Kannada, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
446 {LANG_KANNADA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
447 MS_MAKE_TAG('k','n','d','a'),
448 {'T','u','n','g','a',0}},
449 {{Script_Kannada_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
450 {LANG_KANNADA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
451 MS_MAKE_TAG('k','n','d','a'),
452 {'T','u','n','g','a',0}},
453 {{Script_Malayalam, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
454 {LANG_MALAYALAM, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
455 MS_MAKE_TAG('m','l','y','m'),
456 {'K','a','r','t','i','k','a',0}},
457 {{Script_Malayalam_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
458 {LANG_MALAYALAM, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
459 MS_MAKE_TAG('m','l','y','m'),
460 {'K','a','r','t','i','k','a',0}},
461 {{Script_Diacritical, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
462 {LANG_ENGLISH, 0, 1, 0, 1, ANSI_CHARSET, 0, 0, 0, 0, 0, 1, 1, 0, 0},
463 0x00000000,
464 {0}},
465 {{Script_Punctuation2, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
466 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
467 MS_MAKE_TAG('l','a','t','n'),
468 {0}},
469 {{Script_Numeric2, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
470 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
471 0x00000000,
472 {0}},
473 {{Script_Myanmar, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
474 {0x55, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
475 MS_MAKE_TAG('m','y','m','r'),
476 {0}},
477 {{Script_Myanmar_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
478 {0x55, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
479 MS_MAKE_TAG('m','y','m','r'),
480 {0}},
481 {{Script_Tai_Le, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
482 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
483 MS_MAKE_TAG('t','a','l','e'),
484 {'M','i','c','r','o','s','o','f','t',' ','T','a','i',' ','L','e'}},
485 {{Script_New_Tai_Lue, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
486 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
487 MS_MAKE_TAG('t','a','l','u'),
488 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
489 {{Script_New_Tai_Lue_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
490 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
491 MS_MAKE_TAG('t','a','l','u'),
492 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
493 {{Script_Khmer, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
494 {0x53, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
495 MS_MAKE_TAG('k','h','m','r'),
496 {'D','a','u','n','P','e','n','h'}},
497 {{Script_Khmer, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
498 {0x53, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
499 MS_MAKE_TAG('k','h','m','r'),
500 {'D','a','u','n','P','e','n','h'}},
501 {{Script_CJK_Han, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
502 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
503 MS_MAKE_TAG('h','a','n','i'),
504 {0}},
505 {{Script_Ideograph, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
506 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
507 MS_MAKE_TAG('h','a','n','i'),
508 {0}},
509 {{Script_Bopomofo, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
510 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
511 MS_MAKE_TAG('b','o','p','o'),
512 {0}},
513 {{Script_Kana, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
514 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
515 MS_MAKE_TAG('k','a','n','a'),
516 {0}},
517 {{Script_Hangul, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
518 {LANG_KOREAN, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
519 MS_MAKE_TAG('h','a','n','g'),
520 {0}},
521 {{Script_Yi, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
522 {LANG_ENGLISH, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
523 MS_MAKE_TAG('y','i',' ',' '),
524 {'M','i','c','r','o','s','o','f','t',' ','Y','i',' ','B','a','i','t','i'}},
525 {{Script_Ethiopic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
526 {0x5e, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
527 MS_MAKE_TAG('e','t','h','i'),
528 {'N','y','a','l','a'}},
529 {{Script_Ethiopic_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
530 {0x5e, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
531 MS_MAKE_TAG('e','t','h','i'),
532 {'N','y','a','l','a'}},
533 {{Script_Mongolian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
534 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
535 MS_MAKE_TAG('m','o','n','g'),
536 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
537 {{Script_Mongolian_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
538 {LANG_MONGOLIAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
539 MS_MAKE_TAG('m','o','n','g'),
540 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
541 {{Script_Tifinagh, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
542 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
543 MS_MAKE_TAG('t','f','n','g'),
544 {'E','b','r','i','m','a'}},
545 {{Script_NKo, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
546 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
547 MS_MAKE_TAG('n','k','o',' '),
548 {0}},
549 {{Script_Vai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
550 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
551 MS_MAKE_TAG('v','a','i',' '),
552 {'E','b','r','i','m','a'}},
553 {{Script_Vai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
554 {0, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
555 MS_MAKE_TAG('v','a','i',' '),
556 {'E','b','r','i','m','a'}},
559 static const SCRIPT_PROPERTIES *script_props[] =
561 &scriptInformation[0].props, &scriptInformation[1].props,
562 &scriptInformation[2].props, &scriptInformation[3].props,
563 &scriptInformation[4].props, &scriptInformation[5].props,
564 &scriptInformation[6].props, &scriptInformation[7].props,
565 &scriptInformation[8].props, &scriptInformation[9].props,
566 &scriptInformation[10].props, &scriptInformation[11].props,
567 &scriptInformation[12].props, &scriptInformation[13].props,
568 &scriptInformation[14].props, &scriptInformation[15].props,
569 &scriptInformation[16].props, &scriptInformation[17].props,
570 &scriptInformation[18].props, &scriptInformation[19].props,
571 &scriptInformation[20].props, &scriptInformation[21].props,
572 &scriptInformation[22].props, &scriptInformation[23].props,
573 &scriptInformation[24].props, &scriptInformation[25].props,
574 &scriptInformation[26].props, &scriptInformation[27].props,
575 &scriptInformation[28].props, &scriptInformation[29].props,
576 &scriptInformation[30].props, &scriptInformation[31].props,
577 &scriptInformation[32].props, &scriptInformation[33].props,
578 &scriptInformation[34].props, &scriptInformation[35].props,
579 &scriptInformation[36].props, &scriptInformation[37].props,
580 &scriptInformation[38].props, &scriptInformation[39].props,
581 &scriptInformation[40].props, &scriptInformation[41].props,
582 &scriptInformation[42].props, &scriptInformation[43].props,
583 &scriptInformation[44].props, &scriptInformation[45].props,
584 &scriptInformation[46].props, &scriptInformation[47].props,
585 &scriptInformation[48].props, &scriptInformation[49].props,
586 &scriptInformation[50].props, &scriptInformation[51].props,
587 &scriptInformation[52].props, &scriptInformation[53].props,
588 &scriptInformation[54].props, &scriptInformation[55].props,
589 &scriptInformation[56].props, &scriptInformation[57].props,
590 &scriptInformation[58].props, &scriptInformation[59].props,
591 &scriptInformation[60].props, &scriptInformation[61].props,
592 &scriptInformation[62].props, &scriptInformation[63].props,
593 &scriptInformation[64].props, &scriptInformation[65].props,
594 &scriptInformation[66].props, &scriptInformation[67].props
597 typedef struct {
598 ScriptCache *sc;
599 int numGlyphs;
600 WORD* glyphs;
601 WORD* pwLogClust;
602 int* piAdvance;
603 SCRIPT_VISATTR* psva;
604 GOFFSET* pGoffset;
605 ABC* abc;
606 int iMaxPosX;
607 HFONT fallbackFont;
608 } StringGlyphs;
610 typedef struct {
611 HDC hdc;
612 DWORD dwFlags;
613 BOOL invalid;
614 int clip_len;
615 int cItems;
616 int cMaxGlyphs;
617 SCRIPT_ITEM* pItem;
618 int numItems;
619 StringGlyphs* glyphs;
620 SCRIPT_LOGATTR* logattrs;
621 SIZE* sz;
622 int* logical2visual;
623 } StringAnalysis;
625 static inline void *heap_alloc(SIZE_T size)
627 return HeapAlloc(GetProcessHeap(), 0, size);
630 static inline void *heap_alloc_zero(SIZE_T size)
632 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
635 static inline void *heap_realloc_zero(LPVOID mem, SIZE_T size)
637 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
640 static inline BOOL heap_free(LPVOID mem)
642 return HeapFree(GetProcessHeap(), 0, mem);
645 static inline WCHAR get_cache_default_char(SCRIPT_CACHE *psc)
647 return ((ScriptCache *)*psc)->tm.tmDefaultChar;
650 static inline LONG get_cache_height(SCRIPT_CACHE *psc)
652 return ((ScriptCache *)*psc)->tm.tmHeight;
655 static inline BYTE get_cache_pitch_family(SCRIPT_CACHE *psc)
657 return ((ScriptCache *)*psc)->tm.tmPitchAndFamily;
660 static inline WORD get_cache_glyph(SCRIPT_CACHE *psc, WCHAR c)
662 WORD *block = ((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
664 if (!block) return 0;
665 return block[c & GLYPH_BLOCK_MASK];
668 static inline WORD set_cache_glyph(SCRIPT_CACHE *psc, WCHAR c, WORD glyph)
670 WORD **block = &((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
672 if (!*block && !(*block = heap_alloc_zero(sizeof(WORD) * GLYPH_BLOCK_SIZE))) return 0;
673 return ((*block)[c & GLYPH_BLOCK_MASK] = glyph);
676 static inline BOOL get_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
678 static const ABC nil;
679 ABC *block = ((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
681 if (!block || !memcmp(&block[glyph & GLYPH_BLOCK_MASK], &nil, sizeof(ABC))) return FALSE;
682 memcpy(abc, &block[glyph & GLYPH_BLOCK_MASK], sizeof(ABC));
683 return TRUE;
686 static inline BOOL set_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
688 ABC **block = &((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
690 if (!*block && !(*block = heap_alloc_zero(sizeof(ABC) * GLYPH_BLOCK_SIZE))) return FALSE;
691 memcpy(&(*block)[glyph & GLYPH_BLOCK_MASK], abc, sizeof(ABC));
692 return TRUE;
695 static HRESULT init_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
697 ScriptCache *sc;
699 if (!psc) return E_INVALIDARG;
700 if (*psc) return S_OK;
701 if (!hdc) return E_PENDING;
703 if (!(sc = heap_alloc_zero(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
704 if (!GetTextMetricsW(hdc, &sc->tm))
706 heap_free(sc);
707 return E_INVALIDARG;
709 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(LOGFONTW), &sc->lf))
711 heap_free(sc);
712 return E_INVALIDARG;
714 sc->sfnt = (GetFontData(hdc, MS_MAKE_TAG('h','e','a','d'), 0, NULL, 0)!=GDI_ERROR);
715 *psc = sc;
716 TRACE("<- %p\n", sc);
717 return S_OK;
720 static WCHAR mirror_char( WCHAR ch )
722 extern const WCHAR wine_mirror_map[];
723 return ch + wine_mirror_map[wine_mirror_map[ch >> 8] + (ch & 0xff)];
726 static WORD get_char_script( WCHAR ch)
728 static const WCHAR latin_punc[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
729 WORD type = 0;
730 int i;
732 if (ch == 0xc || ch == 0x20 || ch == 0x202f)
733 return Script_CR;
735 /* These punctuation are separated out as Latin punctuation */
736 if (strchrW(latin_punc,ch))
737 return Script_Punctuation2;
739 /* These chars are itemized as Punctuation by Windows */
740 if (ch == 0x2212 || ch == 0x2044)
741 return Script_Punctuation;
743 GetStringTypeW(CT_CTYPE1, &ch, 1, &type);
745 if (type == 0)
746 return SCRIPT_UNDEFINED;
748 if (type & C1_CNTRL)
749 return Script_Control;
751 i = 0;
754 if (ch < scriptRanges[i].rangeFirst || scriptRanges[i].script == SCRIPT_UNDEFINED)
755 break;
757 if (ch >= scriptRanges[i].rangeFirst && ch <= scriptRanges[i].rangeLast)
759 if (scriptRanges[i].numericScript && type & C1_DIGIT)
760 return scriptRanges[i].numericScript;
761 if (scriptRanges[i].punctScript && type & C1_PUNCT)
762 return scriptRanges[i].punctScript;
763 return scriptRanges[i].script;
765 i++;
766 } while (1);
768 return SCRIPT_UNDEFINED;
771 /***********************************************************************
772 * DllMain
775 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
777 switch(fdwReason)
779 case DLL_PROCESS_ATTACH:
780 DisableThreadLibraryCalls(hInstDLL);
781 break;
782 case DLL_PROCESS_DETACH:
783 break;
785 return TRUE;
788 /***********************************************************************
789 * ScriptFreeCache (USP10.@)
791 * Free a script cache.
793 * PARAMS
794 * psc [I/O] Script cache.
796 * RETURNS
797 * Success: S_OK
798 * Failure: Non-zero HRESULT value.
800 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
802 TRACE("%p\n", psc);
804 if (psc && *psc)
806 unsigned int i;
807 for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++)
809 heap_free(((ScriptCache *)*psc)->glyphs[i]);
810 heap_free(((ScriptCache *)*psc)->widths[i]);
812 heap_free(((ScriptCache *)*psc)->GSUB_Table);
813 heap_free(((ScriptCache *)*psc)->GDEF_Table);
814 heap_free(((ScriptCache *)*psc)->features);
815 heap_free(*psc);
816 *psc = NULL;
818 return S_OK;
821 /***********************************************************************
822 * ScriptGetProperties (USP10.@)
824 * Retrieve a list of script properties.
826 * PARAMS
827 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
828 * num [I] Pointer to the number of scripts.
830 * RETURNS
831 * Success: S_OK
832 * Failure: Non-zero HRESULT value.
834 * NOTES
835 * Behaviour matches WinXP.
837 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
839 TRACE("(%p,%p)\n", props, num);
841 if (!props && !num) return E_INVALIDARG;
843 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
844 if (props) *props = script_props;
846 return S_OK;
849 /***********************************************************************
850 * ScriptGetFontProperties (USP10.@)
852 * Get information on special glyphs.
854 * PARAMS
855 * hdc [I] Device context.
856 * psc [I/O] Opaque pointer to a script cache.
857 * sfp [O] Font properties structure.
859 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
861 HRESULT hr;
863 TRACE("%p,%p,%p\n", hdc, psc, sfp);
865 if (!sfp) return E_INVALIDARG;
866 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
868 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
869 return E_INVALIDARG;
871 /* return something sensible? */
872 sfp->wgBlank = 0;
873 sfp->wgDefault = get_cache_default_char(psc);
874 sfp->wgInvalid = 0;
875 sfp->wgKashida = 0xffff;
876 sfp->iKashidaWidth = 0;
878 return S_OK;
881 /***********************************************************************
882 * ScriptRecordDigitSubstitution (USP10.@)
884 * Record digit substitution settings for a given locale.
886 * PARAMS
887 * locale [I] Locale identifier.
888 * sds [I] Structure to record substitution settings.
890 * RETURNS
891 * Success: S_OK
892 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
894 * SEE ALSO
895 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
897 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
899 DWORD plgid, sub;
901 TRACE("0x%x, %p\n", locale, sds);
903 /* This implementation appears to be correct for all languages, but it's
904 * not clear if sds->DigitSubstitute is ever set to anything except
905 * CONTEXT or NONE in reality */
907 if (!sds) return E_POINTER;
909 locale = ConvertDefaultLocale(locale);
911 if (!IsValidLocale(locale, LCID_INSTALLED))
912 return E_INVALIDARG;
914 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
915 sds->TraditionalDigitLanguage = plgid;
917 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
918 sds->NationalDigitLanguage = plgid;
919 else
920 sds->NationalDigitLanguage = LANG_ENGLISH;
922 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
923 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
925 switch (sub)
927 case 0:
928 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
929 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
930 else
931 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
932 break;
933 case 1:
934 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
935 break;
936 case 2:
937 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
938 break;
939 default:
940 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
941 break;
944 sds->dwReserved = 0;
945 return S_OK;
948 /***********************************************************************
949 * ScriptApplyDigitSubstitution (USP10.@)
951 * Apply digit substitution settings.
953 * PARAMS
954 * sds [I] Structure with recorded substitution settings.
955 * sc [I] Script control structure.
956 * ss [I] Script state structure.
958 * RETURNS
959 * Success: S_OK
960 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
962 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
963 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
965 SCRIPT_DIGITSUBSTITUTE psds;
967 TRACE("%p, %p, %p\n", sds, sc, ss);
969 if (!sc || !ss) return E_POINTER;
970 if (!sds)
972 sds = &psds;
973 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
974 return E_INVALIDARG;
977 sc->uDefaultLanguage = LANG_ENGLISH;
978 sc->fContextDigits = 0;
979 ss->fDigitSubstitute = 0;
981 switch (sds->DigitSubstitute) {
982 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
983 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
984 case SCRIPT_DIGITSUBSTITUTE_NONE:
985 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
986 return S_OK;
987 default:
988 return E_INVALIDARG;
992 static inline BOOL is_indic(WORD script)
994 return (script >= Script_Devanagari && script <= Script_Malayalam_Numeric);
997 static inline WORD base_indic(WORD script)
999 switch (script)
1001 case Script_Devanagari:
1002 case Script_Devanagari_Numeric: return Script_Devanagari;
1003 case Script_Bengali:
1004 case Script_Bengali_Numeric:
1005 case Script_Bengali_Currency: return Script_Bengali;
1006 case Script_Gurmukhi:
1007 case Script_Gurmukhi_Numeric: return Script_Gurmukhi;
1008 case Script_Gujarati:
1009 case Script_Gujarati_Numeric:
1010 case Script_Gujarati_Currency: return Script_Gujarati;
1011 case Script_Oriya:
1012 case Script_Oriya_Numeric: return Script_Oriya;
1013 case Script_Tamil:
1014 case Script_Tamil_Numeric: return Script_Tamil;
1015 case Script_Telugu:
1016 case Script_Telugu_Numeric: return Script_Telugu;
1017 case Script_Kannada:
1018 case Script_Kannada_Numeric: return Script_Kannada;
1019 case Script_Malayalam:
1020 case Script_Malayalam_Numeric: return Script_Malayalam;
1021 default:
1022 return -1;
1026 /***********************************************************************
1027 * ScriptItemizeOpenType (USP10.@)
1029 * Split a Unicode string into shapeable parts.
1031 * PARAMS
1032 * pwcInChars [I] String to split.
1033 * cInChars [I] Number of characters in pwcInChars.
1034 * cMaxItems [I] Maximum number of items to return.
1035 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1036 * psState [I] Pointer to a SCRIPT_STATE structure.
1037 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1038 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
1039 * pcItems [O] Number of script items returned.
1041 * RETURNS
1042 * Success: S_OK
1043 * Failure: Non-zero HRESULT value.
1045 HRESULT WINAPI ScriptItemizeOpenType(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1046 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1047 SCRIPT_ITEM *pItems, OPENTYPE_TAG *pScriptTags, int *pcItems)
1050 #define Numeric_space 0x0020
1051 #define ZWNJ 0x200C
1052 #define ZWJ 0x200D
1054 int cnt = 0, index = 0, str = 0;
1055 int New_Script = -1;
1056 int i;
1057 WORD *levels = NULL;
1058 WORD *strength = NULL;
1059 WORD *scripts = NULL;
1060 WORD baselevel = 0;
1061 BOOL new_run;
1062 WORD last_indic = -1;
1063 WORD layoutRTL = 0;
1064 BOOL forceLevels = FALSE;
1066 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
1067 psControl, psState, pItems, pcItems);
1069 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
1070 return E_INVALIDARG;
1072 scripts = heap_alloc(cInChars * sizeof(WORD));
1073 if (!scripts)
1074 return E_OUTOFMEMORY;
1076 for (i = 0; i < cInChars; i++)
1078 scripts[i] = get_char_script(pwcInChars[i]);
1079 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
1080 all Indic scripts */
1081 if ((pwcInChars[i] == 0x964 || pwcInChars[i] ==0x965) && last_indic > 0)
1082 scripts[i] = last_indic;
1083 else if (is_indic(scripts[i]))
1084 last_indic = base_indic(scripts[i]);
1086 /* Some unicode points (Zero Width Space U+200B -
1087 Right-to-Left Mark U+200F) will force us into bidi mode */
1088 if (!forceLevels && pwcInChars[i] >= 0x200B && pwcInChars[i] <= 0x200F)
1089 forceLevels = TRUE;
1091 /* Diacritical marks merge with other scripts */
1092 if (scripts[i] == Script_Diacritical && i > 0)
1093 scripts[i] = scripts[i-1];
1096 for (i = 0; i < cInChars; i++)
1098 /* Joiners get merged preferencially right */
1099 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ))
1101 int j;
1102 if (i+1 == cInChars)
1103 scripts[i] = scripts[i-1];
1104 else
1106 for (j = i+1; j < cInChars; j++)
1108 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ && pwcInChars[j] != Numeric_space)
1110 scripts[i] = scripts[j];
1111 break;
1118 if (psState && psControl)
1120 levels = heap_alloc_zero(cInChars * sizeof(WORD));
1121 if (!levels)
1123 heap_free(scripts);
1124 return E_OUTOFMEMORY;
1127 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels);
1128 baselevel = levels[0];
1129 for (i = 0; i < cInChars; i++)
1130 if (levels[i]!=levels[0])
1131 break;
1132 if (i >= cInChars && !odd(baselevel) && !odd(psState->uBidiLevel) && !forceLevels)
1134 heap_free(levels);
1135 levels = NULL;
1137 else
1139 BOOL inNumber = FALSE;
1140 static WCHAR math_punc[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
1142 strength = heap_alloc_zero(cInChars * sizeof(WORD));
1143 if (!strength)
1145 heap_free(scripts);
1146 heap_free(levels);
1147 return E_OUTOFMEMORY;
1149 BIDI_GetStrengths(pwcInChars, cInChars, psControl, strength);
1151 /* We currently mis-level leading Diacriticals */
1152 if (scripts[0] == Script_Diacritical)
1153 for (i = 0; i < cInChars && scripts[0] == Script_Diacritical; i++)
1155 levels[i] = odd(levels[i])?levels[i]+1:levels[i];
1156 strength[i] = BIDI_STRONG;
1159 for (i = 0; i < cInChars; i++)
1161 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
1162 if ((levels[i] == 0 || (odd(psState->uBidiLevel) && levels[i] == psState->uBidiLevel+1)) && inNumber && strchrW(math_punc,pwcInChars[i]))
1164 scripts[i] = Script_Numeric;
1165 levels[i] = 2;
1167 else if ((levels[i] == 0 || (odd(psState->uBidiLevel) && levels[i] == psState->uBidiLevel+1)) && scripts[i] == Script_Numeric)
1169 levels[i] = 2;
1170 inNumber = TRUE;
1172 else
1173 inNumber = FALSE;
1175 /* Joiners get merged preferencially right */
1176 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ))
1178 int j;
1179 if (i+1 == cInChars && levels[i-1] == levels[i])
1180 strength[i] = strength[i-1];
1181 else
1182 for (j = i+1; j < cInChars && levels[i] == levels[j]; j++)
1183 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ && pwcInChars[j] != Numeric_space)
1185 strength[i] = strength[j];
1186 break;
1190 if (psControl->fMergeNeutralItems)
1192 /* Merge the neutrals */
1193 for (i = 0; i < cInChars; i++)
1195 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1197 int j;
1198 for (j = i; j > 0; j--)
1200 if (levels[i] != levels[j])
1201 break;
1202 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1204 scripts[i] = scripts[j];
1205 strength[i] = strength[j];
1206 break;
1210 /* Try going the other way */
1211 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1213 int j;
1214 for (j = i; j < cInChars; j++)
1216 if (levels[i] != levels[j])
1217 break;
1218 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1220 scripts[i] = scripts[j];
1221 strength[i] = strength[j];
1222 break;
1231 while ((!levels || (levels && levels[cnt+1] == levels[0])) && (pwcInChars[cnt] == Numeric_space) && cnt < cInChars)
1232 cnt++;
1234 if (cnt == cInChars) /* All Spaces */
1236 cnt = 0;
1237 New_Script = scripts[cnt];
1240 pItems[index].iCharPos = 0;
1241 pItems[index].a = scriptInformation[scripts[cnt]].a;
1242 pScriptTags[index] = scriptInformation[scripts[cnt]].scriptTag;
1244 if (strength && strength[cnt] == BIDI_STRONG)
1245 str = strength[cnt];
1246 else if (strength)
1247 str = strength[0];
1249 cnt = 0;
1251 if (levels)
1253 if (strength[cnt] == BIDI_STRONG)
1254 layoutRTL = (odd(levels[cnt]))?1:0;
1255 else
1256 layoutRTL = (psState->uBidiLevel || odd(levels[cnt]))?1:0;
1257 pItems[index].a.fRTL = odd(levels[cnt]);
1258 pItems[index].a.fLayoutRTL = layoutRTL;
1259 pItems[index].a.s.uBidiLevel = levels[cnt];
1261 else if (!pItems[index].a.s.uBidiLevel)
1263 layoutRTL = (odd(baselevel))?1:0;
1264 pItems[index].a.s.uBidiLevel = baselevel;
1265 pItems[index].a.fLayoutRTL = odd(baselevel);
1266 pItems[index].a.fRTL = odd(baselevel);
1269 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1270 levels?levels[cnt]:-1, str, New_Script, pItems[index].a.eScript, index, cnt,
1271 pItems[index].iCharPos);
1273 for (cnt=1; cnt < cInChars; cnt++)
1275 if(pwcInChars[cnt] != Numeric_space)
1276 New_Script = scripts[cnt];
1277 else if (levels)
1279 int j = 1;
1280 while (cnt + j < cInChars - 1 && pwcInChars[cnt+j] == Numeric_space && levels[cnt] == levels[cnt+j])
1281 j++;
1282 if (cnt + j < cInChars && levels[cnt] == levels[cnt+j])
1283 New_Script = scripts[cnt+j];
1284 else
1285 New_Script = scripts[cnt];
1288 new_run = FALSE;
1289 /* merge space strengths*/
1290 if (strength && strength[cnt] == BIDI_STRONG && str != BIDI_STRONG && New_Script == pItems[index].a.eScript)
1291 str = BIDI_STRONG;
1293 if (strength && strength[cnt] == BIDI_NEUTRAL && str == BIDI_STRONG && pwcInChars[cnt] != Numeric_space && New_Script == pItems[index].a.eScript)
1294 str = BIDI_NEUTRAL;
1296 /* changes in level */
1297 if (levels && (levels[cnt] != pItems[index].a.s.uBidiLevel))
1299 TRACE("Level break(%i/%i)\n",pItems[index].a.s.uBidiLevel,levels[cnt]);
1300 new_run = TRUE;
1302 /* changes in strength */
1303 else if (strength && pwcInChars[cnt] != Numeric_space && str != strength[cnt])
1305 TRACE("Strength break (%i/%i)\n",str,strength[cnt]);
1306 new_run = TRUE;
1308 /* changes in script */
1309 else if (((pwcInChars[cnt] != Numeric_space) && (New_Script != -1) && (New_Script != pItems[index].a.eScript)) || (New_Script == Script_Control))
1311 TRACE("Script break(%i/%i)\n",pItems[index].a.eScript,New_Script);
1312 new_run = TRUE;
1315 if (!new_run && strength && str == BIDI_STRONG)
1317 layoutRTL = odd(levels[cnt])?1:0;
1318 pItems[index].a.fLayoutRTL = layoutRTL;
1321 if (new_run)
1323 TRACE("New_Level = %i, New_Strength = %i, New_Script=%d, eScript=%d\n", levels?levels[cnt]:-1, strength?strength[cnt]:str, New_Script, pItems[index].a.eScript);
1325 index++;
1326 if (index+1 > cMaxItems)
1327 return E_OUTOFMEMORY;
1329 if (strength)
1330 str = strength[cnt];
1332 pItems[index].iCharPos = cnt;
1333 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1335 pItems[index].a = scriptInformation[New_Script].a;
1336 pScriptTags[index] = scriptInformation[New_Script].scriptTag;
1337 if (levels)
1339 if (levels[cnt] == 0)
1340 layoutRTL = 0;
1341 else
1342 layoutRTL = (layoutRTL || odd(levels[cnt]))?1:0;
1343 pItems[index].a.fRTL = odd(levels[cnt]);
1344 pItems[index].a.fLayoutRTL = layoutRTL;
1345 pItems[index].a.s.uBidiLevel = levels[cnt];
1347 else if (!pItems[index].a.s.uBidiLevel)
1349 pItems[index].a.s.uBidiLevel = baselevel;
1350 pItems[index].a.fLayoutRTL = layoutRTL;
1351 pItems[index].a.fRTL = odd(baselevel);
1354 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1358 /* While not strictly necessary according to the spec, make sure the n+1
1359 * item is set up to prevent random behaviour if the caller erroneously
1360 * checks the n+1 structure */
1361 index++;
1362 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1364 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1366 /* Set one SCRIPT_STATE item being returned */
1367 if (index + 1 > cMaxItems) return E_OUTOFMEMORY;
1368 if (pcItems) *pcItems = index;
1370 /* Set SCRIPT_ITEM */
1371 pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */
1372 heap_free(levels);
1373 heap_free(strength);
1374 heap_free(scripts);
1375 return S_OK;
1378 /***********************************************************************
1379 * ScriptItemize (USP10.@)
1381 * Split a Unicode string into shapeable parts.
1383 * PARAMS
1384 * pwcInChars [I] String to split.
1385 * cInChars [I] Number of characters in pwcInChars.
1386 * cMaxItems [I] Maximum number of items to return.
1387 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1388 * psState [I] Pointer to a SCRIPT_STATE structure.
1389 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1390 * pcItems [O] Number of script items returned.
1392 * RETURNS
1393 * Success: S_OK
1394 * Failure: Non-zero HRESULT value.
1396 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1397 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1398 SCRIPT_ITEM *pItems, int *pcItems)
1400 OPENTYPE_TAG *discarded_tags;
1401 HRESULT res;
1403 discarded_tags = heap_alloc(cMaxItems * sizeof(OPENTYPE_TAG));
1404 if (!discarded_tags)
1405 return E_OUTOFMEMORY;
1406 res = ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, discarded_tags, pcItems);
1407 heap_free(discarded_tags);
1408 return res;
1411 static inline int getGivenTabWidth(ScriptCache *psc, SCRIPT_TABDEF *pTabdef, int charPos, int current_x)
1413 int defWidth;
1414 int cTabStops=0;
1415 INT *lpTabPos = NULL;
1416 INT nTabOrg = 0;
1417 INT x = 0;
1419 if (pTabdef)
1420 lpTabPos = pTabdef->pTabStops;
1422 if (pTabdef && pTabdef->iTabOrigin)
1424 if (pTabdef->iScale)
1425 nTabOrg = (pTabdef->iTabOrigin * pTabdef->iScale)/4;
1426 else
1427 nTabOrg = pTabdef->iTabOrigin * psc->tm.tmAveCharWidth;
1430 if (pTabdef)
1431 cTabStops = pTabdef->cTabStops;
1433 if (cTabStops == 1)
1435 if (pTabdef->iScale)
1436 defWidth = ((pTabdef->pTabStops[0])*pTabdef->iScale) / 4;
1437 else
1438 defWidth = (pTabdef->pTabStops[0])*psc->tm.tmAveCharWidth;
1439 cTabStops = 0;
1441 else
1442 defWidth = 8 * psc->tm.tmAveCharWidth;
1444 for (; cTabStops>0 ; lpTabPos++, cTabStops--)
1446 int position = *lpTabPos;
1447 if (position < 0)
1448 position = -1 * position;
1449 if (pTabdef->iScale)
1450 position = (position * pTabdef->iScale) / 4;
1451 else
1452 position = position * psc->tm.tmAveCharWidth;
1454 if( nTabOrg + position > current_x)
1456 if( *lpTabPos >= 0)
1458 /* a left aligned tab */
1459 x = (nTabOrg + *lpTabPos) - current_x;
1460 break;
1462 else
1464 FIXME("Negative tabstop\n");
1465 break;
1469 if ((!cTabStops) && (defWidth > 0))
1470 x =((((current_x - nTabOrg) / defWidth)+1) * defWidth) - current_x;
1471 else if ((!cTabStops) && (defWidth < 0))
1472 FIXME("TODO: Negative defWidth\n");
1474 return x;
1477 /***********************************************************************
1478 * Helper function for ScriptStringAnalyse
1480 static BOOL requires_fallback(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
1481 const WCHAR *pwcInChars, int cChars )
1483 /* FIXME: When to properly fallback is still a bit of a mystery */
1484 WORD *glyphs;
1486 if (psa->fNoGlyphIndex)
1487 return FALSE;
1489 if (init_script_cache(hdc, psc) != S_OK)
1490 return FALSE;
1492 if (SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa) != S_OK)
1493 return TRUE;
1495 glyphs = heap_alloc(sizeof(WORD) * cChars);
1496 if (!glyphs)
1497 return FALSE;
1498 if (ScriptGetCMap(hdc, psc, pwcInChars, cChars, 0, glyphs) != S_OK)
1500 heap_free(glyphs);
1501 return TRUE;
1503 heap_free(glyphs);
1505 return FALSE;
1508 static void find_fallback_font(DWORD scriptid, LPWSTR FaceName)
1510 HKEY hkey;
1512 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Uniscribe\\Fallback", &hkey))
1514 static const WCHAR szFmt[] = {'%','x',0};
1515 WCHAR value[10];
1516 DWORD count = LF_FACESIZE * sizeof(WCHAR);
1517 DWORD type;
1519 sprintfW(value, szFmt, scriptInformation[scriptid].scriptTag);
1520 if (RegQueryValueExW(hkey, value, 0, &type, (LPBYTE)FaceName, &count))
1521 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1522 RegCloseKey(hkey);
1524 else
1525 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1528 /***********************************************************************
1529 * ScriptStringAnalyse (USP10.@)
1532 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
1533 int cGlyphs, int iCharset, DWORD dwFlags,
1534 int iReqWidth, SCRIPT_CONTROL *psControl,
1535 SCRIPT_STATE *psState, const int *piDx,
1536 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
1537 SCRIPT_STRING_ANALYSIS *pssa)
1539 HRESULT hr = E_OUTOFMEMORY;
1540 StringAnalysis *analysis = NULL;
1541 SCRIPT_CONTROL sControl;
1542 SCRIPT_STATE sState;
1543 int i, num_items = 255;
1544 BYTE *BidiLevel;
1545 WCHAR *iString = NULL;
1547 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1548 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
1549 psControl, psState, piDx, pTabdef, pbInClass, pssa);
1551 if (iCharset != -1)
1553 FIXME("Only Unicode strings are supported\n");
1554 return E_INVALIDARG;
1556 if (cString < 1 || !pString) return E_INVALIDARG;
1557 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
1559 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
1560 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
1562 /* FIXME: handle clipping */
1563 analysis->clip_len = cString;
1564 analysis->hdc = hdc;
1565 analysis->dwFlags = dwFlags;
1567 if (psState)
1568 sState = *psState;
1569 else
1570 memset(&sState, 0, sizeof(SCRIPT_STATE));
1572 if (psControl)
1573 sControl = *psControl;
1574 else
1575 memset(&sControl, 0, sizeof(SCRIPT_CONTROL));
1577 if (dwFlags & SSA_PASSWORD)
1579 iString = heap_alloc(sizeof(WCHAR)*cString);
1580 if (!iString)
1582 hr = E_OUTOFMEMORY;
1583 goto error;
1585 for (i = 0; i < cString; i++)
1586 iString[i] = *((const WCHAR *)pString);
1587 pString = iString;
1590 hr = ScriptItemize(pString, cString, num_items, &sControl, &sState, analysis->pItem,
1591 &analysis->numItems);
1593 while (hr == E_OUTOFMEMORY)
1595 SCRIPT_ITEM *tmp;
1597 num_items *= 2;
1598 if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
1599 goto error;
1601 analysis->pItem = tmp;
1602 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
1603 &analysis->numItems);
1605 if (hr != S_OK) goto error;
1607 /* set back to out of memory for default goto error behaviour */
1608 hr = E_OUTOFMEMORY;
1610 if (dwFlags & SSA_BREAK)
1612 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
1614 for (i = 0; i < analysis->numItems; i++)
1615 ScriptBreak(&((LPWSTR)pString)[analysis->pItem[i].iCharPos], analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos, &analysis->pItem[i].a, &analysis->logattrs[analysis->pItem[i].iCharPos]);
1617 else
1618 goto error;
1621 if (!(analysis->logical2visual = heap_alloc_zero(sizeof(int) * analysis->numItems)))
1622 goto error;
1623 if (!(BidiLevel = heap_alloc_zero(analysis->numItems)))
1624 goto error;
1626 if (dwFlags & SSA_GLYPHS)
1628 int tab_x = 0;
1629 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
1631 heap_free(BidiLevel);
1632 goto error;
1635 for (i = 0; i < analysis->numItems; i++)
1637 SCRIPT_CACHE *sc = (SCRIPT_CACHE*)&analysis->glyphs[i].sc;
1638 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1639 int numGlyphs = 1.5 * cChar + 16;
1640 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
1641 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
1642 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
1643 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * numGlyphs);
1644 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
1645 ABC *abc = heap_alloc_zero(sizeof(ABC));
1646 int numGlyphsReturned;
1647 HFONT originalFont = 0x0;
1649 /* FIXME: non unicode strings */
1650 const WCHAR* pStr = (const WCHAR*)pString;
1651 analysis->glyphs[i].fallbackFont = NULL;
1653 if (!glyphs || !pwLogClust || !piAdvance || !psva || !pGoffset || !abc)
1655 heap_free (BidiLevel);
1656 heap_free (glyphs);
1657 heap_free (pwLogClust);
1658 heap_free (piAdvance);
1659 heap_free (psva);
1660 heap_free (pGoffset);
1661 heap_free (abc);
1662 hr = E_OUTOFMEMORY;
1663 goto error;
1666 if ((dwFlags & SSA_FALLBACK) && requires_fallback(hdc, sc, &analysis->pItem[i].a, &pStr[analysis->pItem[i].iCharPos], cChar))
1668 LOGFONTW lf;
1669 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), & lf);
1670 lf.lfCharSet = scriptInformation[analysis->pItem[i].a.eScript].props.bCharSet;
1671 find_fallback_font(analysis->pItem[i].a.eScript, lf.lfFaceName);
1672 analysis->glyphs[i].fallbackFont = CreateFontIndirectW(&lf);
1673 if (analysis->glyphs[i].fallbackFont)
1675 ScriptFreeCache(sc);
1676 originalFont = SelectObject(hdc, analysis->glyphs[i].fallbackFont);
1680 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
1681 cChar, numGlyphs, &analysis->pItem[i].a,
1682 glyphs, pwLogClust, psva, &numGlyphsReturned);
1683 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
1684 piAdvance, pGoffset, abc);
1685 if (originalFont)
1686 SelectObject(hdc,originalFont);
1688 if (dwFlags & SSA_TAB)
1690 int tabi = 0;
1691 for (tabi = 0; tabi < cChar; tabi++)
1693 if (pStr[analysis->pItem[i].iCharPos+tabi] == 0x0009)
1694 piAdvance[tabi] = getGivenTabWidth(analysis->glyphs[i].sc, pTabdef, analysis->pItem[i].iCharPos+tabi, tab_x);
1695 tab_x+=piAdvance[tabi];
1699 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
1700 analysis->glyphs[i].glyphs = glyphs;
1701 analysis->glyphs[i].pwLogClust = pwLogClust;
1702 analysis->glyphs[i].piAdvance = piAdvance;
1703 analysis->glyphs[i].psva = psva;
1704 analysis->glyphs[i].pGoffset = pGoffset;
1705 analysis->glyphs[i].abc = abc;
1706 analysis->glyphs[i].iMaxPosX= -1;
1708 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
1711 else
1713 for (i = 0; i < analysis->numItems; i++)
1714 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
1717 ScriptLayout(analysis->numItems, BidiLevel, NULL, analysis->logical2visual);
1718 heap_free(BidiLevel);
1720 *pssa = analysis;
1721 heap_free(iString);
1722 return S_OK;
1724 error:
1725 heap_free(iString);
1726 heap_free(analysis->glyphs);
1727 heap_free(analysis->logattrs);
1728 heap_free(analysis->pItem);
1729 heap_free(analysis->logical2visual);
1730 heap_free(analysis);
1731 return hr;
1734 static inline BOOL does_glyph_start_cluster(const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cChars, int glyph, int direction)
1736 int i;
1738 if (pva[glyph].fClusterStart)
1739 return TRUE;
1740 for (i = 0; i < cChars; i++)
1741 if (pwLogClust[i] == glyph) break;
1742 if (i != cChars)
1743 return TRUE;
1745 return FALSE;
1749 static HRESULT SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa,
1750 int iX,
1751 int iY,
1752 int iItem,
1753 int cStart,
1754 int cEnd,
1755 UINT uOptions,
1756 const RECT *prc,
1757 BOOL fSelected,
1758 BOOL fDisabled)
1760 StringAnalysis *analysis;
1761 int off_x = 0;
1762 HRESULT hr;
1763 COLORREF BkColor = 0x0;
1764 COLORREF TextColor = 0x0;
1765 INT BkMode = 0;
1766 INT runStart, runEnd;
1767 INT iGlyph, cGlyphs;
1768 HFONT oldFont = 0x0;
1770 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1771 ssa, iX, iY, iItem, cStart, cEnd, uOptions, fSelected, fDisabled);
1773 if (!(analysis = ssa)) return E_INVALIDARG;
1775 if ((cStart >= 0 && analysis->pItem[iItem+1].iCharPos <= cStart) ||
1776 (cEnd >= 0 && analysis->pItem[iItem].iCharPos >= cEnd))
1777 return S_OK;
1779 if (fSelected)
1781 BkMode = GetBkMode(analysis->hdc);
1782 SetBkMode( analysis->hdc, OPAQUE);
1783 BkColor = GetBkColor(analysis->hdc);
1784 SetBkColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHT));
1785 if (!fDisabled)
1787 TextColor = GetTextColor(analysis->hdc);
1788 SetTextColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
1791 if (analysis->glyphs[iItem].fallbackFont)
1792 oldFont = SelectObject(analysis->hdc, analysis->glyphs[iItem].fallbackFont);
1794 if (cStart >= 0 && analysis->pItem[iItem+1].iCharPos > cStart && analysis->pItem[iItem].iCharPos <= cStart)
1795 runStart = cStart - analysis->pItem[iItem].iCharPos;
1796 else
1797 runStart = 0;
1798 if (cEnd >= 0 && analysis->pItem[iItem+1].iCharPos > cEnd && analysis->pItem[iItem].iCharPos <= cEnd)
1799 runEnd = (cEnd-1) - analysis->pItem[iItem].iCharPos;
1800 else
1801 runEnd = (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos) - 1;
1803 if (analysis->pItem[iItem].a.fRTL)
1805 if (cEnd >= 0 && cEnd < analysis->pItem[iItem+1].iCharPos)
1806 ScriptStringCPtoX(ssa, cEnd, FALSE, &off_x);
1807 else
1808 ScriptStringCPtoX(ssa, analysis->pItem[iItem+1].iCharPos-1, TRUE, &off_x);
1810 else
1812 if (cStart >=0 && runStart)
1813 ScriptStringCPtoX(ssa, cStart, FALSE, &off_x);
1814 else
1815 ScriptStringCPtoX(ssa, analysis->pItem[iItem].iCharPos, FALSE, &off_x);
1818 if (analysis->pItem[iItem].a.fRTL)
1819 iGlyph = analysis->glyphs[iItem].pwLogClust[runEnd];
1820 else
1821 iGlyph = analysis->glyphs[iItem].pwLogClust[runStart];
1823 if (analysis->pItem[iItem].a.fRTL)
1824 cGlyphs = analysis->glyphs[iItem].pwLogClust[runStart] - iGlyph;
1825 else
1826 cGlyphs = analysis->glyphs[iItem].pwLogClust[runEnd] - iGlyph;
1828 cGlyphs++;
1830 if (cEnd < 0 || scriptInformation[analysis->pItem[iItem].a.eScript].props.fNeedsCaretInfo)
1832 INT direction;
1833 INT clust_glyph;
1835 clust_glyph = iGlyph + cGlyphs;
1836 if (analysis->pItem[iItem].a.fRTL)
1837 direction = -1;
1838 else
1839 direction = 1;
1841 while(clust_glyph < analysis->glyphs[iItem].numGlyphs &&
1842 !does_glyph_start_cluster(analysis->glyphs[iItem].psva, analysis->glyphs[iItem].pwLogClust, (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos), clust_glyph, direction))
1844 cGlyphs++;
1845 clust_glyph++;
1849 hr = ScriptTextOut(analysis->hdc,
1850 (SCRIPT_CACHE *)&analysis->glyphs[iItem].sc, iX + off_x,
1851 iY, uOptions, prc, &analysis->pItem[iItem].a, NULL, 0,
1852 &analysis->glyphs[iItem].glyphs[iGlyph], cGlyphs,
1853 &analysis->glyphs[iItem].piAdvance[iGlyph], NULL,
1854 &analysis->glyphs[iItem].pGoffset[iGlyph]);
1856 TRACE("ScriptTextOut hr=%08x\n", hr);
1858 if (fSelected)
1860 SetBkColor(analysis->hdc, BkColor);
1861 SetBkMode( analysis->hdc, BkMode);
1862 if (!fDisabled)
1863 SetTextColor(analysis->hdc, TextColor);
1865 if (analysis->glyphs[iItem].fallbackFont)
1866 SelectObject(analysis->hdc, oldFont);
1868 return hr;
1871 /***********************************************************************
1872 * ScriptStringOut (USP10.@)
1874 * This function takes the output of ScriptStringAnalyse and joins the segments
1875 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1876 * only processes glyphs.
1878 * Parameters:
1879 * ssa [I] buffer to hold the analysed string components
1880 * iX [I] X axis displacement for output
1881 * iY [I] Y axis displacement for output
1882 * uOptions [I] flags controling output processing
1883 * prc [I] rectangle coordinates
1884 * iMinSel [I] starting pos for substringing output string
1885 * iMaxSel [I] ending pos for substringing output string
1886 * fDisabled [I] controls text highlighting
1888 * RETURNS
1889 * Success: S_OK
1890 * Failure: is the value returned by ScriptTextOut
1892 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
1893 int iX,
1894 int iY,
1895 UINT uOptions,
1896 const RECT *prc,
1897 int iMinSel,
1898 int iMaxSel,
1899 BOOL fDisabled)
1901 StringAnalysis *analysis;
1902 int item;
1903 HRESULT hr;
1905 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1906 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
1908 if (!(analysis = ssa)) return E_INVALIDARG;
1909 if (!(analysis->dwFlags & SSA_GLYPHS)) return E_INVALIDARG;
1911 for (item = 0; item < analysis->numItems; item++)
1913 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], -1, -1, uOptions, prc, FALSE, fDisabled);
1914 if (FAILED(hr))
1915 return hr;
1918 if (iMinSel < iMaxSel && (iMinSel > 0 || iMaxSel > 0))
1920 if (iMaxSel > 0 && iMinSel < 0)
1921 iMinSel = 0;
1922 for (item = 0; item < analysis->numItems; item++)
1924 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], iMinSel, iMaxSel, uOptions, prc, TRUE, fDisabled);
1925 if (FAILED(hr))
1926 return hr;
1930 return S_OK;
1933 /***********************************************************************
1934 * ScriptStringCPtoX (USP10.@)
1937 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
1939 int item;
1940 int runningX = 0;
1941 StringAnalysis* analysis = ssa;
1943 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
1945 if (!ssa || !pX) return S_FALSE;
1946 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
1948 /* icp out of range */
1949 if(icp < 0)
1951 analysis->invalid = TRUE;
1952 return E_INVALIDARG;
1955 for(item=0; item<analysis->numItems; item++)
1957 int CP, i;
1958 int offset;
1960 i = analysis->logical2visual[item];
1961 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1962 /* initialize max extents for uninitialized runs */
1963 if (analysis->glyphs[i].iMaxPosX == -1)
1965 if (analysis->pItem[i].a.fRTL)
1966 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1967 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1968 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1969 else
1970 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1971 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1972 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1975 if (icp >= analysis->pItem[i+1].iCharPos || icp < analysis->pItem[i].iCharPos)
1977 runningX += analysis->glyphs[i].iMaxPosX;
1978 continue;
1981 icp -= analysis->pItem[i].iCharPos;
1982 ScriptCPtoX(icp, fTrailing, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1983 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1984 &analysis->pItem[i].a, &offset);
1985 runningX += offset;
1987 *pX = runningX;
1988 return S_OK;
1991 /* icp out of range */
1992 analysis->invalid = TRUE;
1993 return E_INVALIDARG;
1996 /***********************************************************************
1997 * ScriptStringXtoCP (USP10.@)
2000 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
2002 StringAnalysis* analysis = ssa;
2003 int item;
2005 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
2007 if (!ssa || !piCh || !piTrailing) return S_FALSE;
2008 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
2010 /* out of range */
2011 if(iX < 0)
2013 if (analysis->pItem[0].a.fRTL)
2015 *piCh = 1;
2016 *piTrailing = FALSE;
2018 else
2020 *piCh = -1;
2021 *piTrailing = TRUE;
2023 return S_OK;
2026 for(item=0; item<analysis->numItems; item++)
2028 int i;
2029 int CP;
2031 for (i = 0; i < analysis->numItems && analysis->logical2visual[i] != item; i++)
2032 /* nothing */;
2034 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
2035 /* initialize max extents for uninitialized runs */
2036 if (analysis->glyphs[i].iMaxPosX == -1)
2038 if (analysis->pItem[i].a.fRTL)
2039 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2040 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2041 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2042 else
2043 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2044 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2045 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2048 if (iX > analysis->glyphs[i].iMaxPosX)
2050 iX -= analysis->glyphs[i].iMaxPosX;
2051 continue;
2054 ScriptXtoCP(iX, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2055 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2056 &analysis->pItem[i].a, piCh, piTrailing);
2057 *piCh += analysis->pItem[i].iCharPos;
2059 return S_OK;
2062 /* out of range */
2063 *piCh = analysis->pItem[analysis->numItems].iCharPos;
2064 *piTrailing = FALSE;
2066 return S_OK;
2070 /***********************************************************************
2071 * ScriptStringFree (USP10.@)
2073 * Free a string analysis.
2075 * PARAMS
2076 * pssa [I] string analysis.
2078 * RETURNS
2079 * Success: S_OK
2080 * Failure: Non-zero HRESULT value.
2082 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
2084 StringAnalysis* analysis;
2085 BOOL invalid;
2086 int i;
2088 TRACE("(%p)\n", pssa);
2090 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
2092 invalid = analysis->invalid;
2094 if (analysis->glyphs)
2096 for (i = 0; i < analysis->numItems; i++)
2098 heap_free(analysis->glyphs[i].glyphs);
2099 heap_free(analysis->glyphs[i].pwLogClust);
2100 heap_free(analysis->glyphs[i].piAdvance);
2101 heap_free(analysis->glyphs[i].psva);
2102 heap_free(analysis->glyphs[i].pGoffset);
2103 heap_free(analysis->glyphs[i].abc);
2104 if (analysis->glyphs[i].fallbackFont)
2105 DeleteObject(analysis->glyphs[i].fallbackFont);
2106 ScriptFreeCache((SCRIPT_CACHE *)&analysis->glyphs[i].sc);
2107 heap_free(analysis->glyphs[i].sc);
2109 heap_free(analysis->glyphs);
2112 heap_free(analysis->pItem);
2113 heap_free(analysis->logattrs);
2114 heap_free(analysis->sz);
2115 heap_free(analysis->logical2visual);
2116 heap_free(analysis);
2118 if (invalid) return E_INVALIDARG;
2119 return S_OK;
2122 static inline int get_cluster_size(const WORD *pwLogClust, int cChars, int item,
2123 int direction, int* iCluster, int *check_out)
2125 int clust_size = 1;
2126 int check;
2127 WORD clust = pwLogClust[item];
2129 for (check = item+direction; check < cChars && check >= 0; check+=direction)
2131 if (pwLogClust[check] == clust)
2133 clust_size ++;
2134 if (iCluster && *iCluster == -1)
2135 *iCluster = item;
2137 else break;
2140 if (check_out)
2141 *check_out = check;
2143 return clust_size;
2146 static inline int get_glyph_cluster_advance(const int* piAdvance, const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cGlyphs, int cChars, int glyph, int direction)
2148 int advance;
2149 int log_clust_max = 0;
2150 int i;
2152 advance = piAdvance[glyph];
2154 for (i = 0; i < cChars; i++)
2156 if (pwLogClust[i] > log_clust_max)
2157 log_clust_max = pwLogClust[i];
2160 if (glyph > log_clust_max)
2161 return advance;
2163 for (glyph+=direction; glyph < cGlyphs && glyph >= 0; glyph +=direction)
2166 if (does_glyph_start_cluster(pva, pwLogClust, cChars, glyph, direction))
2167 break;
2168 if (glyph > log_clust_max)
2169 break;
2170 advance += piAdvance[glyph];
2173 return advance;
2176 /***********************************************************************
2177 * ScriptCPtoX (USP10.@)
2180 HRESULT WINAPI ScriptCPtoX(int iCP,
2181 BOOL fTrailing,
2182 int cChars,
2183 int cGlyphs,
2184 const WORD *pwLogClust,
2185 const SCRIPT_VISATTR *psva,
2186 const int *piAdvance,
2187 const SCRIPT_ANALYSIS *psa,
2188 int *piX)
2190 int item;
2191 float iPosX;
2192 int iSpecial = -1;
2193 int iCluster = -1;
2194 int clust_size = 1;
2195 float special_size = 0.0;
2196 int iMaxPos = 0;
2197 int advance = 0;
2198 BOOL rtl = FALSE;
2200 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2201 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
2202 psa, piX);
2204 if (psa->fRTL && ! psa->fLogicalOrder)
2205 rtl = TRUE;
2207 if (fTrailing)
2208 iCP++;
2210 if (rtl)
2212 int max_clust = pwLogClust[0];
2214 for (item=0; item < cGlyphs; item++)
2215 if (pwLogClust[item] > max_clust)
2217 ERR("We do not handle non reversed clusters properly\n");
2218 break;
2221 iMaxPos = 0;
2222 for (item = max_clust; item >=0; item --)
2223 iMaxPos += piAdvance[item];
2226 iPosX = 0.0;
2227 for (item=0; item < iCP && item < cChars; item++)
2229 if (iSpecial == -1 && (iCluster == -1 || (iCluster != -1 && iCluster+clust_size <= item)))
2231 int check;
2232 int clust = pwLogClust[item];
2234 iCluster = -1;
2235 clust_size = get_cluster_size(pwLogClust, cChars, item, 1, &iCluster,
2236 &check);
2238 advance = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, clust, 1);
2240 if (check >= cChars && !iMaxPos)
2242 for (check = clust; check < cChars; check++)
2243 special_size += get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, check, 1);
2244 iSpecial = item;
2245 special_size /= (cChars - item);
2246 iPosX += special_size;
2248 else
2250 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2252 clust_size --;
2253 if (clust_size == 0)
2254 iPosX += advance;
2256 else
2257 iPosX += advance / (float)clust_size;
2260 else if (iSpecial != -1)
2261 iPosX += special_size;
2262 else /* (iCluster != -1) */
2264 int adv = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, pwLogClust[iCluster], 1);
2265 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2267 clust_size --;
2268 if (clust_size == 0)
2269 iPosX += adv;
2271 else
2272 iPosX += adv / (float)clust_size;
2276 if (iMaxPos > 0)
2278 iPosX = iMaxPos - iPosX;
2279 if (iPosX < 0)
2280 iPosX = 0;
2283 *piX = iPosX;
2284 TRACE("*piX=%d\n", *piX);
2285 return S_OK;
2288 /***********************************************************************
2289 * ScriptXtoCP (USP10.@)
2292 HRESULT WINAPI ScriptXtoCP(int iX,
2293 int cChars,
2294 int cGlyphs,
2295 const WORD *pwLogClust,
2296 const SCRIPT_VISATTR *psva,
2297 const int *piAdvance,
2298 const SCRIPT_ANALYSIS *psa,
2299 int *piCP,
2300 int *piTrailing)
2302 int item;
2303 float iPosX;
2304 float iLastPosX;
2305 int iSpecial = -1;
2306 int iCluster = -1;
2307 int clust_size = 1;
2308 int cjump = 0;
2309 int advance;
2310 float special_size = 0.0;
2311 int direction = 1;
2313 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2314 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
2315 psa, piCP, piTrailing);
2317 if (psa->fRTL && ! psa->fLogicalOrder)
2318 direction = -1;
2320 if (direction<0)
2322 int max_clust = pwLogClust[0];
2324 if (iX < 0)
2326 *piCP = cChars;
2327 *piTrailing = 0;
2328 return S_OK;
2331 for (item=0; item < cChars; item++)
2332 if (pwLogClust[item] > max_clust)
2334 ERR("We do not handle non reversed clusters properly\n");
2335 break;
2339 if (iX < 0)
2341 *piCP = -1;
2342 *piTrailing = 1;
2343 return S_OK;
2346 iPosX = iLastPosX = 0;
2347 if (direction > 0)
2348 item = 0;
2349 else
2350 item = cChars - 1;
2351 for (; iPosX <= iX && item < cChars && item >= 0; item+=direction)
2353 iLastPosX = iPosX;
2354 if (iSpecial == -1 &&
2355 (iCluster == -1 ||
2356 (iCluster != -1 &&
2357 ((direction > 0 && iCluster+clust_size <= item) ||
2358 (direction < 0 && iCluster-clust_size >= item))
2363 int check;
2364 int clust = pwLogClust[item];
2366 iCluster = -1;
2367 cjump = 0;
2368 clust_size = get_cluster_size(pwLogClust, cChars, item, direction,
2369 &iCluster, &check);
2370 advance = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, clust, direction);
2372 if (check >= cChars && direction > 0)
2374 for (check = clust; check < cChars; check++)
2375 special_size += get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, check, direction);
2376 iSpecial = item;
2377 special_size /= (cChars - item);
2378 iPosX += special_size;
2380 else
2382 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2384 if (!cjump)
2385 iPosX += advance;
2386 cjump++;
2388 else
2389 iPosX += advance / (float)clust_size;
2392 else if (iSpecial != -1)
2393 iPosX += special_size;
2394 else /* (iCluster != -1) */
2396 int adv = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, pwLogClust[iCluster], direction);
2397 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2399 if (!cjump)
2400 iPosX += adv;
2401 cjump++;
2403 else
2404 iPosX += adv / (float)clust_size;
2408 if (direction > 0)
2410 if (iPosX > iX)
2411 item--;
2412 if (item < cChars && ((iPosX - iLastPosX) / 2.0) + iX >= iPosX)
2414 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo && clust_size > 1)
2415 item+=(clust_size-1);
2416 *piTrailing = 1;
2418 else
2419 *piTrailing = 0;
2421 else
2423 if (iX == iLastPosX)
2424 item++;
2425 if (iX >= iLastPosX && iX <= iPosX)
2426 item++;
2428 if (iLastPosX == iX)
2429 *piTrailing = 0;
2430 else if (item < 0 || ((iLastPosX - iPosX) / 2.0) + iX <= iLastPosX)
2432 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo && clust_size > 1)
2433 item-=(clust_size-1);
2434 *piTrailing = 1;
2436 else
2437 *piTrailing = 0;
2440 *piCP = item;
2442 TRACE("*piCP=%d\n", *piCP);
2443 TRACE("*piTrailing=%d\n", *piTrailing);
2444 return S_OK;
2447 /***********************************************************************
2448 * ScriptBreak (USP10.@)
2450 * Retrieve line break information.
2452 * PARAMS
2453 * chars [I] Array of characters.
2454 * sa [I] String analysis.
2455 * la [I] Array of logical attribute structures.
2457 * RETURNS
2458 * Success: S_OK
2459 * Failure: S_FALSE
2461 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
2463 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
2465 if (!la) return S_FALSE;
2467 BREAK_line(chars, count, sa, la);
2469 return S_OK;
2472 /***********************************************************************
2473 * ScriptIsComplex (USP10.@)
2475 * Determine if a string is complex.
2477 * PARAMS
2478 * chars [I] Array of characters to test.
2479 * len [I] Length in characters.
2480 * flag [I] Flag.
2482 * RETURNS
2483 * Success: S_OK
2484 * Failure: S_FALSE
2487 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
2489 int i;
2491 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
2493 for (i = 0; i < len; i++)
2495 int script;
2497 if ((flag & SIC_ASCIIDIGIT) && chars[i] >= 0x30 && chars[i] <= 0x39)
2498 return S_OK;
2500 script = get_char_script(chars[i]);
2501 if ((scriptInformation[script].props.fComplex && (flag & SIC_COMPLEX))||
2502 (!scriptInformation[script].props.fComplex && (flag & SIC_NEUTRAL)))
2503 return S_OK;
2505 return S_FALSE;
2508 /***********************************************************************
2509 * ScriptShapeOpenType (USP10.@)
2511 * Produce glyphs and visual attributes for a run.
2513 * PARAMS
2514 * hdc [I] Device context.
2515 * psc [I/O] Opaque pointer to a script cache.
2516 * psa [I/O] Script analysis.
2517 * tagScript [I] The OpenType tag for the Script
2518 * tagLangSys [I] The OpenType tag for the Language
2519 * rcRangeChars[I] Array of Character counts in each range
2520 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2521 * cRanges [I] Count of ranges
2522 * pwcChars [I] Array of characters specifying the run.
2523 * cChars [I] Number of characters in pwcChars.
2524 * cMaxGlyphs [I] Length of pwOutGlyphs.
2525 * pwLogClust [O] Array of logical cluster info.
2526 * pCharProps [O] Array of character property values
2527 * pwOutGlyphs [O] Array of glyphs.
2528 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2529 * pcGlyphs [O] Number of glyphs returned.
2531 * RETURNS
2532 * Success: S_OK
2533 * Failure: Non-zero HRESULT value.
2535 HRESULT WINAPI ScriptShapeOpenType( HDC hdc, SCRIPT_CACHE *psc,
2536 SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript,
2537 OPENTYPE_TAG tagLangSys, int *rcRangeChars,
2538 TEXTRANGE_PROPERTIES **rpRangeProperties,
2539 int cRanges, const WCHAR *pwcChars, int cChars,
2540 int cMaxGlyphs, WORD *pwLogClust,
2541 SCRIPT_CHARPROP *pCharProps, WORD *pwOutGlyphs,
2542 SCRIPT_GLYPHPROP *pOutGlyphProps, int *pcGlyphs)
2544 HRESULT hr;
2545 unsigned int i;
2546 BOOL rtl;
2548 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2549 hdc, psc, psa,
2550 debugstr_an((char*)&tagScript,4), debugstr_an((char*)&tagLangSys,4),
2551 rcRangeChars, rpRangeProperties, cRanges, debugstr_wn(pwcChars, cChars),
2552 cChars, cMaxGlyphs, pwLogClust, pCharProps, pwOutGlyphs, pOutGlyphProps, pcGlyphs);
2554 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
2555 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
2557 if (!pOutGlyphProps || !pcGlyphs || !pCharProps) return E_INVALIDARG;
2558 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
2560 if (cRanges)
2561 FIXME("Ranges not supported yet\n");
2563 rtl = (psa && !psa->fLogicalOrder && psa->fRTL);
2565 *pcGlyphs = cChars;
2566 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2567 if (!pwLogClust) return E_FAIL;
2569 ((ScriptCache *)*psc)->userScript = tagScript;
2570 ((ScriptCache *)*psc)->userLang = tagLangSys;
2572 /* set fNoGlyphIndex non truetype/opentype fonts */
2573 if (!psa->fNoGlyphIndex && !((ScriptCache *)*psc)->sfnt)
2574 psa->fNoGlyphIndex = TRUE;
2576 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2577 for (i = 0; i < cChars; i++)
2579 int idx = i;
2580 if (rtl) idx = cChars - 1 - i;
2581 /* FIXME: set to better values */
2582 pOutGlyphProps[i].sva.uJustification = (pwcChars[idx] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER;
2583 pOutGlyphProps[i].sva.fClusterStart = 1;
2584 pOutGlyphProps[i].sva.fDiacritic = 0;
2585 pOutGlyphProps[i].sva.fZeroWidth = 0;
2586 pOutGlyphProps[i].sva.fReserved = 0;
2587 pOutGlyphProps[i].sva.fShapeReserved = 0;
2589 /* FIXME: have the shaping engine set this */
2590 pCharProps[i].fCanGlyphAlone = 0;
2592 pwLogClust[i] = idx;
2595 if (psa && !psa->fNoGlyphIndex)
2597 WCHAR *rChars;
2598 if ((hr = SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa)) != S_OK) return hr;
2600 rChars = heap_alloc(sizeof(WCHAR) * cChars);
2601 if (!rChars) return E_OUTOFMEMORY;
2602 for (i = 0; i < cChars; i++)
2604 int idx = i;
2605 WCHAR chInput;
2606 if (rtl) idx = cChars - 1 - i;
2607 if (psa->fRTL)
2608 chInput = mirror_char(pwcChars[idx]);
2609 else
2610 chInput = pwcChars[idx];
2611 /* special case for tabs */
2612 if (chInput == 0x0009)
2613 chInput = 0x0020;
2614 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, chInput)))
2616 WORD glyph;
2617 if (!hdc)
2619 heap_free(rChars);
2620 return E_PENDING;
2622 if (GetGlyphIndicesW(hdc, &chInput, 1, &glyph, 0) == GDI_ERROR)
2624 heap_free(rChars);
2625 return S_FALSE;
2627 pwOutGlyphs[i] = set_cache_glyph(psc, chInput, glyph);
2629 rChars[i] = chInput;
2632 SHAPE_ContextualShaping(hdc, (ScriptCache *)*psc, psa, rChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
2633 SHAPE_ApplyDefaultOpentypeFeatures(hdc, (ScriptCache *)*psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, pwLogClust);
2634 SHAPE_CharGlyphProp(hdc, (ScriptCache *)*psc, psa, pwcChars, cChars, pwOutGlyphs, *pcGlyphs, pwLogClust, pCharProps, pOutGlyphProps);
2635 heap_free(rChars);
2637 else
2639 TRACE("no glyph translation\n");
2640 for (i = 0; i < cChars; i++)
2642 int idx = i;
2643 /* No mirroring done here */
2644 if (rtl) idx = cChars - 1 - i;
2645 pwOutGlyphs[i] = pwcChars[idx];
2649 return S_OK;
2653 /***********************************************************************
2654 * ScriptShape (USP10.@)
2656 * Produce glyphs and visual attributes for a run.
2658 * PARAMS
2659 * hdc [I] Device context.
2660 * psc [I/O] Opaque pointer to a script cache.
2661 * pwcChars [I] Array of characters specifying the run.
2662 * cChars [I] Number of characters in pwcChars.
2663 * cMaxGlyphs [I] Length of pwOutGlyphs.
2664 * psa [I/O] Script analysis.
2665 * pwOutGlyphs [O] Array of glyphs.
2666 * pwLogClust [O] Array of logical cluster info.
2667 * psva [O] Array of visual attributes.
2668 * pcGlyphs [O] Number of glyphs returned.
2670 * RETURNS
2671 * Success: S_OK
2672 * Failure: Non-zero HRESULT value.
2674 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
2675 int cChars, int cMaxGlyphs,
2676 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
2677 SCRIPT_VISATTR *psva, int *pcGlyphs)
2679 HRESULT hr;
2680 int i;
2681 SCRIPT_CHARPROP *charProps;
2682 SCRIPT_GLYPHPROP *glyphProps;
2684 if (!psva || !pcGlyphs) return E_INVALIDARG;
2685 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
2687 charProps = heap_alloc_zero(sizeof(SCRIPT_CHARPROP)*cChars);
2688 if (!charProps) return E_OUTOFMEMORY;
2689 glyphProps = heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP)*cMaxGlyphs);
2690 if (!glyphProps)
2692 heap_free(charProps);
2693 return E_OUTOFMEMORY;
2696 hr = ScriptShapeOpenType(hdc, psc, psa, scriptInformation[psa->eScript].scriptTag, 0, NULL, NULL, 0, pwcChars, cChars, cMaxGlyphs, pwLogClust, charProps, pwOutGlyphs, glyphProps, pcGlyphs);
2698 if (SUCCEEDED(hr))
2700 for (i = 0; i < *pcGlyphs; i++)
2701 psva[i] = glyphProps[i].sva;
2704 heap_free(charProps);
2705 heap_free(glyphProps);
2707 return hr;
2710 /***********************************************************************
2711 * ScriptPlaceOpenType (USP10.@)
2713 * Produce advance widths for a run.
2715 * PARAMS
2716 * hdc [I] Device context.
2717 * psc [I/O] Opaque pointer to a script cache.
2718 * psa [I/O] String analysis.
2719 * tagScript [I] The OpenType tag for the Script
2720 * tagLangSys [I] The OpenType tag for the Language
2721 * rcRangeChars[I] Array of Character counts in each range
2722 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2723 * cRanges [I] Count of ranges
2724 * pwcChars [I] Array of characters specifying the run.
2725 * pwLogClust [I] Array of logical cluster info
2726 * pCharProps [I] Array of character property values
2727 * cChars [I] Number of characters in pwcChars.
2728 * pwGlyphs [I] Array of glyphs.
2729 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2730 * cGlyphs [I] Count of Glyphs
2731 * piAdvance [O] Array of advance widths.
2732 * pGoffset [O] Glyph offsets.
2733 * pABC [O] Combined ABC width.
2735 * RETURNS
2736 * Success: S_OK
2737 * Failure: Non-zero HRESULT value.
2740 HRESULT WINAPI ScriptPlaceOpenType( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
2741 OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys,
2742 int *rcRangeChars, TEXTRANGE_PROPERTIES **rpRangeProperties,
2743 int cRanges, const WCHAR *pwcChars, WORD *pwLogClust,
2744 SCRIPT_CHARPROP *pCharProps, int cChars,
2745 const WORD *pwGlyphs, const SCRIPT_GLYPHPROP *pGlyphProps,
2746 int cGlyphs, int *piAdvance,
2747 GOFFSET *pGoffset, ABC *pABC
2750 HRESULT hr;
2751 int i;
2753 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2754 hdc, psc, psa,
2755 debugstr_an((char*)&tagScript,4), debugstr_an((char*)&tagLangSys,4),
2756 rcRangeChars, rpRangeProperties, cRanges, debugstr_wn(pwcChars, cChars),
2757 pwLogClust, pCharProps, cChars, pwGlyphs, pGlyphProps, cGlyphs, piAdvance,
2758 pGoffset, pABC);
2760 if (!pGlyphProps) return E_INVALIDARG;
2761 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2762 if (!pGoffset) return E_FAIL;
2764 if (cRanges)
2765 FIXME("Ranges not supported yet\n");
2767 ((ScriptCache *)*psc)->userScript = tagScript;
2768 ((ScriptCache *)*psc)->userLang = tagLangSys;
2770 if (pABC) memset(pABC, 0, sizeof(ABC));
2771 for (i = 0; i < cGlyphs; i++)
2773 ABC abc;
2774 if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc))
2776 if (!hdc) return E_PENDING;
2777 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
2779 if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE;
2781 else
2783 INT width;
2784 if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE;
2785 abc.abcB = width;
2786 abc.abcA = abc.abcC = 0;
2788 set_cache_glyph_widths(psc, pwGlyphs[i], &abc);
2790 if (pABC)
2792 pABC->abcA += abc.abcA;
2793 pABC->abcB += abc.abcB;
2794 pABC->abcC += abc.abcC;
2796 /* FIXME: set to more reasonable values */
2797 pGoffset[i].du = pGoffset[i].dv = 0;
2798 if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC;
2801 if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
2802 return S_OK;
2805 /***********************************************************************
2806 * ScriptPlace (USP10.@)
2808 * Produce advance widths for a run.
2810 * PARAMS
2811 * hdc [I] Device context.
2812 * psc [I/O] Opaque pointer to a script cache.
2813 * pwGlyphs [I] Array of glyphs.
2814 * cGlyphs [I] Number of glyphs in pwGlyphs.
2815 * psva [I] Array of visual attributes.
2816 * psa [I/O] String analysis.
2817 * piAdvance [O] Array of advance widths.
2818 * pGoffset [O] Glyph offsets.
2819 * pABC [O] Combined ABC width.
2821 * RETURNS
2822 * Success: S_OK
2823 * Failure: Non-zero HRESULT value.
2825 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
2826 int cGlyphs, const SCRIPT_VISATTR *psva,
2827 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
2829 HRESULT hr;
2830 SCRIPT_GLYPHPROP *glyphProps;
2831 int i;
2833 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa,
2834 piAdvance, pGoffset, pABC);
2836 if (!psva) return E_INVALIDARG;
2837 if (!pGoffset) return E_FAIL;
2839 glyphProps = heap_alloc(sizeof(SCRIPT_GLYPHPROP)*cGlyphs);
2840 if (!glyphProps) return E_OUTOFMEMORY;
2842 for (i = 0; i < cGlyphs; i++)
2843 glyphProps[i].sva = psva[i];
2845 hr = ScriptPlaceOpenType(hdc, psc, psa, scriptInformation[psa->eScript].scriptTag, 0, NULL, NULL, 0, NULL, NULL, NULL, 0, pwGlyphs, glyphProps, cGlyphs, piAdvance, pGoffset, pABC);
2847 heap_free(glyphProps);
2849 return hr;
2852 /***********************************************************************
2853 * ScriptGetCMap (USP10.@)
2855 * Retrieve glyph indices.
2857 * PARAMS
2858 * hdc [I] Device context.
2859 * psc [I/O] Opaque pointer to a script cache.
2860 * pwcInChars [I] Array of Unicode characters.
2861 * cChars [I] Number of characters in pwcInChars.
2862 * dwFlags [I] Flags.
2863 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2865 * RETURNS
2866 * Success: S_OK
2867 * Failure: Non-zero HRESULT value.
2869 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
2870 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
2872 HRESULT hr;
2873 int i;
2875 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
2876 cChars, dwFlags, pwOutGlyphs);
2878 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2880 hr = S_OK;
2882 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
2884 for (i = 0; i < cChars; i++)
2886 WCHAR inChar;
2887 if (dwFlags == SGCM_RTL)
2888 inChar = mirror_char(pwcInChars[i]);
2889 else
2890 inChar = pwcInChars[i];
2891 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, inChar)))
2893 WORD glyph;
2894 if (!hdc) return E_PENDING;
2895 if (GetGlyphIndicesW(hdc, &inChar, 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE;
2896 if (glyph == 0xffff)
2898 hr = S_FALSE;
2899 glyph = 0x0;
2901 pwOutGlyphs[i] = set_cache_glyph(psc, inChar, glyph);
2905 else
2907 TRACE("no glyph translation\n");
2908 for (i = 0; i < cChars; i++)
2910 WCHAR inChar;
2911 if (dwFlags == SGCM_RTL)
2912 inChar = mirror_char(pwcInChars[i]);
2913 else
2914 inChar = pwcInChars[i];
2915 pwOutGlyphs[i] = inChar;
2918 return hr;
2921 /***********************************************************************
2922 * ScriptTextOut (USP10.@)
2925 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
2926 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
2927 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
2928 const int *piJustify, const GOFFSET *pGoffset)
2930 HRESULT hr = S_OK;
2932 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2933 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
2934 piAdvance, piJustify, pGoffset);
2936 if (!hdc || !psc) return E_INVALIDARG;
2937 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
2939 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
2940 fuOptions |= ETO_IGNORELANGUAGE;
2941 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
2942 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
2944 if (psa->fRTL && psa->fLogicalOrder)
2946 int i;
2947 WORD *rtlGlyphs;
2949 rtlGlyphs = heap_alloc(cGlyphs * sizeof(WORD));
2950 if (!rtlGlyphs)
2951 return E_OUTOFMEMORY;
2953 for (i = 0; i < cGlyphs; i++)
2954 rtlGlyphs[i] = pwGlyphs[cGlyphs-1-i];
2956 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, rtlGlyphs, cGlyphs, NULL))
2957 hr = S_FALSE;
2958 heap_free(rtlGlyphs);
2960 else
2961 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
2962 hr = S_FALSE;
2964 return hr;
2967 /***********************************************************************
2968 * ScriptCacheGetHeight (USP10.@)
2970 * Retrieve the height of the font in the cache.
2972 * PARAMS
2973 * hdc [I] Device context.
2974 * psc [I/O] Opaque pointer to a script cache.
2975 * height [O] Receives font height.
2977 * RETURNS
2978 * Success: S_OK
2979 * Failure: Non-zero HRESULT value.
2981 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
2983 HRESULT hr;
2985 TRACE("(%p, %p, %p)\n", hdc, psc, height);
2987 if (!height) return E_INVALIDARG;
2988 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2990 *height = get_cache_height(psc);
2991 return S_OK;
2994 /***********************************************************************
2995 * ScriptGetGlyphABCWidth (USP10.@)
2997 * Retrieve the width of a glyph.
2999 * PARAMS
3000 * hdc [I] Device context.
3001 * psc [I/O] Opaque pointer to a script cache.
3002 * glyph [I] Glyph to retrieve the width for.
3003 * abc [O] ABC widths of the glyph.
3005 * RETURNS
3006 * Success: S_OK
3007 * Failure: Non-zero HRESULT value.
3009 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
3011 HRESULT hr;
3013 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
3015 if (!abc) return E_INVALIDARG;
3016 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
3018 if (!get_cache_glyph_widths(psc, glyph, abc))
3020 if (!hdc) return E_PENDING;
3021 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
3023 if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE;
3025 else
3027 INT width;
3028 if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE;
3029 abc->abcB = width;
3030 abc->abcA = abc->abcC = 0;
3032 set_cache_glyph_widths(psc, glyph, abc);
3034 return S_OK;
3037 /***********************************************************************
3038 * ScriptLayout (USP10.@)
3040 * Map embedding levels to visual and/or logical order.
3042 * PARAMS
3043 * runs [I] Size of level array.
3044 * level [I] Array of embedding levels.
3045 * vistolog [O] Map of embedding levels from visual to logical order.
3046 * logtovis [O] Map of embedding levels from logical to visual order.
3048 * RETURNS
3049 * Success: S_OK
3050 * Failure: Non-zero HRESULT value.
3052 * BUGS
3053 * This stub works correctly for any sequence of a single
3054 * embedding level but not for sequences of different
3055 * embedding levels, i.e. mixtures of RTL and LTR scripts.
3057 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
3059 int* indexs;
3060 int ich;
3062 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
3064 if (!level || (!vistolog && !logtovis))
3065 return E_INVALIDARG;
3067 indexs = heap_alloc(sizeof(int) * runs);
3068 if (!indexs)
3069 return E_OUTOFMEMORY;
3072 if (vistolog)
3074 for( ich = 0; ich < runs; ich++)
3075 indexs[ich] = ich;
3077 ich = 0;
3078 while (ich < runs)
3079 ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
3080 for (ich = 0; ich < runs; ich++)
3081 vistolog[ich] = indexs[ich];
3085 if (logtovis)
3087 for( ich = 0; ich < runs; ich++)
3088 indexs[ich] = ich;
3090 ich = 0;
3091 while (ich < runs)
3092 ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
3093 for (ich = 0; ich < runs; ich++)
3094 logtovis[ich] = indexs[ich];
3096 heap_free(indexs);
3098 return S_OK;
3101 /***********************************************************************
3102 * ScriptStringGetLogicalWidths (USP10.@)
3104 * Returns logical widths from a string analysis.
3106 * PARAMS
3107 * ssa [I] string analysis.
3108 * piDx [O] logical widths returned.
3110 * RETURNS
3111 * Success: S_OK
3112 * Failure: a non-zero HRESULT.
3114 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
3116 int i, j, next = 0;
3117 StringAnalysis *analysis = ssa;
3119 TRACE("%p, %p\n", ssa, piDx);
3121 if (!analysis) return S_FALSE;
3122 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
3124 for (i = 0; i < analysis->numItems; i++)
3126 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
3127 int direction = 1;
3129 if (analysis->pItem[i].a.fRTL && ! analysis->pItem[i].a.fLogicalOrder)
3130 direction = -1;
3132 for (j = 0; j < cChar; j++)
3134 int k;
3135 int glyph = analysis->glyphs[i].pwLogClust[j];
3136 int clust_size = get_cluster_size(analysis->glyphs[i].pwLogClust,
3137 cChar, j, direction, NULL, NULL);
3138 int advance = get_glyph_cluster_advance(analysis->glyphs[i].piAdvance, analysis->glyphs[i].psva, analysis->glyphs[i].pwLogClust, analysis->glyphs[i].numGlyphs, cChar, glyph, direction);
3140 for (k = 0; k < clust_size; k++)
3142 piDx[next] = advance / clust_size;
3143 next++;
3144 if (k) j++;
3148 return S_OK;
3151 /***********************************************************************
3152 * ScriptStringValidate (USP10.@)
3154 * Validate a string analysis.
3156 * PARAMS
3157 * ssa [I] string analysis.
3159 * RETURNS
3160 * Success: S_OK
3161 * Failure: S_FALSE if invalid sequences are found
3162 * or a non-zero HRESULT if it fails.
3164 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
3166 StringAnalysis *analysis = ssa;
3168 TRACE("(%p)\n", ssa);
3170 if (!analysis) return E_INVALIDARG;
3171 return (analysis->invalid) ? S_FALSE : S_OK;
3174 /***********************************************************************
3175 * ScriptString_pSize (USP10.@)
3177 * Retrieve width and height of an analysed string.
3179 * PARAMS
3180 * ssa [I] string analysis.
3182 * RETURNS
3183 * Success: Pointer to a SIZE structure.
3184 * Failure: NULL
3186 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
3188 int i, j;
3189 StringAnalysis *analysis = ssa;
3191 TRACE("(%p)\n", ssa);
3193 if (!analysis) return NULL;
3194 if (!(analysis->dwFlags & SSA_GLYPHS)) return NULL;
3196 if (!analysis->sz)
3198 if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL;
3199 analysis->sz->cy = analysis->glyphs[0].sc->tm.tmHeight;
3201 analysis->sz->cx = 0;
3202 for (i = 0; i < analysis->numItems; i++)
3204 if (analysis->glyphs[i].sc->tm.tmHeight > analysis->sz->cy)
3205 analysis->sz->cy = analysis->glyphs[i].sc->tm.tmHeight;
3206 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
3207 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
3210 return analysis->sz;
3213 /***********************************************************************
3214 * ScriptString_pLogAttr (USP10.@)
3216 * Retrieve logical attributes of an analysed string.
3218 * PARAMS
3219 * ssa [I] string analysis.
3221 * RETURNS
3222 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3223 * Failure: NULL
3225 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
3227 StringAnalysis *analysis = ssa;
3229 TRACE("(%p)\n", ssa);
3231 if (!analysis) return NULL;
3232 if (!(analysis->dwFlags & SSA_BREAK)) return NULL;
3233 return analysis->logattrs;
3236 /***********************************************************************
3237 * ScriptString_pcOutChars (USP10.@)
3239 * Retrieve the length of a string after clipping.
3241 * PARAMS
3242 * ssa [I] String analysis.
3244 * RETURNS
3245 * Success: Pointer to the length.
3246 * Failure: NULL
3248 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
3250 StringAnalysis *analysis = ssa;
3252 TRACE("(%p)\n", ssa);
3254 if (!analysis) return NULL;
3255 return &analysis->clip_len;
3258 /***********************************************************************
3259 * ScriptStringGetOrder (USP10.@)
3261 * Retrieve a glyph order map.
3263 * PARAMS
3264 * ssa [I] String analysis.
3265 * order [I/O] Array of glyph positions.
3267 * RETURNS
3268 * Success: S_OK
3269 * Failure: a non-zero HRESULT.
3271 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
3273 int i, j;
3274 unsigned int k;
3275 StringAnalysis *analysis = ssa;
3277 TRACE("(%p)\n", ssa);
3279 if (!analysis) return S_FALSE;
3280 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
3282 /* FIXME: handle RTL scripts */
3283 for (i = 0, k = 0; i < analysis->numItems; i++)
3284 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
3285 order[k] = k;
3287 return S_OK;
3290 /***********************************************************************
3291 * ScriptGetLogicalWidths (USP10.@)
3293 * Convert advance widths to logical widths.
3295 * PARAMS
3296 * sa [I] Script analysis.
3297 * nbchars [I] Number of characters.
3298 * nbglyphs [I] Number of glyphs.
3299 * glyph_width [I] Array of glyph widths.
3300 * log_clust [I] Array of logical clusters.
3301 * sva [I] Visual attributes.
3302 * widths [O] Array of logical widths.
3304 * RETURNS
3305 * Success: S_OK
3306 * Failure: a non-zero HRESULT.
3308 HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs,
3309 const int *glyph_width, const WORD *log_clust,
3310 const SCRIPT_VISATTR *sva, int *widths)
3312 int i;
3314 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3315 sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths);
3317 /* FIXME */
3318 for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i];
3319 return S_OK;
3322 /***********************************************************************
3323 * ScriptApplyLogicalWidth (USP10.@)
3325 * Generate glyph advance widths.
3327 * PARAMS
3328 * dx [I] Array of logical advance widths.
3329 * num_chars [I] Number of characters.
3330 * num_glyphs [I] Number of glyphs.
3331 * log_clust [I] Array of logical clusters.
3332 * sva [I] Visual attributes.
3333 * advance [I] Array of glyph advance widths.
3334 * sa [I] Script analysis.
3335 * abc [I/O] Summed ABC widths.
3336 * justify [O] Array of glyph advance widths.
3338 * RETURNS
3339 * Success: S_OK
3340 * Failure: a non-zero HRESULT.
3342 HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs,
3343 const WORD *log_clust, const SCRIPT_VISATTR *sva,
3344 const int *advance, const SCRIPT_ANALYSIS *sa,
3345 ABC *abc, int *justify)
3347 int i;
3349 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3350 dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify);
3352 for (i = 0; i < num_chars; i++) justify[i] = advance[i];
3353 return S_OK;
3356 HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance,
3357 int num_glyphs, int dx, int min_kashida, int *justify)
3359 int i;
3361 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify);
3363 for (i = 0; i < num_glyphs; i++) justify[i] = advance[i];
3364 return S_OK;