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
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
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
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 /* Cherokee: U+13A0–U+13FF */
122 { Script_Cherokee
, 0x13a0, 0x13ff, 0, 0},
123 /* Canadian Aboriginal Syllabics: U+1400–U+167F */
124 { Script_Canadian
, 0x1400, 0x167f, 0, 0},
125 /* Ogham: U+1680–U+169F */
126 { Script_Ogham
, 0x1680, 0x169f, 0, 0},
127 /* Runic: U+16A0–U+16F0 */
128 { Script_Runic
, 0x16a0, 0x16f0, 0, 0},
129 /* Khmer: U+1780–U+17FF */
130 { Script_Khmer
, 0x1780, 0x17ff, Script_Khmer_Numeric
, 0},
131 /* Mongolian: U+1800–U+18AF */
132 { Script_Mongolian
, 0x1800, 0x18af, Script_Mongolian_Numeric
, 0},
133 /* Canadian Aboriginal Syllabics Extended: U+18B0–U+18FF */
134 { Script_Canadian
, 0x18b0, 0x18ff, 0, 0},
135 /* Tai Le: U+1950–U+197F */
136 { Script_Tai_Le
, 0x1950, 0x197f, 0, 0},
137 /* New Tai Lue: U+1980–U+19DF */
138 { Script_New_Tai_Lue
,0x1980, 0x19df, Script_New_Tai_Lue_Numeric
, 0},
139 /* Khmer Symbols: U+19E0–U+19FF */
140 { Script_Khmer
, 0x19e0, 0x19ff, Script_Khmer_Numeric
, 0},
141 /* Vedic Extensions: U+1CD0-U+1CFF */
142 { Script_Devanagari
, 0x1cd0, 0x1cff, Script_Devanagari_Numeric
, 0},
143 /* Phonetic Extensions: U+1D00–U+1DBF */
144 { Script_Latin
, 0x1d00, 0x1dbf, 0, 0},
145 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
146 { Script_Diacritical
,0x1dc0, 0x1dff, 0, 0},
147 /* Latin Extended Additional: U+1E00–U+1EFF */
148 { Script_Latin
, 0x1e00, 0x1eff, 0, 0},
149 /* Greek Extended: U+1F00–U+1FFF */
150 { Script_Greek
, 0x1f00, 0x1fff, 0, 0},
151 /* General Punctuation: U+2000 –U+206f */
152 { Script_Latin
, 0x2000, 0x206f, 0, 0},
153 /* Superscripts and Subscripts : U+2070 –U+209f */
154 /* Currency Symbols : U+20a0 –U+20cf */
155 { Script_Numeric2
, 0x2070, 0x2070, 0, 0},
156 { Script_Latin
, 0x2071, 0x2073, 0, 0},
157 { Script_Numeric2
, 0x2074, 0x2079, 0, 0},
158 { Script_Latin
, 0x207a, 0x207f, 0, 0},
159 { Script_Numeric2
, 0x2080, 0x2089, 0, 0},
160 { Script_Latin
, 0x208a, 0x20cf, 0, 0},
161 /* Letterlike Symbols : U+2100 –U+214f */
162 /* Number Forms : U+2150 –U+218f */
163 /* Arrows : U+2190 –U+21ff */
164 /* Mathematical Operators : U+2200 –U+22ff */
165 /* Miscellaneous Technical : U+2300 –U+23ff */
166 /* Control Pictures : U+2400 –U+243f */
167 /* Optical Character Recognition : U+2440 –U+245f */
168 /* Enclosed Alphanumerics : U+2460 –U+24ff */
169 /* Box Drawing : U+2500 –U+25ff */
170 /* Block Elements : U+2580 –U+259f */
171 /* Geometric Shapes : U+25a0 –U+25ff */
172 /* Miscellaneous Symbols : U+2600 –U+26ff */
173 /* Dingbats : U+2700 –U+27bf */
174 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
175 /* Supplemental Arrows-A : U+27f0 –U+27ff */
176 { Script_Latin
, 0x2100, 0x27ff, 0, 0},
177 /* Braille Patterns: U+2800–U+28FF */
178 { Script_Braille
, 0x2800, 0x28ff, 0, 0},
179 /* Supplemental Arrows-B : U+2900 –U+297f */
180 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
181 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
182 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
183 { Script_Latin
, 0x2900, 0x2bff, 0, 0},
184 /* Latin Extended-C: U+2C60–U+2C7F */
185 { Script_Latin
, 0x2c60, 0x2c7f, 0, 0},
186 /* Georgian: U+2D00–U+2D2F */
187 { Script_Georgian
, 0x2d00, 0x2d2f, 0, 0},
188 /* Tifinagh: U+2D30–U+2D7F */
189 { Script_Tifinagh
, 0x2d30, 0x2d7f, 0, 0},
190 /* Ethiopic Extensions: U+2D80–U+2DDF */
191 { Script_Ethiopic
, 0x2d80, 0x2ddf, 0, 0},
192 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
193 { Script_Cyrillic
, 0x2de0, 0x2dff, 0, 0},
194 /* CJK Radicals Supplement: U+2E80–U+2EFF */
195 /* Kangxi Radicals: U+2F00–U+2FDF */
196 { Script_CJK_Han
, 0x2e80, 0x2fdf, 0, 0},
197 /* Ideographic Description Characters: U+2FF0–U+2FFF */
198 { Script_Ideograph
,0x2ff0, 0x2fff, 0, 0},
199 /* CJK Symbols and Punctuation: U+3000–U+303F */
200 { Script_Ideograph
,0x3000, 0x3004, 0, 0},
201 { Script_CJK_Han
,0x3005, 0x3005, 0, 0},
202 { Script_Ideograph
,0x3006, 0x3006, 0, 0},
203 { Script_CJK_Han
,0x3007, 0x3007, 0, 0},
204 { Script_Ideograph
,0x3008, 0x3020, 0, 0},
205 { Script_CJK_Han
,0x3021, 0x3029, 0, 0},
206 { Script_Ideograph
,0x302a, 0x3030, 0, 0},
208 { Script_Kana
,0x3031, 0x3035, 0, 0},
209 { Script_Ideograph
,0x3036, 0x3037, 0, 0},
210 { Script_CJK_Han
,0x3038, 0x303b, 0, 0},
211 { Script_Ideograph
,0x303c, 0x303f, 0, 0},
212 /* Hiragana: U+3040–U+309F */
213 /* Katakana: U+30A0–U+30FF */
214 { Script_Kana
,0x3040, 0x30ff, 0, 0},
215 /* Bopomofo: U+3100–U+312F */
216 { Script_Bopomofo
,0x3100, 0x312f, 0, 0},
217 /* Hangul Compatibility Jamo: U+3130–U+318F */
218 { Script_Hangul
,0x3130, 0x318f, 0, 0},
219 /* Kanbun: U+3190–U+319F */
220 { Script_Ideograph
,0x3190, 0x319f, 0, 0},
221 /* Bopomofo Extended: U+31A0–U+31BF */
222 { Script_Bopomofo
,0x31a0, 0x31bf, 0, 0},
223 /* CJK Strokes: U+31C0–U+31EF */
224 { Script_Ideograph
,0x31c0, 0x31ef, 0, 0},
225 /* Katakana Phonetic Extensions: U+31F0–U+31FF */
226 { Script_Kana
,0x31f0, 0x31ff, 0, 0},
227 /* Enclosed CJK Letters and Months: U+3200–U+32FF */
228 { Script_Hangul
,0x3200, 0x321f, 0, 0},
229 { Script_Ideograph
,0x3220, 0x325f, 0, 0},
230 { Script_Hangul
,0x3260, 0x327f, 0, 0},
231 { Script_Ideograph
,0x3280, 0x32ef, 0, 0},
232 { Script_Kana
,0x32d0, 0x31ff, 0, 0},
233 /* CJK Compatibility: U+3300–U+33FF*/
234 { Script_Kana
,0x3300, 0x3357, 0, 0},
235 { Script_Ideograph
,0x3358, 0x33ff, 0, 0},
236 /* CJK Unified Ideographs Extension A: U+3400–U+4DBF */
237 { Script_CJK_Han
,0x3400, 0x4dbf, 0, 0},
238 /* CJK Unified Ideographs: U+4E00–U+9FFF */
239 { Script_CJK_Han
,0x4e00, 0x9fff, 0, 0},
240 /* Yi: U+A000–U+A4CF */
241 { Script_Yi
,0xa000, 0xa4cf, 0, 0},
242 /* Vai: U+A500–U+A63F */
243 { Script_Vai
,0xa500, 0xa63f, Script_Vai_Numeric
, 0},
244 /* Cyrillic Extended-B: U+A640–U+A69F */
245 { Script_Cyrillic
, 0xa640, 0xa69f, 0, 0},
246 /* Modifier Tone Letters: U+A700–U+A71F */
247 /* Latin Extended-D: U+A720–U+A7FF */
248 { Script_Latin
, 0xa700, 0xa7ff, 0, 0},
249 /* Phags-pa: U+A840–U+A87F */
250 { Script_Phags_pa
, 0xa840, 0xa87f, 0, 0},
251 /* Devanagari Extended: U+A8E0-U+A8FF */
252 { Script_Devanagari
, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric
, 0},
253 /* Myanmar Extended-A: U+AA60–U+AA7F */
254 { Script_Myanmar
, 0xaa60, 0xaa7f, Script_Myanmar_Numeric
, 0},
255 /* Hangul Jamo Extended-A: U+A960–U+A97F */
256 { Script_Hangul
, 0xa960, 0xa97f, 0, 0},
257 /* Hangul Syllables: U+AC00–U+D7A3 */
258 { Script_Hangul
, 0xac00, 0xd7a3, 0, 0},
259 /* Hangul Jamo Extended-B: U+D7B0–U+D7FF */
260 { Script_Hangul
, 0xd7b0, 0xd7ff, 0, 0},
261 /* CJK Compatibility Ideographs: U+F900–U+FAFF */
262 { Script_CJK_Han
,0xf900, 0xfaff, 0, 0},
263 /* Latin Ligatures: U+FB00–U+FB06 */
264 { Script_Latin
, 0xfb00, 0xfb06, 0, 0},
265 /* Armenian ligatures U+FB13..U+FB17 */
266 { Script_Armenian
, 0xfb13, 0xfb17, 0, 0},
267 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
268 { Script_Hebrew
, 0xfb1d, 0xfb4f, 0, 0},
269 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
270 { Script_Arabic
, 0xfb50, 0xfdff, 0, 0},
271 /* Vertical Forms: U+FE10–U+FE1F */
272 /* Combining Half Marks: U+FE20–U+FE2F */
273 /* CJK Compatibility Forms: U+FE30–U+FE4F */
274 /* Small Form Variants: U+FE50–U+FE6F */
275 { Script_Ideograph
,0xfe10, 0xfe6f, 0, 0},
276 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
277 { Script_Arabic
, 0xfe70, 0xfeff, 0, 0},
278 /* Halfwidth and Fullwidth Forms: U+FF00–FFEF */
279 { Script_Ideograph
,0xff00, 0xff64, Script_Numeric2
, 0},
280 { Script_Kana
,0xff65, 0xff9f, 0, 0},
281 { Script_Hangul
,0xffa0, 0xffdf, 0, 0},
282 { Script_Ideograph
,0xffe0, 0xffef, 0, 0},
284 { SCRIPT_UNDEFINED
, 0, 0, 0}
287 typedef struct _scriptData
290 SCRIPT_PROPERTIES props
;
291 OPENTYPE_TAG scriptTag
;
292 WCHAR fallbackFont
[LF_FACESIZE
];
295 /* the must be in order so that the index matches the Script value */
296 static const scriptData scriptInformation
[] = {
297 {{SCRIPT_UNDEFINED
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
298 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
301 {{Script_Latin
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
302 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
303 MS_MAKE_TAG('l','a','t','n'),
305 {{Script_CR
, 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},
309 {{Script_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
310 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
313 {{Script_Control
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
314 {LANG_ENGLISH
, 0, 1, 0, 0, ANSI_CHARSET
, 1, 0, 0, 0, 0, 0, 1, 0, 0},
317 {{Script_Punctuation
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
318 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
321 {{Script_Arabic
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
322 {LANG_ARABIC
, 0, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 1, 0},
323 MS_MAKE_TAG('a','r','a','b'),
324 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
325 {{Script_Arabic_Numeric
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
326 {LANG_ARABIC
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
327 MS_MAKE_TAG('a','r','a','b'),
328 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
329 {{Script_Hebrew
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
330 {LANG_HEBREW
, 0, 1, 0, 1, HEBREW_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
331 MS_MAKE_TAG('h','e','b','r'),
332 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
333 {{Script_Syriac
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
334 {LANG_SYRIAC
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 1, 0},
335 MS_MAKE_TAG('s','y','r','c'),
336 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
337 {{Script_Persian
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
338 {LANG_PERSIAN
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
339 MS_MAKE_TAG('s','y','r','c'),
340 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
341 {{Script_Thaana
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
342 {LANG_DIVEHI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
343 MS_MAKE_TAG('t','h','a','a'),
344 {'M','V',' ','B','o','l','i',0}},
345 {{Script_Greek
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
346 {LANG_GREEK
, 0, 0, 0, 0, GREEK_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
347 MS_MAKE_TAG('g','r','e','k'),
349 {{Script_Cyrillic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
350 {LANG_RUSSIAN
, 0, 0, 0, 0, RUSSIAN_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
351 MS_MAKE_TAG('c','y','r','l'),
353 {{Script_Armenian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
354 {LANG_ARMENIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
355 MS_MAKE_TAG('a','r','m','n'),
356 {'S','y','l','f','a','e','n',0}},
357 {{Script_Georgian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
358 {LANG_GEORGIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
359 MS_MAKE_TAG('g','e','o','r'),
360 {'S','y','l','f','a','e','n',0}},
361 {{Script_Sinhala
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
362 {LANG_SINHALESE
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
363 MS_MAKE_TAG('s','i','n','h'),
364 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
365 {{Script_Tibetan
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
366 {LANG_TIBETAN
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
367 MS_MAKE_TAG('t','i','b','t'),
368 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
369 {{Script_Tibetan_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
370 {LANG_TIBETAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
371 MS_MAKE_TAG('t','i','b','t'),
372 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
373 {{Script_Phags_pa
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
374 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
375 MS_MAKE_TAG('p','h','a','g'),
376 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
377 {{Script_Thai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
378 {LANG_THAI
, 0, 1, 1, 1, THAI_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 1},
379 MS_MAKE_TAG('t','h','a','i'),
380 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
381 {{Script_Thai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
382 {LANG_THAI
, 1, 1, 0, 0, THAI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
383 MS_MAKE_TAG('t','h','a','i'),
384 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
385 {{Script_Lao
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
386 {LANG_LAO
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
387 MS_MAKE_TAG('l','a','o',' '),
388 {'D','o','k','C','h','a','m','p','a',0}},
389 {{Script_Lao_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
390 {LANG_LAO
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
391 MS_MAKE_TAG('l','a','o',' '),
392 {'D','o','k','C','h','a','m','p','a',0}},
393 {{Script_Devanagari
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
394 {LANG_HINDI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
395 MS_MAKE_TAG('d','e','v','a'),
396 {'M','a','n','g','a','l',0}},
397 {{Script_Devanagari_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
398 {LANG_HINDI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
399 MS_MAKE_TAG('d','e','v','a'),
400 {'M','a','n','g','a','l',0}},
401 {{Script_Bengali
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
402 {LANG_BENGALI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
403 MS_MAKE_TAG('b','e','n','g'),
404 {'V','r','i','n','d','a',0}},
405 {{Script_Bengali_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
406 {LANG_BENGALI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
407 MS_MAKE_TAG('b','e','n','g'),
408 {'V','r','i','n','d','a',0}},
409 {{Script_Bengali_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
410 {LANG_BENGALI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
411 MS_MAKE_TAG('b','e','n','g'),
412 {'V','r','i','n','d','a',0}},
413 {{Script_Gurmukhi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
414 {LANG_PUNJABI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
415 MS_MAKE_TAG('g','u','r','u'),
416 {'R','a','a','v','i',0}},
417 {{Script_Gurmukhi_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
418 {LANG_PUNJABI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
419 MS_MAKE_TAG('g','u','r','u'),
420 {'R','a','a','v','i',0}},
421 {{Script_Gujarati
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
422 {LANG_GUJARATI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
423 MS_MAKE_TAG('g','u','j','r'),
424 {'S','h','r','u','t','i',0}},
425 {{Script_Gujarati_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
426 {LANG_GUJARATI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
427 MS_MAKE_TAG('g','u','j','r'),
428 {'S','h','r','u','t','i',0}},
429 {{Script_Gujarati_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
430 {LANG_GUJARATI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
431 MS_MAKE_TAG('g','u','j','r'),
432 {'S','h','r','u','t','i',0}},
433 {{Script_Oriya
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
434 {LANG_ORIYA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
435 MS_MAKE_TAG('o','r','y','a'),
436 {'K','a','l','i','n','g','a',0}},
437 {{Script_Oriya_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
438 {LANG_ORIYA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
439 MS_MAKE_TAG('o','r','y','a'),
440 {'K','a','l','i','n','g','a',0}},
441 {{Script_Tamil
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
442 {LANG_TAMIL
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
443 MS_MAKE_TAG('t','a','m','l'),
444 {'L','a','t','h','a',0}},
445 {{Script_Tamil_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
446 {LANG_TAMIL
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
447 MS_MAKE_TAG('t','a','m','l'),
448 {'L','a','t','h','a',0}},
449 {{Script_Telugu
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
450 {LANG_TELUGU
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
451 MS_MAKE_TAG('t','e','l','u'),
452 {'G','a','u','t','a','m','i',0}},
453 {{Script_Telugu_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
454 {LANG_TELUGU
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
455 MS_MAKE_TAG('t','e','l','u'),
456 {'G','a','u','t','a','m','i',0}},
457 {{Script_Kannada
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
458 {LANG_KANNADA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
459 MS_MAKE_TAG('k','n','d','a'),
460 {'T','u','n','g','a',0}},
461 {{Script_Kannada_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
462 {LANG_KANNADA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
463 MS_MAKE_TAG('k','n','d','a'),
464 {'T','u','n','g','a',0}},
465 {{Script_Malayalam
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
466 {LANG_MALAYALAM
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
467 MS_MAKE_TAG('m','l','y','m'),
468 {'K','a','r','t','i','k','a',0}},
469 {{Script_Malayalam_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
470 {LANG_MALAYALAM
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
471 MS_MAKE_TAG('m','l','y','m'),
472 {'K','a','r','t','i','k','a',0}},
473 {{Script_Diacritical
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
474 {LANG_ENGLISH
, 0, 1, 0, 1, ANSI_CHARSET
, 0, 0, 0, 0, 0, 1, 1, 0, 0},
477 {{Script_Punctuation2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
478 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
479 MS_MAKE_TAG('l','a','t','n'),
481 {{Script_Numeric2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
482 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
485 {{Script_Myanmar
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
486 {0x55, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
487 MS_MAKE_TAG('m','y','m','r'),
489 {{Script_Myanmar_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
490 {0x55, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
491 MS_MAKE_TAG('m','y','m','r'),
493 {{Script_Tai_Le
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
494 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
495 MS_MAKE_TAG('t','a','l','e'),
496 {'M','i','c','r','o','s','o','f','t',' ','T','a','i',' ','L','e'}},
497 {{Script_New_Tai_Lue
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
498 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
499 MS_MAKE_TAG('t','a','l','u'),
500 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
501 {{Script_New_Tai_Lue_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
502 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
503 MS_MAKE_TAG('t','a','l','u'),
504 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
505 {{Script_Khmer
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
506 {0x53, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
507 MS_MAKE_TAG('k','h','m','r'),
508 {'D','a','u','n','P','e','n','h'}},
509 {{Script_Khmer
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
510 {0x53, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
511 MS_MAKE_TAG('k','h','m','r'),
512 {'D','a','u','n','P','e','n','h'}},
513 {{Script_CJK_Han
, 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('h','a','n','i'),
517 {{Script_Ideograph
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
518 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
519 MS_MAKE_TAG('h','a','n','i'),
521 {{Script_Bopomofo
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
522 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
523 MS_MAKE_TAG('b','o','p','o'),
525 {{Script_Kana
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
526 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
527 MS_MAKE_TAG('k','a','n','a'),
529 {{Script_Hangul
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
530 {LANG_KOREAN
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
531 MS_MAKE_TAG('h','a','n','g'),
533 {{Script_Yi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
534 {LANG_ENGLISH
, 0, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
535 MS_MAKE_TAG('y','i',' ',' '),
536 {'M','i','c','r','o','s','o','f','t',' ','Y','i',' ','B','a','i','t','i'}},
537 {{Script_Ethiopic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
538 {0x5e, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
539 MS_MAKE_TAG('e','t','h','i'),
540 {'N','y','a','l','a'}},
541 {{Script_Ethiopic_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
542 {0x5e, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
543 MS_MAKE_TAG('e','t','h','i'),
544 {'N','y','a','l','a'}},
545 {{Script_Mongolian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
546 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
547 MS_MAKE_TAG('m','o','n','g'),
548 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
549 {{Script_Mongolian_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
550 {LANG_MONGOLIAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
551 MS_MAKE_TAG('m','o','n','g'),
552 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
553 {{Script_Tifinagh
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
554 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
555 MS_MAKE_TAG('t','f','n','g'),
556 {'E','b','r','i','m','a'}},
557 {{Script_NKo
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
558 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
559 MS_MAKE_TAG('n','k','o',' '),
561 {{Script_Vai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
562 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
563 MS_MAKE_TAG('v','a','i',' '),
564 {'E','b','r','i','m','a'}},
565 {{Script_Vai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
566 {0, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
567 MS_MAKE_TAG('v','a','i',' '),
568 {'E','b','r','i','m','a'}},
569 {{Script_Cherokee
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
570 {0x5c, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
571 MS_MAKE_TAG('c','h','e','r'),
572 {'P','l','a','n','t','a','g','e','n','e','t',' ','C','h','e','r','o','k','e','e'}},
573 {{Script_Canadian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
574 {0x5d, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
575 MS_MAKE_TAG('c','a','n','s'),
576 {'E','u','p','h','e','m','i','a'}},
577 {{Script_Ogham
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
578 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
579 MS_MAKE_TAG('o','g','a','m'),
580 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l'}},
581 {{Script_Runic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
582 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
583 MS_MAKE_TAG('r','u','n','r'),
584 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l'}},
585 {{Script_Braille
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
586 {LANG_ENGLISH
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
587 MS_MAKE_TAG('b','r','a','i'),
588 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l'}},
591 static const SCRIPT_PROPERTIES
*script_props
[] =
593 &scriptInformation
[0].props
, &scriptInformation
[1].props
,
594 &scriptInformation
[2].props
, &scriptInformation
[3].props
,
595 &scriptInformation
[4].props
, &scriptInformation
[5].props
,
596 &scriptInformation
[6].props
, &scriptInformation
[7].props
,
597 &scriptInformation
[8].props
, &scriptInformation
[9].props
,
598 &scriptInformation
[10].props
, &scriptInformation
[11].props
,
599 &scriptInformation
[12].props
, &scriptInformation
[13].props
,
600 &scriptInformation
[14].props
, &scriptInformation
[15].props
,
601 &scriptInformation
[16].props
, &scriptInformation
[17].props
,
602 &scriptInformation
[18].props
, &scriptInformation
[19].props
,
603 &scriptInformation
[20].props
, &scriptInformation
[21].props
,
604 &scriptInformation
[22].props
, &scriptInformation
[23].props
,
605 &scriptInformation
[24].props
, &scriptInformation
[25].props
,
606 &scriptInformation
[26].props
, &scriptInformation
[27].props
,
607 &scriptInformation
[28].props
, &scriptInformation
[29].props
,
608 &scriptInformation
[30].props
, &scriptInformation
[31].props
,
609 &scriptInformation
[32].props
, &scriptInformation
[33].props
,
610 &scriptInformation
[34].props
, &scriptInformation
[35].props
,
611 &scriptInformation
[36].props
, &scriptInformation
[37].props
,
612 &scriptInformation
[38].props
, &scriptInformation
[39].props
,
613 &scriptInformation
[40].props
, &scriptInformation
[41].props
,
614 &scriptInformation
[42].props
, &scriptInformation
[43].props
,
615 &scriptInformation
[44].props
, &scriptInformation
[45].props
,
616 &scriptInformation
[46].props
, &scriptInformation
[47].props
,
617 &scriptInformation
[48].props
, &scriptInformation
[49].props
,
618 &scriptInformation
[50].props
, &scriptInformation
[51].props
,
619 &scriptInformation
[52].props
, &scriptInformation
[53].props
,
620 &scriptInformation
[54].props
, &scriptInformation
[55].props
,
621 &scriptInformation
[56].props
, &scriptInformation
[57].props
,
622 &scriptInformation
[58].props
, &scriptInformation
[59].props
,
623 &scriptInformation
[60].props
, &scriptInformation
[61].props
,
624 &scriptInformation
[62].props
, &scriptInformation
[63].props
,
625 &scriptInformation
[64].props
, &scriptInformation
[65].props
,
626 &scriptInformation
[66].props
, &scriptInformation
[67].props
,
627 &scriptInformation
[68].props
, &scriptInformation
[69].props
,
628 &scriptInformation
[70].props
, &scriptInformation
[71].props
,
629 &scriptInformation
[72].props
638 SCRIPT_VISATTR
* psva
;
654 StringGlyphs
* glyphs
;
655 SCRIPT_LOGATTR
* logattrs
;
660 static inline void *heap_alloc(SIZE_T size
)
662 return HeapAlloc(GetProcessHeap(), 0, size
);
665 static inline void *heap_alloc_zero(SIZE_T size
)
667 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
670 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
672 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
675 static inline BOOL
heap_free(LPVOID mem
)
677 return HeapFree(GetProcessHeap(), 0, mem
);
680 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
682 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
685 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
687 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
690 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
692 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
695 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
697 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
699 if (!block
) return 0;
700 return block
[c
& GLYPH_BLOCK_MASK
];
703 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
705 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
707 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
708 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
711 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
713 static const ABC nil
;
714 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
716 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
717 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
721 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
723 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
725 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
726 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
730 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
734 if (!psc
) return E_INVALIDARG
;
735 if (*psc
) return S_OK
;
736 if (!hdc
) return E_PENDING
;
738 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
739 if (!GetTextMetricsW(hdc
, &sc
->tm
))
744 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
749 sc
->sfnt
= (GetFontData(hdc
, MS_MAKE_TAG('h','e','a','d'), 0, NULL
, 0)!=GDI_ERROR
);
751 TRACE("<- %p\n", sc
);
755 static WCHAR
mirror_char( WCHAR ch
)
757 extern const WCHAR wine_mirror_map
[];
758 return ch
+ wine_mirror_map
[wine_mirror_map
[ch
>> 8] + (ch
& 0xff)];
761 static WORD
get_char_script( WCHAR ch
)
763 static const WCHAR latin_punc
[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
767 if (ch
== 0xc || ch
== 0x20 || ch
== 0x202f)
770 /* These punctuation are separated out as Latin punctuation */
771 if (strchrW(latin_punc
,ch
))
772 return Script_Punctuation2
;
774 /* These chars are itemized as Punctuation by Windows */
775 if (ch
== 0x2212 || ch
== 0x2044)
776 return Script_Punctuation
;
778 GetStringTypeW(CT_CTYPE1
, &ch
, 1, &type
);
781 return SCRIPT_UNDEFINED
;
784 return Script_Control
;
789 if (ch
< scriptRanges
[i
].rangeFirst
|| scriptRanges
[i
].script
== SCRIPT_UNDEFINED
)
792 if (ch
>= scriptRanges
[i
].rangeFirst
&& ch
<= scriptRanges
[i
].rangeLast
)
794 if (scriptRanges
[i
].numericScript
&& type
& C1_DIGIT
)
795 return scriptRanges
[i
].numericScript
;
796 if (scriptRanges
[i
].punctScript
&& type
& C1_PUNCT
)
797 return scriptRanges
[i
].punctScript
;
798 return scriptRanges
[i
].script
;
803 return SCRIPT_UNDEFINED
;
806 /***********************************************************************
810 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
814 case DLL_PROCESS_ATTACH
:
815 DisableThreadLibraryCalls(hInstDLL
);
817 case DLL_PROCESS_DETACH
:
823 /***********************************************************************
824 * ScriptFreeCache (USP10.@)
826 * Free a script cache.
829 * psc [I/O] Script cache.
833 * Failure: Non-zero HRESULT value.
835 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
842 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
844 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
845 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
847 heap_free(((ScriptCache
*)*psc
)->GSUB_Table
);
848 heap_free(((ScriptCache
*)*psc
)->GDEF_Table
);
849 heap_free(((ScriptCache
*)*psc
)->features
);
856 /***********************************************************************
857 * ScriptGetProperties (USP10.@)
859 * Retrieve a list of script properties.
862 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
863 * num [I] Pointer to the number of scripts.
867 * Failure: Non-zero HRESULT value.
870 * Behaviour matches WinXP.
872 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
874 TRACE("(%p,%p)\n", props
, num
);
876 if (!props
&& !num
) return E_INVALIDARG
;
878 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
879 if (props
) *props
= script_props
;
884 /***********************************************************************
885 * ScriptGetFontProperties (USP10.@)
887 * Get information on special glyphs.
890 * hdc [I] Device context.
891 * psc [I/O] Opaque pointer to a script cache.
892 * sfp [O] Font properties structure.
894 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
898 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
900 if (!sfp
) return E_INVALIDARG
;
901 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
903 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
906 /* return something sensible? */
908 sfp
->wgDefault
= get_cache_default_char(psc
);
910 sfp
->wgKashida
= 0xffff;
911 sfp
->iKashidaWidth
= 0;
916 /***********************************************************************
917 * ScriptRecordDigitSubstitution (USP10.@)
919 * Record digit substitution settings for a given locale.
922 * locale [I] Locale identifier.
923 * sds [I] Structure to record substitution settings.
927 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
930 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
932 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
936 TRACE("0x%x, %p\n", locale
, sds
);
938 /* This implementation appears to be correct for all languages, but it's
939 * not clear if sds->DigitSubstitute is ever set to anything except
940 * CONTEXT or NONE in reality */
942 if (!sds
) return E_POINTER
;
944 locale
= ConvertDefaultLocale(locale
);
946 if (!IsValidLocale(locale
, LCID_INSTALLED
))
949 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
950 sds
->TraditionalDigitLanguage
= plgid
;
952 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
953 sds
->NationalDigitLanguage
= plgid
;
955 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
957 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
958 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
963 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
964 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
966 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
969 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
972 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
975 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
983 /***********************************************************************
984 * ScriptApplyDigitSubstitution (USP10.@)
986 * Apply digit substitution settings.
989 * sds [I] Structure with recorded substitution settings.
990 * sc [I] Script control structure.
991 * ss [I] Script state structure.
995 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
997 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
998 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
1000 SCRIPT_DIGITSUBSTITUTE psds
;
1002 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
1004 if (!sc
|| !ss
) return E_POINTER
;
1008 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
1009 return E_INVALIDARG
;
1012 sc
->uDefaultLanguage
= LANG_ENGLISH
;
1013 sc
->fContextDigits
= 0;
1014 ss
->fDigitSubstitute
= 0;
1016 switch (sds
->DigitSubstitute
) {
1017 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
1018 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
1019 case SCRIPT_DIGITSUBSTITUTE_NONE
:
1020 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
1023 return E_INVALIDARG
;
1027 static inline BOOL
is_indic(WORD script
)
1029 return (script
>= Script_Devanagari
&& script
<= Script_Malayalam_Numeric
);
1032 static inline WORD
base_indic(WORD script
)
1036 case Script_Devanagari
:
1037 case Script_Devanagari_Numeric
: return Script_Devanagari
;
1038 case Script_Bengali
:
1039 case Script_Bengali_Numeric
:
1040 case Script_Bengali_Currency
: return Script_Bengali
;
1041 case Script_Gurmukhi
:
1042 case Script_Gurmukhi_Numeric
: return Script_Gurmukhi
;
1043 case Script_Gujarati
:
1044 case Script_Gujarati_Numeric
:
1045 case Script_Gujarati_Currency
: return Script_Gujarati
;
1047 case Script_Oriya_Numeric
: return Script_Oriya
;
1049 case Script_Tamil_Numeric
: return Script_Tamil
;
1051 case Script_Telugu_Numeric
: return Script_Telugu
;
1052 case Script_Kannada
:
1053 case Script_Kannada_Numeric
: return Script_Kannada
;
1054 case Script_Malayalam
:
1055 case Script_Malayalam_Numeric
: return Script_Malayalam
;
1061 /***********************************************************************
1062 * ScriptItemizeOpenType (USP10.@)
1064 * Split a Unicode string into shapeable parts.
1067 * pwcInChars [I] String to split.
1068 * cInChars [I] Number of characters in pwcInChars.
1069 * cMaxItems [I] Maximum number of items to return.
1070 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1071 * psState [I] Pointer to a SCRIPT_STATE structure.
1072 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1073 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
1074 * pcItems [O] Number of script items returned.
1078 * Failure: Non-zero HRESULT value.
1080 HRESULT WINAPI
ScriptItemizeOpenType(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1081 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1082 SCRIPT_ITEM
*pItems
, OPENTYPE_TAG
*pScriptTags
, int *pcItems
)
1085 #define Numeric_space 0x0020
1089 int cnt
= 0, index
= 0, str
= 0;
1090 int New_Script
= -1;
1092 WORD
*levels
= NULL
;
1093 WORD
*strength
= NULL
;
1094 WORD
*scripts
= NULL
;
1097 WORD last_indic
= -1;
1099 BOOL forceLevels
= FALSE
;
1101 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
1102 psControl
, psState
, pItems
, pcItems
);
1104 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
1105 return E_INVALIDARG
;
1107 scripts
= heap_alloc(cInChars
* sizeof(WORD
));
1109 return E_OUTOFMEMORY
;
1111 for (i
= 0; i
< cInChars
; i
++)
1113 scripts
[i
] = get_char_script(pwcInChars
[i
]);
1114 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
1115 all Indic scripts */
1116 if ((pwcInChars
[i
] == 0x964 || pwcInChars
[i
] ==0x965) && last_indic
> 0)
1117 scripts
[i
] = last_indic
;
1118 else if (is_indic(scripts
[i
]))
1119 last_indic
= base_indic(scripts
[i
]);
1121 /* Some unicode points (Zero Width Space U+200B -
1122 Right-to-Left Mark U+200F) will force us into bidi mode */
1123 if (!forceLevels
&& pwcInChars
[i
] >= 0x200B && pwcInChars
[i
] <= 0x200F)
1126 /* Diacritical marks merge with other scripts */
1127 if (scripts
[i
] == Script_Diacritical
&& i
> 0)
1128 scripts
[i
] = scripts
[i
-1];
1131 for (i
= 0; i
< cInChars
; i
++)
1133 /* Joiners get merged preferencially right */
1134 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
1137 if (i
+1 == cInChars
)
1138 scripts
[i
] = scripts
[i
-1];
1141 for (j
= i
+1; j
< cInChars
; j
++)
1143 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
1145 scripts
[i
] = scripts
[j
];
1153 if (psState
&& psControl
)
1155 levels
= heap_alloc_zero(cInChars
* sizeof(WORD
));
1159 return E_OUTOFMEMORY
;
1162 BIDI_DetermineLevels(pwcInChars
, cInChars
, psState
, psControl
, levels
);
1163 baselevel
= levels
[0];
1164 for (i
= 0; i
< cInChars
; i
++)
1165 if (levels
[i
]!=levels
[0])
1167 if (i
>= cInChars
&& !odd(baselevel
) && !odd(psState
->uBidiLevel
) && !forceLevels
)
1174 BOOL inNumber
= FALSE
;
1175 static WCHAR math_punc
[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
1177 strength
= heap_alloc_zero(cInChars
* sizeof(WORD
));
1182 return E_OUTOFMEMORY
;
1184 BIDI_GetStrengths(pwcInChars
, cInChars
, psControl
, strength
);
1186 /* We currently mis-level leading Diacriticals */
1187 if (scripts
[0] == Script_Diacritical
)
1188 for (i
= 0; i
< cInChars
&& scripts
[0] == Script_Diacritical
; i
++)
1190 levels
[i
] = odd(levels
[i
])?levels
[i
]+1:levels
[i
];
1191 strength
[i
] = BIDI_STRONG
;
1194 for (i
= 0; i
< cInChars
; i
++)
1196 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
1197 if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && inNumber
&& strchrW(math_punc
,pwcInChars
[i
]))
1199 scripts
[i
] = Script_Numeric
;
1202 else if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && scripts
[i
] == Script_Numeric
)
1210 /* Joiners get merged preferencially right */
1211 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
1214 if (i
+1 == cInChars
&& levels
[i
-1] == levels
[i
])
1215 strength
[i
] = strength
[i
-1];
1217 for (j
= i
+1; j
< cInChars
&& levels
[i
] == levels
[j
]; j
++)
1218 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
1220 strength
[i
] = strength
[j
];
1225 if (psControl
->fMergeNeutralItems
)
1227 /* Merge the neutrals */
1228 for (i
= 0; i
< cInChars
; i
++)
1230 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1233 for (j
= i
; j
> 0; j
--)
1235 if (levels
[i
] != levels
[j
])
1237 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1239 scripts
[i
] = scripts
[j
];
1240 strength
[i
] = strength
[j
];
1245 /* Try going the other way */
1246 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1249 for (j
= i
; j
< cInChars
; j
++)
1251 if (levels
[i
] != levels
[j
])
1253 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1255 scripts
[i
] = scripts
[j
];
1256 strength
[i
] = strength
[j
];
1266 while ((!levels
|| (levels
&& levels
[cnt
+1] == levels
[0])) && (pwcInChars
[cnt
] == Numeric_space
) && cnt
< cInChars
)
1269 if (cnt
== cInChars
) /* All Spaces */
1272 New_Script
= scripts
[cnt
];
1275 pItems
[index
].iCharPos
= 0;
1276 pItems
[index
].a
= scriptInformation
[scripts
[cnt
]].a
;
1277 pScriptTags
[index
] = scriptInformation
[scripts
[cnt
]].scriptTag
;
1279 if (strength
&& strength
[cnt
] == BIDI_STRONG
)
1280 str
= strength
[cnt
];
1288 if (strength
[cnt
] == BIDI_STRONG
)
1289 layoutRTL
= (odd(levels
[cnt
]))?1:0;
1291 layoutRTL
= (psState
->uBidiLevel
|| odd(levels
[cnt
]))?1:0;
1292 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1293 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1294 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1296 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1298 layoutRTL
= (odd(baselevel
))?1:0;
1299 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1300 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
1301 pItems
[index
].a
.fRTL
= odd(baselevel
);
1304 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1305 levels
?levels
[cnt
]:-1, str
, New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
1306 pItems
[index
].iCharPos
);
1308 for (cnt
=1; cnt
< cInChars
; cnt
++)
1310 if(pwcInChars
[cnt
] != Numeric_space
)
1311 New_Script
= scripts
[cnt
];
1315 while (cnt
+ j
< cInChars
- 1 && pwcInChars
[cnt
+j
] == Numeric_space
&& levels
[cnt
] == levels
[cnt
+j
])
1317 if (cnt
+ j
< cInChars
&& levels
[cnt
] == levels
[cnt
+j
])
1318 New_Script
= scripts
[cnt
+j
];
1320 New_Script
= scripts
[cnt
];
1324 /* merge space strengths*/
1325 if (strength
&& strength
[cnt
] == BIDI_STRONG
&& str
!= BIDI_STRONG
&& New_Script
== pItems
[index
].a
.eScript
)
1328 if (strength
&& strength
[cnt
] == BIDI_NEUTRAL
&& str
== BIDI_STRONG
&& pwcInChars
[cnt
] != Numeric_space
&& New_Script
== pItems
[index
].a
.eScript
)
1331 /* changes in level */
1332 if (levels
&& (levels
[cnt
] != pItems
[index
].a
.s
.uBidiLevel
))
1334 TRACE("Level break(%i/%i)\n",pItems
[index
].a
.s
.uBidiLevel
,levels
[cnt
]);
1337 /* changes in strength */
1338 else if (strength
&& pwcInChars
[cnt
] != Numeric_space
&& str
!= strength
[cnt
])
1340 TRACE("Strength break (%i/%i)\n",str
,strength
[cnt
]);
1343 /* changes in script */
1344 else if (((pwcInChars
[cnt
] != Numeric_space
) && (New_Script
!= -1) && (New_Script
!= pItems
[index
].a
.eScript
)) || (New_Script
== Script_Control
))
1346 TRACE("Script break(%i/%i)\n",pItems
[index
].a
.eScript
,New_Script
);
1350 if (!new_run
&& strength
&& str
== BIDI_STRONG
)
1352 layoutRTL
= odd(levels
[cnt
])?1:0;
1353 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1358 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
);
1361 if (index
+1 > cMaxItems
)
1362 return E_OUTOFMEMORY
;
1365 str
= strength
[cnt
];
1367 pItems
[index
].iCharPos
= cnt
;
1368 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1370 pItems
[index
].a
= scriptInformation
[New_Script
].a
;
1371 pScriptTags
[index
] = scriptInformation
[New_Script
].scriptTag
;
1374 if (levels
[cnt
] == 0)
1377 layoutRTL
= (layoutRTL
|| odd(levels
[cnt
]))?1:0;
1378 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1379 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1380 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1382 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1384 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1385 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1386 pItems
[index
].a
.fRTL
= odd(baselevel
);
1389 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1393 /* While not strictly necessary according to the spec, make sure the n+1
1394 * item is set up to prevent random behaviour if the caller erroneously
1395 * checks the n+1 structure */
1397 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1399 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1401 /* Set one SCRIPT_STATE item being returned */
1402 if (index
+ 1 > cMaxItems
) return E_OUTOFMEMORY
;
1403 if (pcItems
) *pcItems
= index
;
1405 /* Set SCRIPT_ITEM */
1406 pItems
[index
].iCharPos
= cnt
; /* the last item contains the ptr to the lastchar */
1408 heap_free(strength
);
1413 /***********************************************************************
1414 * ScriptItemize (USP10.@)
1416 * Split a Unicode string into shapeable parts.
1419 * pwcInChars [I] String to split.
1420 * cInChars [I] Number of characters in pwcInChars.
1421 * cMaxItems [I] Maximum number of items to return.
1422 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1423 * psState [I] Pointer to a SCRIPT_STATE structure.
1424 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1425 * pcItems [O] Number of script items returned.
1429 * Failure: Non-zero HRESULT value.
1431 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1432 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1433 SCRIPT_ITEM
*pItems
, int *pcItems
)
1435 OPENTYPE_TAG
*discarded_tags
;
1438 discarded_tags
= heap_alloc(cMaxItems
* sizeof(OPENTYPE_TAG
));
1439 if (!discarded_tags
)
1440 return E_OUTOFMEMORY
;
1441 res
= ScriptItemizeOpenType(pwcInChars
, cInChars
, cMaxItems
, psControl
, psState
, pItems
, discarded_tags
, pcItems
);
1442 heap_free(discarded_tags
);
1446 static inline int getGivenTabWidth(ScriptCache
*psc
, SCRIPT_TABDEF
*pTabdef
, int charPos
, int current_x
)
1450 INT
*lpTabPos
= NULL
;
1455 lpTabPos
= pTabdef
->pTabStops
;
1457 if (pTabdef
&& pTabdef
->iTabOrigin
)
1459 if (pTabdef
->iScale
)
1460 nTabOrg
= (pTabdef
->iTabOrigin
* pTabdef
->iScale
)/4;
1462 nTabOrg
= pTabdef
->iTabOrigin
* psc
->tm
.tmAveCharWidth
;
1466 cTabStops
= pTabdef
->cTabStops
;
1470 if (pTabdef
->iScale
)
1471 defWidth
= ((pTabdef
->pTabStops
[0])*pTabdef
->iScale
) / 4;
1473 defWidth
= (pTabdef
->pTabStops
[0])*psc
->tm
.tmAveCharWidth
;
1477 defWidth
= 8 * psc
->tm
.tmAveCharWidth
;
1479 for (; cTabStops
>0 ; lpTabPos
++, cTabStops
--)
1481 int position
= *lpTabPos
;
1483 position
= -1 * position
;
1484 if (pTabdef
->iScale
)
1485 position
= (position
* pTabdef
->iScale
) / 4;
1487 position
= position
* psc
->tm
.tmAveCharWidth
;
1489 if( nTabOrg
+ position
> current_x
)
1493 /* a left aligned tab */
1494 x
= (nTabOrg
+ *lpTabPos
) - current_x
;
1499 FIXME("Negative tabstop\n");
1504 if ((!cTabStops
) && (defWidth
> 0))
1505 x
=((((current_x
- nTabOrg
) / defWidth
)+1) * defWidth
) - current_x
;
1506 else if ((!cTabStops
) && (defWidth
< 0))
1507 FIXME("TODO: Negative defWidth\n");
1512 /***********************************************************************
1513 * Helper function for ScriptStringAnalyse
1515 static BOOL
requires_fallback(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
1516 const WCHAR
*pwcInChars
, int cChars
)
1518 /* FIXME: When to properly fallback is still a bit of a mystery */
1521 if (psa
->fNoGlyphIndex
)
1524 if (init_script_cache(hdc
, psc
) != S_OK
)
1527 if (SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
) != S_OK
)
1530 glyphs
= heap_alloc(sizeof(WORD
) * cChars
);
1533 if (ScriptGetCMap(hdc
, psc
, pwcInChars
, cChars
, 0, glyphs
) != S_OK
)
1543 static void find_fallback_font(DWORD scriptid
, LPWSTR FaceName
)
1547 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Uniscribe\\Fallback", &hkey
))
1549 static const WCHAR szFmt
[] = {'%','x',0};
1551 DWORD count
= LF_FACESIZE
* sizeof(WCHAR
);
1554 sprintfW(value
, szFmt
, scriptInformation
[scriptid
].scriptTag
);
1555 if (RegQueryValueExW(hkey
, value
, 0, &type
, (LPBYTE
)FaceName
, &count
))
1556 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1560 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1563 /***********************************************************************
1564 * ScriptStringAnalyse (USP10.@)
1567 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
1568 int cGlyphs
, int iCharset
, DWORD dwFlags
,
1569 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
1570 SCRIPT_STATE
*psState
, const int *piDx
,
1571 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
1572 SCRIPT_STRING_ANALYSIS
*pssa
)
1574 HRESULT hr
= E_OUTOFMEMORY
;
1575 StringAnalysis
*analysis
= NULL
;
1576 SCRIPT_CONTROL sControl
;
1577 SCRIPT_STATE sState
;
1578 int i
, num_items
= 255;
1580 WCHAR
*iString
= NULL
;
1582 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1583 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
1584 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
1588 FIXME("Only Unicode strings are supported\n");
1589 return E_INVALIDARG
;
1591 if (cString
< 1 || !pString
) return E_INVALIDARG
;
1592 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
1594 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
1595 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
1597 /* FIXME: handle clipping */
1598 analysis
->clip_len
= cString
;
1599 analysis
->hdc
= hdc
;
1600 analysis
->dwFlags
= dwFlags
;
1605 memset(&sState
, 0, sizeof(SCRIPT_STATE
));
1608 sControl
= *psControl
;
1610 memset(&sControl
, 0, sizeof(SCRIPT_CONTROL
));
1612 if (dwFlags
& SSA_PASSWORD
)
1614 iString
= heap_alloc(sizeof(WCHAR
)*cString
);
1620 for (i
= 0; i
< cString
; i
++)
1621 iString
[i
] = *((const WCHAR
*)pString
);
1625 hr
= ScriptItemize(pString
, cString
, num_items
, &sControl
, &sState
, analysis
->pItem
,
1626 &analysis
->numItems
);
1628 while (hr
== E_OUTOFMEMORY
)
1633 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
1636 analysis
->pItem
= tmp
;
1637 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
1638 &analysis
->numItems
);
1640 if (hr
!= S_OK
) goto error
;
1642 /* set back to out of memory for default goto error behaviour */
1645 if (dwFlags
& SSA_BREAK
)
1647 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
1649 for (i
= 0; i
< analysis
->numItems
; i
++)
1650 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
]);
1656 if (!(analysis
->logical2visual
= heap_alloc_zero(sizeof(int) * analysis
->numItems
)))
1658 if (!(BidiLevel
= heap_alloc_zero(analysis
->numItems
)))
1661 if (dwFlags
& SSA_GLYPHS
)
1664 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
1666 heap_free(BidiLevel
);
1670 for (i
= 0; i
< analysis
->numItems
; i
++)
1672 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
;
1673 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1674 int numGlyphs
= 1.5 * cChar
+ 16;
1675 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
1676 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
1677 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
1678 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * numGlyphs
);
1679 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
1680 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
1681 int numGlyphsReturned
;
1682 HFONT originalFont
= 0x0;
1684 /* FIXME: non unicode strings */
1685 const WCHAR
* pStr
= (const WCHAR
*)pString
;
1686 analysis
->glyphs
[i
].fallbackFont
= NULL
;
1688 if (!glyphs
|| !pwLogClust
|| !piAdvance
|| !psva
|| !pGoffset
|| !abc
)
1690 heap_free (BidiLevel
);
1692 heap_free (pwLogClust
);
1693 heap_free (piAdvance
);
1695 heap_free (pGoffset
);
1701 if ((dwFlags
& SSA_FALLBACK
) && requires_fallback(hdc
, sc
, &analysis
->pItem
[i
].a
, &pStr
[analysis
->pItem
[i
].iCharPos
], cChar
))
1704 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), & lf
);
1705 lf
.lfCharSet
= scriptInformation
[analysis
->pItem
[i
].a
.eScript
].props
.bCharSet
;
1706 find_fallback_font(analysis
->pItem
[i
].a
.eScript
, lf
.lfFaceName
);
1707 analysis
->glyphs
[i
].fallbackFont
= CreateFontIndirectW(&lf
);
1708 if (analysis
->glyphs
[i
].fallbackFont
)
1710 ScriptFreeCache(sc
);
1711 originalFont
= SelectObject(hdc
, analysis
->glyphs
[i
].fallbackFont
);
1715 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
1716 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
1717 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
1718 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
1719 piAdvance
, pGoffset
, abc
);
1721 SelectObject(hdc
,originalFont
);
1723 if (dwFlags
& SSA_TAB
)
1726 for (tabi
= 0; tabi
< cChar
; tabi
++)
1728 if (pStr
[analysis
->pItem
[i
].iCharPos
+tabi
] == 0x0009)
1729 piAdvance
[tabi
] = getGivenTabWidth(analysis
->glyphs
[i
].sc
, pTabdef
, analysis
->pItem
[i
].iCharPos
+tabi
, tab_x
);
1730 tab_x
+=piAdvance
[tabi
];
1734 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
1735 analysis
->glyphs
[i
].glyphs
= glyphs
;
1736 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
1737 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
1738 analysis
->glyphs
[i
].psva
= psva
;
1739 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
1740 analysis
->glyphs
[i
].abc
= abc
;
1741 analysis
->glyphs
[i
].iMaxPosX
= -1;
1743 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1748 for (i
= 0; i
< analysis
->numItems
; i
++)
1749 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1752 ScriptLayout(analysis
->numItems
, BidiLevel
, NULL
, analysis
->logical2visual
);
1753 heap_free(BidiLevel
);
1761 heap_free(analysis
->glyphs
);
1762 heap_free(analysis
->logattrs
);
1763 heap_free(analysis
->pItem
);
1764 heap_free(analysis
->logical2visual
);
1765 heap_free(analysis
);
1769 static inline BOOL
does_glyph_start_cluster(const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cChars
, int glyph
, int direction
)
1773 if (pva
[glyph
].fClusterStart
)
1775 for (i
= 0; i
< cChars
; i
++)
1776 if (pwLogClust
[i
] == glyph
) break;
1784 static HRESULT
SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa
,
1795 StringAnalysis
*analysis
;
1798 COLORREF BkColor
= 0x0;
1799 COLORREF TextColor
= 0x0;
1801 INT runStart
, runEnd
;
1802 INT iGlyph
, cGlyphs
;
1803 HFONT oldFont
= 0x0;
1805 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1806 ssa
, iX
, iY
, iItem
, cStart
, cEnd
, uOptions
, fSelected
, fDisabled
);
1808 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1810 if ((cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
<= cStart
) ||
1811 (cEnd
>= 0 && analysis
->pItem
[iItem
].iCharPos
>= cEnd
))
1816 BkMode
= GetBkMode(analysis
->hdc
);
1817 SetBkMode( analysis
->hdc
, OPAQUE
);
1818 BkColor
= GetBkColor(analysis
->hdc
);
1819 SetBkColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1822 TextColor
= GetTextColor(analysis
->hdc
);
1823 SetTextColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1826 if (analysis
->glyphs
[iItem
].fallbackFont
)
1827 oldFont
= SelectObject(analysis
->hdc
, analysis
->glyphs
[iItem
].fallbackFont
);
1829 if (cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cStart
&& analysis
->pItem
[iItem
].iCharPos
<= cStart
)
1830 runStart
= cStart
- analysis
->pItem
[iItem
].iCharPos
;
1833 if (cEnd
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cEnd
&& analysis
->pItem
[iItem
].iCharPos
<= cEnd
)
1834 runEnd
= (cEnd
-1) - analysis
->pItem
[iItem
].iCharPos
;
1836 runEnd
= (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
) - 1;
1838 if (analysis
->pItem
[iItem
].a
.fRTL
)
1840 if (cEnd
>= 0 && cEnd
< analysis
->pItem
[iItem
+1].iCharPos
)
1841 ScriptStringCPtoX(ssa
, cEnd
, FALSE
, &off_x
);
1843 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
+1].iCharPos
-1, TRUE
, &off_x
);
1847 if (cStart
>=0 && runStart
)
1848 ScriptStringCPtoX(ssa
, cStart
, FALSE
, &off_x
);
1850 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
].iCharPos
, FALSE
, &off_x
);
1853 if (analysis
->pItem
[iItem
].a
.fRTL
)
1854 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
];
1856 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
];
1858 if (analysis
->pItem
[iItem
].a
.fRTL
)
1859 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
] - iGlyph
;
1861 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
] - iGlyph
;
1865 if (cEnd
< 0 || scriptInformation
[analysis
->pItem
[iItem
].a
.eScript
].props
.fNeedsCaretInfo
)
1870 clust_glyph
= iGlyph
+ cGlyphs
;
1871 if (analysis
->pItem
[iItem
].a
.fRTL
)
1876 while(clust_glyph
< analysis
->glyphs
[iItem
].numGlyphs
&&
1877 !does_glyph_start_cluster(analysis
->glyphs
[iItem
].psva
, analysis
->glyphs
[iItem
].pwLogClust
, (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
), clust_glyph
, direction
))
1884 hr
= ScriptTextOut(analysis
->hdc
,
1885 (SCRIPT_CACHE
*)&analysis
->glyphs
[iItem
].sc
, iX
+ off_x
,
1886 iY
, uOptions
, prc
, &analysis
->pItem
[iItem
].a
, NULL
, 0,
1887 &analysis
->glyphs
[iItem
].glyphs
[iGlyph
], cGlyphs
,
1888 &analysis
->glyphs
[iItem
].piAdvance
[iGlyph
], NULL
,
1889 &analysis
->glyphs
[iItem
].pGoffset
[iGlyph
]);
1891 TRACE("ScriptTextOut hr=%08x\n", hr
);
1895 SetBkColor(analysis
->hdc
, BkColor
);
1896 SetBkMode( analysis
->hdc
, BkMode
);
1898 SetTextColor(analysis
->hdc
, TextColor
);
1900 if (analysis
->glyphs
[iItem
].fallbackFont
)
1901 SelectObject(analysis
->hdc
, oldFont
);
1906 /***********************************************************************
1907 * ScriptStringOut (USP10.@)
1909 * This function takes the output of ScriptStringAnalyse and joins the segments
1910 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1911 * only processes glyphs.
1914 * ssa [I] buffer to hold the analysed string components
1915 * iX [I] X axis displacement for output
1916 * iY [I] Y axis displacement for output
1917 * uOptions [I] flags controling output processing
1918 * prc [I] rectangle coordinates
1919 * iMinSel [I] starting pos for substringing output string
1920 * iMaxSel [I] ending pos for substringing output string
1921 * fDisabled [I] controls text highlighting
1925 * Failure: is the value returned by ScriptTextOut
1927 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1936 StringAnalysis
*analysis
;
1940 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1941 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1943 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1944 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return E_INVALIDARG
;
1946 for (item
= 0; item
< analysis
->numItems
; item
++)
1948 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], -1, -1, uOptions
, prc
, FALSE
, fDisabled
);
1953 if (iMinSel
< iMaxSel
&& (iMinSel
> 0 || iMaxSel
> 0))
1955 if (iMaxSel
> 0 && iMinSel
< 0)
1957 for (item
= 0; item
< analysis
->numItems
; item
++)
1959 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], iMinSel
, iMaxSel
, uOptions
, prc
, TRUE
, fDisabled
);
1968 /***********************************************************************
1969 * ScriptStringCPtoX (USP10.@)
1972 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1976 StringAnalysis
* analysis
= ssa
;
1978 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1980 if (!ssa
|| !pX
) return S_FALSE
;
1981 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1983 /* icp out of range */
1986 analysis
->invalid
= TRUE
;
1987 return E_INVALIDARG
;
1990 for(item
=0; item
<analysis
->numItems
; item
++)
1995 i
= analysis
->logical2visual
[item
];
1996 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1997 /* initialize max extents for uninitialized runs */
1998 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
2000 if (analysis
->pItem
[i
].a
.fRTL
)
2001 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2002 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2003 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2005 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2006 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2007 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2010 if (icp
>= analysis
->pItem
[i
+1].iCharPos
|| icp
< analysis
->pItem
[i
].iCharPos
)
2012 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
2016 icp
-= analysis
->pItem
[i
].iCharPos
;
2017 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2018 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2019 &analysis
->pItem
[i
].a
, &offset
);
2026 /* icp out of range */
2027 analysis
->invalid
= TRUE
;
2028 return E_INVALIDARG
;
2031 /***********************************************************************
2032 * ScriptStringXtoCP (USP10.@)
2035 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
2037 StringAnalysis
* analysis
= ssa
;
2040 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
2042 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
2043 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
2048 if (analysis
->pItem
[0].a
.fRTL
)
2051 *piTrailing
= FALSE
;
2061 for(item
=0; item
<analysis
->numItems
; item
++)
2066 for (i
= 0; i
< analysis
->numItems
&& analysis
->logical2visual
[i
] != item
; i
++)
2069 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
2070 /* initialize max extents for uninitialized runs */
2071 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
2073 if (analysis
->pItem
[i
].a
.fRTL
)
2074 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2075 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2076 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2078 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2079 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2080 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2083 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
2085 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
2089 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2090 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2091 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
2092 *piCh
+= analysis
->pItem
[i
].iCharPos
;
2098 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
2099 *piTrailing
= FALSE
;
2105 /***********************************************************************
2106 * ScriptStringFree (USP10.@)
2108 * Free a string analysis.
2111 * pssa [I] string analysis.
2115 * Failure: Non-zero HRESULT value.
2117 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
2119 StringAnalysis
* analysis
;
2123 TRACE("(%p)\n", pssa
);
2125 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
2127 invalid
= analysis
->invalid
;
2129 if (analysis
->glyphs
)
2131 for (i
= 0; i
< analysis
->numItems
; i
++)
2133 heap_free(analysis
->glyphs
[i
].glyphs
);
2134 heap_free(analysis
->glyphs
[i
].pwLogClust
);
2135 heap_free(analysis
->glyphs
[i
].piAdvance
);
2136 heap_free(analysis
->glyphs
[i
].psva
);
2137 heap_free(analysis
->glyphs
[i
].pGoffset
);
2138 heap_free(analysis
->glyphs
[i
].abc
);
2139 if (analysis
->glyphs
[i
].fallbackFont
)
2140 DeleteObject(analysis
->glyphs
[i
].fallbackFont
);
2141 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
);
2142 heap_free(analysis
->glyphs
[i
].sc
);
2144 heap_free(analysis
->glyphs
);
2147 heap_free(analysis
->pItem
);
2148 heap_free(analysis
->logattrs
);
2149 heap_free(analysis
->sz
);
2150 heap_free(analysis
->logical2visual
);
2151 heap_free(analysis
);
2153 if (invalid
) return E_INVALIDARG
;
2157 static inline int get_cluster_size(const WORD
*pwLogClust
, int cChars
, int item
,
2158 int direction
, int* iCluster
, int *check_out
)
2162 WORD clust
= pwLogClust
[item
];
2164 for (check
= item
+direction
; check
< cChars
&& check
>= 0; check
+=direction
)
2166 if (pwLogClust
[check
] == clust
)
2169 if (iCluster
&& *iCluster
== -1)
2181 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
)
2184 int log_clust_max
= 0;
2187 advance
= piAdvance
[glyph
];
2189 for (i
= 0; i
< cChars
; i
++)
2191 if (pwLogClust
[i
] > log_clust_max
)
2192 log_clust_max
= pwLogClust
[i
];
2195 if (glyph
> log_clust_max
)
2198 for (glyph
+=direction
; glyph
< cGlyphs
&& glyph
>= 0; glyph
+=direction
)
2201 if (does_glyph_start_cluster(pva
, pwLogClust
, cChars
, glyph
, direction
))
2203 if (glyph
> log_clust_max
)
2205 advance
+= piAdvance
[glyph
];
2211 /***********************************************************************
2212 * ScriptCPtoX (USP10.@)
2215 HRESULT WINAPI
ScriptCPtoX(int iCP
,
2219 const WORD
*pwLogClust
,
2220 const SCRIPT_VISATTR
*psva
,
2221 const int *piAdvance
,
2222 const SCRIPT_ANALYSIS
*psa
,
2230 float special_size
= 0.0;
2235 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2236 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2239 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2247 int max_clust
= pwLogClust
[0];
2249 for (item
=0; item
< cGlyphs
; item
++)
2250 if (pwLogClust
[item
] > max_clust
)
2252 ERR("We do not handle non reversed clusters properly\n");
2257 for (item
= max_clust
; item
>=0; item
--)
2258 iMaxPos
+= piAdvance
[item
];
2262 for (item
=0; item
< iCP
&& item
< cChars
; item
++)
2264 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
2267 int clust
= pwLogClust
[item
];
2270 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, 1, &iCluster
,
2273 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, 1);
2275 if (check
>= cChars
&& !iMaxPos
)
2277 for (check
= clust
; check
< cChars
; check
++)
2278 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, 1);
2280 special_size
/= (cChars
- item
);
2281 iPosX
+= special_size
;
2285 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2288 if (clust_size
== 0)
2292 iPosX
+= advance
/ (float)clust_size
;
2295 else if (iSpecial
!= -1)
2296 iPosX
+= special_size
;
2297 else /* (iCluster != -1) */
2299 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], 1);
2300 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2303 if (clust_size
== 0)
2307 iPosX
+= adv
/ (float)clust_size
;
2313 iPosX
= iMaxPos
- iPosX
;
2319 TRACE("*piX=%d\n", *piX
);
2323 /***********************************************************************
2324 * ScriptXtoCP (USP10.@)
2327 HRESULT WINAPI
ScriptXtoCP(int iX
,
2330 const WORD
*pwLogClust
,
2331 const SCRIPT_VISATTR
*psva
,
2332 const int *piAdvance
,
2333 const SCRIPT_ANALYSIS
*psa
,
2345 float special_size
= 0.0;
2348 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2349 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2350 psa
, piCP
, piTrailing
);
2352 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2357 int max_clust
= pwLogClust
[0];
2366 for (item
=0; item
< cChars
; item
++)
2367 if (pwLogClust
[item
] > max_clust
)
2369 ERR("We do not handle non reversed clusters properly\n");
2381 iPosX
= iLastPosX
= 0;
2386 for (; iPosX
<= iX
&& item
< cChars
&& item
>= 0; item
+=direction
)
2389 if (iSpecial
== -1 &&
2392 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
2393 (direction
< 0 && iCluster
-clust_size
>= item
))
2399 int clust
= pwLogClust
[item
];
2403 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, direction
,
2405 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, direction
);
2407 if (check
>= cChars
&& direction
> 0)
2409 for (check
= clust
; check
< cChars
; check
++)
2410 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, direction
);
2412 special_size
/= (cChars
- item
);
2413 iPosX
+= special_size
;
2417 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2424 iPosX
+= advance
/ (float)clust_size
;
2427 else if (iSpecial
!= -1)
2428 iPosX
+= special_size
;
2429 else /* (iCluster != -1) */
2431 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], direction
);
2432 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2439 iPosX
+= adv
/ (float)clust_size
;
2447 if (item
< cChars
&& ((iPosX
- iLastPosX
) / 2.0) + iX
>= iPosX
)
2449 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2450 item
+=(clust_size
-1);
2458 if (iX
== iLastPosX
)
2460 if (iX
>= iLastPosX
&& iX
<= iPosX
)
2463 if (iLastPosX
== iX
)
2465 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
2467 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2468 item
-=(clust_size
-1);
2477 TRACE("*piCP=%d\n", *piCP
);
2478 TRACE("*piTrailing=%d\n", *piTrailing
);
2482 /***********************************************************************
2483 * ScriptBreak (USP10.@)
2485 * Retrieve line break information.
2488 * chars [I] Array of characters.
2489 * sa [I] String analysis.
2490 * la [I] Array of logical attribute structures.
2496 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
2498 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
2500 if (!la
) return S_FALSE
;
2502 BREAK_line(chars
, count
, sa
, la
);
2507 /***********************************************************************
2508 * ScriptIsComplex (USP10.@)
2510 * Determine if a string is complex.
2513 * chars [I] Array of characters to test.
2514 * len [I] Length in characters.
2522 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
2526 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
2528 for (i
= 0; i
< len
; i
++)
2532 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
2535 script
= get_char_script(chars
[i
]);
2536 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
2537 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
2543 /***********************************************************************
2544 * ScriptShapeOpenType (USP10.@)
2546 * Produce glyphs and visual attributes for a run.
2549 * hdc [I] Device context.
2550 * psc [I/O] Opaque pointer to a script cache.
2551 * psa [I/O] Script analysis.
2552 * tagScript [I] The OpenType tag for the Script
2553 * tagLangSys [I] The OpenType tag for the Language
2554 * rcRangeChars[I] Array of Character counts in each range
2555 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2556 * cRanges [I] Count of ranges
2557 * pwcChars [I] Array of characters specifying the run.
2558 * cChars [I] Number of characters in pwcChars.
2559 * cMaxGlyphs [I] Length of pwOutGlyphs.
2560 * pwLogClust [O] Array of logical cluster info.
2561 * pCharProps [O] Array of character property values
2562 * pwOutGlyphs [O] Array of glyphs.
2563 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2564 * pcGlyphs [O] Number of glyphs returned.
2568 * Failure: Non-zero HRESULT value.
2570 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
2571 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
2572 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
2573 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2574 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
2575 int cMaxGlyphs
, WORD
*pwLogClust
,
2576 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
2577 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
2583 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2585 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2586 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2587 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
2589 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
2590 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
2592 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
2593 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2596 FIXME("Ranges not supported yet\n");
2598 rtl
= (psa
&& !psa
->fLogicalOrder
&& psa
->fRTL
);
2601 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2602 if (!pwLogClust
) return E_FAIL
;
2604 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2605 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2607 /* set fNoGlyphIndex non truetype/opentype fonts */
2608 if (!psa
->fNoGlyphIndex
&& !((ScriptCache
*)*psc
)->sfnt
)
2609 psa
->fNoGlyphIndex
= TRUE
;
2611 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2612 for (i
= 0; i
< cChars
; i
++)
2615 if (rtl
) idx
= cChars
- 1 - i
;
2616 /* FIXME: set to better values */
2617 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
2618 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
2619 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
2620 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
2621 pOutGlyphProps
[i
].sva
.fReserved
= 0;
2622 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
2624 /* FIXME: have the shaping engine set this */
2625 pCharProps
[i
].fCanGlyphAlone
= 0;
2627 pwLogClust
[i
] = idx
;
2630 if (psa
&& !psa
->fNoGlyphIndex
)
2633 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
2635 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
2636 if (!rChars
) return E_OUTOFMEMORY
;
2637 for (i
= 0; i
< cChars
; i
++)
2641 if (rtl
) idx
= cChars
- 1 - i
;
2643 chInput
= mirror_char(pwcChars
[idx
]);
2645 chInput
= pwcChars
[idx
];
2646 /* special case for tabs */
2647 if (chInput
== 0x0009)
2649 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
2657 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
)
2662 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
2664 rChars
[i
] = chInput
;
2667 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
2668 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
2669 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
2674 TRACE("no glyph translation\n");
2675 for (i
= 0; i
< cChars
; i
++)
2678 /* No mirroring done here */
2679 if (rtl
) idx
= cChars
- 1 - i
;
2680 pwOutGlyphs
[i
] = pwcChars
[idx
];
2688 /***********************************************************************
2689 * ScriptShape (USP10.@)
2691 * Produce glyphs and visual attributes for a run.
2694 * hdc [I] Device context.
2695 * psc [I/O] Opaque pointer to a script cache.
2696 * pwcChars [I] Array of characters specifying the run.
2697 * cChars [I] Number of characters in pwcChars.
2698 * cMaxGlyphs [I] Length of pwOutGlyphs.
2699 * psa [I/O] Script analysis.
2700 * pwOutGlyphs [O] Array of glyphs.
2701 * pwLogClust [O] Array of logical cluster info.
2702 * psva [O] Array of visual attributes.
2703 * pcGlyphs [O] Number of glyphs returned.
2707 * Failure: Non-zero HRESULT value.
2709 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
2710 int cChars
, int cMaxGlyphs
,
2711 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
2712 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
2716 SCRIPT_CHARPROP
*charProps
;
2717 SCRIPT_GLYPHPROP
*glyphProps
;
2719 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
2720 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2722 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
2723 if (!charProps
) return E_OUTOFMEMORY
;
2724 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
2727 heap_free(charProps
);
2728 return E_OUTOFMEMORY
;
2731 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
2735 for (i
= 0; i
< *pcGlyphs
; i
++)
2736 psva
[i
] = glyphProps
[i
].sva
;
2739 heap_free(charProps
);
2740 heap_free(glyphProps
);
2745 /***********************************************************************
2746 * ScriptPlaceOpenType (USP10.@)
2748 * Produce advance widths for a run.
2751 * hdc [I] Device context.
2752 * psc [I/O] Opaque pointer to a script cache.
2753 * psa [I/O] String analysis.
2754 * tagScript [I] The OpenType tag for the Script
2755 * tagLangSys [I] The OpenType tag for the Language
2756 * rcRangeChars[I] Array of Character counts in each range
2757 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2758 * cRanges [I] Count of ranges
2759 * pwcChars [I] Array of characters specifying the run.
2760 * pwLogClust [I] Array of logical cluster info
2761 * pCharProps [I] Array of character property values
2762 * cChars [I] Number of characters in pwcChars.
2763 * pwGlyphs [I] Array of glyphs.
2764 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2765 * cGlyphs [I] Count of Glyphs
2766 * piAdvance [O] Array of advance widths.
2767 * pGoffset [O] Glyph offsets.
2768 * pABC [O] Combined ABC width.
2772 * Failure: Non-zero HRESULT value.
2775 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
2776 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
2777 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2778 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
2779 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
2780 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
2781 int cGlyphs
, int *piAdvance
,
2782 GOFFSET
*pGoffset
, ABC
*pABC
2788 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2790 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2791 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2792 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
2795 if (!pGlyphProps
) return E_INVALIDARG
;
2796 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2797 if (!pGoffset
) return E_FAIL
;
2800 FIXME("Ranges not supported yet\n");
2802 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2803 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2805 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
2806 for (i
= 0; i
< cGlyphs
; i
++)
2809 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
2811 if (!hdc
) return E_PENDING
;
2812 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
2814 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
2819 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
2821 abc
.abcA
= abc
.abcC
= 0;
2823 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
2827 pABC
->abcA
+= abc
.abcA
;
2828 pABC
->abcB
+= abc
.abcB
;
2829 pABC
->abcC
+= abc
.abcC
;
2831 /* FIXME: set to more reasonable values */
2832 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
2833 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
2836 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
2840 /***********************************************************************
2841 * ScriptPlace (USP10.@)
2843 * Produce advance widths for a run.
2846 * hdc [I] Device context.
2847 * psc [I/O] Opaque pointer to a script cache.
2848 * pwGlyphs [I] Array of glyphs.
2849 * cGlyphs [I] Number of glyphs in pwGlyphs.
2850 * psva [I] Array of visual attributes.
2851 * psa [I/O] String analysis.
2852 * piAdvance [O] Array of advance widths.
2853 * pGoffset [O] Glyph offsets.
2854 * pABC [O] Combined ABC width.
2858 * Failure: Non-zero HRESULT value.
2860 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
2861 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
2862 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
2865 SCRIPT_GLYPHPROP
*glyphProps
;
2868 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
2869 piAdvance
, pGoffset
, pABC
);
2871 if (!psva
) return E_INVALIDARG
;
2872 if (!pGoffset
) return E_FAIL
;
2874 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
2875 if (!glyphProps
) return E_OUTOFMEMORY
;
2877 for (i
= 0; i
< cGlyphs
; i
++)
2878 glyphProps
[i
].sva
= psva
[i
];
2880 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
2882 heap_free(glyphProps
);
2887 /***********************************************************************
2888 * ScriptGetCMap (USP10.@)
2890 * Retrieve glyph indices.
2893 * hdc [I] Device context.
2894 * psc [I/O] Opaque pointer to a script cache.
2895 * pwcInChars [I] Array of Unicode characters.
2896 * cChars [I] Number of characters in pwcInChars.
2897 * dwFlags [I] Flags.
2898 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2902 * Failure: Non-zero HRESULT value.
2904 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
2905 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
2910 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
2911 cChars
, dwFlags
, pwOutGlyphs
);
2913 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2917 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2919 for (i
= 0; i
< cChars
; i
++)
2922 if (dwFlags
== SGCM_RTL
)
2923 inChar
= mirror_char(pwcInChars
[i
]);
2925 inChar
= pwcInChars
[i
];
2926 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
2929 if (!hdc
) return E_PENDING
;
2930 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
2931 if (glyph
== 0xffff)
2936 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
2942 TRACE("no glyph translation\n");
2943 for (i
= 0; i
< cChars
; i
++)
2946 if (dwFlags
== SGCM_RTL
)
2947 inChar
= mirror_char(pwcInChars
[i
]);
2949 inChar
= pwcInChars
[i
];
2950 pwOutGlyphs
[i
] = inChar
;
2956 /***********************************************************************
2957 * ScriptTextOut (USP10.@)
2960 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
2961 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
2962 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
2963 const int *piJustify
, const GOFFSET
*pGoffset
)
2967 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2968 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
2969 piAdvance
, piJustify
, pGoffset
);
2971 if (!hdc
|| !psc
) return E_INVALIDARG
;
2972 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
2974 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
2975 fuOptions
|= ETO_IGNORELANGUAGE
;
2976 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
2977 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
2979 if (psa
->fRTL
&& psa
->fLogicalOrder
)
2984 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
2986 return E_OUTOFMEMORY
;
2988 for (i
= 0; i
< cGlyphs
; i
++)
2989 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
2991 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
2993 heap_free(rtlGlyphs
);
2996 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
3002 /***********************************************************************
3003 * ScriptCacheGetHeight (USP10.@)
3005 * Retrieve the height of the font in the cache.
3008 * hdc [I] Device context.
3009 * psc [I/O] Opaque pointer to a script cache.
3010 * height [O] Receives font height.
3014 * Failure: Non-zero HRESULT value.
3016 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
3020 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
3022 if (!height
) return E_INVALIDARG
;
3023 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
3025 *height
= get_cache_height(psc
);
3029 /***********************************************************************
3030 * ScriptGetGlyphABCWidth (USP10.@)
3032 * Retrieve the width of a glyph.
3035 * hdc [I] Device context.
3036 * psc [I/O] Opaque pointer to a script cache.
3037 * glyph [I] Glyph to retrieve the width for.
3038 * abc [O] ABC widths of the glyph.
3042 * Failure: Non-zero HRESULT value.
3044 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
3048 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
3050 if (!abc
) return E_INVALIDARG
;
3051 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
3053 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
3055 if (!hdc
) return E_PENDING
;
3056 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
3058 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
3063 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
3065 abc
->abcA
= abc
->abcC
= 0;
3067 set_cache_glyph_widths(psc
, glyph
, abc
);
3072 /***********************************************************************
3073 * ScriptLayout (USP10.@)
3075 * Map embedding levels to visual and/or logical order.
3078 * runs [I] Size of level array.
3079 * level [I] Array of embedding levels.
3080 * vistolog [O] Map of embedding levels from visual to logical order.
3081 * logtovis [O] Map of embedding levels from logical to visual order.
3085 * Failure: Non-zero HRESULT value.
3088 * This stub works correctly for any sequence of a single
3089 * embedding level but not for sequences of different
3090 * embedding levels, i.e. mixtures of RTL and LTR scripts.
3092 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
3097 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
3099 if (!level
|| (!vistolog
&& !logtovis
))
3100 return E_INVALIDARG
;
3102 indexs
= heap_alloc(sizeof(int) * runs
);
3104 return E_OUTOFMEMORY
;
3109 for( ich
= 0; ich
< runs
; ich
++)
3114 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
3115 for (ich
= 0; ich
< runs
; ich
++)
3116 vistolog
[ich
] = indexs
[ich
];
3122 for( ich
= 0; ich
< runs
; ich
++)
3127 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
3128 for (ich
= 0; ich
< runs
; ich
++)
3129 logtovis
[ich
] = indexs
[ich
];
3136 /***********************************************************************
3137 * ScriptStringGetLogicalWidths (USP10.@)
3139 * Returns logical widths from a string analysis.
3142 * ssa [I] string analysis.
3143 * piDx [O] logical widths returned.
3147 * Failure: a non-zero HRESULT.
3149 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
3152 StringAnalysis
*analysis
= ssa
;
3154 TRACE("%p, %p\n", ssa
, piDx
);
3156 if (!analysis
) return S_FALSE
;
3157 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3159 for (i
= 0; i
< analysis
->numItems
; i
++)
3161 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
3164 if (analysis
->pItem
[i
].a
.fRTL
&& ! analysis
->pItem
[i
].a
.fLogicalOrder
)
3167 for (j
= 0; j
< cChar
; j
++)
3170 int glyph
= analysis
->glyphs
[i
].pwLogClust
[j
];
3171 int clust_size
= get_cluster_size(analysis
->glyphs
[i
].pwLogClust
,
3172 cChar
, j
, direction
, NULL
, NULL
);
3173 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
);
3175 for (k
= 0; k
< clust_size
; k
++)
3177 piDx
[next
] = advance
/ clust_size
;
3186 /***********************************************************************
3187 * ScriptStringValidate (USP10.@)
3189 * Validate a string analysis.
3192 * ssa [I] string analysis.
3196 * Failure: S_FALSE if invalid sequences are found
3197 * or a non-zero HRESULT if it fails.
3199 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
3201 StringAnalysis
*analysis
= ssa
;
3203 TRACE("(%p)\n", ssa
);
3205 if (!analysis
) return E_INVALIDARG
;
3206 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
3209 /***********************************************************************
3210 * ScriptString_pSize (USP10.@)
3212 * Retrieve width and height of an analysed string.
3215 * ssa [I] string analysis.
3218 * Success: Pointer to a SIZE structure.
3221 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
3224 StringAnalysis
*analysis
= ssa
;
3226 TRACE("(%p)\n", ssa
);
3228 if (!analysis
) return NULL
;
3229 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return NULL
;
3233 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
3234 analysis
->sz
->cy
= analysis
->glyphs
[0].sc
->tm
.tmHeight
;
3236 analysis
->sz
->cx
= 0;
3237 for (i
= 0; i
< analysis
->numItems
; i
++)
3239 if (analysis
->glyphs
[i
].sc
->tm
.tmHeight
> analysis
->sz
->cy
)
3240 analysis
->sz
->cy
= analysis
->glyphs
[i
].sc
->tm
.tmHeight
;
3241 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
3242 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
3245 return analysis
->sz
;
3248 /***********************************************************************
3249 * ScriptString_pLogAttr (USP10.@)
3251 * Retrieve logical attributes of an analysed string.
3254 * ssa [I] string analysis.
3257 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3260 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
3262 StringAnalysis
*analysis
= ssa
;
3264 TRACE("(%p)\n", ssa
);
3266 if (!analysis
) return NULL
;
3267 if (!(analysis
->dwFlags
& SSA_BREAK
)) return NULL
;
3268 return analysis
->logattrs
;
3271 /***********************************************************************
3272 * ScriptString_pcOutChars (USP10.@)
3274 * Retrieve the length of a string after clipping.
3277 * ssa [I] String analysis.
3280 * Success: Pointer to the length.
3283 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
3285 StringAnalysis
*analysis
= ssa
;
3287 TRACE("(%p)\n", ssa
);
3289 if (!analysis
) return NULL
;
3290 return &analysis
->clip_len
;
3293 /***********************************************************************
3294 * ScriptStringGetOrder (USP10.@)
3296 * Retrieve a glyph order map.
3299 * ssa [I] String analysis.
3300 * order [I/O] Array of glyph positions.
3304 * Failure: a non-zero HRESULT.
3306 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
3310 StringAnalysis
*analysis
= ssa
;
3312 TRACE("(%p)\n", ssa
);
3314 if (!analysis
) return S_FALSE
;
3315 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3317 /* FIXME: handle RTL scripts */
3318 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
3319 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
3325 /***********************************************************************
3326 * ScriptGetLogicalWidths (USP10.@)
3328 * Convert advance widths to logical widths.
3331 * sa [I] Script analysis.
3332 * nbchars [I] Number of characters.
3333 * nbglyphs [I] Number of glyphs.
3334 * glyph_width [I] Array of glyph widths.
3335 * log_clust [I] Array of logical clusters.
3336 * sva [I] Visual attributes.
3337 * widths [O] Array of logical widths.
3341 * Failure: a non-zero HRESULT.
3343 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
3344 const int *glyph_width
, const WORD
*log_clust
,
3345 const SCRIPT_VISATTR
*sva
, int *widths
)
3349 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3350 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
3353 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
3357 /***********************************************************************
3358 * ScriptApplyLogicalWidth (USP10.@)
3360 * Generate glyph advance widths.
3363 * dx [I] Array of logical advance widths.
3364 * num_chars [I] Number of characters.
3365 * num_glyphs [I] Number of glyphs.
3366 * log_clust [I] Array of logical clusters.
3367 * sva [I] Visual attributes.
3368 * advance [I] Array of glyph advance widths.
3369 * sa [I] Script analysis.
3370 * abc [I/O] Summed ABC widths.
3371 * justify [O] Array of glyph advance widths.
3375 * Failure: a non-zero HRESULT.
3377 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
3378 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
3379 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
3380 ABC
*abc
, int *justify
)
3384 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3385 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
3387 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
3391 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
3392 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
3396 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
3398 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];