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
);
41 Script_Devanagari
= 18,
55 Script_Malayalam
= 44,
56 Script_Mongolian
= 45,
58 Script_New_TaiLue
= 47,
65 Script_Sundanese
= 62,
74 Script_Unknown
= (UINT16
)-1
83 static const struct script_range script_ranges
[] = {
84 /* C0 Controls: U+0000–U+001F */
85 /* ASCII punctuation and symbols: U+0020–U+002F */
86 /* ASCII digits: U+0030–U+0039 */
87 /* ASCII punctuation and symbols: U+003A–U+0040 */
88 { Script_Symbol
, 0x00, 0x040 },
89 /* Latin uppercase: U+0041–U+005A */
90 { Script_Latin
, 0x41, 0x5a },
91 /* ASCII punctuation and symbols: U+005B–U+0060 */
92 { Script_Symbol
, 0x5b, 0x060 },
93 /* Latin lowercase: U+0061–U+007A */
94 { Script_Latin
, 0x61, 0x7a },
95 /* ASCII punctuation and symbols, control char DEL: U+007B–U+007F */
96 { Script_Symbol
, 0x7b, 0x7f },
97 /* C1 Controls: U+0080–U+009F */
98 { Script_Controls
, 0x80, 0x9f },
99 /* Latin-1 Supplement: U+00A0–U+00FF */
100 /* Latin Extended-A: U+0100–U+017F */
101 /* Latin Extended-B: U+0180–U+024F */
102 /* IPA Extensions: U+0250–U+02AF */
103 /* Spacing Modifier Letters: U+02B0–U+02FF */
104 { Script_Latin
, 0xa0, 0x2ff },
105 /* Combining Diacritical Marks: U+0300–U+036F */
106 { Script_Symbol
, 0x300, 0x36f },
107 /* Greek: U+0370–U+03E1 */
108 { Script_Greek
, 0x370, 0x3e1 },
109 /* Coptic: U+03E2–U+03Ef */
110 { Script_Coptic
, 0x3e2, 0x3ef },
111 /* Greek: U+03F0–U+03FF */
112 { Script_Greek
, 0x3f0, 0x3ff },
113 /* Cyrillic: U+0400–U+04FF */
114 /* Cyrillic Supplement: U+0500–U+052F */
115 /* Cyrillic Supplement range is incomplete cause it's based on Unicode 5.2
116 that doesn't define some Abkhaz and Azerbaijani letters, we support Unicode 6.0 range here */
117 { Script_Cyrillic
, 0x400, 0x52f },
118 /* Armenian: U+0530–U+058F */
119 { Script_Armenian
, 0x530, 0x58f },
120 /* Hebrew: U+0590–U+05FF */
121 { Script_Hebrew
, 0x590, 0x5ff },
122 /* Arabic: U+0600–U+06FF */
123 { Script_Arabic
, 0x600, 0x6ff },
124 /* Syriac: U+0600–U+06FF */
125 { Script_Syriac
, 0x700, 0x74f },
126 /* Arabic Supplement: U+0750–U+077F */
127 { Script_Arabic
, 0x750, 0x77f },
128 /* Thaana: U+0780–U+07BF */
129 { Script_Thaana
, 0x780, 0x7bf },
130 /* N'Ko: U+07C0–U+07FF */
131 { Script_NKo
, 0x7c0, 0x7ff },
132 /* Devanagari: U+0900–U+097F */
133 { Script_Devanagari
, 0x900, 0x97f },
134 /* Bengali: U+0980–U+09FF */
135 { Script_Bengali
, 0x980, 0x9ff },
136 /* Gurmukhi: U+0A00–U+0A7F */
137 { Script_Gurmukhi
, 0xa00, 0xa7f },
138 /* Gujarati: U+0A80–U+0AFF */
139 { Script_Gujarati
, 0xa80, 0xaff },
140 /* Oriya: U+0B00–U+0B7F */
141 { Script_Oriya
, 0xb00, 0xb7f },
142 /* Tamil: U+0B80–U+0BFF */
143 { Script_Tamil
, 0xb80, 0xbff },
144 /* Telugu: U+0C00–U+0C7F */
145 { Script_Telugu
, 0xc00, 0xc7f },
146 /* Kannada: U+0C80–U+0CFF */
147 { Script_Kannada
, 0xc80, 0xcff },
148 /* Malayalam: U+0D00–U+0D7F */
149 { Script_Malayalam
, 0xd00, 0xd7f },
150 /* Sinhala: U+0D80–U+0DFF */
151 { Script_Sinhala
, 0xd80, 0xdff },
152 /* Thai: U+0E00–U+0E7F */
153 { Script_Thai
, 0xe00, 0xe7f },
154 /* Lao: U+0E80–U+0EFF */
155 { Script_Lao
, 0xe80, 0xeff },
156 /* Tibetan: U+0F00–U+0FFF */
157 { Script_Tibetan
, 0xf00, 0xfff },
158 /* Myanmar: U+1000–U+109F */
159 { Script_Myanmar
, 0x1000, 0x109f },
160 /* Georgian: U+10A0–U+10FF */
161 { Script_Georgian
, 0x10a0, 0x10ff },
162 /* Hangul Jamo: U+1100–U+11FF */
163 { Script_Hangul
, 0x1100, 0x11ff },
164 /* Ethiopic: U+1200–U+137F */
165 /* Ethiopic Extensions: U+1380–U+139F */
166 { Script_Ethiopic
, 0x1200, 0x139f },
167 /* Cherokee: U+13A0–U+13FF */
168 { Script_Cherokee
, 0x13a0, 0x13ff },
169 /* Canadian Aboriginal Syllabics: U+1400–U+167F */
170 { Script_Canadian
, 0x1400, 0x167f },
171 /* Ogham: U+1680–U+169F */
172 { Script_Ogham
, 0x1680, 0x169f },
173 /* Runic: U+16A0–U+16F0 */
174 { Script_Runic
, 0x16a0, 0x16f0 },
175 /* Khmer: U+1780–U+17FF */
176 { Script_Khmer
, 0x1780, 0x17ff },
177 /* Mongolian: U+1800–U+18AF */
178 { Script_Mongolian
, 0x1800, 0x18af },
179 /* Limbu: U+1900–U+194F */
180 { Script_Limbu
, 0x1900, 0x194f },
181 /* Tai Le: U+1950–U+197F */
182 { Script_TaiLe
, 0x1950, 0x197f },
183 /* New Tai Lue: U+1980–U+19DF */
184 { Script_New_TaiLue
, 0x1980, 0x19df },
185 /* Khmer Symbols: U+19E0–U+19FF */
186 { Script_Khmer
, 0x19e0, 0x19ff },
187 /* Buginese: U+1A00–U+1A1F */
188 { Script_Buginese
, 0x1a00, 0x1a1f },
189 /* Tai Tham: U+1A20–U+1AAF */
190 { Script_Symbol
, 0x1a20, 0x1aaf },
191 /* Balinese: U+1B00–U+1B7F */
192 { Script_Balinese
, 0x1b00, 0x1b7f },
193 /* Sundanese: U+1B80–U+1BBF */
194 { Script_Sundanese
, 0x1b80, 0x1bbf },
195 /* Batak: U+1BC0–U+1BFF */
196 { Script_Symbol
, 0x1bc0, 0x1bff },
197 /* Lepcha: U+1C00–U+1C4F */
198 { Script_Lepcha
, 0x1c00, 0x1c4f },
199 /* Ol Chiki: U+1C50–U+1C7F */
200 { Script_OlChiki
, 0x1c50, 0x1c7f },
201 /* Sundanese Supplement: U+1CC0–U+1CCF */
202 { Script_Symbol
, 0x1cc0, 0x1ccf },
203 /* Vedic Extensions: U+1CD0-U+1CFF */
204 { Script_Devanagari
, 0x1cd0, 0x1cff },
205 /* Phonetic Extensions: U+1D00–U+1DBF */
206 { Script_Latin
, 0x1d00, 0x1dbf },
207 /* unsupported range */
211 static UINT16
get_char_script( WCHAR c
)
216 for (i
= 0; i
< sizeof(script_ranges
)/sizeof(struct script_range
); i
++)
218 const struct script_range
*range
= &script_ranges
[i
];
219 if (range
->script
== Script_Unknown
|| (range
->first
<= ch
&& range
->last
>= ch
))
220 return range
->script
;
223 return Script_Unknown
;
226 static HRESULT
analyze_script(const WCHAR
*text
, UINT32 len
, IDWriteTextAnalysisSink
*sink
)
228 DWRITE_SCRIPT_ANALYSIS sa
;
229 UINT32 pos
, i
, length
;
231 if (!len
) return S_OK
;
233 sa
.script
= get_char_script(*text
);
238 for (i
= 1; i
< len
; i
++)
240 UINT16 script
= get_char_script(text
[i
]);
242 /* Script_Latin_Symb script type is ignored when preceded or followed by another script */
243 if (sa
.script
== Script_Symbol
) sa
.script
= script
;
244 if (script
== Script_Symbol
) script
= sa
.script
;
245 /* this is a length of a sequence to be reported next */
246 if (sa
.script
== script
) length
++;
248 if (sa
.script
!= script
)
252 sa
.shapes
= sa
.script
!= Script_Controls
? DWRITE_SCRIPT_SHAPES_DEFAULT
: DWRITE_SCRIPT_SHAPES_NO_VISUAL
;
253 hr
= IDWriteTextAnalysisSink_SetScriptAnalysis(sink
, pos
, length
, &sa
);
254 if (FAILED(hr
)) return hr
;
261 /* 1 length case or normal completion call */
262 sa
.shapes
= sa
.script
!= Script_Controls
? DWRITE_SCRIPT_SHAPES_DEFAULT
: DWRITE_SCRIPT_SHAPES_NO_VISUAL
;
263 return IDWriteTextAnalysisSink_SetScriptAnalysis(sink
, pos
, length
, &sa
);
266 static HRESULT WINAPI
dwritetextanalyzer_QueryInterface(IDWriteTextAnalyzer
*iface
, REFIID riid
, void **obj
)
268 TRACE("(%s %p)\n", debugstr_guid(riid
), obj
);
270 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteTextAnalyzer
))
277 return E_NOINTERFACE
;
281 static ULONG WINAPI
dwritetextanalyzer_AddRef(IDWriteTextAnalyzer
*iface
)
286 static ULONG WINAPI
dwritetextanalyzer_Release(IDWriteTextAnalyzer
*iface
)
291 static HRESULT WINAPI
dwritetextanalyzer_AnalyzeScript(IDWriteTextAnalyzer
*iface
,
292 IDWriteTextAnalysisSource
* source
, UINT32 position
, UINT32 length
, IDWriteTextAnalysisSink
* sink
)
298 TRACE("(%p %u %u %p)\n", source
, position
, length
, sink
);
300 hr
= IDWriteTextAnalysisSource_GetTextAtPosition(source
, position
, &text
, &len
);
301 if (FAILED(hr
)) return hr
;
303 return analyze_script(text
, len
, sink
);
306 static HRESULT WINAPI
dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer
*iface
,
307 IDWriteTextAnalysisSource
* source
, UINT32 position
, UINT32 length
, IDWriteTextAnalysisSink
* sink
)
309 FIXME("(%p %u %u %p): stub\n", source
, position
, length
, sink
);
313 static HRESULT WINAPI
dwritetextanalyzer_AnalyzeNumberSubstitution(IDWriteTextAnalyzer
*iface
,
314 IDWriteTextAnalysisSource
* source
, UINT32 position
, UINT32 length
, IDWriteTextAnalysisSink
* sink
)
316 FIXME("(%p %u %u %p): stub\n", source
, position
, length
, sink
);
320 static HRESULT WINAPI
dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnalyzer
*iface
,
321 IDWriteTextAnalysisSource
* source
, UINT32 position
, UINT32 length
, IDWriteTextAnalysisSink
* sink
)
323 FIXME("(%p %u %u %p): stub\n", source
, position
, length
, sink
);
327 static HRESULT WINAPI
dwritetextanalyzer_GetGlyphs(IDWriteTextAnalyzer
*iface
,
328 WCHAR
const* text
, UINT32 length
, IDWriteFontFace
* font_face
, BOOL is_sideways
,
329 BOOL is_rtl
, DWRITE_SCRIPT_ANALYSIS
const* analysis
, WCHAR
const* locale
,
330 IDWriteNumberSubstitution
* substitution
, DWRITE_TYPOGRAPHIC_FEATURES
const** features
,
331 UINT32
const* feature_range_len
, UINT32 feature_ranges
, UINT32 max_glyph_count
,
332 UINT16
* clustermap
, DWRITE_SHAPING_TEXT_PROPERTIES
* text_props
, UINT16
* glyph_indices
,
333 DWRITE_SHAPING_GLYPH_PROPERTIES
* glyph_props
, UINT32
* actual_glyph_count
)
335 FIXME("(%s:%u %p %d %d %p %s %p %p %p %u %u %p %p %p %p %p): stub\n", debugstr_wn(text
, length
),
336 length
, font_face
, is_sideways
, is_rtl
, analysis
, debugstr_w(locale
), substitution
, features
, feature_range_len
,
337 feature_ranges
, max_glyph_count
, clustermap
, text_props
, glyph_indices
, glyph_props
, actual_glyph_count
);
341 static HRESULT WINAPI
dwritetextanalyzer_GetGlyphPlacements(IDWriteTextAnalyzer
*iface
,
342 WCHAR
const* text
, UINT16
const* clustermap
, DWRITE_SHAPING_TEXT_PROPERTIES
* props
,
343 UINT32 text_len
, UINT16
const* glyph_indices
, DWRITE_SHAPING_GLYPH_PROPERTIES
const* glyph_props
,
344 UINT32 glyph_count
, IDWriteFontFace
* font_face
, FLOAT fontEmSize
, BOOL is_sideways
, BOOL is_rtl
,
345 DWRITE_SCRIPT_ANALYSIS
const* analysis
, WCHAR
const* locale
, DWRITE_TYPOGRAPHIC_FEATURES
const** features
,
346 UINT32
const* feature_range_len
, UINT32 feature_ranges
, FLOAT
* glyph_advances
, DWRITE_GLYPH_OFFSET
* glyph_offsets
)
348 FIXME("(%s %p %p %u %p %p %u %p %f %d %d %p %s %p %p %u %p %p): stub\n", debugstr_w(text
),
349 clustermap
, props
, text_len
, glyph_indices
, glyph_props
, glyph_count
, font_face
, fontEmSize
, is_sideways
,
350 is_rtl
, analysis
, debugstr_w(locale
), features
, feature_range_len
, feature_ranges
, glyph_advances
, glyph_offsets
);
354 static HRESULT WINAPI
dwritetextanalyzer_GetGdiCompatibleGlyphPlacements(IDWriteTextAnalyzer
*iface
,
355 WCHAR
const* text
, UINT16
const* clustermap
, DWRITE_SHAPING_TEXT_PROPERTIES
* props
,
356 UINT32 text_len
, UINT16
const* glyph_indices
, DWRITE_SHAPING_GLYPH_PROPERTIES
const* glyph_props
,
357 UINT32 glyph_count
, IDWriteFontFace
* font_face
, FLOAT fontEmSize
, FLOAT pixels_per_dip
,
358 DWRITE_MATRIX
const* transform
, BOOL use_gdi_natural
, BOOL is_sideways
, BOOL is_rtl
,
359 DWRITE_SCRIPT_ANALYSIS
const* analysis
, WCHAR
const* locale
, DWRITE_TYPOGRAPHIC_FEATURES
const** features
,
360 UINT32
const* feature_range_lengths
, UINT32 feature_ranges
, FLOAT
* glyph_advances
, DWRITE_GLYPH_OFFSET
* glyph_offsets
)
362 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
),
363 clustermap
, props
, text_len
, glyph_indices
, glyph_props
, glyph_count
, font_face
, fontEmSize
, pixels_per_dip
,
364 transform
, use_gdi_natural
, is_sideways
, is_rtl
, analysis
, debugstr_w(locale
), features
, feature_range_lengths
,
365 feature_ranges
, glyph_advances
, glyph_offsets
);
369 static const struct IDWriteTextAnalyzerVtbl textanalyzervtbl
= {
370 dwritetextanalyzer_QueryInterface
,
371 dwritetextanalyzer_AddRef
,
372 dwritetextanalyzer_Release
,
373 dwritetextanalyzer_AnalyzeScript
,
374 dwritetextanalyzer_AnalyzeBidi
,
375 dwritetextanalyzer_AnalyzeNumberSubstitution
,
376 dwritetextanalyzer_AnalyzeLineBreakpoints
,
377 dwritetextanalyzer_GetGlyphs
,
378 dwritetextanalyzer_GetGlyphPlacements
,
379 dwritetextanalyzer_GetGdiCompatibleGlyphPlacements
382 static IDWriteTextAnalyzer textanalyzer
= { &textanalyzervtbl
};
384 HRESULT
get_textanalyzer(IDWriteTextAnalyzer
**ret
)
386 *ret
= &textanalyzer
;