usp10_internal.h 11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Implementation of Uniscribe Script Processor (usp10.dll)
 *
 * Copyright 2010 CodeWeavers, Aric Stewart
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */
21 22 23 24 25 26
#define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
          ( ( (ULONG)_x4 << 24 ) |     \
            ( (ULONG)_x3 << 16 ) |     \
            ( (ULONG)_x2 <<  8 ) |     \
              (ULONG)_x1         )

27 28 29
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif
30

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
enum usp10_script
{
    Script_Undefined = 0x00,
    Script_Latin = 0x01,
    Script_CR = 0x02,
    Script_Numeric = 0x03,
    Script_Control = 0x04,
    Script_Punctuation = 0x05,
    Script_Arabic = 0x06,
    Script_Arabic_Numeric = 0x07,
    Script_Hebrew = 0x08,
    Script_Syriac = 0x09,
    Script_Persian = 0x0a,
    Script_Thaana = 0x0b,
    Script_Greek = 0x0c,
    Script_Cyrillic = 0x0d,
    Script_Armenian = 0x0e,
    Script_Georgian = 0x0f,
    /* Unicode Chapter 10 */
    Script_Sinhala = 0x10,
    Script_Tibetan = 0x11,
    Script_Tibetan_Numeric = 0x12,
    Script_Phags_pa = 0x13,
    /* Unicode Chapter 11 */
    Script_Thai = 0x14,
    Script_Thai_Numeric = 0x15,
    Script_Lao = 0x16,
    Script_Lao_Numeric = 0x17,
    /* Unicode Chapter 9 */
    Script_Devanagari = 0x18,
    Script_Devanagari_Numeric = 0x19,
    Script_Bengali = 0x1a,
    Script_Bengali_Numeric = 0x1b,
    Script_Bengali_Currency = 0x1c,
    Script_Gurmukhi = 0x1d,
    Script_Gurmukhi_Numeric = 0x1e,
    Script_Gujarati = 0x1f,
    Script_Gujarati_Numeric = 0x20,
    Script_Gujarati_Currency = 0x21,
    Script_Oriya = 0x22,
    Script_Oriya_Numeric = 0x23,
    Script_Tamil = 0x24,
    Script_Tamil_Numeric = 0x25,
    Script_Telugu = 0x26,
    Script_Telugu_Numeric = 0x27,
    Script_Kannada = 0x28,
    Script_Kannada_Numeric = 0x29,
    Script_Malayalam = 0x2a,
    Script_Malayalam_Numeric = 0x2b,
    /* More supplemental */
    Script_Diacritical = 0x2c,
    Script_Punctuation2 = 0x2d,
    Script_Numeric2 = 0x2e,
    /* Unicode Chapter 11 continued */
    Script_Myanmar = 0x2f,
    Script_Myanmar_Numeric = 0x30,
    Script_Tai_Le = 0x31,
    Script_New_Tai_Lue = 0x32,
    Script_New_Tai_Lue_Numeric = 0x33,
    Script_Khmer = 0x34,
    Script_Khmer_Numeric = 0x35,
    /* Unicode Chapter 12 */
    Script_CJK_Han = 0x36,
    Script_Ideograph = 0x37,
    Script_Bopomofo = 0x38,
    Script_Kana = 0x39,
    Script_Hangul = 0x3a,
    Script_Yi = 0x3b,
    /* Unicode Chapter 13 */
    Script_Ethiopic = 0x3c,
    Script_Ethiopic_Numeric = 0x3d,
    Script_Mongolian = 0x3e,
    Script_Mongolian_Numeric = 0x3f,
    Script_Tifinagh = 0x40,
    Script_NKo = 0x41,
    Script_Vai = 0x42,
    Script_Vai_Numeric = 0x43,
    Script_Cherokee = 0x44,
    Script_Canadian = 0x45,
    /* Unicode Chapter 14 */
    Script_Ogham = 0x46,
    Script_Runic = 0x47,
    /* Unicode Chapter 15 */
    Script_Braille = 0x48,
    /* Unicode Chapter 16 */
    Script_Surrogates = 0x49,
    Script_Private = 0x4a,
    /* Unicode Chapter 13 : Plane 1 */
    Script_Deseret = 0x4b,
    Script_Osmanya = 0x4c,
    Script_Osmanya_Numeric = 0x4d,
    /* Unicode Chapter 15 : Plane 1 */
    Script_MathAlpha = 0x4e,
    /* Additional Currency Scripts */
    Script_Hebrew_Currency = 0x4f,
    Script_Vietnamese_Currency = 0x50,
    Script_Thai_Currency = 0x51,
};
129 130 131 132 133 134

#define GLYPH_BLOCK_SHIFT 8
#define GLYPH_BLOCK_SIZE  (1UL << GLYPH_BLOCK_SHIFT)
#define GLYPH_BLOCK_MASK  (GLYPH_BLOCK_SIZE - 1)
#define GLYPH_MAX         65536

135 136
#define NUM_PAGES         17

137 138
#define GSUB_E_NOFEATURE -20
#define GSUB_E_NOGLYPH -10
139

140 141 142 143
#define FEATURE_ALL_TABLES 0
#define FEATURE_GSUB_TABLE 1
#define FEATURE_GPOS_TABLE 2

144
typedef struct {
145
    OPENTYPE_TAG tag;
146
    CHAR tableType;
Henri Verbeet's avatar
Henri Verbeet committed
147
    const void *feature;
148 149
    INT lookup_count;
    WORD *lookups;
150 151
} LoadedFeature;

152 153
typedef struct {
    OPENTYPE_TAG tag;
Henri Verbeet's avatar
Henri Verbeet committed
154 155
    const void *gsub_table;
    const void *gpos_table;
156
    BOOL features_initialized;
157 158
    INT feature_count;
    LoadedFeature *features;
159 160 161 162
} LoadedLanguage;

typedef struct {
    OPENTYPE_TAG tag;
Henri Verbeet's avatar
Henri Verbeet committed
163 164
    const void *gsub_table;
    const void *gpos_table;
165
    LoadedLanguage default_language;
166
    BOOL languages_initialized;
167
    LoadedLanguage *languages;
168 169
    SIZE_T languages_size;
    SIZE_T language_count;
170 171
} LoadedScript;

172 173 174 175
typedef struct {
    WORD *glyphs[GLYPH_MAX / GLYPH_BLOCK_SIZE];
} CacheGlyphPage;

176 177 178
typedef struct {
    LOGFONTW lf;
    TEXTMETRICW tm;
179
    OUTLINETEXTMETRICW *otm;
180
    SCRIPT_FONTPROPERTIES sfp;
181
    BOOL sfnt;
182
    CacheGlyphPage *page[NUM_PAGES];
183
    ABC *widths[GLYPH_MAX / GLYPH_BLOCK_SIZE];
Henri Verbeet's avatar
Henri Verbeet committed
184 185 186 187 188
    void *GSUB_Table;
    void *GDEF_Table;
    void *CMAP_Table;
    void *CMAP_format12_Table;
    void *GPOS_Table;
189
    BOOL scripts_initialized;
190
    LoadedScript *scripts;
191 192
    SIZE_T scripts_size;
    SIZE_T script_count;
193 194 195

    OPENTYPE_TAG userScript;
    OPENTYPE_TAG userLang;
196 197
} ScriptCache;

198 199 200 201 202 203 204 205
typedef struct _scriptData
{
    SCRIPT_ANALYSIS a;
    SCRIPT_PROPERTIES props;
    OPENTYPE_TAG scriptTag;
    WCHAR fallbackFont[LF_FACESIZE];
} scriptData;

206 207 208
typedef struct {
    INT start;
    INT base;
209
    INT ralf;
210
    INT blwf;
211
    INT pref;
212 213 214
    INT end;
} IndicSyllable;

215
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};
216

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
{
    return HeapAlloc(GetProcessHeap(), 0, size);
}

static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size)
{
    return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
}

static inline BOOL heap_free(void *mem)
{
    return HeapFree(GetProcessHeap(), 0, mem);
}

232 233 234 235 236
static inline BOOL is_consonant( int type )
{
    return (type == lex_Ra || type == lex_Consonant);
}

237
static inline unsigned short get_table_entry( const unsigned short *table, WCHAR ch )
238 239 240 241
{
    return table[table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0xf)];
}

242
typedef int (*lexical_function)(WCHAR c);
Henri Verbeet's avatar
Henri Verbeet committed
243
typedef void (*reorder_function)(WCHAR *chars, IndicSyllable *syllable, lexical_function lex);
244

245
#define odd(x) ((x) & 1)
246 247 248
#define BIDI_STRONG  1
#define BIDI_WEAK    2
#define BIDI_NEUTRAL 0
249

250
BOOL usp10_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
251 252
int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target) DECLSPEC_HIDDEN;

Henri Verbeet's avatar
Henri Verbeet committed
253 254 255 256
BOOL BIDI_DetermineLevels(const WCHAR *string, unsigned int count, const SCRIPT_STATE *s,
        const SCRIPT_CONTROL *c, WORD *levels, WORD *overrides) DECLSPEC_HIDDEN;
BOOL BIDI_GetStrengths(const WCHAR *string, unsigned int count,
        const SCRIPT_CONTROL *c, WORD *strength) DECLSPEC_HIDDEN;
257 258 259 260
INT BIDI_ReorderV2lLevel(int level, int *pIndexs, const BYTE* plevel, int cch, BOOL fReverse) DECLSPEC_HIDDEN;
INT BIDI_ReorderL2vLevel(int level, int *pIndexs, const BYTE* plevel, int cch, BOOL fReverse) DECLSPEC_HIDDEN;
void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust) DECLSPEC_HIDDEN;
void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust) DECLSPEC_HIDDEN;
261
void SHAPE_ApplyOpenTypePositions(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WORD* pwGlyphs, INT cGlyphs, int *piAdvance, GOFFSET *pGoffset ) DECLSPEC_HIDDEN;
262 263
HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa) DECLSPEC_HIDDEN;
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;
264
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;
265
HRESULT SHAPE_GetFontScriptTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
266
HRESULT SHAPE_GetFontLanguageTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, int cMaxTags, OPENTYPE_TAG *pLangSysTags, int *pcTags) DECLSPEC_HIDDEN;
267
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;
268

Henri Verbeet's avatar
Henri Verbeet committed
269 270 271
void Indic_ReorderCharacters(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, WCHAR *input, unsigned int cChars,
        IndicSyllable **syllables, int *syllable_count, lexical_function lexical_f,
        reorder_function reorder_f, BOOL modern) DECLSPEC_HIDDEN;
Henri Verbeet's avatar
Henri Verbeet committed
272 273
void Indic_ParseSyllables(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache* psc, const WCHAR *input, unsigned int cChar,
        IndicSyllable **syllables, int *syllable_count, lexical_function lex, BOOL modern) DECLSPEC_HIDDEN;
274 275

void BREAK_line(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la) DECLSPEC_HIDDEN;
276

277
DWORD OpenType_CMAP_GetGlyphIndex(HDC hdc, ScriptCache *psc, DWORD utf32c, LPWORD pgi, DWORD flags) DECLSPEC_HIDDEN;
278
void OpenType_GDEF_UpdateGlyphProps(ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, const WORD cChars, SCRIPT_GLYPHPROP *pGlyphProp) DECLSPEC_HIDDEN;
Henri Verbeet's avatar
Henri Verbeet committed
279 280
int OpenType_apply_GSUB_lookup(const void *table, unsigned int lookup_index, WORD *glyphs,
        unsigned int glyph_index, int write_dir, int *glyph_count) DECLSPEC_HIDDEN;
281 282 283
unsigned int OpenType_apply_GPOS_lookup(const ScriptCache *psc, const OUTLINETEXTMETRICW *otm,
        const LOGFONTW *logfont, const SCRIPT_ANALYSIS *analysis, int *advance, unsigned int lookup_index,
        const WORD *glyphs, unsigned int glyph_index, unsigned int glyph_count, GOFFSET *goffset) DECLSPEC_HIDDEN;
284
HRESULT OpenType_GetFontScriptTags(ScriptCache *psc, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
285
HRESULT OpenType_GetFontLanguageTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pLanguageTags, int *pcTags) DECLSPEC_HIDDEN;
286
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;