2010-04-13 21:49:07 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2018-01-12 14:30:13 +01:00
|
|
|
|
|
|
|
#include "wine/list.h"
|
|
|
|
|
2011-05-10 20:09:47 +02:00
|
|
|
#define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
|
|
|
|
( ( (ULONG)_x4 << 24 ) | \
|
|
|
|
( (ULONG)_x3 << 16 ) | \
|
|
|
|
( (ULONG)_x2 << 8 ) | \
|
|
|
|
(ULONG)_x1 )
|
|
|
|
|
2017-03-07 08:57:29 +01:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
|
|
|
#endif
|
2010-04-13 21:49:07 +02:00
|
|
|
|
2017-03-07 08:57:28 +01:00
|
|
|
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,
|
|
|
|
};
|
2010-05-19 16:17:00 +02:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2016-08-09 16:45:24 +02:00
|
|
|
#define NUM_PAGES 17
|
|
|
|
|
2017-01-27 18:31:37 +01:00
|
|
|
#define GSUB_E_NOFEATURE -20
|
|
|
|
#define GSUB_E_NOGLYPH -10
|
2012-01-04 15:13:44 +01:00
|
|
|
|
2013-01-08 17:00:06 +01:00
|
|
|
#define FEATURE_ALL_TABLES 0
|
|
|
|
#define FEATURE_GSUB_TABLE 1
|
|
|
|
#define FEATURE_GPOS_TABLE 2
|
|
|
|
|
2010-08-12 21:58:14 +02:00
|
|
|
typedef struct {
|
2012-01-03 13:51:20 +01:00
|
|
|
OPENTYPE_TAG tag;
|
2013-01-08 17:00:06 +01:00
|
|
|
CHAR tableType;
|
2017-03-23 22:49:41 +01:00
|
|
|
const void *feature;
|
2012-01-03 13:51:33 +01:00
|
|
|
INT lookup_count;
|
|
|
|
WORD *lookups;
|
2010-08-12 21:58:14 +02:00
|
|
|
} LoadedFeature;
|
|
|
|
|
2011-12-29 21:50:12 +01:00
|
|
|
typedef struct {
|
|
|
|
OPENTYPE_TAG tag;
|
2017-03-23 22:49:41 +01:00
|
|
|
const void *gsub_table;
|
|
|
|
const void *gpos_table;
|
2013-02-08 16:46:08 +01:00
|
|
|
BOOL features_initialized;
|
2012-01-03 13:51:23 +01:00
|
|
|
INT feature_count;
|
|
|
|
LoadedFeature *features;
|
2012-01-03 13:51:07 +01:00
|
|
|
} LoadedLanguage;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
OPENTYPE_TAG tag;
|
2017-03-23 22:49:41 +01:00
|
|
|
const void *gsub_table;
|
|
|
|
const void *gpos_table;
|
2012-01-03 13:51:07 +01:00
|
|
|
LoadedLanguage default_language;
|
2013-02-08 16:46:08 +01:00
|
|
|
BOOL languages_initialized;
|
2012-01-03 13:51:07 +01:00
|
|
|
LoadedLanguage *languages;
|
2017-03-27 22:57:02 +02:00
|
|
|
SIZE_T languages_size;
|
|
|
|
SIZE_T language_count;
|
2011-12-29 21:50:12 +01:00
|
|
|
} LoadedScript;
|
|
|
|
|
2012-06-04 18:14:27 +02:00
|
|
|
typedef struct {
|
|
|
|
WORD *glyphs[GLYPH_MAX / GLYPH_BLOCK_SIZE];
|
|
|
|
} CacheGlyphPage;
|
|
|
|
|
2010-05-19 16:17:00 +02:00
|
|
|
typedef struct {
|
2018-01-12 14:30:13 +01:00
|
|
|
struct list entry;
|
|
|
|
DWORD refcount;
|
2010-05-19 16:17:00 +02:00
|
|
|
LOGFONTW lf;
|
|
|
|
TEXTMETRICW tm;
|
2012-07-31 15:49:57 +02:00
|
|
|
OUTLINETEXTMETRICW *otm;
|
2012-11-21 11:13:14 +01:00
|
|
|
SCRIPT_FONTPROPERTIES sfp;
|
2011-09-14 15:53:05 +02:00
|
|
|
BOOL sfnt;
|
2016-08-09 16:45:24 +02:00
|
|
|
CacheGlyphPage *page[NUM_PAGES];
|
2010-05-19 16:17:00 +02:00
|
|
|
ABC *widths[GLYPH_MAX / GLYPH_BLOCK_SIZE];
|
2017-03-23 22:49:42 +01:00
|
|
|
void *GSUB_Table;
|
|
|
|
void *GDEF_Table;
|
|
|
|
void *CMAP_Table;
|
|
|
|
void *CMAP_format12_Table;
|
|
|
|
void *GPOS_Table;
|
2013-02-08 16:46:08 +01:00
|
|
|
BOOL scripts_initialized;
|
2011-12-29 21:50:12 +01:00
|
|
|
LoadedScript *scripts;
|
2017-03-27 22:57:01 +02:00
|
|
|
SIZE_T scripts_size;
|
|
|
|
SIZE_T script_count;
|
2011-05-12 20:57:26 +02:00
|
|
|
|
|
|
|
OPENTYPE_TAG userScript;
|
|
|
|
OPENTYPE_TAG userLang;
|
2010-05-19 16:17:00 +02:00
|
|
|
} ScriptCache;
|
|
|
|
|
2011-12-29 21:50:23 +01:00
|
|
|
typedef struct _scriptData
|
|
|
|
{
|
|
|
|
SCRIPT_ANALYSIS a;
|
|
|
|
SCRIPT_PROPERTIES props;
|
|
|
|
OPENTYPE_TAG scriptTag;
|
|
|
|
WCHAR fallbackFont[LF_FACESIZE];
|
|
|
|
} scriptData;
|
|
|
|
|
2011-06-15 16:54:00 +02:00
|
|
|
typedef struct {
|
|
|
|
INT start;
|
|
|
|
INT base;
|
2011-06-15 16:54:24 +02:00
|
|
|
INT ralf;
|
2011-06-16 18:28:43 +02:00
|
|
|
INT blwf;
|
2011-06-16 18:29:03 +02:00
|
|
|
INT pref;
|
2011-06-15 16:54:00 +02:00
|
|
|
INT end;
|
|
|
|
} IndicSyllable;
|
|
|
|
|
2011-06-06 14:28:54 +02:00
|
|
|
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};
|
2011-06-02 21:56:07 +02:00
|
|
|
|
2011-06-15 16:54:28 +02:00
|
|
|
static inline BOOL is_consonant( int type )
|
|
|
|
{
|
|
|
|
return (type == lex_Ra || type == lex_Consonant);
|
|
|
|
}
|
|
|
|
|
2014-09-22 17:21:47 +02:00
|
|
|
static inline unsigned short get_table_entry( const unsigned short *table, WCHAR ch )
|
2011-07-07 17:30:35 +02:00
|
|
|
{
|
|
|
|
return table[table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0xf)];
|
|
|
|
}
|
|
|
|
|
2011-06-02 21:56:07 +02:00
|
|
|
typedef int (*lexical_function)(WCHAR c);
|
2017-03-23 22:49:40 +01:00
|
|
|
typedef void (*reorder_function)(WCHAR *chars, IndicSyllable *syllable, lexical_function lex);
|
2011-06-02 21:56:07 +02:00
|
|
|
|
2010-04-13 21:49:07 +02:00
|
|
|
#define odd(x) ((x) & 1)
|
2011-11-14 21:16:59 +01:00
|
|
|
#define BIDI_STRONG 1
|
|
|
|
#define BIDI_WEAK 2
|
|
|
|
#define BIDI_NEUTRAL 0
|
2010-04-13 21:49:07 +02:00
|
|
|
|
2017-03-27 22:57:01 +02:00
|
|
|
BOOL usp10_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
|
2012-01-30 14:30:08 +01:00
|
|
|
int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target) DECLSPEC_HIDDEN;
|
|
|
|
|
2017-03-22 23:11:40 +01:00
|
|
|
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;
|
2011-05-13 18:21:24 +02:00
|
|
|
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;
|
2012-12-27 19:30:09 +01:00
|
|
|
void SHAPE_ApplyOpenTypePositions(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WORD* pwGlyphs, INT cGlyphs, int *piAdvance, GOFFSET *pGoffset ) DECLSPEC_HIDDEN;
|
2011-05-13 18:21:24 +02:00
|
|
|
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;
|
2011-06-15 16:54:07 +02:00
|
|
|
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;
|
2012-01-02 21:57:39 +01:00
|
|
|
HRESULT SHAPE_GetFontScriptTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
|
2012-01-03 13:51:07 +01:00
|
|
|
HRESULT SHAPE_GetFontLanguageTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, int cMaxTags, OPENTYPE_TAG *pLangSysTags, int *pcTags) DECLSPEC_HIDDEN;
|
2012-01-03 13:51:23 +01:00
|
|
|
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;
|
2011-06-02 21:56:07 +02:00
|
|
|
|
2017-03-23 22:49:40 +01:00
|
|
|
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;
|
2017-03-22 23:11:40 +01:00
|
|
|
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;
|
2011-06-27 18:01:24 +02:00
|
|
|
|
|
|
|
void BREAK_line(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la) DECLSPEC_HIDDEN;
|
2011-12-19 14:25:00 +01:00
|
|
|
|
2012-01-04 15:13:38 +01:00
|
|
|
DWORD OpenType_CMAP_GetGlyphIndex(HDC hdc, ScriptCache *psc, DWORD utf32c, LPWORD pgi, DWORD flags) DECLSPEC_HIDDEN;
|
2013-01-18 17:35:24 +01:00
|
|
|
void OpenType_GDEF_UpdateGlyphProps(ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, const WORD cChars, SCRIPT_GLYPHPROP *pGlyphProp) DECLSPEC_HIDDEN;
|
2017-03-23 22:49:41 +01:00
|
|
|
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;
|
2017-03-19 22:59:47 +01:00
|
|
|
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;
|
2012-07-16 14:23:39 +02:00
|
|
|
HRESULT OpenType_GetFontScriptTags(ScriptCache *psc, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
|
2012-07-16 14:23:42 +02:00
|
|
|
HRESULT OpenType_GetFontLanguageTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pLanguageTags, int *pcTags) DECLSPEC_HIDDEN;
|
2013-01-08 17:00:06 +01:00
|
|
|
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;
|