kernel32: Do not omit mandatory argument to DeviceIoControl.
[wine.git] / dlls / dwrite / analyzer.c
blob2b7056eb26dc5d980cd7860ab05e6da61de87930
1 /*
2 * Text analyzer
4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include "dwrite.h"
24 #include "dwrite_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
30 enum scriptcode {
31 Script_Arabic = 0,
32 Script_Armenian = 1,
33 Script_Balinese = 2,
34 Script_Bengali = 3,
35 Script_Buginese = 6,
36 Script_Canadian = 8,
37 Script_Cherokee = 11,
38 Script_Controls = 12,
39 Script_Coptic = 13,
40 Script_Cyrillic = 16,
41 Script_Devanagari = 18,
42 Script_Ethiopic = 19,
43 Script_Georgian = 20,
44 Script_Glagolitic = 22,
45 Script_Greek = 23,
46 Script_Gujarati = 24,
47 Script_Gurmukhi = 25,
48 Script_Hangul = 27,
49 Script_Hebrew = 29,
50 Script_Kannada = 32,
51 Script_Khmer = 36,
52 Script_Lao = 37,
53 Script_Latin = 38,
54 Script_Lepcha = 39,
55 Script_Limbu = 40,
56 Script_Malayalam = 44,
57 Script_Mongolian = 45,
58 Script_Myanmar = 46,
59 Script_New_TaiLue = 47,
60 Script_NKo = 48,
61 Script_Ogham = 49,
62 Script_OlChiki = 50,
63 Script_Oriya = 53,
64 Script_Runic = 58,
65 Script_Sinhala = 61,
66 Script_Sundanese = 62,
67 Script_Syriac = 64,
68 Script_TaiLe = 67,
69 Script_Tamil = 68,
70 Script_Telugu = 69,
71 Script_Thaana = 70,
72 Script_Thai = 71,
73 Script_Tibetan = 72,
74 Script_Tifinagh = 73,
75 Script_Symbol = 77,
76 Script_Unknown = (UINT16)-1
79 struct script_range {
80 UINT16 script;
81 DWORD first;
82 DWORD last;
85 static const struct script_range script_ranges[] = {
86 /* C0 Controls: U+0000–U+001F */
87 /* ASCII punctuation and symbols: U+0020–U+002F */
88 /* ASCII digits: U+0030–U+0039 */
89 /* ASCII punctuation and symbols: U+003A–U+0040 */
90 { Script_Symbol, 0x00, 0x040 },
91 /* Latin uppercase: U+0041–U+005A */
92 { Script_Latin, 0x41, 0x5a },
93 /* ASCII punctuation and symbols: U+005B–U+0060 */
94 { Script_Symbol, 0x5b, 0x060 },
95 /* Latin lowercase: U+0061–U+007A */
96 { Script_Latin, 0x61, 0x7a },
97 /* ASCII punctuation and symbols, control char DEL: U+007B–U+007F */
98 { Script_Symbol, 0x7b, 0x7f },
99 /* C1 Controls: U+0080–U+009F */
100 { Script_Controls, 0x80, 0x9f },
101 /* Latin-1 Supplement: U+00A0–U+00FF */
102 /* Latin Extended-A: U+0100–U+017F */
103 /* Latin Extended-B: U+0180–U+024F */
104 /* IPA Extensions: U+0250–U+02AF */
105 /* Spacing Modifier Letters: U+02B0–U+02FF */
106 { Script_Latin, 0xa0, 0x2ff },
107 /* Combining Diacritical Marks: U+0300–U+036F */
108 { Script_Symbol, 0x300, 0x36f },
109 /* Greek: U+0370–U+03E1 */
110 { Script_Greek, 0x370, 0x3e1 },
111 /* Coptic: U+03E2–U+03Ef */
112 { Script_Coptic, 0x3e2, 0x3ef },
113 /* Greek: U+03F0–U+03FF */
114 { Script_Greek, 0x3f0, 0x3ff },
115 /* Cyrillic: U+0400–U+04FF */
116 /* Cyrillic Supplement: U+0500–U+052F */
117 /* Cyrillic Supplement range is incomplete cause it's based on Unicode 5.2
118 that doesn't define some Abkhaz and Azerbaijani letters, we support Unicode 6.0 range here */
119 { Script_Cyrillic, 0x400, 0x52f },
120 /* Armenian: U+0530–U+058F */
121 { Script_Armenian, 0x530, 0x58f },
122 /* Hebrew: U+0590–U+05FF */
123 { Script_Hebrew, 0x590, 0x5ff },
124 /* Arabic: U+0600–U+06FF */
125 { Script_Arabic, 0x600, 0x6ff },
126 /* Syriac: U+0600–U+06FF */
127 { Script_Syriac, 0x700, 0x74f },
128 /* Arabic Supplement: U+0750–U+077F */
129 { Script_Arabic, 0x750, 0x77f },
130 /* Thaana: U+0780–U+07BF */
131 { Script_Thaana, 0x780, 0x7bf },
132 /* N'Ko: U+07C0–U+07FF */
133 { Script_NKo, 0x7c0, 0x7ff },
134 /* Devanagari: U+0900–U+097F */
135 { Script_Devanagari, 0x900, 0x97f },
136 /* Bengali: U+0980–U+09FF */
137 { Script_Bengali, 0x980, 0x9ff },
138 /* Gurmukhi: U+0A00–U+0A7F */
139 { Script_Gurmukhi, 0xa00, 0xa7f },
140 /* Gujarati: U+0A80–U+0AFF */
141 { Script_Gujarati, 0xa80, 0xaff },
142 /* Oriya: U+0B00–U+0B7F */
143 { Script_Oriya, 0xb00, 0xb7f },
144 /* Tamil: U+0B80–U+0BFF */
145 { Script_Tamil, 0xb80, 0xbff },
146 /* Telugu: U+0C00–U+0C7F */
147 { Script_Telugu, 0xc00, 0xc7f },
148 /* Kannada: U+0C80–U+0CFF */
149 { Script_Kannada, 0xc80, 0xcff },
150 /* Malayalam: U+0D00–U+0D7F */
151 { Script_Malayalam, 0xd00, 0xd7f },
152 /* Sinhala: U+0D80–U+0DFF */
153 { Script_Sinhala, 0xd80, 0xdff },
154 /* Thai: U+0E00–U+0E7F */
155 { Script_Thai, 0xe00, 0xe7f },
156 /* Lao: U+0E80–U+0EFF */
157 { Script_Lao, 0xe80, 0xeff },
158 /* Tibetan: U+0F00–U+0FFF */
159 { Script_Tibetan, 0xf00, 0xfff },
160 /* Myanmar: U+1000–U+109F */
161 { Script_Myanmar, 0x1000, 0x109f },
162 /* Georgian: U+10A0–U+10FF */
163 { Script_Georgian, 0x10a0, 0x10ff },
164 /* Hangul Jamo: U+1100–U+11FF */
165 { Script_Hangul, 0x1100, 0x11ff },
166 /* Ethiopic: U+1200–U+137F */
167 /* Ethiopic Extensions: U+1380–U+139F */
168 { Script_Ethiopic, 0x1200, 0x139f },
169 /* Cherokee: U+13A0–U+13FF */
170 { Script_Cherokee, 0x13a0, 0x13ff },
171 /* Canadian Aboriginal Syllabics: U+1400–U+167F */
172 { Script_Canadian, 0x1400, 0x167f },
173 /* Ogham: U+1680–U+169F */
174 { Script_Ogham, 0x1680, 0x169f },
175 /* Runic: U+16A0–U+16F0 */
176 { Script_Runic, 0x16a0, 0x16f0 },
177 /* Khmer: U+1780–U+17FF */
178 { Script_Khmer, 0x1780, 0x17ff },
179 /* Mongolian: U+1800–U+18AF */
180 { Script_Mongolian, 0x1800, 0x18af },
181 /* Limbu: U+1900–U+194F */
182 { Script_Limbu, 0x1900, 0x194f },
183 /* Tai Le: U+1950–U+197F */
184 { Script_TaiLe, 0x1950, 0x197f },
185 /* New Tai Lue: U+1980–U+19DF */
186 { Script_New_TaiLue, 0x1980, 0x19df },
187 /* Khmer Symbols: U+19E0–U+19FF */
188 { Script_Khmer, 0x19e0, 0x19ff },
189 /* Buginese: U+1A00–U+1A1F */
190 { Script_Buginese, 0x1a00, 0x1a1f },
191 /* Tai Tham: U+1A20–U+1AAF */
192 { Script_Symbol, 0x1a20, 0x1aaf },
193 /* Balinese: U+1B00–U+1B7F */
194 { Script_Balinese, 0x1b00, 0x1b7f },
195 /* Sundanese: U+1B80–U+1BBF */
196 { Script_Sundanese, 0x1b80, 0x1bbf },
197 /* Batak: U+1BC0–U+1BFF */
198 { Script_Symbol, 0x1bc0, 0x1bff },
199 /* Lepcha: U+1C00–U+1C4F */
200 { Script_Lepcha, 0x1c00, 0x1c4f },
201 /* Ol Chiki: U+1C50–U+1C7F */
202 { Script_OlChiki, 0x1c50, 0x1c7f },
203 /* Sundanese Supplement: U+1CC0–U+1CCF */
204 { Script_Symbol, 0x1cc0, 0x1ccf },
205 /* Vedic Extensions: U+1CD0-U+1CFF */
206 { Script_Devanagari, 0x1cd0, 0x1cff },
207 /* Phonetic Extensions: U+1D00–U+1DBF */
208 { Script_Latin, 0x1d00, 0x1dbf },
209 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
210 { Script_Symbol, 0x1dc0, 0x1dff },
211 /* Latin Extended Additional: U+1E00–U+1EFF */
212 { Script_Latin, 0x1e00, 0x1eff },
213 /* Greek Extended: U+1F00–U+1F00 */
214 { Script_Greek, 0x1f00, 0x1fff },
215 /* General Punctuation: U+2000–U+206f */
216 /* Superscripts and Subscripts: U+2070–U+209f */
217 /* Currency Symbols: U+20A0–U+20CF */
218 /* Combining Diacritical Marks for Symbols: U+20D0–U+20FF */
219 /* Letterlike Symbols: U+2100–U+214F */
220 /* Number Forms: U+2150–U+218F */
221 /* Arrows: U+2190–U+21FF */
222 /* Mathematical Operators: U+2200–U+22FF */
223 /* Miscellaneous Technical: U+2300–U+23FF */
224 /* Control Pictures: U+2400–U+243F */
225 /* Optical Character Recognition: U+2440–U+245F */
226 /* Enclosed Alphanumerics: U+2460–U+24FF */
227 /* Box Drawing: U+2500–U+25FF */
228 /* Block Elements: U+2580–U+259F */
229 /* Geometric Shapes: U+25A0–U+25FF */
230 /* Miscellaneous Symbols: U+2600–U+26FF */
231 /* Dingbats: U+2700–U+27BF */
232 /* Miscellaneous Mathematical Symbols-A: U+27C0–U+27EF */
233 /* Supplemental Arrows-A: U+27F0–U+27FF */
234 /* Braille Patterns: U+2800–U+28FF */
235 /* Supplemental Arrows-B: U+2900–U+297F */
236 /* Miscellaneous Mathematical Symbols-B: U+2980–U+29FF */
237 /* Supplemental Mathematical Operators: U+2A00–U+2AFF */
238 /* Miscellaneous Symbols and Arrows: U+2B00–U+2BFF */
239 { Script_Symbol, 0x2000, 0x2bff },
240 /* Glagolitic: U+2C00–U+2C5F */
241 { Script_Glagolitic, 0x2c00, 0x2c5f },
242 /* Latin Extended-C: U+2C60–U+2C7F */
243 { Script_Latin, 0x2c60, 0x2c7f },
244 /* Coptic: U+2C80–U+2CFF */
245 { Script_Coptic, 0x2c80, 0x2cff },
246 /* Georgian Supplement: U+2D00–U+2D2F */
247 { Script_Georgian, 0x2d00, 0x2d2f },
248 /* Tifinagh: U+2D30–U+2D7F */
249 { Script_Tifinagh, 0x2d30, 0x2d7f },
250 /* unsupported range */
251 { Script_Unknown }
254 static UINT16 get_char_script( WCHAR c )
256 DWORD ch = c;
257 unsigned int i;
259 for (i = 0; i < sizeof(script_ranges)/sizeof(struct script_range); i++)
261 const struct script_range *range = &script_ranges[i];
262 if (range->script == Script_Unknown || (range->first <= ch && range->last >= ch))
263 return range->script;
266 return Script_Unknown;
269 static HRESULT analyze_script(const WCHAR *text, UINT32 len, IDWriteTextAnalysisSink *sink)
271 DWRITE_SCRIPT_ANALYSIS sa;
272 UINT32 pos, i, length;
274 if (!len) return S_OK;
276 sa.script = get_char_script(*text);
278 pos = 0;
279 length = 1;
281 for (i = 1; i < len; i++)
283 UINT16 script = get_char_script(text[i]);
285 /* Script_Latin_Symb script type is ignored when preceded or followed by another script */
286 if (sa.script == Script_Symbol) sa.script = script;
287 if (script == Script_Symbol) script = sa.script;
288 /* this is a length of a sequence to be reported next */
289 if (sa.script == script) length++;
291 if (sa.script != script)
293 HRESULT hr;
295 sa.shapes = sa.script != Script_Controls ? DWRITE_SCRIPT_SHAPES_DEFAULT : DWRITE_SCRIPT_SHAPES_NO_VISUAL;
296 hr = IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, length, &sa);
297 if (FAILED(hr)) return hr;
298 pos = i;
299 length = 1;
300 sa.script = script;
304 /* 1 length case or normal completion call */
305 sa.shapes = sa.script != Script_Controls ? DWRITE_SCRIPT_SHAPES_DEFAULT : DWRITE_SCRIPT_SHAPES_NO_VISUAL;
306 return IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, length, &sa);
309 static HRESULT WINAPI dwritetextanalyzer_QueryInterface(IDWriteTextAnalyzer *iface, REFIID riid, void **obj)
311 TRACE("(%s %p)\n", debugstr_guid(riid), obj);
313 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteTextAnalyzer))
315 *obj = iface;
316 return S_OK;
319 *obj = NULL;
320 return E_NOINTERFACE;
324 static ULONG WINAPI dwritetextanalyzer_AddRef(IDWriteTextAnalyzer *iface)
326 return 2;
329 static ULONG WINAPI dwritetextanalyzer_Release(IDWriteTextAnalyzer *iface)
331 return 1;
334 static HRESULT WINAPI dwritetextanalyzer_AnalyzeScript(IDWriteTextAnalyzer *iface,
335 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
337 const WCHAR *text;
338 HRESULT hr;
339 UINT32 len;
341 TRACE("(%p %u %u %p)\n", source, position, length, sink);
343 hr = IDWriteTextAnalysisSource_GetTextAtPosition(source, position, &text, &len);
344 if (FAILED(hr)) return hr;
346 return analyze_script(text, len, sink);
349 static HRESULT WINAPI dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer *iface,
350 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
352 FIXME("(%p %u %u %p): stub\n", source, position, length, sink);
353 return E_NOTIMPL;
356 static HRESULT WINAPI dwritetextanalyzer_AnalyzeNumberSubstitution(IDWriteTextAnalyzer *iface,
357 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
359 FIXME("(%p %u %u %p): stub\n", source, position, length, sink);
360 return E_NOTIMPL;
363 static HRESULT WINAPI dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnalyzer *iface,
364 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
366 FIXME("(%p %u %u %p): stub\n", source, position, length, sink);
367 return E_NOTIMPL;
370 static HRESULT WINAPI dwritetextanalyzer_GetGlyphs(IDWriteTextAnalyzer *iface,
371 WCHAR const* text, UINT32 length, IDWriteFontFace* font_face, BOOL is_sideways,
372 BOOL is_rtl, DWRITE_SCRIPT_ANALYSIS const* analysis, WCHAR const* locale,
373 IDWriteNumberSubstitution* substitution, DWRITE_TYPOGRAPHIC_FEATURES const** features,
374 UINT32 const* feature_range_len, UINT32 feature_ranges, UINT32 max_glyph_count,
375 UINT16* clustermap, DWRITE_SHAPING_TEXT_PROPERTIES* text_props, UINT16* glyph_indices,
376 DWRITE_SHAPING_GLYPH_PROPERTIES* glyph_props, UINT32* actual_glyph_count)
378 FIXME("(%s:%u %p %d %d %p %s %p %p %p %u %u %p %p %p %p %p): stub\n", debugstr_wn(text, length),
379 length, font_face, is_sideways, is_rtl, analysis, debugstr_w(locale), substitution, features, feature_range_len,
380 feature_ranges, max_glyph_count, clustermap, text_props, glyph_indices, glyph_props, actual_glyph_count);
381 return E_NOTIMPL;
384 static HRESULT WINAPI dwritetextanalyzer_GetGlyphPlacements(IDWriteTextAnalyzer *iface,
385 WCHAR const* text, UINT16 const* clustermap, DWRITE_SHAPING_TEXT_PROPERTIES* props,
386 UINT32 text_len, UINT16 const* glyph_indices, DWRITE_SHAPING_GLYPH_PROPERTIES const* glyph_props,
387 UINT32 glyph_count, IDWriteFontFace * font_face, FLOAT fontEmSize, BOOL is_sideways, BOOL is_rtl,
388 DWRITE_SCRIPT_ANALYSIS const* analysis, WCHAR const* locale, DWRITE_TYPOGRAPHIC_FEATURES const** features,
389 UINT32 const* feature_range_len, UINT32 feature_ranges, FLOAT* glyph_advances, DWRITE_GLYPH_OFFSET* glyph_offsets)
391 FIXME("(%s %p %p %u %p %p %u %p %f %d %d %p %s %p %p %u %p %p): stub\n", debugstr_w(text),
392 clustermap, props, text_len, glyph_indices, glyph_props, glyph_count, font_face, fontEmSize, is_sideways,
393 is_rtl, analysis, debugstr_w(locale), features, feature_range_len, feature_ranges, glyph_advances, glyph_offsets);
394 return E_NOTIMPL;
397 static HRESULT WINAPI dwritetextanalyzer_GetGdiCompatibleGlyphPlacements(IDWriteTextAnalyzer *iface,
398 WCHAR const* text, UINT16 const* clustermap, DWRITE_SHAPING_TEXT_PROPERTIES* props,
399 UINT32 text_len, UINT16 const* glyph_indices, DWRITE_SHAPING_GLYPH_PROPERTIES const* glyph_props,
400 UINT32 glyph_count, IDWriteFontFace * font_face, FLOAT fontEmSize, FLOAT pixels_per_dip,
401 DWRITE_MATRIX const* transform, BOOL use_gdi_natural, BOOL is_sideways, BOOL is_rtl,
402 DWRITE_SCRIPT_ANALYSIS const* analysis, WCHAR const* locale, DWRITE_TYPOGRAPHIC_FEATURES const** features,
403 UINT32 const* feature_range_lengths, UINT32 feature_ranges, FLOAT* glyph_advances, DWRITE_GLYPH_OFFSET* glyph_offsets)
405 FIXME("(%s %p %p %u %p %p %u %p %f %f %p %d %d %d %p %s %p %p %u %p %p): stub\n", debugstr_w(text),
406 clustermap, props, text_len, glyph_indices, glyph_props, glyph_count, font_face, fontEmSize, pixels_per_dip,
407 transform, use_gdi_natural, is_sideways, is_rtl, analysis, debugstr_w(locale), features, feature_range_lengths,
408 feature_ranges, glyph_advances, glyph_offsets);
409 return E_NOTIMPL;
412 static const struct IDWriteTextAnalyzerVtbl textanalyzervtbl = {
413 dwritetextanalyzer_QueryInterface,
414 dwritetextanalyzer_AddRef,
415 dwritetextanalyzer_Release,
416 dwritetextanalyzer_AnalyzeScript,
417 dwritetextanalyzer_AnalyzeBidi,
418 dwritetextanalyzer_AnalyzeNumberSubstitution,
419 dwritetextanalyzer_AnalyzeLineBreakpoints,
420 dwritetextanalyzer_GetGlyphs,
421 dwritetextanalyzer_GetGlyphPlacements,
422 dwritetextanalyzer_GetGdiCompatibleGlyphPlacements
425 static IDWriteTextAnalyzer textanalyzer = { &textanalyzervtbl };
427 HRESULT get_textanalyzer(IDWriteTextAnalyzer **ret)
429 *ret = &textanalyzer;
430 return S_OK;