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 /* Khmer: U+1780–U+17FF */
126 { Script_Khmer
, 0x1780, 0x17ff, Script_Khmer_Numeric
, 0},
127 /* Mongolian: U+1800–U+18AF */
128 { Script_Mongolian
, 0x1800, 0x18af, Script_Mongolian_Numeric
, 0},
129 /* Canadian Aboriginal Syllabics Extended: U+18B0–U+18FF */
130 { Script_Canadian
, 0x18b0, 0x18ff, 0, 0},
131 /* Tai Le: U+1950–U+197F */
132 { Script_Tai_Le
, 0x1950, 0x197f, 0, 0},
133 /* New Tai Lue: U+1980–U+19DF */
134 { Script_New_Tai_Lue
,0x1980, 0x19df, Script_New_Tai_Lue_Numeric
, 0},
135 /* Khmer Symbols: U+19E0–U+19FF */
136 { Script_Khmer
, 0x19e0, 0x19ff, Script_Khmer_Numeric
, 0},
137 /* Vedic Extensions: U+1CD0-U+1CFF */
138 { Script_Devanagari
, 0x1cd0, 0x1cff, Script_Devanagari_Numeric
, 0},
139 /* Phonetic Extensions: U+1D00–U+1DBF */
140 { Script_Latin
, 0x1d00, 0x1dbf, 0, 0},
141 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
142 { Script_Diacritical
,0x1dc0, 0x1dff, 0, 0},
143 /* Latin Extended Additional: U+1E00–U+1EFF */
144 { Script_Latin
, 0x1e00, 0x1eff, 0, 0},
145 /* Greek Extended: U+1F00–U+1FFF */
146 { Script_Greek
, 0x1f00, 0x1fff, 0, 0},
147 /* General Punctuation: U+2000 –U+206f */
148 { Script_Latin
, 0x2000, 0x206f, 0, 0},
149 /* Superscripts and Subscripts : U+2070 –U+209f */
150 /* Currency Symbols : U+20a0 –U+20cf */
151 { Script_Numeric2
, 0x2070, 0x2070, 0, 0},
152 { Script_Latin
, 0x2071, 0x2073, 0, 0},
153 { Script_Numeric2
, 0x2074, 0x2079, 0, 0},
154 { Script_Latin
, 0x207a, 0x207f, 0, 0},
155 { Script_Numeric2
, 0x2080, 0x2089, 0, 0},
156 { Script_Latin
, 0x208a, 0x20cf, 0, 0},
157 /* Letterlike Symbols : U+2100 –U+214f */
158 /* Number Forms : U+2150 –U+218f */
159 /* Arrows : U+2190 –U+21ff */
160 /* Mathematical Operators : U+2200 –U+22ff */
161 /* Miscellaneous Technical : U+2300 –U+23ff */
162 /* Control Pictures : U+2400 –U+243f */
163 /* Optical Character Recognition : U+2440 –U+245f */
164 /* Enclosed Alphanumerics : U+2460 –U+24ff */
165 /* Box Drawing : U+2500 –U+25ff */
166 /* Block Elements : U+2580 –U+259f */
167 /* Geometric Shapes : U+25a0 –U+25ff */
168 /* Miscellaneous Symbols : U+2600 –U+26ff */
169 /* Dingbats : U+2700 –U+27bf */
170 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
171 /* Supplemental Arrows-A : U+27f0 –U+27ff */
172 { Script_Latin
, 0x2100, 0x27ff, 0, 0},
173 /* Supplemental Arrows-B : U+2900 –U+297f */
174 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
175 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
176 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
177 { Script_Latin
, 0x2900, 0x2bff, 0, 0},
178 /* Latin Extended-C: U+2C60–U+2C7F */
179 { Script_Latin
, 0x2c60, 0x2c7f, 0, 0},
180 /* Georgian: U+2D00–U+2D2F */
181 { Script_Georgian
, 0x2d00, 0x2d2f, 0, 0},
182 /* Tifinagh: U+2D30–U+2D7F */
183 { Script_Tifinagh
, 0x2d30, 0x2d7f, 0, 0},
184 /* Ethiopic Extensions: U+2D80–U+2DDF */
185 { Script_Ethiopic
, 0x2d80, 0x2ddf, 0, 0},
186 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
187 { Script_Cyrillic
, 0x2de0, 0x2dff, 0, 0},
188 /* CJK Radicals Supplement: U+2E80–U+2EFF */
189 /* Kangxi Radicals: U+2F00–U+2FDF */
190 { Script_CJK_Han
, 0x2e80, 0x2fdf, 0, 0},
191 /* Ideographic Description Characters: U+2FF0–U+2FFF */
192 { Script_Ideograph
,0x2ff0, 0x2fff, 0, 0},
193 /* CJK Symbols and Punctuation: U+3000–U+303F */
194 { Script_Ideograph
,0x3000, 0x3004, 0, 0},
195 { Script_CJK_Han
,0x3005, 0x3005, 0, 0},
196 { Script_Ideograph
,0x3006, 0x3006, 0, 0},
197 { Script_CJK_Han
,0x3007, 0x3007, 0, 0},
198 { Script_Ideograph
,0x3008, 0x3020, 0, 0},
199 { Script_CJK_Han
,0x3021, 0x3029, 0, 0},
200 { Script_Ideograph
,0x302a, 0x3030, 0, 0},
202 { Script_Kana
,0x3031, 0x3035, 0, 0},
203 { Script_Ideograph
,0x3036, 0x3037, 0, 0},
204 { Script_CJK_Han
,0x3038, 0x303b, 0, 0},
205 { Script_Ideograph
,0x303c, 0x303f, 0, 0},
206 /* Hiragana: U+3040–U+309F */
207 /* Katakana: U+30A0–U+30FF */
208 { Script_Kana
,0x3040, 0x30ff, 0, 0},
209 /* Bopomofo: U+3100–U+312F */
210 { Script_Bopomofo
,0x3100, 0x312f, 0, 0},
211 /* Hangul Compatibility Jamo: U+3130–U+318F */
212 { Script_Hangul
,0x3130, 0x318f, 0, 0},
213 /* Kanbun: U+3190–U+319F */
214 { Script_Ideograph
,0x3190, 0x319f, 0, 0},
215 /* Bopomofo Extended: U+31A0–U+31BF */
216 { Script_Bopomofo
,0x31a0, 0x31bf, 0, 0},
217 /* CJK Strokes: U+31C0–U+31EF */
218 { Script_Ideograph
,0x31c0, 0x31ef, 0, 0},
219 /* Katakana Phonetic Extensions: U+31F0–U+31FF */
220 { Script_Kana
,0x31f0, 0x31ff, 0, 0},
221 /* Enclosed CJK Letters and Months: U+3200–U+32FF */
222 { Script_Hangul
,0x3200, 0x321f, 0, 0},
223 { Script_Ideograph
,0x3220, 0x325f, 0, 0},
224 { Script_Hangul
,0x3260, 0x327f, 0, 0},
225 { Script_Ideograph
,0x3280, 0x32ef, 0, 0},
226 { Script_Kana
,0x32d0, 0x31ff, 0, 0},
227 /* CJK Compatibility: U+3300–U+33FF*/
228 { Script_Kana
,0x3300, 0x3357, 0, 0},
229 { Script_Ideograph
,0x3358, 0x33ff, 0, 0},
230 /* CJK Unified Ideographs Extension A: U+3400–U+4DBF */
231 { Script_CJK_Han
,0x3400, 0x4dbf, 0, 0},
232 /* CJK Unified Ideographs: U+4E00–U+9FFF */
233 { Script_CJK_Han
,0x4e00, 0x9fff, 0, 0},
234 /* Yi: U+A000–U+A4CF */
235 { Script_Yi
,0xa000, 0xa4cf, 0, 0},
236 /* Vai: U+A500–U+A63F */
237 { Script_Vai
,0xa500, 0xa63f, Script_Vai_Numeric
, 0},
238 /* Cyrillic Extended-B: U+A640–U+A69F */
239 { Script_Cyrillic
, 0xa640, 0xa69f, 0, 0},
240 /* Modifier Tone Letters: U+A700–U+A71F */
241 /* Latin Extended-D: U+A720–U+A7FF */
242 { Script_Latin
, 0xa700, 0xa7ff, 0, 0},
243 /* Phags-pa: U+A840–U+A87F */
244 { Script_Phags_pa
, 0xa840, 0xa87f, 0, 0},
245 /* Devanagari Extended: U+A8E0-U+A8FF */
246 { Script_Devanagari
, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric
, 0},
247 /* Myanmar Extended-A: U+AA60–U+AA7F */
248 { Script_Myanmar
, 0xaa60, 0xaa7f, Script_Myanmar_Numeric
, 0},
249 /* Hangul Jamo Extended-A: U+A960–U+A97F */
250 { Script_Hangul
, 0xa960, 0xa97f, 0, 0},
251 /* Hangul Syllables: U+AC00–U+D7A3 */
252 { Script_Hangul
, 0xac00, 0xd7a3, 0, 0},
253 /* Hangul Jamo Extended-B: U+D7B0–U+D7FF */
254 { Script_Hangul
, 0xd7b0, 0xd7ff, 0, 0},
255 /* CJK Compatibility Ideographs: U+F900–U+FAFF */
256 { Script_CJK_Han
,0xf900, 0xfaff, 0, 0},
257 /* Latin Ligatures: U+FB00–U+FB06 */
258 { Script_Latin
, 0xfb00, 0xfb06, 0, 0},
259 /* Armenian ligatures U+FB13..U+FB17 */
260 { Script_Armenian
, 0xfb13, 0xfb17, 0, 0},
261 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
262 { Script_Hebrew
, 0xfb1d, 0xfb4f, 0, 0},
263 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
264 { Script_Arabic
, 0xfb50, 0xfdff, 0, 0},
265 /* Vertical Forms: U+FE10–U+FE1F */
266 /* Combining Half Marks: U+FE20–U+FE2F */
267 /* CJK Compatibility Forms: U+FE30–U+FE4F */
268 /* Small Form Variants: U+FE50–U+FE6F */
269 { Script_Ideograph
,0xfe10, 0xfe6f, 0, 0},
270 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
271 { Script_Arabic
, 0xfe70, 0xfeff, 0, 0},
272 /* Halfwidth and Fullwidth Forms: U+FF00–FFEF */
273 { Script_Ideograph
,0xff00, 0xff64, Script_Numeric2
, 0},
274 { Script_Kana
,0xff65, 0xff9f, 0, 0},
275 { Script_Hangul
,0xffa0, 0xffdf, 0, 0},
276 { Script_Ideograph
,0xffe0, 0xffef, 0, 0},
278 { SCRIPT_UNDEFINED
, 0, 0, 0}
281 typedef struct _scriptData
284 SCRIPT_PROPERTIES props
;
285 OPENTYPE_TAG scriptTag
;
286 WCHAR fallbackFont
[LF_FACESIZE
];
289 /* the must be in order so that the index matches the Script value */
290 static const scriptData scriptInformation
[] = {
291 {{SCRIPT_UNDEFINED
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
292 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
295 {{Script_Latin
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
296 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
297 MS_MAKE_TAG('l','a','t','n'),
299 {{Script_CR
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
300 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
303 {{Script_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
304 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
307 {{Script_Control
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
308 {LANG_ENGLISH
, 0, 1, 0, 0, ANSI_CHARSET
, 1, 0, 0, 0, 0, 0, 1, 0, 0},
311 {{Script_Punctuation
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
312 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
315 {{Script_Arabic
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
316 {LANG_ARABIC
, 0, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 1, 0},
317 MS_MAKE_TAG('a','r','a','b'),
318 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
319 {{Script_Arabic_Numeric
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
320 {LANG_ARABIC
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
321 MS_MAKE_TAG('a','r','a','b'),
322 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
323 {{Script_Hebrew
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
324 {LANG_HEBREW
, 0, 1, 0, 1, HEBREW_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
325 MS_MAKE_TAG('h','e','b','r'),
326 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
327 {{Script_Syriac
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
328 {LANG_SYRIAC
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 1, 0},
329 MS_MAKE_TAG('s','y','r','c'),
330 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
331 {{Script_Persian
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
332 {LANG_PERSIAN
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
333 MS_MAKE_TAG('s','y','r','c'),
334 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
335 {{Script_Thaana
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
336 {LANG_DIVEHI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
337 MS_MAKE_TAG('t','h','a','a'),
338 {'M','V',' ','B','o','l','i',0}},
339 {{Script_Greek
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
340 {LANG_GREEK
, 0, 0, 0, 0, GREEK_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
341 MS_MAKE_TAG('g','r','e','k'),
343 {{Script_Cyrillic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
344 {LANG_RUSSIAN
, 0, 0, 0, 0, RUSSIAN_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
345 MS_MAKE_TAG('c','y','r','l'),
347 {{Script_Armenian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
348 {LANG_ARMENIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
349 MS_MAKE_TAG('a','r','m','n'),
350 {'S','y','l','f','a','e','n',0}},
351 {{Script_Georgian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
352 {LANG_GEORGIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
353 MS_MAKE_TAG('g','e','o','r'),
354 {'S','y','l','f','a','e','n',0}},
355 {{Script_Sinhala
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
356 {LANG_SINHALESE
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
357 MS_MAKE_TAG('s','i','n','h'),
358 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
359 {{Script_Tibetan
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
360 {LANG_TIBETAN
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
361 MS_MAKE_TAG('t','i','b','t'),
362 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
363 {{Script_Tibetan_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
364 {LANG_TIBETAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
365 MS_MAKE_TAG('t','i','b','t'),
366 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
367 {{Script_Phags_pa
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
368 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
369 MS_MAKE_TAG('p','h','a','g'),
370 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
371 {{Script_Thai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
372 {LANG_THAI
, 0, 1, 1, 1, THAI_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 1},
373 MS_MAKE_TAG('t','h','a','i'),
374 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
375 {{Script_Thai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
376 {LANG_THAI
, 1, 1, 0, 0, THAI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
377 MS_MAKE_TAG('t','h','a','i'),
378 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
379 {{Script_Lao
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
380 {LANG_LAO
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
381 MS_MAKE_TAG('l','a','o',' '),
382 {'D','o','k','C','h','a','m','p','a',0}},
383 {{Script_Lao_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
384 {LANG_LAO
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
385 MS_MAKE_TAG('l','a','o',' '),
386 {'D','o','k','C','h','a','m','p','a',0}},
387 {{Script_Devanagari
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
388 {LANG_HINDI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
389 MS_MAKE_TAG('d','e','v','a'),
390 {'M','a','n','g','a','l',0}},
391 {{Script_Devanagari_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
392 {LANG_HINDI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
393 MS_MAKE_TAG('d','e','v','a'),
394 {'M','a','n','g','a','l',0}},
395 {{Script_Bengali
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
396 {LANG_BENGALI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
397 MS_MAKE_TAG('b','e','n','g'),
398 {'V','r','i','n','d','a',0}},
399 {{Script_Bengali_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
400 {LANG_BENGALI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
401 MS_MAKE_TAG('b','e','n','g'),
402 {'V','r','i','n','d','a',0}},
403 {{Script_Bengali_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
404 {LANG_BENGALI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
405 MS_MAKE_TAG('b','e','n','g'),
406 {'V','r','i','n','d','a',0}},
407 {{Script_Gurmukhi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
408 {LANG_PUNJABI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
409 MS_MAKE_TAG('g','u','r','u'),
410 {'R','a','a','v','i',0}},
411 {{Script_Gurmukhi_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
412 {LANG_PUNJABI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
413 MS_MAKE_TAG('g','u','r','u'),
414 {'R','a','a','v','i',0}},
415 {{Script_Gujarati
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
416 {LANG_GUJARATI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
417 MS_MAKE_TAG('g','u','j','r'),
418 {'S','h','r','u','t','i',0}},
419 {{Script_Gujarati_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
420 {LANG_GUJARATI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
421 MS_MAKE_TAG('g','u','j','r'),
422 {'S','h','r','u','t','i',0}},
423 {{Script_Gujarati_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
424 {LANG_GUJARATI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
425 MS_MAKE_TAG('g','u','j','r'),
426 {'S','h','r','u','t','i',0}},
427 {{Script_Oriya
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
428 {LANG_ORIYA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
429 MS_MAKE_TAG('o','r','y','a'),
430 {'K','a','l','i','n','g','a',0}},
431 {{Script_Oriya_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
432 {LANG_ORIYA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
433 MS_MAKE_TAG('o','r','y','a'),
434 {'K','a','l','i','n','g','a',0}},
435 {{Script_Tamil
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
436 {LANG_TAMIL
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
437 MS_MAKE_TAG('t','a','m','l'),
438 {'L','a','t','h','a',0}},
439 {{Script_Tamil_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
440 {LANG_TAMIL
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
441 MS_MAKE_TAG('t','a','m','l'),
442 {'L','a','t','h','a',0}},
443 {{Script_Telugu
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
444 {LANG_TELUGU
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
445 MS_MAKE_TAG('t','e','l','u'),
446 {'G','a','u','t','a','m','i',0}},
447 {{Script_Telugu_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
448 {LANG_TELUGU
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
449 MS_MAKE_TAG('t','e','l','u'),
450 {'G','a','u','t','a','m','i',0}},
451 {{Script_Kannada
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
452 {LANG_KANNADA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
453 MS_MAKE_TAG('k','n','d','a'),
454 {'T','u','n','g','a',0}},
455 {{Script_Kannada_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
456 {LANG_KANNADA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
457 MS_MAKE_TAG('k','n','d','a'),
458 {'T','u','n','g','a',0}},
459 {{Script_Malayalam
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
460 {LANG_MALAYALAM
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
461 MS_MAKE_TAG('m','l','y','m'),
462 {'K','a','r','t','i','k','a',0}},
463 {{Script_Malayalam_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
464 {LANG_MALAYALAM
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
465 MS_MAKE_TAG('m','l','y','m'),
466 {'K','a','r','t','i','k','a',0}},
467 {{Script_Diacritical
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
468 {LANG_ENGLISH
, 0, 1, 0, 1, ANSI_CHARSET
, 0, 0, 0, 0, 0, 1, 1, 0, 0},
471 {{Script_Punctuation2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
472 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
473 MS_MAKE_TAG('l','a','t','n'),
475 {{Script_Numeric2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
476 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
479 {{Script_Myanmar
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
480 {0x55, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
481 MS_MAKE_TAG('m','y','m','r'),
483 {{Script_Myanmar_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
484 {0x55, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
485 MS_MAKE_TAG('m','y','m','r'),
487 {{Script_Tai_Le
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
488 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
489 MS_MAKE_TAG('t','a','l','e'),
490 {'M','i','c','r','o','s','o','f','t',' ','T','a','i',' ','L','e'}},
491 {{Script_New_Tai_Lue
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
492 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
493 MS_MAKE_TAG('t','a','l','u'),
494 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
495 {{Script_New_Tai_Lue_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
496 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
497 MS_MAKE_TAG('t','a','l','u'),
498 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
499 {{Script_Khmer
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
500 {0x53, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
501 MS_MAKE_TAG('k','h','m','r'),
502 {'D','a','u','n','P','e','n','h'}},
503 {{Script_Khmer
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
504 {0x53, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
505 MS_MAKE_TAG('k','h','m','r'),
506 {'D','a','u','n','P','e','n','h'}},
507 {{Script_CJK_Han
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
508 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
509 MS_MAKE_TAG('h','a','n','i'),
511 {{Script_Ideograph
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
512 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
513 MS_MAKE_TAG('h','a','n','i'),
515 {{Script_Bopomofo
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
516 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
517 MS_MAKE_TAG('b','o','p','o'),
519 {{Script_Kana
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
520 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
521 MS_MAKE_TAG('k','a','n','a'),
523 {{Script_Hangul
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
524 {LANG_KOREAN
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
525 MS_MAKE_TAG('h','a','n','g'),
527 {{Script_Yi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
528 {LANG_ENGLISH
, 0, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
529 MS_MAKE_TAG('y','i',' ',' '),
530 {'M','i','c','r','o','s','o','f','t',' ','Y','i',' ','B','a','i','t','i'}},
531 {{Script_Ethiopic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
532 {0x5e, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
533 MS_MAKE_TAG('e','t','h','i'),
534 {'N','y','a','l','a'}},
535 {{Script_Ethiopic_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
536 {0x5e, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
537 MS_MAKE_TAG('e','t','h','i'),
538 {'N','y','a','l','a'}},
539 {{Script_Mongolian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
540 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
541 MS_MAKE_TAG('m','o','n','g'),
542 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
543 {{Script_Mongolian_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
544 {LANG_MONGOLIAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
545 MS_MAKE_TAG('m','o','n','g'),
546 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
547 {{Script_Tifinagh
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
548 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
549 MS_MAKE_TAG('t','f','n','g'),
550 {'E','b','r','i','m','a'}},
551 {{Script_NKo
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
552 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
553 MS_MAKE_TAG('n','k','o',' '),
555 {{Script_Vai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
556 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
557 MS_MAKE_TAG('v','a','i',' '),
558 {'E','b','r','i','m','a'}},
559 {{Script_Vai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
560 {0, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
561 MS_MAKE_TAG('v','a','i',' '),
562 {'E','b','r','i','m','a'}},
563 {{Script_Cherokee
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
564 {0x5c, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
565 MS_MAKE_TAG('c','h','e','r'),
566 {'P','l','a','n','t','a','g','e','n','e','t',' ','C','h','e','r','o','k','e','e'}},
567 {{Script_Canadian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
568 {0x5d, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
569 MS_MAKE_TAG('c','a','n','s'),
570 {'E','u','p','h','e','m','i','a'}},
573 static const SCRIPT_PROPERTIES
*script_props
[] =
575 &scriptInformation
[0].props
, &scriptInformation
[1].props
,
576 &scriptInformation
[2].props
, &scriptInformation
[3].props
,
577 &scriptInformation
[4].props
, &scriptInformation
[5].props
,
578 &scriptInformation
[6].props
, &scriptInformation
[7].props
,
579 &scriptInformation
[8].props
, &scriptInformation
[9].props
,
580 &scriptInformation
[10].props
, &scriptInformation
[11].props
,
581 &scriptInformation
[12].props
, &scriptInformation
[13].props
,
582 &scriptInformation
[14].props
, &scriptInformation
[15].props
,
583 &scriptInformation
[16].props
, &scriptInformation
[17].props
,
584 &scriptInformation
[18].props
, &scriptInformation
[19].props
,
585 &scriptInformation
[20].props
, &scriptInformation
[21].props
,
586 &scriptInformation
[22].props
, &scriptInformation
[23].props
,
587 &scriptInformation
[24].props
, &scriptInformation
[25].props
,
588 &scriptInformation
[26].props
, &scriptInformation
[27].props
,
589 &scriptInformation
[28].props
, &scriptInformation
[29].props
,
590 &scriptInformation
[30].props
, &scriptInformation
[31].props
,
591 &scriptInformation
[32].props
, &scriptInformation
[33].props
,
592 &scriptInformation
[34].props
, &scriptInformation
[35].props
,
593 &scriptInformation
[36].props
, &scriptInformation
[37].props
,
594 &scriptInformation
[38].props
, &scriptInformation
[39].props
,
595 &scriptInformation
[40].props
, &scriptInformation
[41].props
,
596 &scriptInformation
[42].props
, &scriptInformation
[43].props
,
597 &scriptInformation
[44].props
, &scriptInformation
[45].props
,
598 &scriptInformation
[46].props
, &scriptInformation
[47].props
,
599 &scriptInformation
[48].props
, &scriptInformation
[49].props
,
600 &scriptInformation
[50].props
, &scriptInformation
[51].props
,
601 &scriptInformation
[52].props
, &scriptInformation
[53].props
,
602 &scriptInformation
[54].props
, &scriptInformation
[55].props
,
603 &scriptInformation
[56].props
, &scriptInformation
[57].props
,
604 &scriptInformation
[58].props
, &scriptInformation
[59].props
,
605 &scriptInformation
[60].props
, &scriptInformation
[61].props
,
606 &scriptInformation
[62].props
, &scriptInformation
[63].props
,
607 &scriptInformation
[64].props
, &scriptInformation
[65].props
,
608 &scriptInformation
[66].props
, &scriptInformation
[67].props
,
609 &scriptInformation
[68].props
, &scriptInformation
[69].props
618 SCRIPT_VISATTR
* psva
;
634 StringGlyphs
* glyphs
;
635 SCRIPT_LOGATTR
* logattrs
;
640 static inline void *heap_alloc(SIZE_T size
)
642 return HeapAlloc(GetProcessHeap(), 0, size
);
645 static inline void *heap_alloc_zero(SIZE_T size
)
647 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
650 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
652 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
655 static inline BOOL
heap_free(LPVOID mem
)
657 return HeapFree(GetProcessHeap(), 0, mem
);
660 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
662 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
665 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
667 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
670 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
672 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
675 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
677 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
679 if (!block
) return 0;
680 return block
[c
& GLYPH_BLOCK_MASK
];
683 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
685 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
687 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
688 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
691 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
693 static const ABC nil
;
694 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
696 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
697 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
701 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
703 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
705 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
706 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
710 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
714 if (!psc
) return E_INVALIDARG
;
715 if (*psc
) return S_OK
;
716 if (!hdc
) return E_PENDING
;
718 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
719 if (!GetTextMetricsW(hdc
, &sc
->tm
))
724 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
729 sc
->sfnt
= (GetFontData(hdc
, MS_MAKE_TAG('h','e','a','d'), 0, NULL
, 0)!=GDI_ERROR
);
731 TRACE("<- %p\n", sc
);
735 static WCHAR
mirror_char( WCHAR ch
)
737 extern const WCHAR wine_mirror_map
[];
738 return ch
+ wine_mirror_map
[wine_mirror_map
[ch
>> 8] + (ch
& 0xff)];
741 static WORD
get_char_script( WCHAR ch
)
743 static const WCHAR latin_punc
[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
747 if (ch
== 0xc || ch
== 0x20 || ch
== 0x202f)
750 /* These punctuation are separated out as Latin punctuation */
751 if (strchrW(latin_punc
,ch
))
752 return Script_Punctuation2
;
754 /* These chars are itemized as Punctuation by Windows */
755 if (ch
== 0x2212 || ch
== 0x2044)
756 return Script_Punctuation
;
758 GetStringTypeW(CT_CTYPE1
, &ch
, 1, &type
);
761 return SCRIPT_UNDEFINED
;
764 return Script_Control
;
769 if (ch
< scriptRanges
[i
].rangeFirst
|| scriptRanges
[i
].script
== SCRIPT_UNDEFINED
)
772 if (ch
>= scriptRanges
[i
].rangeFirst
&& ch
<= scriptRanges
[i
].rangeLast
)
774 if (scriptRanges
[i
].numericScript
&& type
& C1_DIGIT
)
775 return scriptRanges
[i
].numericScript
;
776 if (scriptRanges
[i
].punctScript
&& type
& C1_PUNCT
)
777 return scriptRanges
[i
].punctScript
;
778 return scriptRanges
[i
].script
;
783 return SCRIPT_UNDEFINED
;
786 /***********************************************************************
790 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
794 case DLL_PROCESS_ATTACH
:
795 DisableThreadLibraryCalls(hInstDLL
);
797 case DLL_PROCESS_DETACH
:
803 /***********************************************************************
804 * ScriptFreeCache (USP10.@)
806 * Free a script cache.
809 * psc [I/O] Script cache.
813 * Failure: Non-zero HRESULT value.
815 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
822 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
824 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
825 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
827 heap_free(((ScriptCache
*)*psc
)->GSUB_Table
);
828 heap_free(((ScriptCache
*)*psc
)->GDEF_Table
);
829 heap_free(((ScriptCache
*)*psc
)->features
);
836 /***********************************************************************
837 * ScriptGetProperties (USP10.@)
839 * Retrieve a list of script properties.
842 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
843 * num [I] Pointer to the number of scripts.
847 * Failure: Non-zero HRESULT value.
850 * Behaviour matches WinXP.
852 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
854 TRACE("(%p,%p)\n", props
, num
);
856 if (!props
&& !num
) return E_INVALIDARG
;
858 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
859 if (props
) *props
= script_props
;
864 /***********************************************************************
865 * ScriptGetFontProperties (USP10.@)
867 * Get information on special glyphs.
870 * hdc [I] Device context.
871 * psc [I/O] Opaque pointer to a script cache.
872 * sfp [O] Font properties structure.
874 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
878 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
880 if (!sfp
) return E_INVALIDARG
;
881 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
883 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
886 /* return something sensible? */
888 sfp
->wgDefault
= get_cache_default_char(psc
);
890 sfp
->wgKashida
= 0xffff;
891 sfp
->iKashidaWidth
= 0;
896 /***********************************************************************
897 * ScriptRecordDigitSubstitution (USP10.@)
899 * Record digit substitution settings for a given locale.
902 * locale [I] Locale identifier.
903 * sds [I] Structure to record substitution settings.
907 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
910 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
912 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
916 TRACE("0x%x, %p\n", locale
, sds
);
918 /* This implementation appears to be correct for all languages, but it's
919 * not clear if sds->DigitSubstitute is ever set to anything except
920 * CONTEXT or NONE in reality */
922 if (!sds
) return E_POINTER
;
924 locale
= ConvertDefaultLocale(locale
);
926 if (!IsValidLocale(locale
, LCID_INSTALLED
))
929 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
930 sds
->TraditionalDigitLanguage
= plgid
;
932 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
933 sds
->NationalDigitLanguage
= plgid
;
935 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
937 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
938 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
943 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
944 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
946 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
949 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
952 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
955 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
963 /***********************************************************************
964 * ScriptApplyDigitSubstitution (USP10.@)
966 * Apply digit substitution settings.
969 * sds [I] Structure with recorded substitution settings.
970 * sc [I] Script control structure.
971 * ss [I] Script state structure.
975 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
977 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
978 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
980 SCRIPT_DIGITSUBSTITUTE psds
;
982 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
984 if (!sc
|| !ss
) return E_POINTER
;
988 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
992 sc
->uDefaultLanguage
= LANG_ENGLISH
;
993 sc
->fContextDigits
= 0;
994 ss
->fDigitSubstitute
= 0;
996 switch (sds
->DigitSubstitute
) {
997 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
998 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
999 case SCRIPT_DIGITSUBSTITUTE_NONE
:
1000 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
1003 return E_INVALIDARG
;
1007 static inline BOOL
is_indic(WORD script
)
1009 return (script
>= Script_Devanagari
&& script
<= Script_Malayalam_Numeric
);
1012 static inline WORD
base_indic(WORD script
)
1016 case Script_Devanagari
:
1017 case Script_Devanagari_Numeric
: return Script_Devanagari
;
1018 case Script_Bengali
:
1019 case Script_Bengali_Numeric
:
1020 case Script_Bengali_Currency
: return Script_Bengali
;
1021 case Script_Gurmukhi
:
1022 case Script_Gurmukhi_Numeric
: return Script_Gurmukhi
;
1023 case Script_Gujarati
:
1024 case Script_Gujarati_Numeric
:
1025 case Script_Gujarati_Currency
: return Script_Gujarati
;
1027 case Script_Oriya_Numeric
: return Script_Oriya
;
1029 case Script_Tamil_Numeric
: return Script_Tamil
;
1031 case Script_Telugu_Numeric
: return Script_Telugu
;
1032 case Script_Kannada
:
1033 case Script_Kannada_Numeric
: return Script_Kannada
;
1034 case Script_Malayalam
:
1035 case Script_Malayalam_Numeric
: return Script_Malayalam
;
1041 /***********************************************************************
1042 * ScriptItemizeOpenType (USP10.@)
1044 * Split a Unicode string into shapeable parts.
1047 * pwcInChars [I] String to split.
1048 * cInChars [I] Number of characters in pwcInChars.
1049 * cMaxItems [I] Maximum number of items to return.
1050 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1051 * psState [I] Pointer to a SCRIPT_STATE structure.
1052 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1053 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
1054 * pcItems [O] Number of script items returned.
1058 * Failure: Non-zero HRESULT value.
1060 HRESULT WINAPI
ScriptItemizeOpenType(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1061 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1062 SCRIPT_ITEM
*pItems
, OPENTYPE_TAG
*pScriptTags
, int *pcItems
)
1065 #define Numeric_space 0x0020
1069 int cnt
= 0, index
= 0, str
= 0;
1070 int New_Script
= -1;
1072 WORD
*levels
= NULL
;
1073 WORD
*strength
= NULL
;
1074 WORD
*scripts
= NULL
;
1077 WORD last_indic
= -1;
1079 BOOL forceLevels
= FALSE
;
1081 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
1082 psControl
, psState
, pItems
, pcItems
);
1084 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
1085 return E_INVALIDARG
;
1087 scripts
= heap_alloc(cInChars
* sizeof(WORD
));
1089 return E_OUTOFMEMORY
;
1091 for (i
= 0; i
< cInChars
; i
++)
1093 scripts
[i
] = get_char_script(pwcInChars
[i
]);
1094 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
1095 all Indic scripts */
1096 if ((pwcInChars
[i
] == 0x964 || pwcInChars
[i
] ==0x965) && last_indic
> 0)
1097 scripts
[i
] = last_indic
;
1098 else if (is_indic(scripts
[i
]))
1099 last_indic
= base_indic(scripts
[i
]);
1101 /* Some unicode points (Zero Width Space U+200B -
1102 Right-to-Left Mark U+200F) will force us into bidi mode */
1103 if (!forceLevels
&& pwcInChars
[i
] >= 0x200B && pwcInChars
[i
] <= 0x200F)
1106 /* Diacritical marks merge with other scripts */
1107 if (scripts
[i
] == Script_Diacritical
&& i
> 0)
1108 scripts
[i
] = scripts
[i
-1];
1111 for (i
= 0; i
< cInChars
; i
++)
1113 /* Joiners get merged preferencially right */
1114 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
1117 if (i
+1 == cInChars
)
1118 scripts
[i
] = scripts
[i
-1];
1121 for (j
= i
+1; j
< cInChars
; j
++)
1123 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
1125 scripts
[i
] = scripts
[j
];
1133 if (psState
&& psControl
)
1135 levels
= heap_alloc_zero(cInChars
* sizeof(WORD
));
1139 return E_OUTOFMEMORY
;
1142 BIDI_DetermineLevels(pwcInChars
, cInChars
, psState
, psControl
, levels
);
1143 baselevel
= levels
[0];
1144 for (i
= 0; i
< cInChars
; i
++)
1145 if (levels
[i
]!=levels
[0])
1147 if (i
>= cInChars
&& !odd(baselevel
) && !odd(psState
->uBidiLevel
) && !forceLevels
)
1154 BOOL inNumber
= FALSE
;
1155 static WCHAR math_punc
[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
1157 strength
= heap_alloc_zero(cInChars
* sizeof(WORD
));
1162 return E_OUTOFMEMORY
;
1164 BIDI_GetStrengths(pwcInChars
, cInChars
, psControl
, strength
);
1166 /* We currently mis-level leading Diacriticals */
1167 if (scripts
[0] == Script_Diacritical
)
1168 for (i
= 0; i
< cInChars
&& scripts
[0] == Script_Diacritical
; i
++)
1170 levels
[i
] = odd(levels
[i
])?levels
[i
]+1:levels
[i
];
1171 strength
[i
] = BIDI_STRONG
;
1174 for (i
= 0; i
< cInChars
; i
++)
1176 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
1177 if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && inNumber
&& strchrW(math_punc
,pwcInChars
[i
]))
1179 scripts
[i
] = Script_Numeric
;
1182 else if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && scripts
[i
] == Script_Numeric
)
1190 /* Joiners get merged preferencially right */
1191 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
1194 if (i
+1 == cInChars
&& levels
[i
-1] == levels
[i
])
1195 strength
[i
] = strength
[i
-1];
1197 for (j
= i
+1; j
< cInChars
&& levels
[i
] == levels
[j
]; j
++)
1198 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
1200 strength
[i
] = strength
[j
];
1205 if (psControl
->fMergeNeutralItems
)
1207 /* Merge the neutrals */
1208 for (i
= 0; i
< cInChars
; i
++)
1210 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1213 for (j
= i
; j
> 0; j
--)
1215 if (levels
[i
] != levels
[j
])
1217 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1219 scripts
[i
] = scripts
[j
];
1220 strength
[i
] = strength
[j
];
1225 /* Try going the other way */
1226 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1229 for (j
= i
; j
< cInChars
; j
++)
1231 if (levels
[i
] != levels
[j
])
1233 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1235 scripts
[i
] = scripts
[j
];
1236 strength
[i
] = strength
[j
];
1246 while ((!levels
|| (levels
&& levels
[cnt
+1] == levels
[0])) && (pwcInChars
[cnt
] == Numeric_space
) && cnt
< cInChars
)
1249 if (cnt
== cInChars
) /* All Spaces */
1252 New_Script
= scripts
[cnt
];
1255 pItems
[index
].iCharPos
= 0;
1256 pItems
[index
].a
= scriptInformation
[scripts
[cnt
]].a
;
1257 pScriptTags
[index
] = scriptInformation
[scripts
[cnt
]].scriptTag
;
1259 if (strength
&& strength
[cnt
] == BIDI_STRONG
)
1260 str
= strength
[cnt
];
1268 if (strength
[cnt
] == BIDI_STRONG
)
1269 layoutRTL
= (odd(levels
[cnt
]))?1:0;
1271 layoutRTL
= (psState
->uBidiLevel
|| odd(levels
[cnt
]))?1:0;
1272 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1273 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1274 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1276 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1278 layoutRTL
= (odd(baselevel
))?1:0;
1279 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1280 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
1281 pItems
[index
].a
.fRTL
= odd(baselevel
);
1284 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1285 levels
?levels
[cnt
]:-1, str
, New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
1286 pItems
[index
].iCharPos
);
1288 for (cnt
=1; cnt
< cInChars
; cnt
++)
1290 if(pwcInChars
[cnt
] != Numeric_space
)
1291 New_Script
= scripts
[cnt
];
1295 while (cnt
+ j
< cInChars
- 1 && pwcInChars
[cnt
+j
] == Numeric_space
&& levels
[cnt
] == levels
[cnt
+j
])
1297 if (cnt
+ j
< cInChars
&& levels
[cnt
] == levels
[cnt
+j
])
1298 New_Script
= scripts
[cnt
+j
];
1300 New_Script
= scripts
[cnt
];
1304 /* merge space strengths*/
1305 if (strength
&& strength
[cnt
] == BIDI_STRONG
&& str
!= BIDI_STRONG
&& New_Script
== pItems
[index
].a
.eScript
)
1308 if (strength
&& strength
[cnt
] == BIDI_NEUTRAL
&& str
== BIDI_STRONG
&& pwcInChars
[cnt
] != Numeric_space
&& New_Script
== pItems
[index
].a
.eScript
)
1311 /* changes in level */
1312 if (levels
&& (levels
[cnt
] != pItems
[index
].a
.s
.uBidiLevel
))
1314 TRACE("Level break(%i/%i)\n",pItems
[index
].a
.s
.uBidiLevel
,levels
[cnt
]);
1317 /* changes in strength */
1318 else if (strength
&& pwcInChars
[cnt
] != Numeric_space
&& str
!= strength
[cnt
])
1320 TRACE("Strength break (%i/%i)\n",str
,strength
[cnt
]);
1323 /* changes in script */
1324 else if (((pwcInChars
[cnt
] != Numeric_space
) && (New_Script
!= -1) && (New_Script
!= pItems
[index
].a
.eScript
)) || (New_Script
== Script_Control
))
1326 TRACE("Script break(%i/%i)\n",pItems
[index
].a
.eScript
,New_Script
);
1330 if (!new_run
&& strength
&& str
== BIDI_STRONG
)
1332 layoutRTL
= odd(levels
[cnt
])?1:0;
1333 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1338 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
);
1341 if (index
+1 > cMaxItems
)
1342 return E_OUTOFMEMORY
;
1345 str
= strength
[cnt
];
1347 pItems
[index
].iCharPos
= cnt
;
1348 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1350 pItems
[index
].a
= scriptInformation
[New_Script
].a
;
1351 pScriptTags
[index
] = scriptInformation
[New_Script
].scriptTag
;
1354 if (levels
[cnt
] == 0)
1357 layoutRTL
= (layoutRTL
|| odd(levels
[cnt
]))?1:0;
1358 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1359 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1360 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1362 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1364 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1365 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1366 pItems
[index
].a
.fRTL
= odd(baselevel
);
1369 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1373 /* While not strictly necessary according to the spec, make sure the n+1
1374 * item is set up to prevent random behaviour if the caller erroneously
1375 * checks the n+1 structure */
1377 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1379 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1381 /* Set one SCRIPT_STATE item being returned */
1382 if (index
+ 1 > cMaxItems
) return E_OUTOFMEMORY
;
1383 if (pcItems
) *pcItems
= index
;
1385 /* Set SCRIPT_ITEM */
1386 pItems
[index
].iCharPos
= cnt
; /* the last item contains the ptr to the lastchar */
1388 heap_free(strength
);
1393 /***********************************************************************
1394 * ScriptItemize (USP10.@)
1396 * Split a Unicode string into shapeable parts.
1399 * pwcInChars [I] String to split.
1400 * cInChars [I] Number of characters in pwcInChars.
1401 * cMaxItems [I] Maximum number of items to return.
1402 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1403 * psState [I] Pointer to a SCRIPT_STATE structure.
1404 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1405 * pcItems [O] Number of script items returned.
1409 * Failure: Non-zero HRESULT value.
1411 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1412 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1413 SCRIPT_ITEM
*pItems
, int *pcItems
)
1415 OPENTYPE_TAG
*discarded_tags
;
1418 discarded_tags
= heap_alloc(cMaxItems
* sizeof(OPENTYPE_TAG
));
1419 if (!discarded_tags
)
1420 return E_OUTOFMEMORY
;
1421 res
= ScriptItemizeOpenType(pwcInChars
, cInChars
, cMaxItems
, psControl
, psState
, pItems
, discarded_tags
, pcItems
);
1422 heap_free(discarded_tags
);
1426 static inline int getGivenTabWidth(ScriptCache
*psc
, SCRIPT_TABDEF
*pTabdef
, int charPos
, int current_x
)
1430 INT
*lpTabPos
= NULL
;
1435 lpTabPos
= pTabdef
->pTabStops
;
1437 if (pTabdef
&& pTabdef
->iTabOrigin
)
1439 if (pTabdef
->iScale
)
1440 nTabOrg
= (pTabdef
->iTabOrigin
* pTabdef
->iScale
)/4;
1442 nTabOrg
= pTabdef
->iTabOrigin
* psc
->tm
.tmAveCharWidth
;
1446 cTabStops
= pTabdef
->cTabStops
;
1450 if (pTabdef
->iScale
)
1451 defWidth
= ((pTabdef
->pTabStops
[0])*pTabdef
->iScale
) / 4;
1453 defWidth
= (pTabdef
->pTabStops
[0])*psc
->tm
.tmAveCharWidth
;
1457 defWidth
= 8 * psc
->tm
.tmAveCharWidth
;
1459 for (; cTabStops
>0 ; lpTabPos
++, cTabStops
--)
1461 int position
= *lpTabPos
;
1463 position
= -1 * position
;
1464 if (pTabdef
->iScale
)
1465 position
= (position
* pTabdef
->iScale
) / 4;
1467 position
= position
* psc
->tm
.tmAveCharWidth
;
1469 if( nTabOrg
+ position
> current_x
)
1473 /* a left aligned tab */
1474 x
= (nTabOrg
+ *lpTabPos
) - current_x
;
1479 FIXME("Negative tabstop\n");
1484 if ((!cTabStops
) && (defWidth
> 0))
1485 x
=((((current_x
- nTabOrg
) / defWidth
)+1) * defWidth
) - current_x
;
1486 else if ((!cTabStops
) && (defWidth
< 0))
1487 FIXME("TODO: Negative defWidth\n");
1492 /***********************************************************************
1493 * Helper function for ScriptStringAnalyse
1495 static BOOL
requires_fallback(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
1496 const WCHAR
*pwcInChars
, int cChars
)
1498 /* FIXME: When to properly fallback is still a bit of a mystery */
1501 if (psa
->fNoGlyphIndex
)
1504 if (init_script_cache(hdc
, psc
) != S_OK
)
1507 if (SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
) != S_OK
)
1510 glyphs
= heap_alloc(sizeof(WORD
) * cChars
);
1513 if (ScriptGetCMap(hdc
, psc
, pwcInChars
, cChars
, 0, glyphs
) != S_OK
)
1523 static void find_fallback_font(DWORD scriptid
, LPWSTR FaceName
)
1527 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Uniscribe\\Fallback", &hkey
))
1529 static const WCHAR szFmt
[] = {'%','x',0};
1531 DWORD count
= LF_FACESIZE
* sizeof(WCHAR
);
1534 sprintfW(value
, szFmt
, scriptInformation
[scriptid
].scriptTag
);
1535 if (RegQueryValueExW(hkey
, value
, 0, &type
, (LPBYTE
)FaceName
, &count
))
1536 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1540 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1543 /***********************************************************************
1544 * ScriptStringAnalyse (USP10.@)
1547 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
1548 int cGlyphs
, int iCharset
, DWORD dwFlags
,
1549 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
1550 SCRIPT_STATE
*psState
, const int *piDx
,
1551 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
1552 SCRIPT_STRING_ANALYSIS
*pssa
)
1554 HRESULT hr
= E_OUTOFMEMORY
;
1555 StringAnalysis
*analysis
= NULL
;
1556 SCRIPT_CONTROL sControl
;
1557 SCRIPT_STATE sState
;
1558 int i
, num_items
= 255;
1560 WCHAR
*iString
= NULL
;
1562 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1563 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
1564 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
1568 FIXME("Only Unicode strings are supported\n");
1569 return E_INVALIDARG
;
1571 if (cString
< 1 || !pString
) return E_INVALIDARG
;
1572 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
1574 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
1575 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
1577 /* FIXME: handle clipping */
1578 analysis
->clip_len
= cString
;
1579 analysis
->hdc
= hdc
;
1580 analysis
->dwFlags
= dwFlags
;
1585 memset(&sState
, 0, sizeof(SCRIPT_STATE
));
1588 sControl
= *psControl
;
1590 memset(&sControl
, 0, sizeof(SCRIPT_CONTROL
));
1592 if (dwFlags
& SSA_PASSWORD
)
1594 iString
= heap_alloc(sizeof(WCHAR
)*cString
);
1600 for (i
= 0; i
< cString
; i
++)
1601 iString
[i
] = *((const WCHAR
*)pString
);
1605 hr
= ScriptItemize(pString
, cString
, num_items
, &sControl
, &sState
, analysis
->pItem
,
1606 &analysis
->numItems
);
1608 while (hr
== E_OUTOFMEMORY
)
1613 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
1616 analysis
->pItem
= tmp
;
1617 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
1618 &analysis
->numItems
);
1620 if (hr
!= S_OK
) goto error
;
1622 /* set back to out of memory for default goto error behaviour */
1625 if (dwFlags
& SSA_BREAK
)
1627 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
1629 for (i
= 0; i
< analysis
->numItems
; i
++)
1630 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
]);
1636 if (!(analysis
->logical2visual
= heap_alloc_zero(sizeof(int) * analysis
->numItems
)))
1638 if (!(BidiLevel
= heap_alloc_zero(analysis
->numItems
)))
1641 if (dwFlags
& SSA_GLYPHS
)
1644 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
1646 heap_free(BidiLevel
);
1650 for (i
= 0; i
< analysis
->numItems
; i
++)
1652 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
;
1653 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1654 int numGlyphs
= 1.5 * cChar
+ 16;
1655 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
1656 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
1657 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
1658 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * numGlyphs
);
1659 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
1660 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
1661 int numGlyphsReturned
;
1662 HFONT originalFont
= 0x0;
1664 /* FIXME: non unicode strings */
1665 const WCHAR
* pStr
= (const WCHAR
*)pString
;
1666 analysis
->glyphs
[i
].fallbackFont
= NULL
;
1668 if (!glyphs
|| !pwLogClust
|| !piAdvance
|| !psva
|| !pGoffset
|| !abc
)
1670 heap_free (BidiLevel
);
1672 heap_free (pwLogClust
);
1673 heap_free (piAdvance
);
1675 heap_free (pGoffset
);
1681 if ((dwFlags
& SSA_FALLBACK
) && requires_fallback(hdc
, sc
, &analysis
->pItem
[i
].a
, &pStr
[analysis
->pItem
[i
].iCharPos
], cChar
))
1684 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), & lf
);
1685 lf
.lfCharSet
= scriptInformation
[analysis
->pItem
[i
].a
.eScript
].props
.bCharSet
;
1686 find_fallback_font(analysis
->pItem
[i
].a
.eScript
, lf
.lfFaceName
);
1687 analysis
->glyphs
[i
].fallbackFont
= CreateFontIndirectW(&lf
);
1688 if (analysis
->glyphs
[i
].fallbackFont
)
1690 ScriptFreeCache(sc
);
1691 originalFont
= SelectObject(hdc
, analysis
->glyphs
[i
].fallbackFont
);
1695 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
1696 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
1697 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
1698 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
1699 piAdvance
, pGoffset
, abc
);
1701 SelectObject(hdc
,originalFont
);
1703 if (dwFlags
& SSA_TAB
)
1706 for (tabi
= 0; tabi
< cChar
; tabi
++)
1708 if (pStr
[analysis
->pItem
[i
].iCharPos
+tabi
] == 0x0009)
1709 piAdvance
[tabi
] = getGivenTabWidth(analysis
->glyphs
[i
].sc
, pTabdef
, analysis
->pItem
[i
].iCharPos
+tabi
, tab_x
);
1710 tab_x
+=piAdvance
[tabi
];
1714 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
1715 analysis
->glyphs
[i
].glyphs
= glyphs
;
1716 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
1717 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
1718 analysis
->glyphs
[i
].psva
= psva
;
1719 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
1720 analysis
->glyphs
[i
].abc
= abc
;
1721 analysis
->glyphs
[i
].iMaxPosX
= -1;
1723 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1728 for (i
= 0; i
< analysis
->numItems
; i
++)
1729 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1732 ScriptLayout(analysis
->numItems
, BidiLevel
, NULL
, analysis
->logical2visual
);
1733 heap_free(BidiLevel
);
1741 heap_free(analysis
->glyphs
);
1742 heap_free(analysis
->logattrs
);
1743 heap_free(analysis
->pItem
);
1744 heap_free(analysis
->logical2visual
);
1745 heap_free(analysis
);
1749 static inline BOOL
does_glyph_start_cluster(const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cChars
, int glyph
, int direction
)
1753 if (pva
[glyph
].fClusterStart
)
1755 for (i
= 0; i
< cChars
; i
++)
1756 if (pwLogClust
[i
] == glyph
) break;
1764 static HRESULT
SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa
,
1775 StringAnalysis
*analysis
;
1778 COLORREF BkColor
= 0x0;
1779 COLORREF TextColor
= 0x0;
1781 INT runStart
, runEnd
;
1782 INT iGlyph
, cGlyphs
;
1783 HFONT oldFont
= 0x0;
1785 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1786 ssa
, iX
, iY
, iItem
, cStart
, cEnd
, uOptions
, fSelected
, fDisabled
);
1788 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1790 if ((cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
<= cStart
) ||
1791 (cEnd
>= 0 && analysis
->pItem
[iItem
].iCharPos
>= cEnd
))
1796 BkMode
= GetBkMode(analysis
->hdc
);
1797 SetBkMode( analysis
->hdc
, OPAQUE
);
1798 BkColor
= GetBkColor(analysis
->hdc
);
1799 SetBkColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1802 TextColor
= GetTextColor(analysis
->hdc
);
1803 SetTextColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1806 if (analysis
->glyphs
[iItem
].fallbackFont
)
1807 oldFont
= SelectObject(analysis
->hdc
, analysis
->glyphs
[iItem
].fallbackFont
);
1809 if (cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cStart
&& analysis
->pItem
[iItem
].iCharPos
<= cStart
)
1810 runStart
= cStart
- analysis
->pItem
[iItem
].iCharPos
;
1813 if (cEnd
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cEnd
&& analysis
->pItem
[iItem
].iCharPos
<= cEnd
)
1814 runEnd
= (cEnd
-1) - analysis
->pItem
[iItem
].iCharPos
;
1816 runEnd
= (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
) - 1;
1818 if (analysis
->pItem
[iItem
].a
.fRTL
)
1820 if (cEnd
>= 0 && cEnd
< analysis
->pItem
[iItem
+1].iCharPos
)
1821 ScriptStringCPtoX(ssa
, cEnd
, FALSE
, &off_x
);
1823 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
+1].iCharPos
-1, TRUE
, &off_x
);
1827 if (cStart
>=0 && runStart
)
1828 ScriptStringCPtoX(ssa
, cStart
, FALSE
, &off_x
);
1830 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
].iCharPos
, FALSE
, &off_x
);
1833 if (analysis
->pItem
[iItem
].a
.fRTL
)
1834 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
];
1836 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
];
1838 if (analysis
->pItem
[iItem
].a
.fRTL
)
1839 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
] - iGlyph
;
1841 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
] - iGlyph
;
1845 if (cEnd
< 0 || scriptInformation
[analysis
->pItem
[iItem
].a
.eScript
].props
.fNeedsCaretInfo
)
1850 clust_glyph
= iGlyph
+ cGlyphs
;
1851 if (analysis
->pItem
[iItem
].a
.fRTL
)
1856 while(clust_glyph
< analysis
->glyphs
[iItem
].numGlyphs
&&
1857 !does_glyph_start_cluster(analysis
->glyphs
[iItem
].psva
, analysis
->glyphs
[iItem
].pwLogClust
, (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
), clust_glyph
, direction
))
1864 hr
= ScriptTextOut(analysis
->hdc
,
1865 (SCRIPT_CACHE
*)&analysis
->glyphs
[iItem
].sc
, iX
+ off_x
,
1866 iY
, uOptions
, prc
, &analysis
->pItem
[iItem
].a
, NULL
, 0,
1867 &analysis
->glyphs
[iItem
].glyphs
[iGlyph
], cGlyphs
,
1868 &analysis
->glyphs
[iItem
].piAdvance
[iGlyph
], NULL
,
1869 &analysis
->glyphs
[iItem
].pGoffset
[iGlyph
]);
1871 TRACE("ScriptTextOut hr=%08x\n", hr
);
1875 SetBkColor(analysis
->hdc
, BkColor
);
1876 SetBkMode( analysis
->hdc
, BkMode
);
1878 SetTextColor(analysis
->hdc
, TextColor
);
1880 if (analysis
->glyphs
[iItem
].fallbackFont
)
1881 SelectObject(analysis
->hdc
, oldFont
);
1886 /***********************************************************************
1887 * ScriptStringOut (USP10.@)
1889 * This function takes the output of ScriptStringAnalyse and joins the segments
1890 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1891 * only processes glyphs.
1894 * ssa [I] buffer to hold the analysed string components
1895 * iX [I] X axis displacement for output
1896 * iY [I] Y axis displacement for output
1897 * uOptions [I] flags controling output processing
1898 * prc [I] rectangle coordinates
1899 * iMinSel [I] starting pos for substringing output string
1900 * iMaxSel [I] ending pos for substringing output string
1901 * fDisabled [I] controls text highlighting
1905 * Failure: is the value returned by ScriptTextOut
1907 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1916 StringAnalysis
*analysis
;
1920 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1921 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1923 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1924 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return E_INVALIDARG
;
1926 for (item
= 0; item
< analysis
->numItems
; item
++)
1928 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], -1, -1, uOptions
, prc
, FALSE
, fDisabled
);
1933 if (iMinSel
< iMaxSel
&& (iMinSel
> 0 || iMaxSel
> 0))
1935 if (iMaxSel
> 0 && iMinSel
< 0)
1937 for (item
= 0; item
< analysis
->numItems
; item
++)
1939 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], iMinSel
, iMaxSel
, uOptions
, prc
, TRUE
, fDisabled
);
1948 /***********************************************************************
1949 * ScriptStringCPtoX (USP10.@)
1952 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1956 StringAnalysis
* analysis
= ssa
;
1958 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1960 if (!ssa
|| !pX
) return S_FALSE
;
1961 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1963 /* icp out of range */
1966 analysis
->invalid
= TRUE
;
1967 return E_INVALIDARG
;
1970 for(item
=0; item
<analysis
->numItems
; item
++)
1975 i
= analysis
->logical2visual
[item
];
1976 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1977 /* initialize max extents for uninitialized runs */
1978 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1980 if (analysis
->pItem
[i
].a
.fRTL
)
1981 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1982 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1983 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1985 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1986 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1987 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1990 if (icp
>= analysis
->pItem
[i
+1].iCharPos
|| icp
< analysis
->pItem
[i
].iCharPos
)
1992 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
1996 icp
-= analysis
->pItem
[i
].iCharPos
;
1997 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1998 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1999 &analysis
->pItem
[i
].a
, &offset
);
2006 /* icp out of range */
2007 analysis
->invalid
= TRUE
;
2008 return E_INVALIDARG
;
2011 /***********************************************************************
2012 * ScriptStringXtoCP (USP10.@)
2015 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
2017 StringAnalysis
* analysis
= ssa
;
2020 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
2022 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
2023 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
2028 if (analysis
->pItem
[0].a
.fRTL
)
2031 *piTrailing
= FALSE
;
2041 for(item
=0; item
<analysis
->numItems
; item
++)
2046 for (i
= 0; i
< analysis
->numItems
&& analysis
->logical2visual
[i
] != item
; i
++)
2049 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
2050 /* initialize max extents for uninitialized runs */
2051 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
2053 if (analysis
->pItem
[i
].a
.fRTL
)
2054 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2055 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2056 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2058 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2059 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2060 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2063 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
2065 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
2069 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2070 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2071 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
2072 *piCh
+= analysis
->pItem
[i
].iCharPos
;
2078 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
2079 *piTrailing
= FALSE
;
2085 /***********************************************************************
2086 * ScriptStringFree (USP10.@)
2088 * Free a string analysis.
2091 * pssa [I] string analysis.
2095 * Failure: Non-zero HRESULT value.
2097 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
2099 StringAnalysis
* analysis
;
2103 TRACE("(%p)\n", pssa
);
2105 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
2107 invalid
= analysis
->invalid
;
2109 if (analysis
->glyphs
)
2111 for (i
= 0; i
< analysis
->numItems
; i
++)
2113 heap_free(analysis
->glyphs
[i
].glyphs
);
2114 heap_free(analysis
->glyphs
[i
].pwLogClust
);
2115 heap_free(analysis
->glyphs
[i
].piAdvance
);
2116 heap_free(analysis
->glyphs
[i
].psva
);
2117 heap_free(analysis
->glyphs
[i
].pGoffset
);
2118 heap_free(analysis
->glyphs
[i
].abc
);
2119 if (analysis
->glyphs
[i
].fallbackFont
)
2120 DeleteObject(analysis
->glyphs
[i
].fallbackFont
);
2121 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
);
2122 heap_free(analysis
->glyphs
[i
].sc
);
2124 heap_free(analysis
->glyphs
);
2127 heap_free(analysis
->pItem
);
2128 heap_free(analysis
->logattrs
);
2129 heap_free(analysis
->sz
);
2130 heap_free(analysis
->logical2visual
);
2131 heap_free(analysis
);
2133 if (invalid
) return E_INVALIDARG
;
2137 static inline int get_cluster_size(const WORD
*pwLogClust
, int cChars
, int item
,
2138 int direction
, int* iCluster
, int *check_out
)
2142 WORD clust
= pwLogClust
[item
];
2144 for (check
= item
+direction
; check
< cChars
&& check
>= 0; check
+=direction
)
2146 if (pwLogClust
[check
] == clust
)
2149 if (iCluster
&& *iCluster
== -1)
2161 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
)
2164 int log_clust_max
= 0;
2167 advance
= piAdvance
[glyph
];
2169 for (i
= 0; i
< cChars
; i
++)
2171 if (pwLogClust
[i
] > log_clust_max
)
2172 log_clust_max
= pwLogClust
[i
];
2175 if (glyph
> log_clust_max
)
2178 for (glyph
+=direction
; glyph
< cGlyphs
&& glyph
>= 0; glyph
+=direction
)
2181 if (does_glyph_start_cluster(pva
, pwLogClust
, cChars
, glyph
, direction
))
2183 if (glyph
> log_clust_max
)
2185 advance
+= piAdvance
[glyph
];
2191 /***********************************************************************
2192 * ScriptCPtoX (USP10.@)
2195 HRESULT WINAPI
ScriptCPtoX(int iCP
,
2199 const WORD
*pwLogClust
,
2200 const SCRIPT_VISATTR
*psva
,
2201 const int *piAdvance
,
2202 const SCRIPT_ANALYSIS
*psa
,
2210 float special_size
= 0.0;
2215 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2216 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2219 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2227 int max_clust
= pwLogClust
[0];
2229 for (item
=0; item
< cGlyphs
; item
++)
2230 if (pwLogClust
[item
] > max_clust
)
2232 ERR("We do not handle non reversed clusters properly\n");
2237 for (item
= max_clust
; item
>=0; item
--)
2238 iMaxPos
+= piAdvance
[item
];
2242 for (item
=0; item
< iCP
&& item
< cChars
; item
++)
2244 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
2247 int clust
= pwLogClust
[item
];
2250 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, 1, &iCluster
,
2253 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, 1);
2255 if (check
>= cChars
&& !iMaxPos
)
2257 for (check
= clust
; check
< cChars
; check
++)
2258 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, 1);
2260 special_size
/= (cChars
- item
);
2261 iPosX
+= special_size
;
2265 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2268 if (clust_size
== 0)
2272 iPosX
+= advance
/ (float)clust_size
;
2275 else if (iSpecial
!= -1)
2276 iPosX
+= special_size
;
2277 else /* (iCluster != -1) */
2279 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], 1);
2280 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2283 if (clust_size
== 0)
2287 iPosX
+= adv
/ (float)clust_size
;
2293 iPosX
= iMaxPos
- iPosX
;
2299 TRACE("*piX=%d\n", *piX
);
2303 /***********************************************************************
2304 * ScriptXtoCP (USP10.@)
2307 HRESULT WINAPI
ScriptXtoCP(int iX
,
2310 const WORD
*pwLogClust
,
2311 const SCRIPT_VISATTR
*psva
,
2312 const int *piAdvance
,
2313 const SCRIPT_ANALYSIS
*psa
,
2325 float special_size
= 0.0;
2328 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2329 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2330 psa
, piCP
, piTrailing
);
2332 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2337 int max_clust
= pwLogClust
[0];
2346 for (item
=0; item
< cChars
; item
++)
2347 if (pwLogClust
[item
] > max_clust
)
2349 ERR("We do not handle non reversed clusters properly\n");
2361 iPosX
= iLastPosX
= 0;
2366 for (; iPosX
<= iX
&& item
< cChars
&& item
>= 0; item
+=direction
)
2369 if (iSpecial
== -1 &&
2372 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
2373 (direction
< 0 && iCluster
-clust_size
>= item
))
2379 int clust
= pwLogClust
[item
];
2383 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, direction
,
2385 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, direction
);
2387 if (check
>= cChars
&& direction
> 0)
2389 for (check
= clust
; check
< cChars
; check
++)
2390 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, direction
);
2392 special_size
/= (cChars
- item
);
2393 iPosX
+= special_size
;
2397 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2404 iPosX
+= advance
/ (float)clust_size
;
2407 else if (iSpecial
!= -1)
2408 iPosX
+= special_size
;
2409 else /* (iCluster != -1) */
2411 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], direction
);
2412 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2419 iPosX
+= adv
/ (float)clust_size
;
2427 if (item
< cChars
&& ((iPosX
- iLastPosX
) / 2.0) + iX
>= iPosX
)
2429 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2430 item
+=(clust_size
-1);
2438 if (iX
== iLastPosX
)
2440 if (iX
>= iLastPosX
&& iX
<= iPosX
)
2443 if (iLastPosX
== iX
)
2445 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
2447 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2448 item
-=(clust_size
-1);
2457 TRACE("*piCP=%d\n", *piCP
);
2458 TRACE("*piTrailing=%d\n", *piTrailing
);
2462 /***********************************************************************
2463 * ScriptBreak (USP10.@)
2465 * Retrieve line break information.
2468 * chars [I] Array of characters.
2469 * sa [I] String analysis.
2470 * la [I] Array of logical attribute structures.
2476 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
2478 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
2480 if (!la
) return S_FALSE
;
2482 BREAK_line(chars
, count
, sa
, la
);
2487 /***********************************************************************
2488 * ScriptIsComplex (USP10.@)
2490 * Determine if a string is complex.
2493 * chars [I] Array of characters to test.
2494 * len [I] Length in characters.
2502 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
2506 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
2508 for (i
= 0; i
< len
; i
++)
2512 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
2515 script
= get_char_script(chars
[i
]);
2516 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
2517 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
2523 /***********************************************************************
2524 * ScriptShapeOpenType (USP10.@)
2526 * Produce glyphs and visual attributes for a run.
2529 * hdc [I] Device context.
2530 * psc [I/O] Opaque pointer to a script cache.
2531 * psa [I/O] Script analysis.
2532 * tagScript [I] The OpenType tag for the Script
2533 * tagLangSys [I] The OpenType tag for the Language
2534 * rcRangeChars[I] Array of Character counts in each range
2535 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2536 * cRanges [I] Count of ranges
2537 * pwcChars [I] Array of characters specifying the run.
2538 * cChars [I] Number of characters in pwcChars.
2539 * cMaxGlyphs [I] Length of pwOutGlyphs.
2540 * pwLogClust [O] Array of logical cluster info.
2541 * pCharProps [O] Array of character property values
2542 * pwOutGlyphs [O] Array of glyphs.
2543 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2544 * pcGlyphs [O] Number of glyphs returned.
2548 * Failure: Non-zero HRESULT value.
2550 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
2551 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
2552 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
2553 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2554 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
2555 int cMaxGlyphs
, WORD
*pwLogClust
,
2556 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
2557 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
2563 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2565 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2566 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2567 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
2569 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
2570 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
2572 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
2573 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2576 FIXME("Ranges not supported yet\n");
2578 rtl
= (psa
&& !psa
->fLogicalOrder
&& psa
->fRTL
);
2581 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2582 if (!pwLogClust
) return E_FAIL
;
2584 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2585 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2587 /* set fNoGlyphIndex non truetype/opentype fonts */
2588 if (!psa
->fNoGlyphIndex
&& !((ScriptCache
*)*psc
)->sfnt
)
2589 psa
->fNoGlyphIndex
= TRUE
;
2591 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2592 for (i
= 0; i
< cChars
; i
++)
2595 if (rtl
) idx
= cChars
- 1 - i
;
2596 /* FIXME: set to better values */
2597 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
2598 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
2599 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
2600 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
2601 pOutGlyphProps
[i
].sva
.fReserved
= 0;
2602 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
2604 /* FIXME: have the shaping engine set this */
2605 pCharProps
[i
].fCanGlyphAlone
= 0;
2607 pwLogClust
[i
] = idx
;
2610 if (psa
&& !psa
->fNoGlyphIndex
)
2613 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
2615 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
2616 if (!rChars
) return E_OUTOFMEMORY
;
2617 for (i
= 0; i
< cChars
; i
++)
2621 if (rtl
) idx
= cChars
- 1 - i
;
2623 chInput
= mirror_char(pwcChars
[idx
]);
2625 chInput
= pwcChars
[idx
];
2626 /* special case for tabs */
2627 if (chInput
== 0x0009)
2629 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
2637 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
)
2642 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
2644 rChars
[i
] = chInput
;
2647 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
2648 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
2649 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
2654 TRACE("no glyph translation\n");
2655 for (i
= 0; i
< cChars
; i
++)
2658 /* No mirroring done here */
2659 if (rtl
) idx
= cChars
- 1 - i
;
2660 pwOutGlyphs
[i
] = pwcChars
[idx
];
2668 /***********************************************************************
2669 * ScriptShape (USP10.@)
2671 * Produce glyphs and visual attributes for a run.
2674 * hdc [I] Device context.
2675 * psc [I/O] Opaque pointer to a script cache.
2676 * pwcChars [I] Array of characters specifying the run.
2677 * cChars [I] Number of characters in pwcChars.
2678 * cMaxGlyphs [I] Length of pwOutGlyphs.
2679 * psa [I/O] Script analysis.
2680 * pwOutGlyphs [O] Array of glyphs.
2681 * pwLogClust [O] Array of logical cluster info.
2682 * psva [O] Array of visual attributes.
2683 * pcGlyphs [O] Number of glyphs returned.
2687 * Failure: Non-zero HRESULT value.
2689 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
2690 int cChars
, int cMaxGlyphs
,
2691 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
2692 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
2696 SCRIPT_CHARPROP
*charProps
;
2697 SCRIPT_GLYPHPROP
*glyphProps
;
2699 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
2700 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2702 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
2703 if (!charProps
) return E_OUTOFMEMORY
;
2704 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
2707 heap_free(charProps
);
2708 return E_OUTOFMEMORY
;
2711 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
2715 for (i
= 0; i
< *pcGlyphs
; i
++)
2716 psva
[i
] = glyphProps
[i
].sva
;
2719 heap_free(charProps
);
2720 heap_free(glyphProps
);
2725 /***********************************************************************
2726 * ScriptPlaceOpenType (USP10.@)
2728 * Produce advance widths for a run.
2731 * hdc [I] Device context.
2732 * psc [I/O] Opaque pointer to a script cache.
2733 * psa [I/O] String analysis.
2734 * tagScript [I] The OpenType tag for the Script
2735 * tagLangSys [I] The OpenType tag for the Language
2736 * rcRangeChars[I] Array of Character counts in each range
2737 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2738 * cRanges [I] Count of ranges
2739 * pwcChars [I] Array of characters specifying the run.
2740 * pwLogClust [I] Array of logical cluster info
2741 * pCharProps [I] Array of character property values
2742 * cChars [I] Number of characters in pwcChars.
2743 * pwGlyphs [I] Array of glyphs.
2744 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2745 * cGlyphs [I] Count of Glyphs
2746 * piAdvance [O] Array of advance widths.
2747 * pGoffset [O] Glyph offsets.
2748 * pABC [O] Combined ABC width.
2752 * Failure: Non-zero HRESULT value.
2755 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
2756 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
2757 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2758 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
2759 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
2760 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
2761 int cGlyphs
, int *piAdvance
,
2762 GOFFSET
*pGoffset
, ABC
*pABC
2768 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2770 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2771 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2772 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
2775 if (!pGlyphProps
) return E_INVALIDARG
;
2776 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2777 if (!pGoffset
) return E_FAIL
;
2780 FIXME("Ranges not supported yet\n");
2782 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2783 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2785 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
2786 for (i
= 0; i
< cGlyphs
; i
++)
2789 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
2791 if (!hdc
) return E_PENDING
;
2792 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
2794 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
2799 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
2801 abc
.abcA
= abc
.abcC
= 0;
2803 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
2807 pABC
->abcA
+= abc
.abcA
;
2808 pABC
->abcB
+= abc
.abcB
;
2809 pABC
->abcC
+= abc
.abcC
;
2811 /* FIXME: set to more reasonable values */
2812 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
2813 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
2816 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
2820 /***********************************************************************
2821 * ScriptPlace (USP10.@)
2823 * Produce advance widths for a run.
2826 * hdc [I] Device context.
2827 * psc [I/O] Opaque pointer to a script cache.
2828 * pwGlyphs [I] Array of glyphs.
2829 * cGlyphs [I] Number of glyphs in pwGlyphs.
2830 * psva [I] Array of visual attributes.
2831 * psa [I/O] String analysis.
2832 * piAdvance [O] Array of advance widths.
2833 * pGoffset [O] Glyph offsets.
2834 * pABC [O] Combined ABC width.
2838 * Failure: Non-zero HRESULT value.
2840 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
2841 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
2842 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
2845 SCRIPT_GLYPHPROP
*glyphProps
;
2848 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
2849 piAdvance
, pGoffset
, pABC
);
2851 if (!psva
) return E_INVALIDARG
;
2852 if (!pGoffset
) return E_FAIL
;
2854 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
2855 if (!glyphProps
) return E_OUTOFMEMORY
;
2857 for (i
= 0; i
< cGlyphs
; i
++)
2858 glyphProps
[i
].sva
= psva
[i
];
2860 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
2862 heap_free(glyphProps
);
2867 /***********************************************************************
2868 * ScriptGetCMap (USP10.@)
2870 * Retrieve glyph indices.
2873 * hdc [I] Device context.
2874 * psc [I/O] Opaque pointer to a script cache.
2875 * pwcInChars [I] Array of Unicode characters.
2876 * cChars [I] Number of characters in pwcInChars.
2877 * dwFlags [I] Flags.
2878 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2882 * Failure: Non-zero HRESULT value.
2884 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
2885 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
2890 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
2891 cChars
, dwFlags
, pwOutGlyphs
);
2893 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2897 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2899 for (i
= 0; i
< cChars
; i
++)
2902 if (dwFlags
== SGCM_RTL
)
2903 inChar
= mirror_char(pwcInChars
[i
]);
2905 inChar
= pwcInChars
[i
];
2906 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
2909 if (!hdc
) return E_PENDING
;
2910 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
2911 if (glyph
== 0xffff)
2916 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
2922 TRACE("no glyph translation\n");
2923 for (i
= 0; i
< cChars
; i
++)
2926 if (dwFlags
== SGCM_RTL
)
2927 inChar
= mirror_char(pwcInChars
[i
]);
2929 inChar
= pwcInChars
[i
];
2930 pwOutGlyphs
[i
] = inChar
;
2936 /***********************************************************************
2937 * ScriptTextOut (USP10.@)
2940 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
2941 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
2942 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
2943 const int *piJustify
, const GOFFSET
*pGoffset
)
2947 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2948 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
2949 piAdvance
, piJustify
, pGoffset
);
2951 if (!hdc
|| !psc
) return E_INVALIDARG
;
2952 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
2954 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
2955 fuOptions
|= ETO_IGNORELANGUAGE
;
2956 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
2957 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
2959 if (psa
->fRTL
&& psa
->fLogicalOrder
)
2964 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
2966 return E_OUTOFMEMORY
;
2968 for (i
= 0; i
< cGlyphs
; i
++)
2969 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
2971 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
2973 heap_free(rtlGlyphs
);
2976 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
2982 /***********************************************************************
2983 * ScriptCacheGetHeight (USP10.@)
2985 * Retrieve the height of the font in the cache.
2988 * hdc [I] Device context.
2989 * psc [I/O] Opaque pointer to a script cache.
2990 * height [O] Receives font height.
2994 * Failure: Non-zero HRESULT value.
2996 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
3000 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
3002 if (!height
) return E_INVALIDARG
;
3003 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
3005 *height
= get_cache_height(psc
);
3009 /***********************************************************************
3010 * ScriptGetGlyphABCWidth (USP10.@)
3012 * Retrieve the width of a glyph.
3015 * hdc [I] Device context.
3016 * psc [I/O] Opaque pointer to a script cache.
3017 * glyph [I] Glyph to retrieve the width for.
3018 * abc [O] ABC widths of the glyph.
3022 * Failure: Non-zero HRESULT value.
3024 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
3028 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
3030 if (!abc
) return E_INVALIDARG
;
3031 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
3033 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
3035 if (!hdc
) return E_PENDING
;
3036 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
3038 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
3043 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
3045 abc
->abcA
= abc
->abcC
= 0;
3047 set_cache_glyph_widths(psc
, glyph
, abc
);
3052 /***********************************************************************
3053 * ScriptLayout (USP10.@)
3055 * Map embedding levels to visual and/or logical order.
3058 * runs [I] Size of level array.
3059 * level [I] Array of embedding levels.
3060 * vistolog [O] Map of embedding levels from visual to logical order.
3061 * logtovis [O] Map of embedding levels from logical to visual order.
3065 * Failure: Non-zero HRESULT value.
3068 * This stub works correctly for any sequence of a single
3069 * embedding level but not for sequences of different
3070 * embedding levels, i.e. mixtures of RTL and LTR scripts.
3072 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
3077 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
3079 if (!level
|| (!vistolog
&& !logtovis
))
3080 return E_INVALIDARG
;
3082 indexs
= heap_alloc(sizeof(int) * runs
);
3084 return E_OUTOFMEMORY
;
3089 for( ich
= 0; ich
< runs
; ich
++)
3094 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
3095 for (ich
= 0; ich
< runs
; ich
++)
3096 vistolog
[ich
] = indexs
[ich
];
3102 for( ich
= 0; ich
< runs
; ich
++)
3107 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
3108 for (ich
= 0; ich
< runs
; ich
++)
3109 logtovis
[ich
] = indexs
[ich
];
3116 /***********************************************************************
3117 * ScriptStringGetLogicalWidths (USP10.@)
3119 * Returns logical widths from a string analysis.
3122 * ssa [I] string analysis.
3123 * piDx [O] logical widths returned.
3127 * Failure: a non-zero HRESULT.
3129 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
3132 StringAnalysis
*analysis
= ssa
;
3134 TRACE("%p, %p\n", ssa
, piDx
);
3136 if (!analysis
) return S_FALSE
;
3137 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3139 for (i
= 0; i
< analysis
->numItems
; i
++)
3141 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
3144 if (analysis
->pItem
[i
].a
.fRTL
&& ! analysis
->pItem
[i
].a
.fLogicalOrder
)
3147 for (j
= 0; j
< cChar
; j
++)
3150 int glyph
= analysis
->glyphs
[i
].pwLogClust
[j
];
3151 int clust_size
= get_cluster_size(analysis
->glyphs
[i
].pwLogClust
,
3152 cChar
, j
, direction
, NULL
, NULL
);
3153 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
);
3155 for (k
= 0; k
< clust_size
; k
++)
3157 piDx
[next
] = advance
/ clust_size
;
3166 /***********************************************************************
3167 * ScriptStringValidate (USP10.@)
3169 * Validate a string analysis.
3172 * ssa [I] string analysis.
3176 * Failure: S_FALSE if invalid sequences are found
3177 * or a non-zero HRESULT if it fails.
3179 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
3181 StringAnalysis
*analysis
= ssa
;
3183 TRACE("(%p)\n", ssa
);
3185 if (!analysis
) return E_INVALIDARG
;
3186 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
3189 /***********************************************************************
3190 * ScriptString_pSize (USP10.@)
3192 * Retrieve width and height of an analysed string.
3195 * ssa [I] string analysis.
3198 * Success: Pointer to a SIZE structure.
3201 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
3204 StringAnalysis
*analysis
= ssa
;
3206 TRACE("(%p)\n", ssa
);
3208 if (!analysis
) return NULL
;
3209 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return NULL
;
3213 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
3214 analysis
->sz
->cy
= analysis
->glyphs
[0].sc
->tm
.tmHeight
;
3216 analysis
->sz
->cx
= 0;
3217 for (i
= 0; i
< analysis
->numItems
; i
++)
3219 if (analysis
->glyphs
[i
].sc
->tm
.tmHeight
> analysis
->sz
->cy
)
3220 analysis
->sz
->cy
= analysis
->glyphs
[i
].sc
->tm
.tmHeight
;
3221 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
3222 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
3225 return analysis
->sz
;
3228 /***********************************************************************
3229 * ScriptString_pLogAttr (USP10.@)
3231 * Retrieve logical attributes of an analysed string.
3234 * ssa [I] string analysis.
3237 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3240 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
3242 StringAnalysis
*analysis
= ssa
;
3244 TRACE("(%p)\n", ssa
);
3246 if (!analysis
) return NULL
;
3247 if (!(analysis
->dwFlags
& SSA_BREAK
)) return NULL
;
3248 return analysis
->logattrs
;
3251 /***********************************************************************
3252 * ScriptString_pcOutChars (USP10.@)
3254 * Retrieve the length of a string after clipping.
3257 * ssa [I] String analysis.
3260 * Success: Pointer to the length.
3263 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
3265 StringAnalysis
*analysis
= ssa
;
3267 TRACE("(%p)\n", ssa
);
3269 if (!analysis
) return NULL
;
3270 return &analysis
->clip_len
;
3273 /***********************************************************************
3274 * ScriptStringGetOrder (USP10.@)
3276 * Retrieve a glyph order map.
3279 * ssa [I] String analysis.
3280 * order [I/O] Array of glyph positions.
3284 * Failure: a non-zero HRESULT.
3286 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
3290 StringAnalysis
*analysis
= ssa
;
3292 TRACE("(%p)\n", ssa
);
3294 if (!analysis
) return S_FALSE
;
3295 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3297 /* FIXME: handle RTL scripts */
3298 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
3299 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
3305 /***********************************************************************
3306 * ScriptGetLogicalWidths (USP10.@)
3308 * Convert advance widths to logical widths.
3311 * sa [I] Script analysis.
3312 * nbchars [I] Number of characters.
3313 * nbglyphs [I] Number of glyphs.
3314 * glyph_width [I] Array of glyph widths.
3315 * log_clust [I] Array of logical clusters.
3316 * sva [I] Visual attributes.
3317 * widths [O] Array of logical widths.
3321 * Failure: a non-zero HRESULT.
3323 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
3324 const int *glyph_width
, const WORD
*log_clust
,
3325 const SCRIPT_VISATTR
*sva
, int *widths
)
3329 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3330 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
3333 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
3337 /***********************************************************************
3338 * ScriptApplyLogicalWidth (USP10.@)
3340 * Generate glyph advance widths.
3343 * dx [I] Array of logical advance widths.
3344 * num_chars [I] Number of characters.
3345 * num_glyphs [I] Number of glyphs.
3346 * log_clust [I] Array of logical clusters.
3347 * sva [I] Visual attributes.
3348 * advance [I] Array of glyph advance widths.
3349 * sa [I] Script analysis.
3350 * abc [I/O] Summed ABC widths.
3351 * justify [O] Array of glyph advance widths.
3355 * Failure: a non-zero HRESULT.
3357 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
3358 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
3359 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
3360 ABC
*abc
, int *justify
)
3364 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3365 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
3367 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
3371 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
3372 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
3376 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
3378 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];