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.
36 #include "usp10_internal.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe
);
43 typedef struct _scriptRange
52 static const scriptRange scriptRanges
[] = {
53 /* Basic Latin: U+0000–U+007A */
54 /* Latin-1 Supplement: U+0080–U+00FF */
55 /* Latin Extended-A: U+0100–U+017F */
56 /* Latin Extended-B: U+0180–U+024F */
57 /* IPA Extensions: U+0250–U+02AF */
58 { Script_Latin
, 0x00, 0x2af , Script_Numeric
, Script_Punctuation
},
59 /* Greek: U+0370–U+03FF */
60 { Script_Greek
, 0x370, 0x3ff, 0, 0},
61 /* Cyrillic: U+0400–U+04FF */
62 /* Cyrillic Supplement: U+0500–U+052F */
63 { Script_Cyrillic
, 0x400, 0x52f, 0, 0},
64 /* Armenian: U+0530–U+058F */
65 { Script_Armenian
, 0x530, 0x58f, 0, 0},
66 /* Hebrew: U+0590–U+05FF */
67 { Script_Hebrew
, 0x590, 0x5ff, 0, 0},
68 /* Arabic: U+0600–U+06FF */
69 { Script_Arabic
, 0x600, 0x6ef, Script_Arabic_Numeric
, 0},
70 /* Defined by Windows */
71 { Script_Persian
, 0x6f0, 0x6f9, 0, 0},
72 /* Continue Arabic: U+0600–U+06FF */
73 { Script_Arabic
, 0x6fa, 0x6ff, 0, 0},
74 /* Syriac: U+0700–U+074F*/
75 { Script_Syriac
, 0x700, 0x74f, 0, 0},
76 /* Arabic Supplement: U+0750–U+077F */
77 { Script_Arabic
, 0x750, 0x77f, 0, 0},
78 /* Thaana: U+0780–U+07BF */
79 { Script_Thaana
, 0x780, 0x7bf, 0, 0},
80 /* Devanagari: U+0900–U+097F */
81 { Script_Devanagari
, 0x900, 0x97f, Script_Devanagari_Numeric
, 0},
82 /* Bengali: U+0980–U+09FF */
83 { Script_Bengali
, 0x980, 0x9ff, Script_Bengali_Numeric
, 0},
84 /* Gurmukhi: U+0A00–U+0A7F*/
85 { Script_Gurmukhi
, 0xa00, 0xa7f, Script_Gurmukhi_Numeric
, 0},
86 /* Gujarati: U+0A80–U+0AFF*/
87 { Script_Gujarati
, 0xa80, 0xaff, Script_Gujarati_Numeric
, 0},
88 /* Oriya: U+0B00–U+0B7F */
89 { Script_Oriya
, 0xb00, 0xb7f, Script_Oriya_Numeric
, 0},
90 /* Tamil: U+0B80–U+0BFF */
91 { Script_Tamil
, 0xb80, 0xbff, Script_Tamil_Numeric
, 0},
92 /* Telugu: U+0C00–U+0C7F */
93 { Script_Telugu
, 0xc00, 0xc7f, Script_Telugu_Numeric
, 0},
94 /* Kannada: U+0C80–U+0CFF */
95 { Script_Kannada
, 0xc80, 0xcff, Script_Kannada_Numeric
, 0},
96 /* Sinhala: U+0D80–U+0DFF */
97 { Script_Sinhala
, 0xd80, 0xdff, 0, 0},
98 /* Thai: U+0E00–U+0E7F */
99 { Script_Thai
, 0xe00, 0xe7f, Script_Thai_Numeric
, 0},
100 /* Lao: U+0E80–U+0EFF */
101 { Script_Lao
, 0xe80, 0xeff, Script_Lao_Numeric
, 0},
102 /* Tibetan: U+0F00–U+0FFF */
103 { Script_Tibetan
, 0xf00, 0xfff, Script_Tibetan_Numeric
, 0},
104 /* Georgian: U+10A0–U+10FF */
105 { Script_Georgian
, 0x10a0, 0x10ff, 0, 0},
106 /* Vedic Extensions: U+1CD0-U+1CFF */
107 { Script_Devanagari
, 0x1cd0, 0x1cff, Script_Devanagari_Numeric
, 0},
108 /* Phonetic Extensions: U+1D00–U+1DBF */
109 { Script_Latin
, 0x1d00, 0x1dbf, 0, 0},
110 /* Latin Extended Additional: U+1E00–U+1EFF */
111 { Script_Latin
, 0x1e00, 0x1eff, 0, 0},
112 /* Greek Extended: U+1F00–U+1FFF */
113 { Script_Greek
, 0x1f00, 0x1fff, 0, 0},
114 /* Latin Extended-C: U+2C60–U+2C7F */
115 { Script_Latin
, 0x2c60, 0x2c7f, 0, 0},
116 /* Georgian: U+2D00–U+2D2F */
117 { Script_Georgian
, 0x2d00, 0x2d2f, 0, 0},
118 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
119 { Script_Cyrillic
, 0x2de0, 0x2dff, 0, 0},
120 /* Cyrillic Extended-B: U+A640–U+A69F */
121 { Script_Cyrillic
, 0xa640, 0xa69f, 0, 0},
122 /* Modifier Tone Letters: U+A700–U+A71F */
123 /* Latin Extended-D: U+A720–U+A7FF */
124 { Script_Latin
, 0xa700, 0xa7ff, 0, 0},
125 /* Phags-pa: U+A840–U+A87F */
126 { Script_Phags_pa
, 0xa840, 0xa87f, 0, 0},
127 /* Devanagari Extended: U+A8E0-U+A8FF */
128 { Script_Devanagari
, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric
, 0},
129 /* Latin Ligatures: U+FB00–U+FB06 */
130 { Script_Latin
, 0xfb00, 0xfb06, 0, 0},
131 /* Armenian ligatures U+FB13..U+FB17 */
132 { Script_Armenian
, 0xfb13, 0xfb17, 0, 0},
133 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
134 { Script_Hebrew
, 0xfb1d, 0xfb4f, 0, 0},
135 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
136 { Script_Arabic
, 0xfb50, 0xfdff, 0, 0},
137 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
138 { Script_Arabic
, 0xfe70, 0xfeff, 0, 0},
140 { SCRIPT_UNDEFINED
, 0, 0, 0}
143 typedef struct _scriptData
146 SCRIPT_PROPERTIES props
;
147 OPENTYPE_TAG scriptTag
;
150 /* the must be in order so that the index matches the Script value */
151 static const scriptData scriptInformation
[] = {
152 {{SCRIPT_UNDEFINED
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
153 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
155 {{Script_Latin
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
156 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
157 MS_MAKE_TAG('l','a','t','n')},
158 {{Script_CR
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
159 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
161 {{Script_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
162 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
164 {{Script_Control
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
165 {LANG_ENGLISH
, 0, 1, 0, 0, ANSI_CHARSET
, 1, 0, 0, 0, 0, 0, 1, 0, 0},
167 {{Script_Punctuation
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
168 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
170 {{Script_Arabic
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
171 {LANG_ARABIC
, 0, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 1, 0},
172 MS_MAKE_TAG('a','r','a','b')},
173 {{Script_Arabic_Numeric
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
174 {LANG_ARABIC
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
175 MS_MAKE_TAG('a','r','a','b')},
176 {{Script_Hebrew
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
177 {LANG_HEBREW
, 0, 1, 0, 1, HEBREW_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
178 MS_MAKE_TAG('h','e','b','r')},
179 {{Script_Syriac
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
180 {LANG_SYRIAC
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 1, 0},
181 MS_MAKE_TAG('s','y','r','c')},
182 {{Script_Persian
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
183 {LANG_PERSIAN
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
184 MS_MAKE_TAG('s','y','r','c')},
185 {{Script_Thaana
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
186 {LANG_DIVEHI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
187 MS_MAKE_TAG('t','h','a','a')},
188 {{Script_Greek
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
189 {LANG_GREEK
, 0, 0, 0, 0, GREEK_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
190 MS_MAKE_TAG('g','r','e','k')},
191 {{Script_Cyrillic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
192 {LANG_RUSSIAN
, 0, 0, 0, 0, RUSSIAN_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
193 MS_MAKE_TAG('c','y','r','l')},
194 {{Script_Armenian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
195 {LANG_ARMENIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
196 MS_MAKE_TAG('a','r','m','n')},
197 {{Script_Georgian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
198 {LANG_GEORGIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
199 MS_MAKE_TAG('g','e','o','r')},
200 {{Script_Sinhala
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
201 {LANG_SINHALESE
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
202 MS_MAKE_TAG('s','i','n','h')},
203 {{Script_Tibetan
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
204 {LANG_TIBETAN
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
205 MS_MAKE_TAG('t','i','b','t')},
206 {{Script_Tibetan_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
207 {LANG_TIBETAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
208 MS_MAKE_TAG('t','i','b','t')},
209 {{Script_Phags_pa
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
210 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
211 MS_MAKE_TAG('p','h','a','g')},
212 {{Script_Thai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
213 {LANG_THAI
, 0, 1, 1, 1, THAI_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 1},
214 MS_MAKE_TAG('t','h','a','i')},
215 {{Script_Thai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
216 {LANG_THAI
, 1, 1, 0, 0, THAI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
217 MS_MAKE_TAG('t','h','a','i')},
218 {{Script_Lao
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
219 {LANG_LAO
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
220 MS_MAKE_TAG('l','a','o',' ')},
221 {{Script_Lao_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
222 {LANG_LAO
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
223 MS_MAKE_TAG('l','a','o',' ')},
224 {{Script_Devanagari
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
225 {LANG_HINDI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
226 MS_MAKE_TAG('d','e','v','a')},
227 {{Script_Devanagari_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
228 {LANG_HINDI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
229 MS_MAKE_TAG('d','e','v','a')},
230 {{Script_Bengali
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
231 {LANG_BENGALI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
232 MS_MAKE_TAG('b','e','n','g')},
233 {{Script_Bengali_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
234 {LANG_BENGALI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
235 MS_MAKE_TAG('b','e','n','g')},
236 {{Script_Bengali_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
237 {LANG_BENGALI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
238 MS_MAKE_TAG('b','e','n','g')},
239 {{Script_Gurmukhi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
240 {LANG_PUNJABI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
241 MS_MAKE_TAG('g','u','r','u')},
242 {{Script_Gurmukhi_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
243 {LANG_PUNJABI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
244 MS_MAKE_TAG('g','u','r','u')},
245 {{Script_Gujarati
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
246 {LANG_GUJARATI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
247 MS_MAKE_TAG('g','u','j','r')},
248 {{Script_Gujarati_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
249 {LANG_GUJARATI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
250 MS_MAKE_TAG('g','u','j','r')},
251 {{Script_Gujarati_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
252 {LANG_GUJARATI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
253 MS_MAKE_TAG('g','u','j','r')},
254 {{Script_Oriya
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
255 {LANG_ORIYA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
256 MS_MAKE_TAG('o','r','y','a')},
257 {{Script_Oriya_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
258 {LANG_ORIYA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
259 MS_MAKE_TAG('o','r','y','a')},
260 {{Script_Tamil
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
261 {LANG_TAMIL
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
262 MS_MAKE_TAG('t','a','m','l')},
263 {{Script_Tamil_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
264 {LANG_TAMIL
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
265 MS_MAKE_TAG('t','a','m','l')},
266 {{Script_Telugu
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
267 {LANG_TELUGU
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
268 MS_MAKE_TAG('t','e','l','u')},
269 {{Script_Telugu_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
270 {LANG_TELUGU
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
271 MS_MAKE_TAG('t','e','l','u')},
272 {{Script_Kannada
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
273 {LANG_KANNADA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
274 MS_MAKE_TAG('k','n','d','a')},
275 {{Script_Kannada_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
276 {LANG_KANNADA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
277 MS_MAKE_TAG('k','n','d','a')},
280 static const SCRIPT_PROPERTIES
*script_props
[] =
282 &scriptInformation
[0].props
, &scriptInformation
[1].props
,
283 &scriptInformation
[2].props
, &scriptInformation
[3].props
,
284 &scriptInformation
[4].props
, &scriptInformation
[5].props
,
285 &scriptInformation
[6].props
, &scriptInformation
[7].props
,
286 &scriptInformation
[8].props
, &scriptInformation
[9].props
,
287 &scriptInformation
[10].props
, &scriptInformation
[11].props
,
288 &scriptInformation
[12].props
, &scriptInformation
[13].props
,
289 &scriptInformation
[14].props
, &scriptInformation
[15].props
,
290 &scriptInformation
[16].props
, &scriptInformation
[17].props
,
291 &scriptInformation
[18].props
, &scriptInformation
[19].props
,
292 &scriptInformation
[20].props
, &scriptInformation
[21].props
,
293 &scriptInformation
[22].props
, &scriptInformation
[23].props
,
294 &scriptInformation
[24].props
, &scriptInformation
[25].props
,
295 &scriptInformation
[26].props
, &scriptInformation
[27].props
,
296 &scriptInformation
[28].props
, &scriptInformation
[29].props
,
297 &scriptInformation
[30].props
, &scriptInformation
[31].props
,
298 &scriptInformation
[32].props
, &scriptInformation
[33].props
,
299 &scriptInformation
[34].props
, &scriptInformation
[35].props
,
300 &scriptInformation
[36].props
, &scriptInformation
[37].props
,
301 &scriptInformation
[38].props
, &scriptInformation
[39].props
,
302 &scriptInformation
[40].props
, &scriptInformation
[41].props
310 SCRIPT_VISATTR
* psva
;
325 StringGlyphs
* glyphs
;
326 SCRIPT_LOGATTR
* logattrs
;
330 static inline void *heap_alloc(SIZE_T size
)
332 return HeapAlloc(GetProcessHeap(), 0, size
);
335 static inline void *heap_alloc_zero(SIZE_T size
)
337 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
340 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
342 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
345 static inline BOOL
heap_free(LPVOID mem
)
347 return HeapFree(GetProcessHeap(), 0, mem
);
350 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
352 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
355 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
357 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
360 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
362 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
365 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
367 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
369 if (!block
) return 0;
370 return block
[c
& GLYPH_BLOCK_MASK
];
373 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
375 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
377 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
378 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
381 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
383 static const ABC nil
;
384 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
386 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
387 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
391 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
393 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
395 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
396 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
400 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
404 if (!psc
) return E_INVALIDARG
;
405 if (*psc
) return S_OK
;
406 if (!hdc
) return E_PENDING
;
408 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
409 if (!GetTextMetricsW(hdc
, &sc
->tm
))
414 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
420 TRACE("<- %p\n", sc
);
424 static WCHAR
mirror_char( WCHAR ch
)
426 extern const WCHAR wine_mirror_map
[];
427 return ch
+ wine_mirror_map
[wine_mirror_map
[ch
>> 8] + (ch
& 0xff)];
430 static WORD
get_char_script( WCHAR ch
)
435 if (ch
== 0xc || ch
== 0x20 || ch
== 0x202f)
438 GetStringTypeW(CT_CTYPE1
, &ch
, 1, &type
);
441 return SCRIPT_UNDEFINED
;
444 return Script_Control
;
449 if (ch
< scriptRanges
[i
].rangeFirst
|| scriptRanges
[i
].script
== SCRIPT_UNDEFINED
)
452 if (ch
>= scriptRanges
[i
].rangeFirst
&& ch
<= scriptRanges
[i
].rangeLast
)
454 if (scriptRanges
[i
].numericScript
&& type
& C1_DIGIT
)
455 return scriptRanges
[i
].numericScript
;
456 if (scriptRanges
[i
].punctScript
&& type
& C1_PUNCT
)
457 return scriptRanges
[i
].punctScript
;
458 return scriptRanges
[i
].script
;
463 return SCRIPT_UNDEFINED
;
466 /***********************************************************************
470 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
474 case DLL_PROCESS_ATTACH
:
475 DisableThreadLibraryCalls(hInstDLL
);
477 case DLL_PROCESS_DETACH
:
483 /***********************************************************************
484 * ScriptFreeCache (USP10.@)
486 * Free a script cache.
489 * psc [I/O] Script cache.
493 * Failure: Non-zero HRESULT value.
495 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
502 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
504 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
505 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
507 heap_free(((ScriptCache
*)*psc
)->GSUB_Table
);
508 heap_free(((ScriptCache
*)*psc
)->features
);
515 /***********************************************************************
516 * ScriptGetProperties (USP10.@)
518 * Retrieve a list of script properties.
521 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
522 * num [I] Pointer to the number of scripts.
526 * Failure: Non-zero HRESULT value.
529 * Behaviour matches WinXP.
531 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
533 TRACE("(%p,%p)\n", props
, num
);
535 if (!props
&& !num
) return E_INVALIDARG
;
537 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
538 if (props
) *props
= script_props
;
543 /***********************************************************************
544 * ScriptGetFontProperties (USP10.@)
546 * Get information on special glyphs.
549 * hdc [I] Device context.
550 * psc [I/O] Opaque pointer to a script cache.
551 * sfp [O] Font properties structure.
553 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
557 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
559 if (!sfp
) return E_INVALIDARG
;
560 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
562 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
565 /* return something sensible? */
567 sfp
->wgDefault
= get_cache_default_char(psc
);
569 sfp
->wgKashida
= 0xffff;
570 sfp
->iKashidaWidth
= 0;
575 /***********************************************************************
576 * ScriptRecordDigitSubstitution (USP10.@)
578 * Record digit substitution settings for a given locale.
581 * locale [I] Locale identifier.
582 * sds [I] Structure to record substitution settings.
586 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
589 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
591 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
595 TRACE("0x%x, %p\n", locale
, sds
);
597 /* This implementation appears to be correct for all languages, but it's
598 * not clear if sds->DigitSubstitute is ever set to anything except
599 * CONTEXT or NONE in reality */
601 if (!sds
) return E_POINTER
;
603 locale
= ConvertDefaultLocale(locale
);
605 if (!IsValidLocale(locale
, LCID_INSTALLED
))
608 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
609 sds
->TraditionalDigitLanguage
= plgid
;
611 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
612 sds
->NationalDigitLanguage
= plgid
;
614 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
616 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
617 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
622 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
623 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
625 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
628 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
631 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
634 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
642 /***********************************************************************
643 * ScriptApplyDigitSubstitution (USP10.@)
645 * Apply digit substitution settings.
648 * sds [I] Structure with recorded substitution settings.
649 * sc [I] Script control structure.
650 * ss [I] Script state structure.
654 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
656 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
657 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
659 SCRIPT_DIGITSUBSTITUTE psds
;
661 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
663 if (!sc
|| !ss
) return E_POINTER
;
667 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
671 sc
->uDefaultLanguage
= LANG_ENGLISH
;
672 sc
->fContextDigits
= 0;
673 ss
->fDigitSubstitute
= 0;
675 switch (sds
->DigitSubstitute
) {
676 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
677 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
678 case SCRIPT_DIGITSUBSTITUTE_NONE
:
679 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
686 /***********************************************************************
687 * ScriptItemizeOpenType (USP10.@)
689 * Split a Unicode string into shapeable parts.
692 * pwcInChars [I] String to split.
693 * cInChars [I] Number of characters in pwcInChars.
694 * cMaxItems [I] Maximum number of items to return.
695 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
696 * psState [I] Pointer to a SCRIPT_STATE structure.
697 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
698 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
699 * pcItems [O] Number of script items returned.
703 * Failure: Non-zero HRESULT value.
705 HRESULT WINAPI
ScriptItemizeOpenType(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
706 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
707 SCRIPT_ITEM
*pItems
, OPENTYPE_TAG
*pScriptTags
, int *pcItems
)
710 #define Numeric_space 0x0020
714 int cnt
= 0, index
= 0, str
= 0;
715 int New_Script
= SCRIPT_UNDEFINED
;
717 WORD
*strength
= NULL
;
720 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
721 psControl
, psState
, pItems
, pcItems
);
723 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
726 if (psState
&& psControl
)
729 levels
= heap_alloc_zero(cInChars
* sizeof(WORD
));
731 return E_OUTOFMEMORY
;
733 BIDI_DetermineLevels(pwcInChars
, cInChars
, psState
, psControl
, levels
);
734 baselevel
= levels
[0];
735 for (i
= 0; i
< cInChars
; i
++)
736 if (levels
[i
]!=levels
[0])
738 if (i
>= cInChars
&& !odd(baselevel
))
745 if (!psControl
->fMergeNeutralItems
)
747 strength
= heap_alloc_zero(cInChars
* sizeof(WORD
));
748 BIDI_GetStrengths(pwcInChars
, cInChars
, psControl
, strength
);
753 while ((pwcInChars
[cnt
] == Numeric_space
|| pwcInChars
[cnt
] == ZWJ
|| pwcInChars
[cnt
] == ZWNJ
) && cnt
< cInChars
)
756 if (cnt
== cInChars
) /* All Spaces */
759 New_Script
= get_char_script(pwcInChars
[cnt
]);
762 pItems
[index
].iCharPos
= 0;
763 pItems
[index
].a
= scriptInformation
[get_char_script(pwcInChars
[cnt
])].a
;
764 pScriptTags
[index
] = scriptInformation
[get_char_script(pwcInChars
[cnt
])].scriptTag
;
772 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
773 pItems
[index
].a
.fLayoutRTL
= odd(levels
[cnt
]);
774 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
776 else if (!pItems
[index
].a
.s
.uBidiLevel
)
778 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
779 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
780 pItems
[index
].a
.fRTL
= odd(baselevel
);
783 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
784 levels
?levels
[cnt
]:-1, str
, New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
785 pItems
[index
].iCharPos
);
787 for (cnt
=1; cnt
< cInChars
; cnt
++)
789 if (levels
&& (levels
[cnt
] == pItems
[index
].a
.s
.uBidiLevel
&& (!strength
|| (strength
[cnt
] == 0 || strength
[cnt
] == str
))))
792 if(pwcInChars
[cnt
] != Numeric_space
&& pwcInChars
[cnt
] != ZWJ
&& pwcInChars
[cnt
] != ZWNJ
)
793 New_Script
= get_char_script(pwcInChars
[cnt
]);
797 while (cnt
+ j
< cInChars
- 1 && (pwcInChars
[cnt
+j
] == Numeric_space
|| pwcInChars
[cnt
+j
] == ZWJ
|| pwcInChars
[cnt
+j
] == ZWNJ
))
799 New_Script
= get_char_script(pwcInChars
[cnt
+j
]);
802 if ((levels
&& (levels
[cnt
] != pItems
[index
].a
.s
.uBidiLevel
|| (strength
&& (strength
[cnt
] != str
)))) || New_Script
!= pItems
[index
].a
.eScript
|| New_Script
== Script_Control
)
804 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
);
806 if (strength
&& strength
[cnt
] != 0)
810 if (index
+1 > cMaxItems
)
811 return E_OUTOFMEMORY
;
813 pItems
[index
].iCharPos
= cnt
;
814 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
816 pItems
[index
].a
= scriptInformation
[New_Script
].a
;
817 pScriptTags
[index
] = scriptInformation
[New_Script
].scriptTag
;
820 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
821 pItems
[index
].a
.fLayoutRTL
= odd(levels
[cnt
]);
822 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
824 else if (!pItems
[index
].a
.s
.uBidiLevel
)
826 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
827 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
828 pItems
[index
].a
.fRTL
= odd(baselevel
);
831 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
835 /* While not strictly necessary according to the spec, make sure the n+1
836 * item is set up to prevent random behaviour if the caller erroneously
837 * checks the n+1 structure */
839 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
841 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
843 /* Set one SCRIPT_STATE item being returned */
844 if (index
+ 1 > cMaxItems
) return E_OUTOFMEMORY
;
845 if (pcItems
) *pcItems
= index
;
847 /* Set SCRIPT_ITEM */
848 pItems
[index
].iCharPos
= cnt
; /* the last item contains the ptr to the lastchar */
854 /***********************************************************************
855 * ScriptItemize (USP10.@)
857 * Split a Unicode string into shapeable parts.
860 * pwcInChars [I] String to split.
861 * cInChars [I] Number of characters in pwcInChars.
862 * cMaxItems [I] Maximum number of items to return.
863 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
864 * psState [I] Pointer to a SCRIPT_STATE structure.
865 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
866 * pcItems [O] Number of script items returned.
870 * Failure: Non-zero HRESULT value.
872 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
873 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
874 SCRIPT_ITEM
*pItems
, int *pcItems
)
876 OPENTYPE_TAG
*discarded_tags
;
879 discarded_tags
= heap_alloc(cMaxItems
* sizeof(OPENTYPE_TAG
));
881 return E_OUTOFMEMORY
;
882 res
= ScriptItemizeOpenType(pwcInChars
, cInChars
, cMaxItems
, psControl
, psState
, pItems
, discarded_tags
, pcItems
);
883 heap_free(discarded_tags
);
887 /***********************************************************************
888 * ScriptStringAnalyse (USP10.@)
891 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
892 int cGlyphs
, int iCharset
, DWORD dwFlags
,
893 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
894 SCRIPT_STATE
*psState
, const int *piDx
,
895 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
896 SCRIPT_STRING_ANALYSIS
*pssa
)
898 HRESULT hr
= E_OUTOFMEMORY
;
899 StringAnalysis
*analysis
= NULL
;
900 int i
, num_items
= 255;
902 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
903 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
904 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
908 FIXME("Only Unicode strings are supported\n");
911 if (cString
< 1 || !pString
) return E_INVALIDARG
;
912 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
914 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
915 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
917 /* FIXME: handle clipping */
918 analysis
->clip_len
= cString
;
921 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
922 &analysis
->numItems
);
924 while (hr
== E_OUTOFMEMORY
)
929 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
932 analysis
->pItem
= tmp
;
933 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
934 &analysis
->numItems
);
936 if (hr
!= S_OK
) goto error
;
938 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
939 ScriptBreak(pString
, cString
, (SCRIPT_STRING_ANALYSIS
)analysis
, analysis
->logattrs
);
943 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
946 for (i
= 0; i
< analysis
->numItems
; i
++)
948 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->sc
;
949 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
950 int numGlyphs
= 1.5 * cChar
+ 16;
951 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
952 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
953 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
954 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * cChar
);
955 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
956 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
957 int numGlyphsReturned
;
959 /* FIXME: non unicode strings */
960 const WCHAR
* pStr
= (const WCHAR
*)pString
;
961 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
962 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
963 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
964 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
965 piAdvance
, pGoffset
, abc
);
967 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
968 analysis
->glyphs
[i
].glyphs
= glyphs
;
969 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
970 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
971 analysis
->glyphs
[i
].psva
= psva
;
972 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
973 analysis
->glyphs
[i
].abc
= abc
;
974 analysis
->glyphs
[i
].iMaxPosX
= -1;
981 heap_free(analysis
->glyphs
);
982 heap_free(analysis
->logattrs
);
983 heap_free(analysis
->pItem
);
984 heap_free(analysis
->sc
);
989 /***********************************************************************
990 * ScriptStringOut (USP10.@)
992 * This function takes the output of ScriptStringAnalyse and joins the segments
993 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
994 * only processes glyphs.
997 * ssa [I] buffer to hold the analysed string components
998 * iX [I] X axis displacement for output
999 * iY [I] Y axis displacement for output
1000 * uOptions [I] flags controling output processing
1001 * prc [I] rectangle coordinates
1002 * iMinSel [I] starting pos for substringing output string
1003 * iMaxSel [I] ending pos for substringing output string
1004 * fDisabled [I] controls text highlighting
1008 * Failure: is the value returned by ScriptTextOut
1010 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1019 StringAnalysis
*analysis
;
1024 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1025 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1027 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1030 * Get storage for the output buffer for the consolidated strings
1033 for (item
= 0; item
< analysis
->numItems
; item
++)
1035 cnt
+= analysis
->glyphs
[item
].numGlyphs
;
1037 if (!(glyphs
= heap_alloc(sizeof(WCHAR
) * cnt
))) return E_OUTOFMEMORY
;
1040 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
1042 uOptions
|= ETO_GLYPH_INDEX
;
1043 analysis
->pItem
[0].a
.fNoGlyphIndex
= FALSE
; /* say that we have glyphs */
1046 * Copy the string items into the output buffer
1049 TRACE("numItems %d\n", analysis
->numItems
);
1052 for (item
= 0; item
< analysis
->numItems
; item
++)
1054 memcpy(&glyphs
[cnt
], analysis
->glyphs
[item
].glyphs
,
1055 sizeof(WCHAR
) * analysis
->glyphs
[item
].numGlyphs
);
1057 TRACE("Item %d, Glyphs %d ", item
, analysis
->glyphs
[item
].numGlyphs
);
1058 for (x
= cnt
; x
< analysis
->glyphs
[item
].numGlyphs
+ cnt
; x
++)
1059 TRACE("%04x", glyphs
[x
]);
1062 cnt
+= analysis
->glyphs
[item
].numGlyphs
; /* point to the end of the copied text */
1065 hr
= ScriptTextOut(analysis
->hdc
, (SCRIPT_CACHE
*)&analysis
->sc
, iX
, iY
,
1066 uOptions
, prc
, &analysis
->pItem
->a
, NULL
, 0, glyphs
, cnt
,
1067 analysis
->glyphs
->piAdvance
, NULL
, analysis
->glyphs
->pGoffset
);
1068 TRACE("ScriptTextOut hr=%08x\n", hr
);
1071 * Free the output buffer and script cache
1077 /***********************************************************************
1078 * ScriptStringCPtoX (USP10.@)
1081 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1085 StringAnalysis
* analysis
= ssa
;
1087 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1089 if (!ssa
|| !pX
) return S_FALSE
;
1091 /* icp out of range */
1094 analysis
->invalid
= TRUE
;
1095 return E_INVALIDARG
;
1098 for(i
=0; i
<analysis
->numItems
; i
++)
1100 int CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1102 /* initialize max extents for uninitialized runs */
1103 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1105 if (analysis
->pItem
[i
].a
.fRTL
)
1106 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1107 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1108 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1110 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1111 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1112 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1117 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
1122 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1123 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1124 &analysis
->pItem
[i
].a
, &offset
);
1131 /* icp out of range */
1132 analysis
->invalid
= TRUE
;
1133 return E_INVALIDARG
;
1136 /***********************************************************************
1137 * ScriptStringXtoCP (USP10.@)
1140 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
1142 StringAnalysis
* analysis
= ssa
;
1146 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
1148 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
1153 if (analysis
->pItem
[0].a
.fRTL
)
1156 *piTrailing
= FALSE
;
1166 for(i
=0; i
<analysis
->numItems
; i
++)
1168 int CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1169 /* initialize max extents for uninitialized runs */
1170 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1172 if (analysis
->pItem
[i
].a
.fRTL
)
1173 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1174 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1175 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1177 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1178 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1179 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1182 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
1184 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
1189 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1190 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1191 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
1198 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
1199 *piTrailing
= FALSE
;
1205 /***********************************************************************
1206 * ScriptStringFree (USP10.@)
1208 * Free a string analysis.
1211 * pssa [I] string analysis.
1215 * Failure: Non-zero HRESULT value.
1217 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
1219 StringAnalysis
* analysis
;
1223 TRACE("(%p)\n", pssa
);
1225 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
1227 invalid
= analysis
->invalid
;
1228 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->sc
);
1230 for (i
= 0; i
< analysis
->numItems
; i
++)
1232 heap_free(analysis
->glyphs
[i
].glyphs
);
1233 heap_free(analysis
->glyphs
[i
].pwLogClust
);
1234 heap_free(analysis
->glyphs
[i
].piAdvance
);
1235 heap_free(analysis
->glyphs
[i
].psva
);
1236 heap_free(analysis
->glyphs
[i
].pGoffset
);
1237 heap_free(analysis
->glyphs
[i
].abc
);
1240 heap_free(analysis
->glyphs
);
1241 heap_free(analysis
->pItem
);
1242 heap_free(analysis
->logattrs
);
1243 heap_free(analysis
->sz
);
1244 heap_free(analysis
->sc
);
1245 heap_free(analysis
);
1247 if (invalid
) return E_INVALIDARG
;
1251 /***********************************************************************
1252 * ScriptCPtoX (USP10.@)
1255 HRESULT WINAPI
ScriptCPtoX(int iCP
,
1259 const WORD
*pwLogClust
,
1260 const SCRIPT_VISATTR
*psva
,
1261 const int *piAdvance
,
1262 const SCRIPT_ANALYSIS
*psa
,
1270 float special_size
= 0.0;
1274 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
1275 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
1278 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
1286 int max_clust
= pwLogClust
[0];
1288 for (item
=0; item
< cGlyphs
; item
++)
1289 if (pwLogClust
[item
] > max_clust
)
1291 ERR("We do not handle non reversed clusters properly\n");
1296 for (item
= max_clust
; item
>=0; item
--)
1297 iMaxPos
+= piAdvance
[item
];
1301 for (item
=0; item
< iCP
&& item
< cGlyphs
; item
++)
1303 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
1306 int clust
= pwLogClust
[item
];
1311 for (check
= item
+1; check
< cGlyphs
; check
++)
1313 if (pwLogClust
[check
] == clust
)
1322 if (check
>= cGlyphs
&& !iMaxPos
)
1324 for (check
= clust
; check
< cGlyphs
; check
++)
1325 special_size
+= piAdvance
[check
];
1327 special_size
/= (cChars
- item
);
1328 iPosX
+= special_size
;
1331 iPosX
+= piAdvance
[clust
] / (float)clust_size
;
1333 else if (iSpecial
!= -1)
1334 iPosX
+= special_size
;
1335 else /* (iCluster != -1) */
1336 iPosX
+= piAdvance
[pwLogClust
[iCluster
]] / (float)clust_size
;
1341 iPosX
= iMaxPos
- iPosX
;
1347 TRACE("*piX=%d\n", *piX
);
1351 /***********************************************************************
1352 * ScriptXtoCP (USP10.@)
1355 HRESULT WINAPI
ScriptXtoCP(int iX
,
1358 const WORD
*pwLogClust
,
1359 const SCRIPT_VISATTR
*psva
,
1360 const int *piAdvance
,
1361 const SCRIPT_ANALYSIS
*psa
,
1371 float special_size
= 0.0;
1374 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1375 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
1376 psa
, piCP
, piTrailing
);
1378 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
1383 int max_clust
= pwLogClust
[0];
1392 for (item
=0; item
< cGlyphs
; item
++)
1393 if (pwLogClust
[item
] > max_clust
)
1395 ERR("We do not handle non reversed clusters properly\n");
1407 iPosX
= iLastPosX
= 0;
1412 for (; iPosX
<= iX
&& item
< cGlyphs
&& item
>= 0; item
+=direction
)
1415 if (iSpecial
== -1 &&
1418 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
1419 (direction
< 0 && iCluster
-clust_size
>= item
))
1425 int clust
= pwLogClust
[item
];
1430 for (check
= item
+direction
; check
< cGlyphs
&& check
>= 0; check
+=direction
)
1432 if (pwLogClust
[check
] == clust
)
1441 if (check
>= cGlyphs
&& direction
> 0)
1443 for (check
= clust
; check
< cGlyphs
; check
++)
1444 special_size
+= piAdvance
[check
];
1446 special_size
/= (cChars
- item
);
1447 iPosX
+= special_size
;
1450 iPosX
+= piAdvance
[clust
] / (float)clust_size
;
1452 else if (iSpecial
!= -1)
1453 iPosX
+= special_size
;
1454 else /* (iCluster != -1) */
1455 iPosX
+= piAdvance
[pwLogClust
[iCluster
]] / (float)clust_size
;
1462 if (item
< cGlyphs
&& ((iPosX
- iLastPosX
) / 2.0) + iX
> iPosX
)
1469 if (iX
== iLastPosX
)
1471 if (iX
>= iLastPosX
&& iX
<= iPosX
)
1474 if (iLastPosX
== iX
)
1476 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
1484 TRACE("*piCP=%d\n", *piCP
);
1485 TRACE("*piTrailing=%d\n", *piTrailing
);
1489 /***********************************************************************
1490 * ScriptBreak (USP10.@)
1492 * Retrieve line break information.
1495 * chars [I] Array of characters.
1496 * sa [I] String analysis.
1497 * la [I] Array of logical attribute structures.
1503 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
1507 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
1509 if (!la
) return S_FALSE
;
1511 for (i
= 0; i
< count
; i
++)
1513 memset(&la
[i
], 0, sizeof(SCRIPT_LOGATTR
));
1515 /* FIXME: set the other flags */
1516 la
[i
].fWhiteSpace
= (chars
[i
] == ' ');
1517 la
[i
].fCharStop
= 1;
1519 if (i
> 0 && la
[i
- 1].fWhiteSpace
)
1521 la
[i
].fSoftBreak
= 1;
1522 la
[i
].fWordStop
= 1;
1528 /***********************************************************************
1529 * ScriptIsComplex (USP10.@)
1531 * Determine if a string is complex.
1534 * chars [I] Array of characters to test.
1535 * len [I] Length in characters.
1543 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
1547 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
1549 for (i
= 0; i
< len
; i
++)
1553 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
1556 script
= get_char_script(chars
[i
]);
1557 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
1558 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
1564 /***********************************************************************
1565 * ScriptShapeOpenType (USP10.@)
1567 * Produce glyphs and visual attributes for a run.
1570 * hdc [I] Device context.
1571 * psc [I/O] Opaque pointer to a script cache.
1572 * psa [I/O] Script analysis.
1573 * tagScript [I] The OpenType tag for the Script
1574 * tagLangSys [I] The OpenType tag for the Language
1575 * rcRangeChars[I] Array of Character counts in each range
1576 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
1577 * cRanges [I] Count of ranges
1578 * pwcChars [I] Array of characters specifying the run.
1579 * cChars [I] Number of characters in pwcChars.
1580 * cMaxGlyphs [I] Length of pwOutGlyphs.
1581 * pwLogClust [O] Array of logical cluster info.
1582 * pCharProps [O] Array of character property values
1583 * pwOutGlyphs [O] Array of glyphs.
1584 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
1585 * pcGlyphs [O] Number of glyphs returned.
1589 * Failure: Non-zero HRESULT value.
1591 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
1592 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
1593 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
1594 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
1595 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
1596 int cMaxGlyphs
, WORD
*pwLogClust
,
1597 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
1598 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
1604 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
1606 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
1607 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
1608 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
1610 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
1611 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
1613 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
1614 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
1617 FIXME("Ranges not supported yet\n");
1619 rtl
= (!psa
->fLogicalOrder
&& psa
->fRTL
);
1622 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1623 if (!pwLogClust
) return E_FAIL
;
1625 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
1626 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
1628 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
1629 for (i
= 0; i
< cChars
; i
++)
1632 if (rtl
) idx
= cChars
- 1 - i
;
1633 /* FIXME: set to better values */
1634 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
1635 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
1636 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
1637 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
1638 pOutGlyphProps
[i
].sva
.fReserved
= 0;
1639 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
1641 /* FIXME: have the shaping engine set this */
1642 pCharProps
[i
].fCanGlyphAlone
= 0;
1644 pwLogClust
[i
] = idx
;
1647 if (!psa
->fNoGlyphIndex
)
1650 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
1652 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
1653 if (!rChars
) return E_OUTOFMEMORY
;
1654 for (i
= 0; i
< cChars
; i
++)
1658 if (rtl
) idx
= cChars
- 1 - i
;
1660 chInput
= mirror_char(pwcChars
[idx
]);
1662 chInput
= pwcChars
[idx
];
1663 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
1666 if (!hdc
) return E_PENDING
;
1667 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
) return S_FALSE
;
1668 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
1670 rChars
[i
] = chInput
;
1673 if (get_cache_pitch_family(psc
) & TMPF_TRUETYPE
)
1675 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
1676 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
1677 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
1683 TRACE("no glyph translation\n");
1684 for (i
= 0; i
< cChars
; i
++)
1687 /* No mirroring done here */
1688 if (rtl
) idx
= cChars
- 1 - i
;
1689 pwOutGlyphs
[i
] = pwcChars
[idx
];
1697 /***********************************************************************
1698 * ScriptShape (USP10.@)
1700 * Produce glyphs and visual attributes for a run.
1703 * hdc [I] Device context.
1704 * psc [I/O] Opaque pointer to a script cache.
1705 * pwcChars [I] Array of characters specifying the run.
1706 * cChars [I] Number of characters in pwcChars.
1707 * cMaxGlyphs [I] Length of pwOutGlyphs.
1708 * psa [I/O] Script analysis.
1709 * pwOutGlyphs [O] Array of glyphs.
1710 * pwLogClust [O] Array of logical cluster info.
1711 * psva [O] Array of visual attributes.
1712 * pcGlyphs [O] Number of glyphs returned.
1716 * Failure: Non-zero HRESULT value.
1718 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
1719 int cChars
, int cMaxGlyphs
,
1720 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
1721 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
1725 SCRIPT_CHARPROP
*charProps
;
1726 SCRIPT_GLYPHPROP
*glyphProps
;
1728 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
1729 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
1731 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
1732 if (!charProps
) return E_OUTOFMEMORY
;
1733 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
1734 if (!glyphProps
) return E_OUTOFMEMORY
;
1736 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
1740 for (i
= 0; i
< *pcGlyphs
; i
++)
1741 psva
[i
] = glyphProps
[i
].sva
;
1744 heap_free(charProps
);
1745 heap_free(glyphProps
);
1750 /***********************************************************************
1751 * ScriptPlaceOpenType (USP10.@)
1753 * Produce advance widths for a run.
1756 * hdc [I] Device context.
1757 * psc [I/O] Opaque pointer to a script cache.
1758 * psa [I/O] String analysis.
1759 * tagScript [I] The OpenType tag for the Script
1760 * tagLangSys [I] The OpenType tag for the Language
1761 * rcRangeChars[I] Array of Character counts in each range
1762 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
1763 * cRanges [I] Count of ranges
1764 * pwcChars [I] Array of characters specifying the run.
1765 * pwLogClust [I] Array of logical cluster info
1766 * pCharProps [I] Array of character property values
1767 * cChars [I] Number of characters in pwcChars.
1768 * pwGlyphs [I] Array of glyphs.
1769 * pGlyphProps [I] Array of attributes for the retrieved glyphs
1770 * cGlyphs [I] Count of Glyphs
1771 * piAdvance [O] Array of advance widths.
1772 * pGoffset [O] Glyph offsets.
1773 * pABC [O] Combined ABC width.
1777 * Failure: Non-zero HRESULT value.
1780 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
1781 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
1782 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
1783 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
1784 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
1785 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
1786 int cGlyphs
, int *piAdvance
,
1787 GOFFSET
*pGoffset
, ABC
*pABC
1793 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
1795 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
1796 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
1797 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
1800 if (!pGlyphProps
) return E_INVALIDARG
;
1801 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1802 if (!pGoffset
) return E_FAIL
;
1805 FIXME("Ranges not supported yet\n");
1807 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
1808 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
1810 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
1811 for (i
= 0; i
< cGlyphs
; i
++)
1814 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
1816 if (!hdc
) return E_PENDING
;
1817 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
1819 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
1824 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
1826 abc
.abcA
= abc
.abcC
= 0;
1828 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
1832 pABC
->abcA
+= abc
.abcA
;
1833 pABC
->abcB
+= abc
.abcB
;
1834 pABC
->abcC
+= abc
.abcC
;
1836 /* FIXME: set to more reasonable values */
1837 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
1838 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
1841 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
1845 /***********************************************************************
1846 * ScriptPlace (USP10.@)
1848 * Produce advance widths for a run.
1851 * hdc [I] Device context.
1852 * psc [I/O] Opaque pointer to a script cache.
1853 * pwGlyphs [I] Array of glyphs.
1854 * cGlyphs [I] Number of glyphs in pwGlyphs.
1855 * psva [I] Array of visual attributes.
1856 * psa [I/O] String analysis.
1857 * piAdvance [O] Array of advance widths.
1858 * pGoffset [O] Glyph offsets.
1859 * pABC [O] Combined ABC width.
1863 * Failure: Non-zero HRESULT value.
1865 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
1866 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
1867 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
1870 SCRIPT_GLYPHPROP
*glyphProps
;
1873 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
1874 piAdvance
, pGoffset
, pABC
);
1876 if (!psva
) return E_INVALIDARG
;
1877 if (!pGoffset
) return E_FAIL
;
1879 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
1880 if (!glyphProps
) return E_OUTOFMEMORY
;
1882 for (i
= 0; i
< cGlyphs
; i
++)
1883 glyphProps
[i
].sva
= psva
[i
];
1885 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
1887 heap_free(glyphProps
);
1892 /***********************************************************************
1893 * ScriptGetCMap (USP10.@)
1895 * Retrieve glyph indices.
1898 * hdc [I] Device context.
1899 * psc [I/O] Opaque pointer to a script cache.
1900 * pwcInChars [I] Array of Unicode characters.
1901 * cChars [I] Number of characters in pwcInChars.
1902 * dwFlags [I] Flags.
1903 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1907 * Failure: Non-zero HRESULT value.
1909 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
1910 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
1915 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
1916 cChars
, dwFlags
, pwOutGlyphs
);
1918 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
1922 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
1924 for (i
= 0; i
< cChars
; i
++)
1927 if (dwFlags
== SGCM_RTL
)
1928 inChar
= mirror_char(pwcInChars
[i
]);
1930 inChar
= pwcInChars
[i
];
1931 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
1934 if (!hdc
) return E_PENDING
;
1935 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
1936 if (glyph
== 0xffff)
1941 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
1947 TRACE("no glyph translation\n");
1948 for (i
= 0; i
< cChars
; i
++)
1951 if (dwFlags
== SGCM_RTL
)
1952 inChar
= mirror_char(pwcInChars
[i
]);
1954 inChar
= pwcInChars
[i
];
1955 pwOutGlyphs
[i
] = inChar
;
1961 /***********************************************************************
1962 * ScriptTextOut (USP10.@)
1965 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
1966 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
1967 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
1968 const int *piJustify
, const GOFFSET
*pGoffset
)
1972 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1973 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
1974 piAdvance
, piJustify
, pGoffset
);
1976 if (!hdc
|| !psc
) return E_INVALIDARG
;
1977 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
1979 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
1980 fuOptions
|= ETO_IGNORELANGUAGE
;
1981 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
1982 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
1984 if (psa
->fRTL
&& psa
->fLogicalOrder
)
1989 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
1991 return E_OUTOFMEMORY
;
1993 for (i
= 0; i
< cGlyphs
; i
++)
1994 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
1996 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
1998 heap_free(rtlGlyphs
);
2001 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
2007 /***********************************************************************
2008 * ScriptCacheGetHeight (USP10.@)
2010 * Retrieve the height of the font in the cache.
2013 * hdc [I] Device context.
2014 * psc [I/O] Opaque pointer to a script cache.
2015 * height [O] Receives font height.
2019 * Failure: Non-zero HRESULT value.
2021 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
2025 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
2027 if (!height
) return E_INVALIDARG
;
2028 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2030 *height
= get_cache_height(psc
);
2034 /***********************************************************************
2035 * ScriptGetGlyphABCWidth (USP10.@)
2037 * Retrieve the width of a glyph.
2040 * hdc [I] Device context.
2041 * psc [I/O] Opaque pointer to a script cache.
2042 * glyph [I] Glyph to retrieve the width for.
2043 * abc [O] ABC widths of the glyph.
2047 * Failure: Non-zero HRESULT value.
2049 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
2053 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
2055 if (!abc
) return E_INVALIDARG
;
2056 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2058 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
2060 if (!hdc
) return E_PENDING
;
2061 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2063 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
2068 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
2070 abc
->abcA
= abc
->abcC
= 0;
2072 set_cache_glyph_widths(psc
, glyph
, abc
);
2077 /***********************************************************************
2078 * ScriptLayout (USP10.@)
2080 * Map embedding levels to visual and/or logical order.
2083 * runs [I] Size of level array.
2084 * level [I] Array of embedding levels.
2085 * vistolog [O] Map of embedding levels from visual to logical order.
2086 * logtovis [O] Map of embedding levels from logical to visual order.
2090 * Failure: Non-zero HRESULT value.
2093 * This stub works correctly for any sequence of a single
2094 * embedding level but not for sequences of different
2095 * embedding levels, i.e. mixtures of RTL and LTR scripts.
2097 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
2102 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
2104 if (!level
|| (!vistolog
&& !logtovis
))
2105 return E_INVALIDARG
;
2107 indexs
= heap_alloc(sizeof(int) * runs
);
2109 return E_OUTOFMEMORY
;
2114 for( ich
= 0; ich
< runs
; ich
++)
2119 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2120 for (ich
= 0; ich
< runs
; ich
++)
2121 vistolog
[ich
] = indexs
[ich
];
2127 for( ich
= 0; ich
< runs
; ich
++)
2132 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2133 for (ich
= 0; ich
< runs
; ich
++)
2134 logtovis
[ich
] = indexs
[ich
];
2141 /***********************************************************************
2142 * ScriptStringGetLogicalWidths (USP10.@)
2144 * Returns logical widths from a string analysis.
2147 * ssa [I] string analysis.
2148 * piDx [O] logical widths returned.
2152 * Failure: a non-zero HRESULT.
2154 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
2157 StringAnalysis
*analysis
= ssa
;
2159 TRACE("%p, %p\n", ssa
, piDx
);
2161 if (!analysis
) return S_FALSE
;
2163 for (i
= 0; i
< analysis
->numItems
; i
++)
2165 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
2167 piDx
[next
] = analysis
->glyphs
[i
].piAdvance
[j
];
2174 /***********************************************************************
2175 * ScriptStringValidate (USP10.@)
2177 * Validate a string analysis.
2180 * ssa [I] string analysis.
2184 * Failure: S_FALSE if invalid sequences are found
2185 * or a non-zero HRESULT if it fails.
2187 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
2189 StringAnalysis
*analysis
= ssa
;
2191 TRACE("(%p)\n", ssa
);
2193 if (!analysis
) return E_INVALIDARG
;
2194 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
2197 /***********************************************************************
2198 * ScriptString_pSize (USP10.@)
2200 * Retrieve width and height of an analysed string.
2203 * ssa [I] string analysis.
2206 * Success: Pointer to a SIZE structure.
2209 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
2212 StringAnalysis
*analysis
= ssa
;
2214 TRACE("(%p)\n", ssa
);
2216 if (!analysis
) return NULL
;
2220 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
2221 analysis
->sz
->cy
= analysis
->sc
->tm
.tmHeight
;
2223 analysis
->sz
->cx
= 0;
2224 for (i
= 0; i
< analysis
->numItems
; i
++)
2225 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
2226 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
2228 return analysis
->sz
;
2231 /***********************************************************************
2232 * ScriptString_pLogAttr (USP10.@)
2234 * Retrieve logical attributes of an analysed string.
2237 * ssa [I] string analysis.
2240 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
2243 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
2245 StringAnalysis
*analysis
= ssa
;
2247 TRACE("(%p)\n", ssa
);
2249 if (!analysis
) return NULL
;
2250 return analysis
->logattrs
;
2253 /***********************************************************************
2254 * ScriptString_pcOutChars (USP10.@)
2256 * Retrieve the length of a string after clipping.
2259 * ssa [I] String analysis.
2262 * Success: Pointer to the length.
2265 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
2267 StringAnalysis
*analysis
= ssa
;
2269 TRACE("(%p)\n", ssa
);
2271 if (!analysis
) return NULL
;
2272 return &analysis
->clip_len
;
2275 /***********************************************************************
2276 * ScriptStringGetOrder (USP10.@)
2278 * Retrieve a glyph order map.
2281 * ssa [I] String analysis.
2282 * order [I/O] Array of glyph positions.
2286 * Failure: a non-zero HRESULT.
2288 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
2292 StringAnalysis
*analysis
= ssa
;
2294 TRACE("(%p)\n", ssa
);
2296 if (!analysis
) return S_FALSE
;
2298 /* FIXME: handle RTL scripts */
2299 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
2300 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
2306 /***********************************************************************
2307 * ScriptGetLogicalWidths (USP10.@)
2309 * Convert advance widths to logical widths.
2312 * sa [I] Script analysis.
2313 * nbchars [I] Number of characters.
2314 * nbglyphs [I] Number of glyphs.
2315 * glyph_width [I] Array of glyph widths.
2316 * log_clust [I] Array of logical clusters.
2317 * sva [I] Visual attributes.
2318 * widths [O] Array of logical widths.
2322 * Failure: a non-zero HRESULT.
2324 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
2325 const int *glyph_width
, const WORD
*log_clust
,
2326 const SCRIPT_VISATTR
*sva
, int *widths
)
2330 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
2331 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
2334 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
2338 /***********************************************************************
2339 * ScriptApplyLogicalWidth (USP10.@)
2341 * Generate glyph advance widths.
2344 * dx [I] Array of logical advance widths.
2345 * num_chars [I] Number of characters.
2346 * num_glyphs [I] Number of glyphs.
2347 * log_clust [I] Array of logical clusters.
2348 * sva [I] Visual attributes.
2349 * advance [I] Array of glyph advance widths.
2350 * sa [I] Script analysis.
2351 * abc [I/O] Summed ABC widths.
2352 * justify [O] Array of glyph advance widths.
2356 * Failure: a non-zero HRESULT.
2358 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
2359 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
2360 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
2361 ABC
*abc
, int *justify
)
2365 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
2366 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
2368 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
2372 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
2373 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
2377 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
2379 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];