2 * Implementation of Uniscribe Script Processor (usp10.dll)
4 * Copyright 2010 CodeWeavers, Aric Stewart
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 "wine/list.h"
26 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
27 ( ( (ULONG)_x4 << 24 ) | \
28 ( (ULONG)_x3 << 16 ) | \
29 ( (ULONG)_x2 << 8 ) | \
33 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
38 Script_Undefined
= 0x00,
41 Script_Numeric
= 0x03,
42 Script_Control
= 0x04,
43 Script_Punctuation
= 0x05,
45 Script_Arabic_Numeric
= 0x07,
48 Script_Persian
= 0x0a,
51 Script_Cyrillic
= 0x0d,
52 Script_Armenian
= 0x0e,
53 Script_Georgian
= 0x0f,
54 /* Unicode Chapter 10 */
55 Script_Sinhala
= 0x10,
56 Script_Tibetan
= 0x11,
57 Script_Tibetan_Numeric
= 0x12,
58 Script_Phags_pa
= 0x13,
59 /* Unicode Chapter 11 */
61 Script_Thai_Numeric
= 0x15,
63 Script_Lao_Numeric
= 0x17,
64 /* Unicode Chapter 9 */
65 Script_Devanagari
= 0x18,
66 Script_Devanagari_Numeric
= 0x19,
67 Script_Bengali
= 0x1a,
68 Script_Bengali_Numeric
= 0x1b,
69 Script_Bengali_Currency
= 0x1c,
70 Script_Gurmukhi
= 0x1d,
71 Script_Gurmukhi_Numeric
= 0x1e,
72 Script_Gujarati
= 0x1f,
73 Script_Gujarati_Numeric
= 0x20,
74 Script_Gujarati_Currency
= 0x21,
76 Script_Oriya_Numeric
= 0x23,
78 Script_Tamil_Numeric
= 0x25,
80 Script_Telugu_Numeric
= 0x27,
81 Script_Kannada
= 0x28,
82 Script_Kannada_Numeric
= 0x29,
83 Script_Malayalam
= 0x2a,
84 Script_Malayalam_Numeric
= 0x2b,
85 /* More supplemental */
86 Script_Diacritical
= 0x2c,
87 Script_Punctuation2
= 0x2d,
88 Script_Numeric2
= 0x2e,
89 /* Unicode Chapter 11 continued */
90 Script_Myanmar
= 0x2f,
91 Script_Myanmar_Numeric
= 0x30,
93 Script_New_Tai_Lue
= 0x32,
94 Script_New_Tai_Lue_Numeric
= 0x33,
96 Script_Khmer_Numeric
= 0x35,
97 /* Unicode Chapter 12 */
98 Script_CJK_Han
= 0x36,
99 Script_Ideograph
= 0x37,
100 Script_Bopomofo
= 0x38,
102 Script_Hangul
= 0x3a,
104 /* Unicode Chapter 13 */
105 Script_Ethiopic
= 0x3c,
106 Script_Ethiopic_Numeric
= 0x3d,
107 Script_Mongolian
= 0x3e,
108 Script_Mongolian_Numeric
= 0x3f,
109 Script_Tifinagh
= 0x40,
112 Script_Vai_Numeric
= 0x43,
113 Script_Cherokee
= 0x44,
114 Script_Canadian
= 0x45,
115 /* Unicode Chapter 14 */
118 /* Unicode Chapter 15 */
119 Script_Braille
= 0x48,
120 /* Unicode Chapter 16 */
121 Script_Surrogates
= 0x49,
122 Script_Private
= 0x4a,
123 /* Unicode Chapter 13 : Plane 1 */
124 Script_Deseret
= 0x4b,
125 Script_Osmanya
= 0x4c,
126 Script_Osmanya_Numeric
= 0x4d,
127 /* Unicode Chapter 15 : Plane 1 */
128 Script_MathAlpha
= 0x4e,
129 /* Additional Currency Scripts */
130 Script_Hebrew_Currency
= 0x4f,
131 Script_Vietnamese_Currency
= 0x50,
132 Script_Thai_Currency
= 0x51,
135 #define GLYPH_BLOCK_SHIFT 8
136 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
137 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
138 #define GLYPH_MAX 65536
142 #define GSUB_E_NOFEATURE -20
143 #define GSUB_E_NOGLYPH -10
145 #define FEATURE_ALL_TABLES 0
146 #define FEATURE_GSUB_TABLE 1
147 #define FEATURE_GPOS_TABLE 2
159 const void *gsub_table
;
160 const void *gpos_table
;
161 BOOL features_initialized
;
163 LoadedFeature
*features
;
168 const void *gsub_table
;
169 const void *gpos_table
;
170 LoadedLanguage default_language
;
171 BOOL languages_initialized
;
172 LoadedLanguage
*languages
;
173 SIZE_T languages_size
;
174 SIZE_T language_count
;
178 WORD
*glyphs
[GLYPH_MAX
/ GLYPH_BLOCK_SIZE
];
186 OUTLINETEXTMETRICW
*otm
;
187 SCRIPT_FONTPROPERTIES sfp
;
189 CacheGlyphPage
*page
[NUM_PAGES
];
190 ABC
*widths
[GLYPH_MAX
/ GLYPH_BLOCK_SIZE
];
194 void *CMAP_format12_Table
;
196 BOOL scripts_initialized
;
197 LoadedScript
*scripts
;
201 OPENTYPE_TAG userScript
;
202 OPENTYPE_TAG userLang
;
205 typedef struct _scriptData
208 SCRIPT_PROPERTIES props
;
209 OPENTYPE_TAG scriptTag
;
210 WCHAR fallbackFont
[LF_FACESIZE
];
222 enum {lex_Halant
, lex_Composed_Vowel
, lex_Matra_post
, lex_Matra_pre
, lex_Matra_above
, lex_Matra_below
, lex_ZWJ
, lex_ZWNJ
, lex_NBSP
, lex_Modifier
, lex_Vowel
, lex_Consonant
, lex_Generic
, lex_Ra
, lex_Vedic
, lex_Anudatta
, lex_Nukta
};
224 static inline BOOL
is_consonant( int type
)
226 return (type
== lex_Ra
|| type
== lex_Consonant
);
229 static inline unsigned short get_table_entry( const unsigned short *table
, WCHAR ch
)
231 return table
[table
[table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0xf)];
234 typedef int (*lexical_function
)(WCHAR c
);
235 typedef void (*reorder_function
)(WCHAR
*chars
, IndicSyllable
*syllable
, lexical_function lex
);
237 #define odd(x) ((x) & 1)
238 #define BIDI_STRONG 1
240 #define BIDI_NEUTRAL 0
242 BOOL
usp10_array_reserve(void **elements
, SIZE_T
*capacity
, SIZE_T count
, SIZE_T size
) DECLSPEC_HIDDEN
;
243 int USP10_FindGlyphInLogClust(const WORD
* pwLogClust
, int cChars
, WORD target
) DECLSPEC_HIDDEN
;
245 BOOL
BIDI_DetermineLevels(const WCHAR
*string
, unsigned int count
, const SCRIPT_STATE
*s
,
246 const SCRIPT_CONTROL
*c
, WORD
*levels
, WORD
*overrides
) DECLSPEC_HIDDEN
;
247 BOOL
BIDI_GetStrengths(const WCHAR
*string
, unsigned int count
,
248 const SCRIPT_CONTROL
*c
, WORD
*strength
) DECLSPEC_HIDDEN
;
249 INT
BIDI_ReorderV2lLevel(int level
, int *pIndexs
, const BYTE
* plevel
, int cch
, BOOL fReverse
) DECLSPEC_HIDDEN
;
250 INT
BIDI_ReorderL2vLevel(int level
, int *pIndexs
, const BYTE
* plevel
, int cch
, BOOL fReverse
) DECLSPEC_HIDDEN
;
251 void SHAPE_ContextualShaping(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
) DECLSPEC_HIDDEN
;
252 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, INT cChars
, WORD
*pwLogClust
) DECLSPEC_HIDDEN
;
253 void SHAPE_ApplyOpenTypePositions(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WORD
* pwGlyphs
, INT cGlyphs
, int *piAdvance
, GOFFSET
*pGoffset
) DECLSPEC_HIDDEN
;
254 HRESULT
SHAPE_CheckFontForRequiredFeatures(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
) DECLSPEC_HIDDEN
;
255 void SHAPE_CharGlyphProp(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
) DECLSPEC_HIDDEN
;
256 INT
SHAPE_does_GSUB_feature_apply_to_chars(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, const WCHAR
*chars
, INT write_dir
, INT count
, const char* feature
) DECLSPEC_HIDDEN
;
257 HRESULT
SHAPE_GetFontScriptTags( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, int cMaxTags
, OPENTYPE_TAG
*pScriptTags
, int *pcTags
) DECLSPEC_HIDDEN
;
258 HRESULT
SHAPE_GetFontLanguageTags( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
, int cMaxTags
, OPENTYPE_TAG
*pLangSysTags
, int *pcTags
) DECLSPEC_HIDDEN
;
259 HRESULT
SHAPE_GetFontFeatureTags( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
, int cMaxTags
, OPENTYPE_TAG
*pFeatureTags
, int *pcTags
) DECLSPEC_HIDDEN
;
261 void Indic_ReorderCharacters(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
*psc
, WCHAR
*input
, unsigned int cChars
,
262 IndicSyllable
**syllables
, int *syllable_count
, lexical_function lexical_f
,
263 reorder_function reorder_f
, BOOL modern
) DECLSPEC_HIDDEN
;
264 void Indic_ParseSyllables(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, const WCHAR
*input
, unsigned int cChar
,
265 IndicSyllable
**syllables
, int *syllable_count
, lexical_function lex
, BOOL modern
) DECLSPEC_HIDDEN
;
267 void BREAK_line(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
) DECLSPEC_HIDDEN
;
269 DWORD
OpenType_CMAP_GetGlyphIndex(HDC hdc
, ScriptCache
*psc
, DWORD utf32c
, LPWORD pgi
, DWORD flags
) DECLSPEC_HIDDEN
;
270 void OpenType_GDEF_UpdateGlyphProps(ScriptCache
*psc
, const WORD
*pwGlyphs
, const WORD cGlyphs
, WORD
* pwLogClust
, const WORD cChars
, SCRIPT_GLYPHPROP
*pGlyphProp
) DECLSPEC_HIDDEN
;
271 int OpenType_apply_GSUB_lookup(const void *table
, unsigned int lookup_index
, WORD
*glyphs
,
272 unsigned int glyph_index
, int write_dir
, int *glyph_count
) DECLSPEC_HIDDEN
;
273 unsigned int OpenType_apply_GPOS_lookup(const ScriptCache
*psc
, const OUTLINETEXTMETRICW
*otm
,
274 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, unsigned int lookup_index
,
275 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, GOFFSET
*goffset
) DECLSPEC_HIDDEN
;
276 HRESULT
OpenType_GetFontScriptTags(ScriptCache
*psc
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pScriptTags
, int *pcTags
) DECLSPEC_HIDDEN
;
277 HRESULT
OpenType_GetFontLanguageTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pLanguageTags
, int *pcTags
) DECLSPEC_HIDDEN
;
278 HRESULT
OpenType_GetFontFeatureTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG language_tag
, BOOL filtered
, OPENTYPE_TAG searchingFor
, char tableType
, int cMaxTags
, OPENTYPE_TAG
*pFeatureTags
, int *pcTags
, LoadedFeature
** feature
) DECLSPEC_HIDDEN
;