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 /* Devanagari: U+0900–U+097F */
85 { Script_Devanagari
, 0x900, 0x97f, Script_Devanagari_Numeric
, 0},
86 /* Bengali: U+0980–U+09FF */
87 { Script_Bengali
, 0x980, 0x9ff, Script_Bengali_Numeric
, 0},
88 /* Gurmukhi: U+0A00–U+0A7F*/
89 { Script_Gurmukhi
, 0xa00, 0xa7f, Script_Gurmukhi_Numeric
, 0},
90 /* Gujarati: U+0A80–U+0AFF*/
91 { Script_Gujarati
, 0xa80, 0xaff, Script_Gujarati_Numeric
, 0},
92 /* Oriya: U+0B00–U+0B7F */
93 { Script_Oriya
, 0xb00, 0xb7f, Script_Oriya_Numeric
, 0},
94 /* Tamil: U+0B80–U+0BFF */
95 { Script_Tamil
, 0xb80, 0xbff, Script_Tamil_Numeric
, 0},
96 /* Telugu: U+0C00–U+0C7F */
97 { Script_Telugu
, 0xc00, 0xc7f, Script_Telugu_Numeric
, 0},
98 /* Kannada: U+0C80–U+0CFF */
99 { Script_Kannada
, 0xc80, 0xcff, Script_Kannada_Numeric
, 0},
100 /* Malayalam: U+0D00–U+0D7F */
101 { Script_Malayalam
, 0xd00, 0xd7f, Script_Malayalam_Numeric
, 0},
102 /* Sinhala: U+0D80–U+0DFF */
103 { Script_Sinhala
, 0xd80, 0xdff, 0, 0},
104 /* Thai: U+0E00–U+0E7F */
105 { Script_Thai
, 0xe00, 0xe7f, Script_Thai_Numeric
, 0},
106 /* Lao: U+0E80–U+0EFF */
107 { Script_Lao
, 0xe80, 0xeff, Script_Lao_Numeric
, 0},
108 /* Tibetan: U+0F00–U+0FFF */
109 { Script_Tibetan
, 0xf00, 0xfff, 0, 0},
110 /* Myanmar: U+1000–U+109F */
111 { Script_Myanmar
, 0x1000, 0x109f, Script_Myanmar_Numeric
, 0},
112 /* Georgian: U+10A0–U+10FF */
113 { Script_Georgian
, 0x10a0, 0x10ff, 0, 0},
114 /* Hangul Jamo: U+1100–U+11FF */
115 { Script_Hangul
, 0x1100, 0x11ff, 0, 0},
116 /* Ethiopic: U+1200–U+137F */
117 /* Ethiopic Extensions: U+1380–U+139F */
118 { Script_Ethiopic
, 0x1200, 0x139f, 0, 0},
119 /* Khmer: U+1780–U+17FF */
120 { Script_Khmer
, 0x1780, 0x17ff, Script_Khmer_Numeric
, 0},
121 /* Mongolian: U+1800–U+18AF */
122 { Script_Mongolian
, 0x1800, 0x18af, Script_Mongolian_Numeric
, 0},
123 /* Tai Le: U+1950–U+197F */
124 { Script_Tai_Le
, 0x1950, 0x197f, 0, 0},
125 /* New Tai Lue: U+1980–U+19DF */
126 { Script_New_Tai_Lue
,0x1980, 0x19df, Script_New_Tai_Lue_Numeric
, 0},
127 /* Khmer Symbols: U+19E0–U+19FF */
128 { Script_Khmer
, 0x19e0, 0x19ff, Script_Khmer_Numeric
, 0},
129 /* Vedic Extensions: U+1CD0-U+1CFF */
130 { Script_Devanagari
, 0x1cd0, 0x1cff, Script_Devanagari_Numeric
, 0},
131 /* Phonetic Extensions: U+1D00–U+1DBF */
132 { Script_Latin
, 0x1d00, 0x1dbf, 0, 0},
133 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
134 { Script_Diacritical
,0x1dc0, 0x1dff, 0, 0},
135 /* Latin Extended Additional: U+1E00–U+1EFF */
136 { Script_Latin
, 0x1e00, 0x1eff, 0, 0},
137 /* Greek Extended: U+1F00–U+1FFF */
138 { Script_Greek
, 0x1f00, 0x1fff, 0, 0},
139 /* General Punctuation: U+2000 –U+206f */
140 { Script_Latin
, 0x2000, 0x206f, 0, 0},
141 /* Superscripts and Subscripts : U+2070 –U+209f */
142 /* Currency Symbols : U+20a0 –U+20cf */
143 { Script_Numeric2
, 0x2070, 0x2070, 0, 0},
144 { Script_Latin
, 0x2071, 0x2073, 0, 0},
145 { Script_Numeric2
, 0x2074, 0x2079, 0, 0},
146 { Script_Latin
, 0x207a, 0x207f, 0, 0},
147 { Script_Numeric2
, 0x2080, 0x2089, 0, 0},
148 { Script_Latin
, 0x208a, 0x20cf, 0, 0},
149 /* Letterlike Symbols : U+2100 –U+214f */
150 /* Number Forms : U+2150 –U+218f */
151 /* Arrows : U+2190 –U+21ff */
152 /* Mathematical Operators : U+2200 –U+22ff */
153 /* Miscellaneous Technical : U+2300 –U+23ff */
154 /* Control Pictures : U+2400 –U+243f */
155 /* Optical Character Recognition : U+2440 –U+245f */
156 /* Enclosed Alphanumerics : U+2460 –U+24ff */
157 /* Box Drawing : U+2500 –U+25ff */
158 /* Block Elements : U+2580 –U+259f */
159 /* Geometric Shapes : U+25a0 –U+25ff */
160 /* Miscellaneous Symbols : U+2600 –U+26ff */
161 /* Dingbats : U+2700 –U+27bf */
162 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
163 /* Supplemental Arrows-A : U+27f0 –U+27ff */
164 { Script_Latin
, 0x2100, 0x27ff, 0, 0},
165 /* Supplemental Arrows-B : U+2900 –U+297f */
166 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
167 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
168 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
169 { Script_Latin
, 0x2900, 0x2bff, 0, 0},
170 /* Latin Extended-C: U+2C60–U+2C7F */
171 { Script_Latin
, 0x2c60, 0x2c7f, 0, 0},
172 /* Georgian: U+2D00–U+2D2F */
173 { Script_Georgian
, 0x2d00, 0x2d2f, 0, 0},
174 /* Tifinagh: U+2D30–U+2D7F */
175 { Script_Tifinagh
, 0x2d30, 0x2d7f, 0, 0},
176 /* Ethiopic Extensions: U+2D80–U+2DDF */
177 { Script_Ethiopic
, 0x2d80, 0x2ddf, 0, 0},
178 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
179 { Script_Cyrillic
, 0x2de0, 0x2dff, 0, 0},
180 /* CJK Radicals Supplement: U+2E80–U+2EFF */
181 /* Kangxi Radicals: U+2F00–U+2FDF */
182 { Script_CJK_Han
, 0x2e80, 0x2fdf, 0, 0},
183 /* Ideographic Description Characters: U+2FF0–U+2FFF */
184 { Script_Ideograph
,0x2ff0, 0x2fff, 0, 0},
185 /* CJK Symbols and Punctuation: U+3000–U+303F */
186 { Script_Ideograph
,0x3000, 0x3004, 0, 0},
187 { Script_CJK_Han
,0x3005, 0x3005, 0, 0},
188 { Script_Ideograph
,0x3006, 0x3006, 0, 0},
189 { Script_CJK_Han
,0x3007, 0x3007, 0, 0},
190 { Script_Ideograph
,0x3008, 0x3020, 0, 0},
191 { Script_CJK_Han
,0x3021, 0x3029, 0, 0},
192 { Script_Ideograph
,0x302a, 0x3030, 0, 0},
194 { Script_Kana
,0x3031, 0x3035, 0, 0},
195 { Script_Ideograph
,0x3036, 0x3037, 0, 0},
196 { Script_CJK_Han
,0x3038, 0x303b, 0, 0},
197 { Script_Ideograph
,0x303c, 0x303f, 0, 0},
198 /* Hiragana: U+3040–U+309F */
199 /* Katakana: U+30A0–U+30FF */
200 { Script_Kana
,0x3040, 0x30ff, 0, 0},
201 /* Bopomofo: U+3100–U+312F */
202 { Script_Bopomofo
,0x3100, 0x312f, 0, 0},
203 /* Hangul Compatibility Jamo: U+3130–U+318F */
204 { Script_Hangul
,0x3130, 0x318f, 0, 0},
205 /* Kanbun: U+3190–U+319F */
206 { Script_Ideograph
,0x3190, 0x319f, 0, 0},
207 /* Bopomofo Extended: U+31A0–U+31BF */
208 { Script_Bopomofo
,0x31a0, 0x31bf, 0, 0},
209 /* CJK Strokes: U+31C0–U+31EF */
210 { Script_Ideograph
,0x31c0, 0x31ef, 0, 0},
211 /* Katakana Phonetic Extensions: U+31F0–U+31FF */
212 { Script_Kana
,0x31f0, 0x31ff, 0, 0},
213 /* Enclosed CJK Letters and Months: U+3200–U+32FF */
214 { Script_Hangul
,0x3200, 0x321f, 0, 0},
215 { Script_Ideograph
,0x3220, 0x325f, 0, 0},
216 { Script_Hangul
,0x3260, 0x327f, 0, 0},
217 { Script_Ideograph
,0x3280, 0x32ef, 0, 0},
218 { Script_Kana
,0x32d0, 0x31ff, 0, 0},
219 /* CJK Compatibility: U+3300–U+33FF*/
220 { Script_Kana
,0x3300, 0x3357, 0, 0},
221 { Script_Ideograph
,0x3358, 0x33ff, 0, 0},
222 /* CJK Unified Ideographs Extension A: U+3400–U+4DBF */
223 { Script_CJK_Han
,0x3400, 0x4dbf, 0, 0},
224 /* CJK Unified Ideographs: U+4E00–U+9FFF */
225 { Script_CJK_Han
,0x4e00, 0x9fff, 0, 0},
226 /* Yi: U+A000–U+A4CF */
227 { Script_Yi
,0xa000, 0xa4cf, 0, 0},
228 /* Cyrillic Extended-B: U+A640–U+A69F */
229 { Script_Cyrillic
, 0xa640, 0xa69f, 0, 0},
230 /* Modifier Tone Letters: U+A700–U+A71F */
231 /* Latin Extended-D: U+A720–U+A7FF */
232 { Script_Latin
, 0xa700, 0xa7ff, 0, 0},
233 /* Phags-pa: U+A840–U+A87F */
234 { Script_Phags_pa
, 0xa840, 0xa87f, 0, 0},
235 /* Devanagari Extended: U+A8E0-U+A8FF */
236 { Script_Devanagari
, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric
, 0},
237 /* Myanmar Extended-A: U+AA60–U+AA7F */
238 { Script_Myanmar
, 0xaa60, 0xaa7f, Script_Myanmar_Numeric
, 0},
239 /* Hangul Jamo Extended-A: U+A960–U+A97F */
240 { Script_Hangul
, 0xa960, 0xa97f, 0, 0},
241 /* Hangul Syllables: U+AC00–U+D7A3 */
242 { Script_Hangul
, 0xac00, 0xd7a3, 0, 0},
243 /* Hangul Jamo Extended-B: U+D7B0–U+D7FF */
244 { Script_Hangul
, 0xd7b0, 0xd7ff, 0, 0},
245 /* CJK Compatibility Ideographs: U+F900–U+FAFF */
246 { Script_CJK_Han
,0xf900, 0xfaff, 0, 0},
247 /* Latin Ligatures: U+FB00–U+FB06 */
248 { Script_Latin
, 0xfb00, 0xfb06, 0, 0},
249 /* Armenian ligatures U+FB13..U+FB17 */
250 { Script_Armenian
, 0xfb13, 0xfb17, 0, 0},
251 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
252 { Script_Hebrew
, 0xfb1d, 0xfb4f, 0, 0},
253 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
254 { Script_Arabic
, 0xfb50, 0xfdff, 0, 0},
255 /* Vertical Forms: U+FE10–U+FE1F */
256 /* Combining Half Marks: U+FE20–U+FE2F */
257 /* CJK Compatibility Forms: U+FE30–U+FE4F */
258 /* Small Form Variants: U+FE50–U+FE6F */
259 { Script_Ideograph
,0xfe10, 0xfe6f, 0, 0},
260 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
261 { Script_Arabic
, 0xfe70, 0xfeff, 0, 0},
262 /* Halfwidth and Fullwidth Forms: U+FF00–FFEF */
263 { Script_Ideograph
,0xff00, 0xff64, Script_Numeric2
, 0},
264 { Script_Kana
,0xff65, 0xff9f, 0, 0},
265 { Script_Hangul
,0xffa0, 0xffdf, 0, 0},
266 { Script_Ideograph
,0xffe0, 0xffef, 0, 0},
268 { SCRIPT_UNDEFINED
, 0, 0, 0}
271 typedef struct _scriptData
274 SCRIPT_PROPERTIES props
;
275 OPENTYPE_TAG scriptTag
;
276 WCHAR fallbackFont
[LF_FACESIZE
];
279 /* the must be in order so that the index matches the Script value */
280 static const scriptData scriptInformation
[] = {
281 {{SCRIPT_UNDEFINED
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
282 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
285 {{Script_Latin
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
286 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
287 MS_MAKE_TAG('l','a','t','n'),
289 {{Script_CR
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
290 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
293 {{Script_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
294 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
297 {{Script_Control
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
298 {LANG_ENGLISH
, 0, 1, 0, 0, ANSI_CHARSET
, 1, 0, 0, 0, 0, 0, 1, 0, 0},
301 {{Script_Punctuation
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
302 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
305 {{Script_Arabic
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
306 {LANG_ARABIC
, 0, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 1, 0},
307 MS_MAKE_TAG('a','r','a','b'),
308 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
309 {{Script_Arabic_Numeric
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
310 {LANG_ARABIC
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
311 MS_MAKE_TAG('a','r','a','b'),
312 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
313 {{Script_Hebrew
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
314 {LANG_HEBREW
, 0, 1, 0, 1, HEBREW_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
315 MS_MAKE_TAG('h','e','b','r'),
316 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
317 {{Script_Syriac
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
318 {LANG_SYRIAC
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 1, 0},
319 MS_MAKE_TAG('s','y','r','c'),
320 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
321 {{Script_Persian
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
322 {LANG_PERSIAN
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
323 MS_MAKE_TAG('s','y','r','c'),
324 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
325 {{Script_Thaana
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
326 {LANG_DIVEHI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
327 MS_MAKE_TAG('t','h','a','a'),
328 {'M','V',' ','B','o','l','i',0}},
329 {{Script_Greek
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
330 {LANG_GREEK
, 0, 0, 0, 0, GREEK_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
331 MS_MAKE_TAG('g','r','e','k'),
333 {{Script_Cyrillic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
334 {LANG_RUSSIAN
, 0, 0, 0, 0, RUSSIAN_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
335 MS_MAKE_TAG('c','y','r','l'),
337 {{Script_Armenian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
338 {LANG_ARMENIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
339 MS_MAKE_TAG('a','r','m','n'),
340 {'S','y','l','f','a','e','n',0}},
341 {{Script_Georgian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
342 {LANG_GEORGIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
343 MS_MAKE_TAG('g','e','o','r'),
344 {'S','y','l','f','a','e','n',0}},
345 {{Script_Sinhala
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
346 {LANG_SINHALESE
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
347 MS_MAKE_TAG('s','i','n','h'),
348 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
349 {{Script_Tibetan
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
350 {LANG_TIBETAN
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
351 MS_MAKE_TAG('t','i','b','t'),
352 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
353 {{Script_Tibetan_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
354 {LANG_TIBETAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
355 MS_MAKE_TAG('t','i','b','t'),
356 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
357 {{Script_Phags_pa
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
358 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
359 MS_MAKE_TAG('p','h','a','g'),
360 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
361 {{Script_Thai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
362 {LANG_THAI
, 0, 1, 1, 1, THAI_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 1},
363 MS_MAKE_TAG('t','h','a','i'),
364 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
365 {{Script_Thai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
366 {LANG_THAI
, 1, 1, 0, 0, THAI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
367 MS_MAKE_TAG('t','h','a','i'),
368 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
369 {{Script_Lao
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
370 {LANG_LAO
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
371 MS_MAKE_TAG('l','a','o',' '),
372 {'D','o','k','C','h','a','m','p','a',0}},
373 {{Script_Lao_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
374 {LANG_LAO
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
375 MS_MAKE_TAG('l','a','o',' '),
376 {'D','o','k','C','h','a','m','p','a',0}},
377 {{Script_Devanagari
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
378 {LANG_HINDI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
379 MS_MAKE_TAG('d','e','v','a'),
380 {'M','a','n','g','a','l',0}},
381 {{Script_Devanagari_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
382 {LANG_HINDI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
383 MS_MAKE_TAG('d','e','v','a'),
384 {'M','a','n','g','a','l',0}},
385 {{Script_Bengali
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
386 {LANG_BENGALI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
387 MS_MAKE_TAG('b','e','n','g'),
388 {'V','r','i','n','d','a',0}},
389 {{Script_Bengali_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
390 {LANG_BENGALI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
391 MS_MAKE_TAG('b','e','n','g'),
392 {'V','r','i','n','d','a',0}},
393 {{Script_Bengali_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
394 {LANG_BENGALI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
395 MS_MAKE_TAG('b','e','n','g'),
396 {'V','r','i','n','d','a',0}},
397 {{Script_Gurmukhi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
398 {LANG_PUNJABI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
399 MS_MAKE_TAG('g','u','r','u'),
400 {'R','a','a','v','i',0}},
401 {{Script_Gurmukhi_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
402 {LANG_PUNJABI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
403 MS_MAKE_TAG('g','u','r','u'),
404 {'R','a','a','v','i',0}},
405 {{Script_Gujarati
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
406 {LANG_GUJARATI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
407 MS_MAKE_TAG('g','u','j','r'),
408 {'S','h','r','u','t','i',0}},
409 {{Script_Gujarati_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
410 {LANG_GUJARATI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
411 MS_MAKE_TAG('g','u','j','r'),
412 {'S','h','r','u','t','i',0}},
413 {{Script_Gujarati_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
414 {LANG_GUJARATI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
415 MS_MAKE_TAG('g','u','j','r'),
416 {'S','h','r','u','t','i',0}},
417 {{Script_Oriya
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
418 {LANG_ORIYA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
419 MS_MAKE_TAG('o','r','y','a'),
420 {'K','a','l','i','n','g','a',0}},
421 {{Script_Oriya_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
422 {LANG_ORIYA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
423 MS_MAKE_TAG('o','r','y','a'),
424 {'K','a','l','i','n','g','a',0}},
425 {{Script_Tamil
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
426 {LANG_TAMIL
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
427 MS_MAKE_TAG('t','a','m','l'),
428 {'L','a','t','h','a',0}},
429 {{Script_Tamil_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
430 {LANG_TAMIL
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
431 MS_MAKE_TAG('t','a','m','l'),
432 {'L','a','t','h','a',0}},
433 {{Script_Telugu
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
434 {LANG_TELUGU
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
435 MS_MAKE_TAG('t','e','l','u'),
436 {'G','a','u','t','a','m','i',0}},
437 {{Script_Telugu_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
438 {LANG_TELUGU
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
439 MS_MAKE_TAG('t','e','l','u'),
440 {'G','a','u','t','a','m','i',0}},
441 {{Script_Kannada
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
442 {LANG_KANNADA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
443 MS_MAKE_TAG('k','n','d','a'),
444 {'T','u','n','g','a',0}},
445 {{Script_Kannada_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
446 {LANG_KANNADA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
447 MS_MAKE_TAG('k','n','d','a'),
448 {'T','u','n','g','a',0}},
449 {{Script_Malayalam
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
450 {LANG_MALAYALAM
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
451 MS_MAKE_TAG('m','l','y','m'),
452 {'K','a','r','t','i','k','a',0}},
453 {{Script_Malayalam_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
454 {LANG_MALAYALAM
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
455 MS_MAKE_TAG('m','l','y','m'),
456 {'K','a','r','t','i','k','a',0}},
457 {{Script_Diacritical
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
458 {LANG_ENGLISH
, 0, 1, 0, 1, ANSI_CHARSET
, 0, 0, 0, 0, 0, 1, 1, 0, 0},
461 {{Script_Punctuation2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
462 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
463 MS_MAKE_TAG('l','a','t','n'),
465 {{Script_Numeric2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
466 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
469 {{Script_Myanmar
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
470 {0x55, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
471 MS_MAKE_TAG('m','y','m','r'),
473 {{Script_Myanmar_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
474 {0x55, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
475 MS_MAKE_TAG('m','y','m','r'),
477 {{Script_Tai_Le
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
478 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
479 MS_MAKE_TAG('t','a','l','e'),
480 {'M','i','c','r','o','s','o','f','t',' ','T','a','i',' ','L','e'}},
481 {{Script_New_Tai_Lue
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
482 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
483 MS_MAKE_TAG('t','a','l','u'),
484 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
485 {{Script_New_Tai_Lue_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
486 {0, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
487 MS_MAKE_TAG('t','a','l','u'),
488 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
489 {{Script_Khmer
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
490 {0x53, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
491 MS_MAKE_TAG('k','h','m','r'),
492 {'D','a','u','n','P','e','n','h'}},
493 {{Script_Khmer
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
494 {0x53, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
495 MS_MAKE_TAG('k','h','m','r'),
496 {'D','a','u','n','P','e','n','h'}},
497 {{Script_CJK_Han
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
498 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
499 MS_MAKE_TAG('h','a','n','i'),
501 {{Script_Ideograph
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
502 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
503 MS_MAKE_TAG('h','a','n','i'),
505 {{Script_Bopomofo
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
506 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
507 MS_MAKE_TAG('b','o','p','o'),
509 {{Script_Kana
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
510 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
511 MS_MAKE_TAG('k','a','n','a'),
513 {{Script_Hangul
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
514 {LANG_KOREAN
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
515 MS_MAKE_TAG('h','a','n','g'),
517 {{Script_Yi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
518 {LANG_ENGLISH
, 0, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
519 MS_MAKE_TAG('y','i',' ',' '),
520 {'M','i','c','r','o','s','o','f','t',' ','Y','i',' ','B','a','i','t','i'}},
521 {{Script_Ethiopic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
522 {0x5e, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
523 MS_MAKE_TAG('e','t','h','i'),
524 {'N','y','a','l','a'}},
525 {{Script_Ethiopic_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
526 {0x5e, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
527 MS_MAKE_TAG('e','t','h','i'),
528 {'N','y','a','l','a'}},
529 {{Script_Mongolian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
530 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
531 MS_MAKE_TAG('m','o','n','g'),
532 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
533 {{Script_Mongolian_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
534 {LANG_MONGOLIAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
535 MS_MAKE_TAG('m','o','n','g'),
536 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
537 {{Script_Tifinagh
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
538 {0, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
539 MS_MAKE_TAG('t','f','n','g'),
540 {'E','b','r','i','m','a'}},
543 static const SCRIPT_PROPERTIES
*script_props
[] =
545 &scriptInformation
[0].props
, &scriptInformation
[1].props
,
546 &scriptInformation
[2].props
, &scriptInformation
[3].props
,
547 &scriptInformation
[4].props
, &scriptInformation
[5].props
,
548 &scriptInformation
[6].props
, &scriptInformation
[7].props
,
549 &scriptInformation
[8].props
, &scriptInformation
[9].props
,
550 &scriptInformation
[10].props
, &scriptInformation
[11].props
,
551 &scriptInformation
[12].props
, &scriptInformation
[13].props
,
552 &scriptInformation
[14].props
, &scriptInformation
[15].props
,
553 &scriptInformation
[16].props
, &scriptInformation
[17].props
,
554 &scriptInformation
[18].props
, &scriptInformation
[19].props
,
555 &scriptInformation
[20].props
, &scriptInformation
[21].props
,
556 &scriptInformation
[22].props
, &scriptInformation
[23].props
,
557 &scriptInformation
[24].props
, &scriptInformation
[25].props
,
558 &scriptInformation
[26].props
, &scriptInformation
[27].props
,
559 &scriptInformation
[28].props
, &scriptInformation
[29].props
,
560 &scriptInformation
[30].props
, &scriptInformation
[31].props
,
561 &scriptInformation
[32].props
, &scriptInformation
[33].props
,
562 &scriptInformation
[34].props
, &scriptInformation
[35].props
,
563 &scriptInformation
[36].props
, &scriptInformation
[37].props
,
564 &scriptInformation
[38].props
, &scriptInformation
[39].props
,
565 &scriptInformation
[40].props
, &scriptInformation
[41].props
,
566 &scriptInformation
[42].props
, &scriptInformation
[43].props
,
567 &scriptInformation
[44].props
, &scriptInformation
[45].props
,
568 &scriptInformation
[46].props
, &scriptInformation
[47].props
,
569 &scriptInformation
[48].props
, &scriptInformation
[49].props
,
570 &scriptInformation
[50].props
, &scriptInformation
[51].props
,
571 &scriptInformation
[52].props
, &scriptInformation
[53].props
,
572 &scriptInformation
[54].props
, &scriptInformation
[55].props
,
573 &scriptInformation
[56].props
, &scriptInformation
[57].props
,
574 &scriptInformation
[58].props
, &scriptInformation
[59].props
,
575 &scriptInformation
[60].props
, &scriptInformation
[61].props
,
576 &scriptInformation
[62].props
, &scriptInformation
[63].props
,
577 &scriptInformation
[64].props
586 SCRIPT_VISATTR
* psva
;
602 StringGlyphs
* glyphs
;
603 SCRIPT_LOGATTR
* logattrs
;
608 static inline void *heap_alloc(SIZE_T size
)
610 return HeapAlloc(GetProcessHeap(), 0, size
);
613 static inline void *heap_alloc_zero(SIZE_T size
)
615 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
618 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
620 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
623 static inline BOOL
heap_free(LPVOID mem
)
625 return HeapFree(GetProcessHeap(), 0, mem
);
628 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
630 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
633 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
635 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
638 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
640 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
643 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
645 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
647 if (!block
) return 0;
648 return block
[c
& GLYPH_BLOCK_MASK
];
651 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
653 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
655 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
656 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
659 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
661 static const ABC nil
;
662 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
664 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
665 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
669 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
671 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
673 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
674 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
678 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
682 if (!psc
) return E_INVALIDARG
;
683 if (*psc
) return S_OK
;
684 if (!hdc
) return E_PENDING
;
686 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
687 if (!GetTextMetricsW(hdc
, &sc
->tm
))
692 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
697 sc
->sfnt
= (GetFontData(hdc
, MS_MAKE_TAG('h','e','a','d'), 0, NULL
, 0)!=GDI_ERROR
);
699 TRACE("<- %p\n", sc
);
703 static WCHAR
mirror_char( WCHAR ch
)
705 extern const WCHAR wine_mirror_map
[];
706 return ch
+ wine_mirror_map
[wine_mirror_map
[ch
>> 8] + (ch
& 0xff)];
709 static WORD
get_char_script( WCHAR ch
)
711 static const WCHAR latin_punc
[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
715 if (ch
== 0xc || ch
== 0x20 || ch
== 0x202f)
718 /* These punctuation are separated out as Latin punctuation */
719 if (strchrW(latin_punc
,ch
))
720 return Script_Punctuation2
;
722 /* These chars are itemized as Punctuation by Windows */
723 if (ch
== 0x2212 || ch
== 0x2044)
724 return Script_Punctuation
;
726 GetStringTypeW(CT_CTYPE1
, &ch
, 1, &type
);
729 return SCRIPT_UNDEFINED
;
732 return Script_Control
;
737 if (ch
< scriptRanges
[i
].rangeFirst
|| scriptRanges
[i
].script
== SCRIPT_UNDEFINED
)
740 if (ch
>= scriptRanges
[i
].rangeFirst
&& ch
<= scriptRanges
[i
].rangeLast
)
742 if (scriptRanges
[i
].numericScript
&& type
& C1_DIGIT
)
743 return scriptRanges
[i
].numericScript
;
744 if (scriptRanges
[i
].punctScript
&& type
& C1_PUNCT
)
745 return scriptRanges
[i
].punctScript
;
746 return scriptRanges
[i
].script
;
751 return SCRIPT_UNDEFINED
;
754 /***********************************************************************
758 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
762 case DLL_PROCESS_ATTACH
:
763 DisableThreadLibraryCalls(hInstDLL
);
765 case DLL_PROCESS_DETACH
:
771 /***********************************************************************
772 * ScriptFreeCache (USP10.@)
774 * Free a script cache.
777 * psc [I/O] Script cache.
781 * Failure: Non-zero HRESULT value.
783 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
790 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
792 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
793 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
795 heap_free(((ScriptCache
*)*psc
)->GSUB_Table
);
796 heap_free(((ScriptCache
*)*psc
)->GDEF_Table
);
797 heap_free(((ScriptCache
*)*psc
)->features
);
804 /***********************************************************************
805 * ScriptGetProperties (USP10.@)
807 * Retrieve a list of script properties.
810 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
811 * num [I] Pointer to the number of scripts.
815 * Failure: Non-zero HRESULT value.
818 * Behaviour matches WinXP.
820 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
822 TRACE("(%p,%p)\n", props
, num
);
824 if (!props
&& !num
) return E_INVALIDARG
;
826 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
827 if (props
) *props
= script_props
;
832 /***********************************************************************
833 * ScriptGetFontProperties (USP10.@)
835 * Get information on special glyphs.
838 * hdc [I] Device context.
839 * psc [I/O] Opaque pointer to a script cache.
840 * sfp [O] Font properties structure.
842 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
846 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
848 if (!sfp
) return E_INVALIDARG
;
849 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
851 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
854 /* return something sensible? */
856 sfp
->wgDefault
= get_cache_default_char(psc
);
858 sfp
->wgKashida
= 0xffff;
859 sfp
->iKashidaWidth
= 0;
864 /***********************************************************************
865 * ScriptRecordDigitSubstitution (USP10.@)
867 * Record digit substitution settings for a given locale.
870 * locale [I] Locale identifier.
871 * sds [I] Structure to record substitution settings.
875 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
878 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
880 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
884 TRACE("0x%x, %p\n", locale
, sds
);
886 /* This implementation appears to be correct for all languages, but it's
887 * not clear if sds->DigitSubstitute is ever set to anything except
888 * CONTEXT or NONE in reality */
890 if (!sds
) return E_POINTER
;
892 locale
= ConvertDefaultLocale(locale
);
894 if (!IsValidLocale(locale
, LCID_INSTALLED
))
897 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
898 sds
->TraditionalDigitLanguage
= plgid
;
900 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
901 sds
->NationalDigitLanguage
= plgid
;
903 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
905 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
906 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
911 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
912 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
914 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
917 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
920 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
923 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
931 /***********************************************************************
932 * ScriptApplyDigitSubstitution (USP10.@)
934 * Apply digit substitution settings.
937 * sds [I] Structure with recorded substitution settings.
938 * sc [I] Script control structure.
939 * ss [I] Script state structure.
943 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
945 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
946 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
948 SCRIPT_DIGITSUBSTITUTE psds
;
950 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
952 if (!sc
|| !ss
) return E_POINTER
;
956 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
960 sc
->uDefaultLanguage
= LANG_ENGLISH
;
961 sc
->fContextDigits
= 0;
962 ss
->fDigitSubstitute
= 0;
964 switch (sds
->DigitSubstitute
) {
965 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
966 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
967 case SCRIPT_DIGITSUBSTITUTE_NONE
:
968 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
975 static inline BOOL
is_indic(WORD script
)
977 return (script
>= Script_Devanagari
&& script
<= Script_Malayalam_Numeric
);
980 static inline WORD
base_indic(WORD script
)
984 case Script_Devanagari
:
985 case Script_Devanagari_Numeric
: return Script_Devanagari
;
987 case Script_Bengali_Numeric
:
988 case Script_Bengali_Currency
: return Script_Bengali
;
989 case Script_Gurmukhi
:
990 case Script_Gurmukhi_Numeric
: return Script_Gurmukhi
;
991 case Script_Gujarati
:
992 case Script_Gujarati_Numeric
:
993 case Script_Gujarati_Currency
: return Script_Gujarati
;
995 case Script_Oriya_Numeric
: return Script_Oriya
;
997 case Script_Tamil_Numeric
: return Script_Tamil
;
999 case Script_Telugu_Numeric
: return Script_Telugu
;
1000 case Script_Kannada
:
1001 case Script_Kannada_Numeric
: return Script_Kannada
;
1002 case Script_Malayalam
:
1003 case Script_Malayalam_Numeric
: return Script_Malayalam
;
1009 /***********************************************************************
1010 * ScriptItemizeOpenType (USP10.@)
1012 * Split a Unicode string into shapeable parts.
1015 * pwcInChars [I] String to split.
1016 * cInChars [I] Number of characters in pwcInChars.
1017 * cMaxItems [I] Maximum number of items to return.
1018 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1019 * psState [I] Pointer to a SCRIPT_STATE structure.
1020 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1021 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
1022 * pcItems [O] Number of script items returned.
1026 * Failure: Non-zero HRESULT value.
1028 HRESULT WINAPI
ScriptItemizeOpenType(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1029 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1030 SCRIPT_ITEM
*pItems
, OPENTYPE_TAG
*pScriptTags
, int *pcItems
)
1033 #define Numeric_space 0x0020
1037 int cnt
= 0, index
= 0, str
= 0;
1038 int New_Script
= -1;
1040 WORD
*levels
= NULL
;
1041 WORD
*strength
= NULL
;
1042 WORD
*scripts
= NULL
;
1045 WORD last_indic
= -1;
1047 BOOL forceLevels
= FALSE
;
1049 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
1050 psControl
, psState
, pItems
, pcItems
);
1052 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
1053 return E_INVALIDARG
;
1055 scripts
= heap_alloc(cInChars
* sizeof(WORD
));
1057 return E_OUTOFMEMORY
;
1059 for (i
= 0; i
< cInChars
; i
++)
1061 scripts
[i
] = get_char_script(pwcInChars
[i
]);
1062 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
1063 all Indic scripts */
1064 if ((pwcInChars
[i
] == 0x964 || pwcInChars
[i
] ==0x965) && last_indic
> 0)
1065 scripts
[i
] = last_indic
;
1066 else if (is_indic(scripts
[i
]))
1067 last_indic
= base_indic(scripts
[i
]);
1069 /* Some unicode points (Zero Width Space U+200B -
1070 Right-to-Left Mark U+200F) will force us into bidi mode */
1071 if (!forceLevels
&& pwcInChars
[i
] >= 0x200B && pwcInChars
[i
] <= 0x200F)
1074 /* Diacritical marks merge with other scripts */
1075 if (scripts
[i
] == Script_Diacritical
&& i
> 0)
1076 scripts
[i
] = scripts
[i
-1];
1079 for (i
= 0; i
< cInChars
; i
++)
1081 /* Joiners get merged preferencially right */
1082 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
1085 if (i
+1 == cInChars
)
1086 scripts
[i
] = scripts
[i
-1];
1089 for (j
= i
+1; j
< cInChars
; j
++)
1091 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
1093 scripts
[i
] = scripts
[j
];
1101 if (psState
&& psControl
)
1103 levels
= heap_alloc_zero(cInChars
* sizeof(WORD
));
1107 return E_OUTOFMEMORY
;
1110 BIDI_DetermineLevels(pwcInChars
, cInChars
, psState
, psControl
, levels
);
1111 baselevel
= levels
[0];
1112 for (i
= 0; i
< cInChars
; i
++)
1113 if (levels
[i
]!=levels
[0])
1115 if (i
>= cInChars
&& !odd(baselevel
) && !odd(psState
->uBidiLevel
) && !forceLevels
)
1122 BOOL inNumber
= FALSE
;
1123 static WCHAR math_punc
[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
1125 strength
= heap_alloc_zero(cInChars
* sizeof(WORD
));
1130 return E_OUTOFMEMORY
;
1132 BIDI_GetStrengths(pwcInChars
, cInChars
, psControl
, strength
);
1134 /* We currently mis-level leading Diacriticals */
1135 if (scripts
[0] == Script_Diacritical
)
1136 for (i
= 0; i
< cInChars
&& scripts
[0] == Script_Diacritical
; i
++)
1138 levels
[i
] = odd(levels
[i
])?levels
[i
]+1:levels
[i
];
1139 strength
[i
] = BIDI_STRONG
;
1142 for (i
= 0; i
< cInChars
; i
++)
1144 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
1145 if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && inNumber
&& strchrW(math_punc
,pwcInChars
[i
]))
1147 scripts
[i
] = Script_Numeric
;
1150 else if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && scripts
[i
] == Script_Numeric
)
1158 /* Joiners get merged preferencially right */
1159 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
1162 if (i
+1 == cInChars
&& levels
[i
-1] == levels
[i
])
1163 strength
[i
] = strength
[i
-1];
1165 for (j
= i
+1; j
< cInChars
&& levels
[i
] == levels
[j
]; j
++)
1166 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
1168 strength
[i
] = strength
[j
];
1173 if (psControl
->fMergeNeutralItems
)
1175 /* Merge the neutrals */
1176 for (i
= 0; i
< cInChars
; i
++)
1178 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1181 for (j
= i
; j
> 0; j
--)
1183 if (levels
[i
] != levels
[j
])
1185 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1187 scripts
[i
] = scripts
[j
];
1188 strength
[i
] = strength
[j
];
1193 /* Try going the other way */
1194 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1197 for (j
= i
; j
< cInChars
; j
++)
1199 if (levels
[i
] != levels
[j
])
1201 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1203 scripts
[i
] = scripts
[j
];
1204 strength
[i
] = strength
[j
];
1214 while ((!levels
|| (levels
&& levels
[cnt
+1] == levels
[0])) && (pwcInChars
[cnt
] == Numeric_space
) && cnt
< cInChars
)
1217 if (cnt
== cInChars
) /* All Spaces */
1220 New_Script
= scripts
[cnt
];
1223 pItems
[index
].iCharPos
= 0;
1224 pItems
[index
].a
= scriptInformation
[scripts
[cnt
]].a
;
1225 pScriptTags
[index
] = scriptInformation
[scripts
[cnt
]].scriptTag
;
1227 if (strength
&& strength
[cnt
] == BIDI_STRONG
)
1228 str
= strength
[cnt
];
1236 if (strength
[cnt
] == BIDI_STRONG
)
1237 layoutRTL
= (odd(levels
[cnt
]))?1:0;
1239 layoutRTL
= (psState
->uBidiLevel
|| odd(levels
[cnt
]))?1:0;
1240 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1241 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1242 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1244 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1246 layoutRTL
= (odd(baselevel
))?1:0;
1247 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1248 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
1249 pItems
[index
].a
.fRTL
= odd(baselevel
);
1252 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1253 levels
?levels
[cnt
]:-1, str
, New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
1254 pItems
[index
].iCharPos
);
1256 for (cnt
=1; cnt
< cInChars
; cnt
++)
1258 if(pwcInChars
[cnt
] != Numeric_space
)
1259 New_Script
= scripts
[cnt
];
1263 while (cnt
+ j
< cInChars
- 1 && pwcInChars
[cnt
+j
] == Numeric_space
&& levels
[cnt
] == levels
[cnt
+j
])
1265 if (cnt
+ j
< cInChars
&& levels
[cnt
] == levels
[cnt
+j
])
1266 New_Script
= scripts
[cnt
+j
];
1268 New_Script
= scripts
[cnt
];
1272 /* merge space strengths*/
1273 if (strength
&& strength
[cnt
] == BIDI_STRONG
&& str
!= BIDI_STRONG
&& New_Script
== pItems
[index
].a
.eScript
)
1276 if (strength
&& strength
[cnt
] == BIDI_NEUTRAL
&& str
== BIDI_STRONG
&& pwcInChars
[cnt
] != Numeric_space
&& New_Script
== pItems
[index
].a
.eScript
)
1279 /* changes in level */
1280 if (levels
&& (levels
[cnt
] != pItems
[index
].a
.s
.uBidiLevel
))
1282 TRACE("Level break(%i/%i)\n",pItems
[index
].a
.s
.uBidiLevel
,levels
[cnt
]);
1285 /* changes in strength */
1286 else if (strength
&& pwcInChars
[cnt
] != Numeric_space
&& str
!= strength
[cnt
])
1288 TRACE("Strength break (%i/%i)\n",str
,strength
[cnt
]);
1291 /* changes in script */
1292 else if (((pwcInChars
[cnt
] != Numeric_space
) && (New_Script
!= -1) && (New_Script
!= pItems
[index
].a
.eScript
)) || (New_Script
== Script_Control
))
1294 TRACE("Script break(%i/%i)\n",pItems
[index
].a
.eScript
,New_Script
);
1298 if (!new_run
&& strength
&& str
== BIDI_STRONG
)
1300 layoutRTL
= odd(levels
[cnt
])?1:0;
1301 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1306 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
);
1309 if (index
+1 > cMaxItems
)
1310 return E_OUTOFMEMORY
;
1313 str
= strength
[cnt
];
1315 pItems
[index
].iCharPos
= cnt
;
1316 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1318 pItems
[index
].a
= scriptInformation
[New_Script
].a
;
1319 pScriptTags
[index
] = scriptInformation
[New_Script
].scriptTag
;
1322 if (levels
[cnt
] == 0)
1325 layoutRTL
= (layoutRTL
|| odd(levels
[cnt
]))?1:0;
1326 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1327 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1328 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1330 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1332 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1333 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1334 pItems
[index
].a
.fRTL
= odd(baselevel
);
1337 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1341 /* While not strictly necessary according to the spec, make sure the n+1
1342 * item is set up to prevent random behaviour if the caller erroneously
1343 * checks the n+1 structure */
1345 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1347 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1349 /* Set one SCRIPT_STATE item being returned */
1350 if (index
+ 1 > cMaxItems
) return E_OUTOFMEMORY
;
1351 if (pcItems
) *pcItems
= index
;
1353 /* Set SCRIPT_ITEM */
1354 pItems
[index
].iCharPos
= cnt
; /* the last item contains the ptr to the lastchar */
1356 heap_free(strength
);
1361 /***********************************************************************
1362 * ScriptItemize (USP10.@)
1364 * Split a Unicode string into shapeable parts.
1367 * pwcInChars [I] String to split.
1368 * cInChars [I] Number of characters in pwcInChars.
1369 * cMaxItems [I] Maximum number of items to return.
1370 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1371 * psState [I] Pointer to a SCRIPT_STATE structure.
1372 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1373 * pcItems [O] Number of script items returned.
1377 * Failure: Non-zero HRESULT value.
1379 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1380 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1381 SCRIPT_ITEM
*pItems
, int *pcItems
)
1383 OPENTYPE_TAG
*discarded_tags
;
1386 discarded_tags
= heap_alloc(cMaxItems
* sizeof(OPENTYPE_TAG
));
1387 if (!discarded_tags
)
1388 return E_OUTOFMEMORY
;
1389 res
= ScriptItemizeOpenType(pwcInChars
, cInChars
, cMaxItems
, psControl
, psState
, pItems
, discarded_tags
, pcItems
);
1390 heap_free(discarded_tags
);
1394 static inline int getGivenTabWidth(ScriptCache
*psc
, SCRIPT_TABDEF
*pTabdef
, int charPos
, int current_x
)
1398 INT
*lpTabPos
= NULL
;
1403 lpTabPos
= pTabdef
->pTabStops
;
1405 if (pTabdef
&& pTabdef
->iTabOrigin
)
1407 if (pTabdef
->iScale
)
1408 nTabOrg
= (pTabdef
->iTabOrigin
* pTabdef
->iScale
)/4;
1410 nTabOrg
= pTabdef
->iTabOrigin
* psc
->tm
.tmAveCharWidth
;
1414 cTabStops
= pTabdef
->cTabStops
;
1418 if (pTabdef
->iScale
)
1419 defWidth
= ((pTabdef
->pTabStops
[0])*pTabdef
->iScale
) / 4;
1421 defWidth
= (pTabdef
->pTabStops
[0])*psc
->tm
.tmAveCharWidth
;
1425 defWidth
= 8 * psc
->tm
.tmAveCharWidth
;
1427 for (; cTabStops
>0 ; lpTabPos
++, cTabStops
--)
1429 int position
= *lpTabPos
;
1431 position
= -1 * position
;
1432 if (pTabdef
->iScale
)
1433 position
= (position
* pTabdef
->iScale
) / 4;
1435 position
= position
* psc
->tm
.tmAveCharWidth
;
1437 if( nTabOrg
+ position
> current_x
)
1441 /* a left aligned tab */
1442 x
= (nTabOrg
+ *lpTabPos
) - current_x
;
1447 FIXME("Negative tabstop\n");
1452 if ((!cTabStops
) && (defWidth
> 0))
1453 x
=((((current_x
- nTabOrg
) / defWidth
)+1) * defWidth
) - current_x
;
1454 else if ((!cTabStops
) && (defWidth
< 0))
1455 FIXME("TODO: Negative defWidth\n");
1460 /***********************************************************************
1461 * Helper function for ScriptStringAnalyse
1463 static BOOL
requires_fallback(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
1464 const WCHAR
*pwcInChars
, int cChars
)
1466 /* FIXME: When to properly fallback is still a bit of a mystery */
1469 if (psa
->fNoGlyphIndex
)
1472 if (init_script_cache(hdc
, psc
) != S_OK
)
1475 if (SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
) != S_OK
)
1478 glyphs
= heap_alloc(sizeof(WORD
) * cChars
);
1481 if (ScriptGetCMap(hdc
, psc
, pwcInChars
, cChars
, 0, glyphs
) != S_OK
)
1491 static void find_fallback_font(DWORD scriptid
, LPWSTR FaceName
)
1495 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Uniscribe\\Fallback", &hkey
))
1497 static const WCHAR szFmt
[] = {'%','x',0};
1499 DWORD count
= LF_FACESIZE
* sizeof(WCHAR
);
1502 sprintfW(value
, szFmt
, scriptInformation
[scriptid
].scriptTag
);
1503 if (RegQueryValueExW(hkey
, value
, 0, &type
, (LPBYTE
)FaceName
, &count
))
1504 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1508 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1511 /***********************************************************************
1512 * ScriptStringAnalyse (USP10.@)
1515 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
1516 int cGlyphs
, int iCharset
, DWORD dwFlags
,
1517 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
1518 SCRIPT_STATE
*psState
, const int *piDx
,
1519 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
1520 SCRIPT_STRING_ANALYSIS
*pssa
)
1522 HRESULT hr
= E_OUTOFMEMORY
;
1523 StringAnalysis
*analysis
= NULL
;
1524 SCRIPT_CONTROL sControl
;
1525 SCRIPT_STATE sState
;
1526 int i
, num_items
= 255;
1528 WCHAR
*iString
= NULL
;
1530 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1531 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
1532 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
1536 FIXME("Only Unicode strings are supported\n");
1537 return E_INVALIDARG
;
1539 if (cString
< 1 || !pString
) return E_INVALIDARG
;
1540 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
1542 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
1543 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
1545 /* FIXME: handle clipping */
1546 analysis
->clip_len
= cString
;
1547 analysis
->hdc
= hdc
;
1548 analysis
->dwFlags
= dwFlags
;
1553 memset(&sState
, 0, sizeof(SCRIPT_STATE
));
1556 sControl
= *psControl
;
1558 memset(&sControl
, 0, sizeof(SCRIPT_CONTROL
));
1560 if (dwFlags
& SSA_PASSWORD
)
1562 iString
= heap_alloc(sizeof(WCHAR
)*cString
);
1568 for (i
= 0; i
< cString
; i
++)
1569 iString
[i
] = *((const WCHAR
*)pString
);
1573 hr
= ScriptItemize(pString
, cString
, num_items
, &sControl
, &sState
, analysis
->pItem
,
1574 &analysis
->numItems
);
1576 while (hr
== E_OUTOFMEMORY
)
1581 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
1584 analysis
->pItem
= tmp
;
1585 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
1586 &analysis
->numItems
);
1588 if (hr
!= S_OK
) goto error
;
1590 /* set back to out of memory for default goto error behaviour */
1593 if (dwFlags
& SSA_BREAK
)
1595 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
1597 for (i
= 0; i
< analysis
->numItems
; i
++)
1598 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
]);
1604 if (!(analysis
->logical2visual
= heap_alloc_zero(sizeof(int) * analysis
->numItems
)))
1606 if (!(BidiLevel
= heap_alloc_zero(analysis
->numItems
)))
1609 if (dwFlags
& SSA_GLYPHS
)
1612 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
1614 heap_free(BidiLevel
);
1618 for (i
= 0; i
< analysis
->numItems
; i
++)
1620 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
;
1621 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1622 int numGlyphs
= 1.5 * cChar
+ 16;
1623 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
1624 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
1625 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
1626 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * numGlyphs
);
1627 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
1628 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
1629 int numGlyphsReturned
;
1630 HFONT originalFont
= 0x0;
1632 /* FIXME: non unicode strings */
1633 const WCHAR
* pStr
= (const WCHAR
*)pString
;
1634 analysis
->glyphs
[i
].fallbackFont
= NULL
;
1636 if (!glyphs
|| !pwLogClust
|| !piAdvance
|| !psva
|| !pGoffset
|| !abc
)
1638 heap_free (BidiLevel
);
1640 heap_free (pwLogClust
);
1641 heap_free (piAdvance
);
1643 heap_free (pGoffset
);
1649 if ((dwFlags
& SSA_FALLBACK
) && requires_fallback(hdc
, sc
, &analysis
->pItem
[i
].a
, &pStr
[analysis
->pItem
[i
].iCharPos
], cChar
))
1652 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), & lf
);
1653 lf
.lfCharSet
= scriptInformation
[analysis
->pItem
[i
].a
.eScript
].props
.bCharSet
;
1654 find_fallback_font(analysis
->pItem
[i
].a
.eScript
, lf
.lfFaceName
);
1655 analysis
->glyphs
[i
].fallbackFont
= CreateFontIndirectW(&lf
);
1656 if (analysis
->glyphs
[i
].fallbackFont
)
1658 ScriptFreeCache(sc
);
1659 originalFont
= SelectObject(hdc
, analysis
->glyphs
[i
].fallbackFont
);
1663 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
1664 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
1665 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
1666 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
1667 piAdvance
, pGoffset
, abc
);
1669 SelectObject(hdc
,originalFont
);
1671 if (dwFlags
& SSA_TAB
)
1674 for (tabi
= 0; tabi
< cChar
; tabi
++)
1676 if (pStr
[analysis
->pItem
[i
].iCharPos
+tabi
] == 0x0009)
1677 piAdvance
[tabi
] = getGivenTabWidth(analysis
->glyphs
[i
].sc
, pTabdef
, analysis
->pItem
[i
].iCharPos
+tabi
, tab_x
);
1678 tab_x
+=piAdvance
[tabi
];
1682 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
1683 analysis
->glyphs
[i
].glyphs
= glyphs
;
1684 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
1685 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
1686 analysis
->glyphs
[i
].psva
= psva
;
1687 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
1688 analysis
->glyphs
[i
].abc
= abc
;
1689 analysis
->glyphs
[i
].iMaxPosX
= -1;
1691 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1696 for (i
= 0; i
< analysis
->numItems
; i
++)
1697 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1700 ScriptLayout(analysis
->numItems
, BidiLevel
, NULL
, analysis
->logical2visual
);
1701 heap_free(BidiLevel
);
1709 heap_free(analysis
->glyphs
);
1710 heap_free(analysis
->logattrs
);
1711 heap_free(analysis
->pItem
);
1712 heap_free(analysis
->logical2visual
);
1713 heap_free(analysis
);
1717 static inline BOOL
does_glyph_start_cluster(const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cChars
, int glyph
, int direction
)
1721 if (pva
[glyph
].fClusterStart
)
1723 for (i
= 0; i
< cChars
; i
++)
1724 if (pwLogClust
[i
] == glyph
) break;
1732 static HRESULT
SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa
,
1743 StringAnalysis
*analysis
;
1746 COLORREF BkColor
= 0x0;
1747 COLORREF TextColor
= 0x0;
1749 INT runStart
, runEnd
;
1750 INT iGlyph
, cGlyphs
;
1751 HFONT oldFont
= 0x0;
1753 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1754 ssa
, iX
, iY
, iItem
, cStart
, cEnd
, uOptions
, fSelected
, fDisabled
);
1756 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1758 if ((cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
<= cStart
) ||
1759 (cEnd
>= 0 && analysis
->pItem
[iItem
].iCharPos
>= cEnd
))
1764 BkMode
= GetBkMode(analysis
->hdc
);
1765 SetBkMode( analysis
->hdc
, OPAQUE
);
1766 BkColor
= GetBkColor(analysis
->hdc
);
1767 SetBkColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1770 TextColor
= GetTextColor(analysis
->hdc
);
1771 SetTextColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1774 if (analysis
->glyphs
[iItem
].fallbackFont
)
1775 oldFont
= SelectObject(analysis
->hdc
, analysis
->glyphs
[iItem
].fallbackFont
);
1777 if (cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cStart
&& analysis
->pItem
[iItem
].iCharPos
<= cStart
)
1778 runStart
= cStart
- analysis
->pItem
[iItem
].iCharPos
;
1781 if (cEnd
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cEnd
&& analysis
->pItem
[iItem
].iCharPos
<= cEnd
)
1782 runEnd
= (cEnd
-1) - analysis
->pItem
[iItem
].iCharPos
;
1784 runEnd
= (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
) - 1;
1786 if (analysis
->pItem
[iItem
].a
.fRTL
)
1788 if (cEnd
>= 0 && cEnd
< analysis
->pItem
[iItem
+1].iCharPos
)
1789 ScriptStringCPtoX(ssa
, cEnd
, FALSE
, &off_x
);
1791 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
+1].iCharPos
-1, TRUE
, &off_x
);
1795 if (cStart
>=0 && runStart
)
1796 ScriptStringCPtoX(ssa
, cStart
, FALSE
, &off_x
);
1798 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
].iCharPos
, FALSE
, &off_x
);
1801 if (analysis
->pItem
[iItem
].a
.fRTL
)
1802 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
];
1804 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
];
1806 if (analysis
->pItem
[iItem
].a
.fRTL
)
1807 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
] - iGlyph
;
1809 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
] - iGlyph
;
1813 if (cEnd
< 0 || scriptInformation
[analysis
->pItem
[iItem
].a
.eScript
].props
.fNeedsCaretInfo
)
1818 clust_glyph
= iGlyph
+ cGlyphs
;
1819 if (analysis
->pItem
[iItem
].a
.fRTL
)
1824 while(clust_glyph
< analysis
->glyphs
[iItem
].numGlyphs
&&
1825 !does_glyph_start_cluster(analysis
->glyphs
[iItem
].psva
, analysis
->glyphs
[iItem
].pwLogClust
, (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
), clust_glyph
, direction
))
1832 hr
= ScriptTextOut(analysis
->hdc
,
1833 (SCRIPT_CACHE
*)&analysis
->glyphs
[iItem
].sc
, iX
+ off_x
,
1834 iY
, uOptions
, prc
, &analysis
->pItem
[iItem
].a
, NULL
, 0,
1835 &analysis
->glyphs
[iItem
].glyphs
[iGlyph
], cGlyphs
,
1836 &analysis
->glyphs
[iItem
].piAdvance
[iGlyph
], NULL
,
1837 &analysis
->glyphs
[iItem
].pGoffset
[iGlyph
]);
1839 TRACE("ScriptTextOut hr=%08x\n", hr
);
1843 SetBkColor(analysis
->hdc
, BkColor
);
1844 SetBkMode( analysis
->hdc
, BkMode
);
1846 SetTextColor(analysis
->hdc
, TextColor
);
1848 if (analysis
->glyphs
[iItem
].fallbackFont
)
1849 SelectObject(analysis
->hdc
, oldFont
);
1854 /***********************************************************************
1855 * ScriptStringOut (USP10.@)
1857 * This function takes the output of ScriptStringAnalyse and joins the segments
1858 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1859 * only processes glyphs.
1862 * ssa [I] buffer to hold the analysed string components
1863 * iX [I] X axis displacement for output
1864 * iY [I] Y axis displacement for output
1865 * uOptions [I] flags controling output processing
1866 * prc [I] rectangle coordinates
1867 * iMinSel [I] starting pos for substringing output string
1868 * iMaxSel [I] ending pos for substringing output string
1869 * fDisabled [I] controls text highlighting
1873 * Failure: is the value returned by ScriptTextOut
1875 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1884 StringAnalysis
*analysis
;
1888 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1889 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1891 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1892 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return E_INVALIDARG
;
1894 for (item
= 0; item
< analysis
->numItems
; item
++)
1896 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], -1, -1, uOptions
, prc
, FALSE
, fDisabled
);
1901 if (iMinSel
< iMaxSel
&& (iMinSel
> 0 || iMaxSel
> 0))
1903 if (iMaxSel
> 0 && iMinSel
< 0)
1905 for (item
= 0; item
< analysis
->numItems
; item
++)
1907 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], iMinSel
, iMaxSel
, uOptions
, prc
, TRUE
, fDisabled
);
1916 /***********************************************************************
1917 * ScriptStringCPtoX (USP10.@)
1920 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1924 StringAnalysis
* analysis
= ssa
;
1926 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1928 if (!ssa
|| !pX
) return S_FALSE
;
1929 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1931 /* icp out of range */
1934 analysis
->invalid
= TRUE
;
1935 return E_INVALIDARG
;
1938 for(item
=0; item
<analysis
->numItems
; item
++)
1943 i
= analysis
->logical2visual
[item
];
1944 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1945 /* initialize max extents for uninitialized runs */
1946 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1948 if (analysis
->pItem
[i
].a
.fRTL
)
1949 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1950 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1951 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1953 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1954 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1955 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1958 if (icp
>= analysis
->pItem
[i
+1].iCharPos
|| icp
< analysis
->pItem
[i
].iCharPos
)
1960 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
1964 icp
-= analysis
->pItem
[i
].iCharPos
;
1965 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1966 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1967 &analysis
->pItem
[i
].a
, &offset
);
1974 /* icp out of range */
1975 analysis
->invalid
= TRUE
;
1976 return E_INVALIDARG
;
1979 /***********************************************************************
1980 * ScriptStringXtoCP (USP10.@)
1983 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
1985 StringAnalysis
* analysis
= ssa
;
1988 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
1990 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
1991 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1996 if (analysis
->pItem
[0].a
.fRTL
)
1999 *piTrailing
= FALSE
;
2009 for(item
=0; item
<analysis
->numItems
; item
++)
2014 for (i
= 0; i
< analysis
->numItems
&& analysis
->logical2visual
[i
] != item
; i
++)
2017 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
2018 /* initialize max extents for uninitialized runs */
2019 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
2021 if (analysis
->pItem
[i
].a
.fRTL
)
2022 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2023 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2024 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2026 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2027 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2028 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
2031 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
2033 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
2037 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
2038 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
2039 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
2040 *piCh
+= analysis
->pItem
[i
].iCharPos
;
2046 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
2047 *piTrailing
= FALSE
;
2053 /***********************************************************************
2054 * ScriptStringFree (USP10.@)
2056 * Free a string analysis.
2059 * pssa [I] string analysis.
2063 * Failure: Non-zero HRESULT value.
2065 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
2067 StringAnalysis
* analysis
;
2071 TRACE("(%p)\n", pssa
);
2073 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
2075 invalid
= analysis
->invalid
;
2077 if (analysis
->glyphs
)
2079 for (i
= 0; i
< analysis
->numItems
; i
++)
2081 heap_free(analysis
->glyphs
[i
].glyphs
);
2082 heap_free(analysis
->glyphs
[i
].pwLogClust
);
2083 heap_free(analysis
->glyphs
[i
].piAdvance
);
2084 heap_free(analysis
->glyphs
[i
].psva
);
2085 heap_free(analysis
->glyphs
[i
].pGoffset
);
2086 heap_free(analysis
->glyphs
[i
].abc
);
2087 if (analysis
->glyphs
[i
].fallbackFont
)
2088 DeleteObject(analysis
->glyphs
[i
].fallbackFont
);
2089 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
);
2090 heap_free(analysis
->glyphs
[i
].sc
);
2092 heap_free(analysis
->glyphs
);
2095 heap_free(analysis
->pItem
);
2096 heap_free(analysis
->logattrs
);
2097 heap_free(analysis
->sz
);
2098 heap_free(analysis
->logical2visual
);
2099 heap_free(analysis
);
2101 if (invalid
) return E_INVALIDARG
;
2105 static inline int get_cluster_size(const WORD
*pwLogClust
, int cChars
, int item
,
2106 int direction
, int* iCluster
, int *check_out
)
2110 WORD clust
= pwLogClust
[item
];
2112 for (check
= item
+direction
; check
< cChars
&& check
>= 0; check
+=direction
)
2114 if (pwLogClust
[check
] == clust
)
2117 if (iCluster
&& *iCluster
== -1)
2129 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
)
2132 int log_clust_max
= 0;
2135 advance
= piAdvance
[glyph
];
2137 for (i
= 0; i
< cChars
; i
++)
2139 if (pwLogClust
[i
] > log_clust_max
)
2140 log_clust_max
= pwLogClust
[i
];
2143 if (glyph
> log_clust_max
)
2146 for (glyph
+=direction
; glyph
< cGlyphs
&& glyph
>= 0; glyph
+=direction
)
2149 if (does_glyph_start_cluster(pva
, pwLogClust
, cChars
, glyph
, direction
))
2151 if (glyph
> log_clust_max
)
2153 advance
+= piAdvance
[glyph
];
2159 /***********************************************************************
2160 * ScriptCPtoX (USP10.@)
2163 HRESULT WINAPI
ScriptCPtoX(int iCP
,
2167 const WORD
*pwLogClust
,
2168 const SCRIPT_VISATTR
*psva
,
2169 const int *piAdvance
,
2170 const SCRIPT_ANALYSIS
*psa
,
2178 float special_size
= 0.0;
2183 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2184 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2187 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2195 int max_clust
= pwLogClust
[0];
2197 for (item
=0; item
< cGlyphs
; item
++)
2198 if (pwLogClust
[item
] > max_clust
)
2200 ERR("We do not handle non reversed clusters properly\n");
2205 for (item
= max_clust
; item
>=0; item
--)
2206 iMaxPos
+= piAdvance
[item
];
2210 for (item
=0; item
< iCP
&& item
< cChars
; item
++)
2212 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
2215 int clust
= pwLogClust
[item
];
2218 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, 1, &iCluster
,
2221 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, 1);
2223 if (check
>= cChars
&& !iMaxPos
)
2225 for (check
= clust
; check
< cChars
; check
++)
2226 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, 1);
2228 special_size
/= (cChars
- item
);
2229 iPosX
+= special_size
;
2233 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2236 if (clust_size
== 0)
2240 iPosX
+= advance
/ (float)clust_size
;
2243 else if (iSpecial
!= -1)
2244 iPosX
+= special_size
;
2245 else /* (iCluster != -1) */
2247 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], 1);
2248 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2251 if (clust_size
== 0)
2255 iPosX
+= adv
/ (float)clust_size
;
2261 iPosX
= iMaxPos
- iPosX
;
2267 TRACE("*piX=%d\n", *piX
);
2271 /***********************************************************************
2272 * ScriptXtoCP (USP10.@)
2275 HRESULT WINAPI
ScriptXtoCP(int iX
,
2278 const WORD
*pwLogClust
,
2279 const SCRIPT_VISATTR
*psva
,
2280 const int *piAdvance
,
2281 const SCRIPT_ANALYSIS
*psa
,
2293 float special_size
= 0.0;
2296 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2297 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2298 psa
, piCP
, piTrailing
);
2300 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2305 int max_clust
= pwLogClust
[0];
2314 for (item
=0; item
< cChars
; item
++)
2315 if (pwLogClust
[item
] > max_clust
)
2317 ERR("We do not handle non reversed clusters properly\n");
2329 iPosX
= iLastPosX
= 0;
2334 for (; iPosX
<= iX
&& item
< cChars
&& item
>= 0; item
+=direction
)
2337 if (iSpecial
== -1 &&
2340 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
2341 (direction
< 0 && iCluster
-clust_size
>= item
))
2347 int clust
= pwLogClust
[item
];
2351 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, direction
,
2353 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, direction
);
2355 if (check
>= cChars
&& direction
> 0)
2357 for (check
= clust
; check
< cChars
; check
++)
2358 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, direction
);
2360 special_size
/= (cChars
- item
);
2361 iPosX
+= special_size
;
2365 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2372 iPosX
+= advance
/ (float)clust_size
;
2375 else if (iSpecial
!= -1)
2376 iPosX
+= special_size
;
2377 else /* (iCluster != -1) */
2379 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], direction
);
2380 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2387 iPosX
+= adv
/ (float)clust_size
;
2395 if (item
< cChars
&& ((iPosX
- iLastPosX
) / 2.0) + iX
>= iPosX
)
2397 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2398 item
+=(clust_size
-1);
2406 if (iX
== iLastPosX
)
2408 if (iX
>= iLastPosX
&& iX
<= iPosX
)
2411 if (iLastPosX
== iX
)
2413 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
2415 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2416 item
-=(clust_size
-1);
2425 TRACE("*piCP=%d\n", *piCP
);
2426 TRACE("*piTrailing=%d\n", *piTrailing
);
2430 /***********************************************************************
2431 * ScriptBreak (USP10.@)
2433 * Retrieve line break information.
2436 * chars [I] Array of characters.
2437 * sa [I] String analysis.
2438 * la [I] Array of logical attribute structures.
2444 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
2446 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
2448 if (!la
) return S_FALSE
;
2450 BREAK_line(chars
, count
, sa
, la
);
2455 /***********************************************************************
2456 * ScriptIsComplex (USP10.@)
2458 * Determine if a string is complex.
2461 * chars [I] Array of characters to test.
2462 * len [I] Length in characters.
2470 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
2474 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
2476 for (i
= 0; i
< len
; i
++)
2480 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
2483 script
= get_char_script(chars
[i
]);
2484 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
2485 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
2491 /***********************************************************************
2492 * ScriptShapeOpenType (USP10.@)
2494 * Produce glyphs and visual attributes for a run.
2497 * hdc [I] Device context.
2498 * psc [I/O] Opaque pointer to a script cache.
2499 * psa [I/O] Script analysis.
2500 * tagScript [I] The OpenType tag for the Script
2501 * tagLangSys [I] The OpenType tag for the Language
2502 * rcRangeChars[I] Array of Character counts in each range
2503 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2504 * cRanges [I] Count of ranges
2505 * pwcChars [I] Array of characters specifying the run.
2506 * cChars [I] Number of characters in pwcChars.
2507 * cMaxGlyphs [I] Length of pwOutGlyphs.
2508 * pwLogClust [O] Array of logical cluster info.
2509 * pCharProps [O] Array of character property values
2510 * pwOutGlyphs [O] Array of glyphs.
2511 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2512 * pcGlyphs [O] Number of glyphs returned.
2516 * Failure: Non-zero HRESULT value.
2518 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
2519 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
2520 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
2521 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2522 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
2523 int cMaxGlyphs
, WORD
*pwLogClust
,
2524 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
2525 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
2531 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2533 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2534 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2535 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
2537 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
2538 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
2540 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
2541 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2544 FIXME("Ranges not supported yet\n");
2546 rtl
= (psa
&& !psa
->fLogicalOrder
&& psa
->fRTL
);
2549 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2550 if (!pwLogClust
) return E_FAIL
;
2552 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2553 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2555 /* set fNoGlyphIndex non truetype/opentype fonts */
2556 if (!psa
->fNoGlyphIndex
&& !((ScriptCache
*)*psc
)->sfnt
)
2557 psa
->fNoGlyphIndex
= TRUE
;
2559 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2560 for (i
= 0; i
< cChars
; i
++)
2563 if (rtl
) idx
= cChars
- 1 - i
;
2564 /* FIXME: set to better values */
2565 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
2566 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
2567 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
2568 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
2569 pOutGlyphProps
[i
].sva
.fReserved
= 0;
2570 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
2572 /* FIXME: have the shaping engine set this */
2573 pCharProps
[i
].fCanGlyphAlone
= 0;
2575 pwLogClust
[i
] = idx
;
2578 if (psa
&& !psa
->fNoGlyphIndex
)
2581 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
2583 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
2584 if (!rChars
) return E_OUTOFMEMORY
;
2585 for (i
= 0; i
< cChars
; i
++)
2589 if (rtl
) idx
= cChars
- 1 - i
;
2591 chInput
= mirror_char(pwcChars
[idx
]);
2593 chInput
= pwcChars
[idx
];
2594 /* special case for tabs */
2595 if (chInput
== 0x0009)
2597 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
2605 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
)
2610 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
2612 rChars
[i
] = chInput
;
2615 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
2616 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
2617 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
2622 TRACE("no glyph translation\n");
2623 for (i
= 0; i
< cChars
; i
++)
2626 /* No mirroring done here */
2627 if (rtl
) idx
= cChars
- 1 - i
;
2628 pwOutGlyphs
[i
] = pwcChars
[idx
];
2636 /***********************************************************************
2637 * ScriptShape (USP10.@)
2639 * Produce glyphs and visual attributes for a run.
2642 * hdc [I] Device context.
2643 * psc [I/O] Opaque pointer to a script cache.
2644 * pwcChars [I] Array of characters specifying the run.
2645 * cChars [I] Number of characters in pwcChars.
2646 * cMaxGlyphs [I] Length of pwOutGlyphs.
2647 * psa [I/O] Script analysis.
2648 * pwOutGlyphs [O] Array of glyphs.
2649 * pwLogClust [O] Array of logical cluster info.
2650 * psva [O] Array of visual attributes.
2651 * pcGlyphs [O] Number of glyphs returned.
2655 * Failure: Non-zero HRESULT value.
2657 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
2658 int cChars
, int cMaxGlyphs
,
2659 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
2660 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
2664 SCRIPT_CHARPROP
*charProps
;
2665 SCRIPT_GLYPHPROP
*glyphProps
;
2667 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
2668 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2670 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
2671 if (!charProps
) return E_OUTOFMEMORY
;
2672 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
2675 heap_free(charProps
);
2676 return E_OUTOFMEMORY
;
2679 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
2683 for (i
= 0; i
< *pcGlyphs
; i
++)
2684 psva
[i
] = glyphProps
[i
].sva
;
2687 heap_free(charProps
);
2688 heap_free(glyphProps
);
2693 /***********************************************************************
2694 * ScriptPlaceOpenType (USP10.@)
2696 * Produce advance widths for a run.
2699 * hdc [I] Device context.
2700 * psc [I/O] Opaque pointer to a script cache.
2701 * psa [I/O] String analysis.
2702 * tagScript [I] The OpenType tag for the Script
2703 * tagLangSys [I] The OpenType tag for the Language
2704 * rcRangeChars[I] Array of Character counts in each range
2705 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2706 * cRanges [I] Count of ranges
2707 * pwcChars [I] Array of characters specifying the run.
2708 * pwLogClust [I] Array of logical cluster info
2709 * pCharProps [I] Array of character property values
2710 * cChars [I] Number of characters in pwcChars.
2711 * pwGlyphs [I] Array of glyphs.
2712 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2713 * cGlyphs [I] Count of Glyphs
2714 * piAdvance [O] Array of advance widths.
2715 * pGoffset [O] Glyph offsets.
2716 * pABC [O] Combined ABC width.
2720 * Failure: Non-zero HRESULT value.
2723 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
2724 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
2725 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2726 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
2727 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
2728 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
2729 int cGlyphs
, int *piAdvance
,
2730 GOFFSET
*pGoffset
, ABC
*pABC
2736 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2738 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2739 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2740 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
2743 if (!pGlyphProps
) return E_INVALIDARG
;
2744 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2745 if (!pGoffset
) return E_FAIL
;
2748 FIXME("Ranges not supported yet\n");
2750 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2751 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2753 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
2754 for (i
= 0; i
< cGlyphs
; i
++)
2757 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
2759 if (!hdc
) return E_PENDING
;
2760 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
2762 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
2767 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
2769 abc
.abcA
= abc
.abcC
= 0;
2771 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
2775 pABC
->abcA
+= abc
.abcA
;
2776 pABC
->abcB
+= abc
.abcB
;
2777 pABC
->abcC
+= abc
.abcC
;
2779 /* FIXME: set to more reasonable values */
2780 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
2781 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
2784 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
2788 /***********************************************************************
2789 * ScriptPlace (USP10.@)
2791 * Produce advance widths for a run.
2794 * hdc [I] Device context.
2795 * psc [I/O] Opaque pointer to a script cache.
2796 * pwGlyphs [I] Array of glyphs.
2797 * cGlyphs [I] Number of glyphs in pwGlyphs.
2798 * psva [I] Array of visual attributes.
2799 * psa [I/O] String analysis.
2800 * piAdvance [O] Array of advance widths.
2801 * pGoffset [O] Glyph offsets.
2802 * pABC [O] Combined ABC width.
2806 * Failure: Non-zero HRESULT value.
2808 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
2809 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
2810 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
2813 SCRIPT_GLYPHPROP
*glyphProps
;
2816 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
2817 piAdvance
, pGoffset
, pABC
);
2819 if (!psva
) return E_INVALIDARG
;
2820 if (!pGoffset
) return E_FAIL
;
2822 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
2823 if (!glyphProps
) return E_OUTOFMEMORY
;
2825 for (i
= 0; i
< cGlyphs
; i
++)
2826 glyphProps
[i
].sva
= psva
[i
];
2828 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
2830 heap_free(glyphProps
);
2835 /***********************************************************************
2836 * ScriptGetCMap (USP10.@)
2838 * Retrieve glyph indices.
2841 * hdc [I] Device context.
2842 * psc [I/O] Opaque pointer to a script cache.
2843 * pwcInChars [I] Array of Unicode characters.
2844 * cChars [I] Number of characters in pwcInChars.
2845 * dwFlags [I] Flags.
2846 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2850 * Failure: Non-zero HRESULT value.
2852 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
2853 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
2858 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
2859 cChars
, dwFlags
, pwOutGlyphs
);
2861 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2865 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2867 for (i
= 0; i
< cChars
; i
++)
2870 if (dwFlags
== SGCM_RTL
)
2871 inChar
= mirror_char(pwcInChars
[i
]);
2873 inChar
= pwcInChars
[i
];
2874 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
2877 if (!hdc
) return E_PENDING
;
2878 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
2879 if (glyph
== 0xffff)
2884 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
2890 TRACE("no glyph translation\n");
2891 for (i
= 0; i
< cChars
; i
++)
2894 if (dwFlags
== SGCM_RTL
)
2895 inChar
= mirror_char(pwcInChars
[i
]);
2897 inChar
= pwcInChars
[i
];
2898 pwOutGlyphs
[i
] = inChar
;
2904 /***********************************************************************
2905 * ScriptTextOut (USP10.@)
2908 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
2909 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
2910 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
2911 const int *piJustify
, const GOFFSET
*pGoffset
)
2915 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2916 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
2917 piAdvance
, piJustify
, pGoffset
);
2919 if (!hdc
|| !psc
) return E_INVALIDARG
;
2920 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
2922 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
2923 fuOptions
|= ETO_IGNORELANGUAGE
;
2924 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
2925 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
2927 if (psa
->fRTL
&& psa
->fLogicalOrder
)
2932 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
2934 return E_OUTOFMEMORY
;
2936 for (i
= 0; i
< cGlyphs
; i
++)
2937 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
2939 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
2941 heap_free(rtlGlyphs
);
2944 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
2950 /***********************************************************************
2951 * ScriptCacheGetHeight (USP10.@)
2953 * Retrieve the height of the font in the cache.
2956 * hdc [I] Device context.
2957 * psc [I/O] Opaque pointer to a script cache.
2958 * height [O] Receives font height.
2962 * Failure: Non-zero HRESULT value.
2964 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
2968 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
2970 if (!height
) return E_INVALIDARG
;
2971 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2973 *height
= get_cache_height(psc
);
2977 /***********************************************************************
2978 * ScriptGetGlyphABCWidth (USP10.@)
2980 * Retrieve the width of a glyph.
2983 * hdc [I] Device context.
2984 * psc [I/O] Opaque pointer to a script cache.
2985 * glyph [I] Glyph to retrieve the width for.
2986 * abc [O] ABC widths of the glyph.
2990 * Failure: Non-zero HRESULT value.
2992 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
2996 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
2998 if (!abc
) return E_INVALIDARG
;
2999 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
3001 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
3003 if (!hdc
) return E_PENDING
;
3004 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
3006 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
3011 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
3013 abc
->abcA
= abc
->abcC
= 0;
3015 set_cache_glyph_widths(psc
, glyph
, abc
);
3020 /***********************************************************************
3021 * ScriptLayout (USP10.@)
3023 * Map embedding levels to visual and/or logical order.
3026 * runs [I] Size of level array.
3027 * level [I] Array of embedding levels.
3028 * vistolog [O] Map of embedding levels from visual to logical order.
3029 * logtovis [O] Map of embedding levels from logical to visual order.
3033 * Failure: Non-zero HRESULT value.
3036 * This stub works correctly for any sequence of a single
3037 * embedding level but not for sequences of different
3038 * embedding levels, i.e. mixtures of RTL and LTR scripts.
3040 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
3045 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
3047 if (!level
|| (!vistolog
&& !logtovis
))
3048 return E_INVALIDARG
;
3050 indexs
= heap_alloc(sizeof(int) * runs
);
3052 return E_OUTOFMEMORY
;
3057 for( ich
= 0; ich
< runs
; ich
++)
3062 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
3063 for (ich
= 0; ich
< runs
; ich
++)
3064 vistolog
[ich
] = indexs
[ich
];
3070 for( ich
= 0; ich
< runs
; ich
++)
3075 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
3076 for (ich
= 0; ich
< runs
; ich
++)
3077 logtovis
[ich
] = indexs
[ich
];
3084 /***********************************************************************
3085 * ScriptStringGetLogicalWidths (USP10.@)
3087 * Returns logical widths from a string analysis.
3090 * ssa [I] string analysis.
3091 * piDx [O] logical widths returned.
3095 * Failure: a non-zero HRESULT.
3097 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
3100 StringAnalysis
*analysis
= ssa
;
3102 TRACE("%p, %p\n", ssa
, piDx
);
3104 if (!analysis
) return S_FALSE
;
3105 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3107 for (i
= 0; i
< analysis
->numItems
; i
++)
3109 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
3112 if (analysis
->pItem
[i
].a
.fRTL
&& ! analysis
->pItem
[i
].a
.fLogicalOrder
)
3115 for (j
= 0; j
< cChar
; j
++)
3118 int glyph
= analysis
->glyphs
[i
].pwLogClust
[j
];
3119 int clust_size
= get_cluster_size(analysis
->glyphs
[i
].pwLogClust
,
3120 cChar
, j
, direction
, NULL
, NULL
);
3121 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
);
3123 for (k
= 0; k
< clust_size
; k
++)
3125 piDx
[next
] = advance
/ clust_size
;
3134 /***********************************************************************
3135 * ScriptStringValidate (USP10.@)
3137 * Validate a string analysis.
3140 * ssa [I] string analysis.
3144 * Failure: S_FALSE if invalid sequences are found
3145 * or a non-zero HRESULT if it fails.
3147 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
3149 StringAnalysis
*analysis
= ssa
;
3151 TRACE("(%p)\n", ssa
);
3153 if (!analysis
) return E_INVALIDARG
;
3154 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
3157 /***********************************************************************
3158 * ScriptString_pSize (USP10.@)
3160 * Retrieve width and height of an analysed string.
3163 * ssa [I] string analysis.
3166 * Success: Pointer to a SIZE structure.
3169 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
3172 StringAnalysis
*analysis
= ssa
;
3174 TRACE("(%p)\n", ssa
);
3176 if (!analysis
) return NULL
;
3177 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return NULL
;
3181 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
3182 analysis
->sz
->cy
= analysis
->glyphs
[0].sc
->tm
.tmHeight
;
3184 analysis
->sz
->cx
= 0;
3185 for (i
= 0; i
< analysis
->numItems
; i
++)
3187 if (analysis
->glyphs
[i
].sc
->tm
.tmHeight
> analysis
->sz
->cy
)
3188 analysis
->sz
->cy
= analysis
->glyphs
[i
].sc
->tm
.tmHeight
;
3189 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
3190 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
3193 return analysis
->sz
;
3196 /***********************************************************************
3197 * ScriptString_pLogAttr (USP10.@)
3199 * Retrieve logical attributes of an analysed string.
3202 * ssa [I] string analysis.
3205 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3208 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
3210 StringAnalysis
*analysis
= ssa
;
3212 TRACE("(%p)\n", ssa
);
3214 if (!analysis
) return NULL
;
3215 if (!(analysis
->dwFlags
& SSA_BREAK
)) return NULL
;
3216 return analysis
->logattrs
;
3219 /***********************************************************************
3220 * ScriptString_pcOutChars (USP10.@)
3222 * Retrieve the length of a string after clipping.
3225 * ssa [I] String analysis.
3228 * Success: Pointer to the length.
3231 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
3233 StringAnalysis
*analysis
= ssa
;
3235 TRACE("(%p)\n", ssa
);
3237 if (!analysis
) return NULL
;
3238 return &analysis
->clip_len
;
3241 /***********************************************************************
3242 * ScriptStringGetOrder (USP10.@)
3244 * Retrieve a glyph order map.
3247 * ssa [I] String analysis.
3248 * order [I/O] Array of glyph positions.
3252 * Failure: a non-zero HRESULT.
3254 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
3258 StringAnalysis
*analysis
= ssa
;
3260 TRACE("(%p)\n", ssa
);
3262 if (!analysis
) return S_FALSE
;
3263 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3265 /* FIXME: handle RTL scripts */
3266 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
3267 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
3273 /***********************************************************************
3274 * ScriptGetLogicalWidths (USP10.@)
3276 * Convert advance widths to logical widths.
3279 * sa [I] Script analysis.
3280 * nbchars [I] Number of characters.
3281 * nbglyphs [I] Number of glyphs.
3282 * glyph_width [I] Array of glyph widths.
3283 * log_clust [I] Array of logical clusters.
3284 * sva [I] Visual attributes.
3285 * widths [O] Array of logical widths.
3289 * Failure: a non-zero HRESULT.
3291 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
3292 const int *glyph_width
, const WORD
*log_clust
,
3293 const SCRIPT_VISATTR
*sva
, int *widths
)
3297 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3298 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
3301 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
3305 /***********************************************************************
3306 * ScriptApplyLogicalWidth (USP10.@)
3308 * Generate glyph advance widths.
3311 * dx [I] Array of logical advance widths.
3312 * num_chars [I] Number of characters.
3313 * num_glyphs [I] Number of glyphs.
3314 * log_clust [I] Array of logical clusters.
3315 * sva [I] Visual attributes.
3316 * advance [I] Array of glyph advance widths.
3317 * sa [I] Script analysis.
3318 * abc [I/O] Summed ABC widths.
3319 * justify [O] Array of glyph advance widths.
3323 * Failure: a non-zero HRESULT.
3325 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
3326 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
3327 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
3328 ABC
*abc
, int *justify
)
3332 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3333 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
3335 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
3339 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
3340 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
3344 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
3346 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];