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
24 #include "dwrite_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
32 Script_C1Controls = 12,
38 Script_Unknown = (UINT16)-1
47 static const struct script_range script_ranges[] = {
48 /* C0 Controls: U+0000–U+001F */
49 /* ASCII punctuation and symbols: U+0020–U+002F */
50 /* ASCII digits: U+0030–U+0039 */
51 /* ASCII punctuation and symbols: U+003A–U+0040 */
52 { Script_Symbol, 0x00, 0x040 },
53 /* Latin uppercase: U+0041–U+005A */
54 { Script_Latin, 0x41, 0x5a },
55 /* ASCII punctuation and symbols: U+005B–U+0060 */
56 { Script_Symbol, 0x5b, 0x060 },
57 /* Latin lowercase: U+0061–U+007A */
58 { Script_Latin, 0x61, 0x7a },
59 /* ASCII punctuation and symbols, control char DEL: U+007B–U+007F */
60 { Script_Symbol, 0x7b, 0x7f },
61 /* C1 Controls: U+0080–U+009F */
62 { Script_C1Controls, 0x80, 0x9f },
63 /* Latin-1 Supplement: U+00A0–U+00FF */
64 /* Latin Extended-A: U+0100–U+017F */
65 /* Latin Extended-B: U+0180–U+024F */
66 /* IPA Extensions: U+0250–U+02AF */
67 /* Spacing Modifier Letters: U+02B0–U+02FF */
68 { Script_Latin, 0xa0, 0x2ff },
69 /* Combining Diacritical Marks: U+0300–U+036F */
70 { Script_Symbol, 0x300, 0x36f },
71 /* Greek: U+0370–U+03E1 */
72 { Script_Greek, 0x370, 0x3e1 },
73 /* Coptic: U+03E2–U+03Ef */
74 { Script_Coptic, 0x3e2, 0x3ef },
75 /* Greek: U+03F0–U+03FF */
76 { Script_Greek, 0x3f0, 0x3ff },
77 /* Cyrillic: U+0400–U+04FF */
78 /* Cyrillic Supplement: U+0500–U+052F */
79 /* Cyrillic Supplement range is incomplete cause it's based on Unicode 5.2
80 that doesn't define some Abkhaz and Azerbaijani letters, we support Unicode 6.0 range here */
81 { Script_Cyrillic, 0x400, 0x52f },
82 /* Arabic: U+0600–U+06FF */
83 { Script_Arabic, 0x600, 0x6ef },
84 /* unsupported range */
88 static UINT16 get_char_script( WCHAR c )
93 for (i = 0; i < sizeof(script_ranges)/sizeof(struct script_range); i++)
95 const struct script_range *range = &script_ranges[i];
96 if (range->script == Script_Unknown || (range->first <= ch && range->last >= ch))
100 return Script_Unknown;
103 static HRESULT analyze_script(const WCHAR *text, UINT32 len, IDWriteTextAnalysisSink *sink)
105 DWRITE_SCRIPT_ANALYSIS sa;
106 UINT32 pos, i, length;
108 if (!len) return S_OK;
110 sa.script = get_char_script(*text);
111 sa.shapes = DWRITE_SCRIPT_SHAPES_DEFAULT;
116 for (i = 1; i < len; i++)
118 UINT16 script = get_char_script(text[i]);
120 /* Script_Latin_Symb script type is ignored when preceded or followed by another script */
121 if (sa.script == Script_Symbol) sa.script = script;
122 if (script == Script_Symbol) script = sa.script;
123 /* this is a length of a sequence to be reported next */
124 if (sa.script == script) length++;
126 if (sa.script != script)
128 HRESULT hr = IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, length, &sa);
129 if (FAILED(hr)) return hr;
136 /* 1 length case or normal completion call */
137 return IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, length, &sa);
140 static HRESULT WINAPI dwritetextanalyzer_QueryInterface(IDWriteTextAnalyzer *iface, REFIID riid, void **obj)
142 TRACE("(%s %p)\n", debugstr_guid(riid), obj);
144 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteTextAnalyzer))
151 return E_NOINTERFACE;
155 static ULONG WINAPI dwritetextanalyzer_AddRef(IDWriteTextAnalyzer *iface)
160 static ULONG WINAPI dwritetextanalyzer_Release(IDWriteTextAnalyzer *iface)
165 static HRESULT WINAPI dwritetextanalyzer_AnalyzeScript(IDWriteTextAnalyzer *iface,
166 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
172 TRACE("(%p %u %u %p)\n", source, position, length, sink);
174 hr = IDWriteTextAnalysisSource_GetTextAtPosition(source, position, &text, &len);
175 if (FAILED(hr)) return hr;
177 return analyze_script(text, len, sink);
180 static HRESULT WINAPI dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer *iface,
181 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
183 FIXME("(%p %u %u %p): stub\n", source, position, length, sink);
187 static HRESULT WINAPI dwritetextanalyzer_AnalyzeNumberSubstitution(IDWriteTextAnalyzer *iface,
188 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
190 FIXME("(%p %u %u %p): stub\n", source, position, length, sink);
194 static HRESULT WINAPI dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnalyzer *iface,
195 IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
197 FIXME("(%p %u %u %p): stub\n", source, position, length, sink);
201 static HRESULT WINAPI dwritetextanalyzer_GetGlyphs(IDWriteTextAnalyzer *iface,
202 WCHAR const* text, UINT32 length, IDWriteFontFace* font_face, BOOL is_sideways,
203 BOOL is_rtl, DWRITE_SCRIPT_ANALYSIS const* analysis, WCHAR const* locale,
204 IDWriteNumberSubstitution* substitution, DWRITE_TYPOGRAPHIC_FEATURES const** features,
205 UINT32 const* feature_range_len, UINT32 feature_ranges, UINT32 max_glyph_count,
206 UINT16* clustermap, DWRITE_SHAPING_TEXT_PROPERTIES* text_props, UINT16* glyph_indices,
207 DWRITE_SHAPING_GLYPH_PROPERTIES* glyph_props, UINT32* actual_glyph_count)
209 FIXME("(%s:%u %p %d %d %p %s %p %p %p %u %u %p %p %p %p %p): stub\n", debugstr_wn(text, length),
210 length, font_face, is_sideways, is_rtl, analysis, debugstr_w(locale), substitution, features, feature_range_len,
211 feature_ranges, max_glyph_count, clustermap, text_props, glyph_indices, glyph_props, actual_glyph_count);
215 static HRESULT WINAPI dwritetextanalyzer_GetGlyphPlacements(IDWriteTextAnalyzer *iface,
216 WCHAR const* text, UINT16 const* clustermap, DWRITE_SHAPING_TEXT_PROPERTIES* props,
217 UINT32 text_len, UINT16 const* glyph_indices, DWRITE_SHAPING_GLYPH_PROPERTIES const* glyph_props,
218 UINT32 glyph_count, IDWriteFontFace * font_face, FLOAT fontEmSize, BOOL is_sideways, BOOL is_rtl,
219 DWRITE_SCRIPT_ANALYSIS const* analysis, WCHAR const* locale, DWRITE_TYPOGRAPHIC_FEATURES const** features,
220 UINT32 const* feature_range_len, UINT32 feature_ranges, FLOAT* glyph_advances, DWRITE_GLYPH_OFFSET* glyph_offsets)
222 FIXME("(%s %p %p %u %p %p %u %p %f %d %d %p %s %p %p %u %p %p): stub\n", debugstr_w(text),
223 clustermap, props, text_len, glyph_indices, glyph_props, glyph_count, font_face, fontEmSize, is_sideways,
224 is_rtl, analysis, debugstr_w(locale), features, feature_range_len, feature_ranges, glyph_advances, glyph_offsets);
228 static HRESULT WINAPI dwritetextanalyzer_GetGdiCompatibleGlyphPlacements(IDWriteTextAnalyzer *iface,
229 WCHAR const* text, UINT16 const* clustermap, DWRITE_SHAPING_TEXT_PROPERTIES* props,
230 UINT32 text_len, UINT16 const* glyph_indices, DWRITE_SHAPING_GLYPH_PROPERTIES const* glyph_props,
231 UINT32 glyph_count, IDWriteFontFace * font_face, FLOAT fontEmSize, FLOAT pixels_per_dip,
232 DWRITE_MATRIX const* transform, BOOL use_gdi_natural, BOOL is_sideways, BOOL is_rtl,
233 DWRITE_SCRIPT_ANALYSIS const* analysis, WCHAR const* locale, DWRITE_TYPOGRAPHIC_FEATURES const** features,
234 UINT32 const* feature_range_lengths, UINT32 feature_ranges, FLOAT* glyph_advances, DWRITE_GLYPH_OFFSET* glyph_offsets)
236 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),
237 clustermap, props, text_len, glyph_indices, glyph_props, glyph_count, font_face, fontEmSize, pixels_per_dip,
238 transform, use_gdi_natural, is_sideways, is_rtl, analysis, debugstr_w(locale), features, feature_range_lengths,
239 feature_ranges, glyph_advances, glyph_offsets);
243 static const struct IDWriteTextAnalyzerVtbl textanalyzervtbl = {
244 dwritetextanalyzer_QueryInterface,
245 dwritetextanalyzer_AddRef,
246 dwritetextanalyzer_Release,
247 dwritetextanalyzer_AnalyzeScript,
248 dwritetextanalyzer_AnalyzeBidi,
249 dwritetextanalyzer_AnalyzeNumberSubstitution,
250 dwritetextanalyzer_AnalyzeLineBreakpoints,
251 dwritetextanalyzer_GetGlyphs,
252 dwritetextanalyzer_GetGlyphPlacements,
253 dwritetextanalyzer_GetGdiCompatibleGlyphPlacements
256 static IDWriteTextAnalyzer textanalyzer = { &textanalyzervtbl };
258 HRESULT get_textanalyzer(IDWriteTextAnalyzer **ret)
260 *ret = &textanalyzer;