usp10: Add Devanagari script.

This commit is contained in:
Aric Stewart 2011-06-02 14:56:17 -05:00 committed by Alexandre Julliard
parent 397c3ac51f
commit b8aad9d3cd
4 changed files with 286 additions and 1 deletions

View File

@ -44,6 +44,7 @@ static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *p
static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
typedef VOID (*ShapeCharGlyphPropProc)( HDC , ScriptCache*, SCRIPT_ANALYSIS*, const WCHAR*, const INT, const WORD*, const INT, WORD*, SCRIPT_CHARPROP*, SCRIPT_GLYPHPROP*);
@ -53,6 +54,7 @@ static void ShapeCharGlyphProp_Arabic( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSI
static void ShapeCharGlyphProp_Thai( 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 );
static void ShapeCharGlyphProp_None( 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 );
static void ShapeCharGlyphProp_Tibet( 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 );
static void ShapeCharGlyphProp_Devanagari( 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 );
extern const unsigned short wine_shaping_table[];
extern const unsigned short wine_shaping_forms[LAST_ARABIC_CHAR - FIRST_ARABIC_CHAR + 1][4];
@ -286,6 +288,12 @@ typedef struct tagVowelComponents
WCHAR parts[3];
} VowelComponents;
typedef struct tagConsonantComponents
{
WCHAR parts[3];
WCHAR output;
} ConsonantComponents;
/* the orders of joined_forms and contextual_features need to line up */
static const char* contextual_features[] =
{
@ -379,6 +387,44 @@ static const char* required_lao_features[] =
NULL
};
static const char* required_devanagari_features[] =
{
"nukt",
"akhn",
"rphf",
"blwf",
"half",
"vatu",
"pres",
"abvs",
"blws",
"psts",
"haln",
NULL
};
static OPENTYPE_FEATURE_RECORD devanagari_features[] =
{
/* Localized forms */
{ MS_MAKE_TAG('l','o','c','l'), 1},
/* Base forms */
{ MS_MAKE_TAG('n','u','k','t'), 1},
{ MS_MAKE_TAG('a','k','h','n'), 1},
{ MS_MAKE_TAG('r','p','h','f'), 1},
{ MS_MAKE_TAG('r','k','r','f'), 1},
{ MS_MAKE_TAG('b','l','w','f'), 1},
{ MS_MAKE_TAG('h','a','l','f'), 1},
{ MS_MAKE_TAG('v','a','t','u'), 1},
{ MS_MAKE_TAG('c','j','c','t'), 1},
/* Presentation forms */
{ MS_MAKE_TAG('p','r','e','s'), 1},
{ MS_MAKE_TAG('a','b','v','s'), 1},
{ MS_MAKE_TAG('b','l','w','s'), 1},
{ MS_MAKE_TAG('p','s','t','s'), 1},
{ MS_MAKE_TAG('h','a','l','n'), 1},
{ MS_MAKE_TAG('c','a','l','t'), 1},
};
typedef struct ScriptShapeDataTag {
TEXTRANGE_PROPERTIES defaultTextRange;
const char** requiredFeatures;
@ -415,6 +461,8 @@ static const ScriptShapeData ShapingData[] =
{{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
{{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
{{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
{{ devanagari_features, 15}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
{{ devanagari_features, 15}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
};
static INT GSUB_is_glyph_covered(LPCVOID table , UINT glyph)
@ -1538,6 +1586,35 @@ static void DecomposeVowels(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const Vowe
}
}
static void ComposeConsonants(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const ConsonantComponents consonants[])
{
int i;
int cWalk;
for (cWalk = 0; cWalk < *pcChars; cWalk++)
{
for (i = 0; consonants[i].output!= 0x0; i++)
{
int j;
for (j = 0; j + cWalk < *pcChars && consonants[i].parts[j]!=0x0; j++)
if (pwOutChars[cWalk+j] != consonants[i].parts[j])
break;
if (consonants[i].parts[j]==0x0) /* matched all */
{
int k;
j--;
pwOutChars[cWalk] = consonants[i].output;
for(k = cWalk+1; k < *pcChars - j; k++)
pwOutChars[k] = pwOutChars[k+j];
*pcChars = *pcChars - j;
break;
}
}
cWalk++;
}
}
static void Reorder_Ra_follows_base(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
{
if (start != main && end > start+1 && lexical(pwChar[start]) == lex_Ra && lexical(pwChar[start+1]) == lex_Halant)
@ -1554,6 +1631,26 @@ static void Reorder_Ra_follows_base(LPWSTR pwChar, INT start, INT main, INT end,
}
}
static void Reorder_Ra_follows_mantra_post(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
{
if (start != main && end > start+1 && lexical(pwChar[start]) == lex_Ra && lexical(pwChar[start+1]) == lex_Halant)
{
int j,loc;
WORD Ra = pwChar[start];
WORD H = pwChar[start+1];
for (loc = main; loc > end; loc++)
if (lexical(pwChar[loc]) == lex_Mantra_post)
break;
if (loc == end) loc = main;
TRACE("Doing reorder of Ra to %i\n",loc);
for (j = start; j < loc-1; j++)
pwChar[j] = pwChar[j+2];
pwChar[loc-1] = Ra;
pwChar[loc] = H;
}
}
static void Reorder_Mantra_precede_base(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
{
int i;
@ -1576,6 +1673,28 @@ static void Reorder_Mantra_precede_base(LPWSTR pwChar, INT start, INT main, INT
}
}
static void Reorder_Mantra_precede_syllable(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
{
int i;
/* reorder Mantras */
if (end > main)
{
for (i = 1; i <= end-main; i++)
{
if (lexical(pwChar[main+i]) == lex_Mantra_pre)
{
int j;
WCHAR c = pwChar[main+i];
TRACE("Doing reorder of %x to %i\n",c,start);
for (j = main+i; j > start; j--)
pwChar[j] = pwChar[j-1];
pwChar[start] = c;
}
}
}
}
static void Reorder_Like_Sinhala(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
{
TRACE("Syllable (%i..%i..%i)\n",start,main,end);
@ -1588,6 +1707,18 @@ static void Reorder_Like_Sinhala(LPWSTR pwChar, INT start, INT main, INT end, le
Reorder_Mantra_precede_base(pwChar, start, main, end, lexical);
}
static void Reorder_Like_Devanagari(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
{
TRACE("Syllable (%i..%i..%i)\n",start,main,end);
if (start == main && main == end) return;
main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
if (lexical(pwChar[main]) == lex_Vowel) return;
Reorder_Ra_follows_mantra_post(pwChar, start, main, end, lexical);
Reorder_Mantra_precede_syllable(pwChar, start, main, end, lexical);
}
static int sinhala_lex(WCHAR c)
{
switch (c)
@ -1654,6 +1785,79 @@ static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *
HeapFree(GetProcessHeap(),0,input);
}
static int devanagari_lex(WCHAR c)
{
switch (c)
{
case 0x0951:
case 0x0952:
case 0x0903: return lex_Modifier;
case 0x0930: return lex_Ra;
case 0x093C: return lex_Nukta;
case 0x0940:
case 0x093E: return lex_Mantra_post;
case 0x093F: return lex_Mantra_pre;
case 0x094D: return lex_Halant;
case 0x0972: return lex_Vowel;
case 0x200C: return lex_ZWNJ;
case 0x200D: return lex_ZWJ;
default:
if (c>=0x0901 && c<=0x0902) return lex_Mantra_above;
else if (c>=0x0904 && c<=0x0914) return lex_Vowel;
else if (c>=0x0915 && c<=0x0939) return lex_Consonant;
else if (c>=0x0941 && c<=0x0944) return lex_Mantra_below;
else if (c>=0x0945 && c<=0x0948) return lex_Mantra_above;
else if (c>=0x0949 && c<=0x094C) return lex_Mantra_post;
else if (c>=0x0953 && c<=0x0954) return lex_Modifier;
else if (c>=0x0958 && c<=0x095F) return lex_Consonant;
else if (c>=0x0960 && c<=0x0961) return lex_Vowel;
else if (c>=0x0962 && c<=0x0963) return lex_Mantra_below;
else if (c>=0x097B && c<=0x097C) return lex_Consonant;
else if (c>=0x097E && c<=0x097F) return lex_Consonant;
else return lex_Generic;
}
}
static const ConsonantComponents Devanagari_consonants[] ={
{{0x0928, 0x093C, 0x00000}, 0x0929},
{{0x0930, 0x093C, 0x00000}, 0x0931},
{{0x0933, 0x093C, 0x00000}, 0x0934},
{{0x0915, 0x093C, 0x00000}, 0x0958},
{{0x0916, 0x093C, 0x00000}, 0x0959},
{{0x0917, 0x093C, 0x00000}, 0x095A},
{{0x091C, 0x093C, 0x00000}, 0x095B},
{{0x0921, 0x093C, 0x00000}, 0x095C},
{{0x0922, 0x093C, 0x00000}, 0x095D},
{{0x092B, 0x093C, 0x00000}, 0x095E},
{{0x092F, 0x093C, 0x00000}, 0x095F}};
static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
{
int cCount = cChars;
WCHAR *input;
if (*pcGlyphs != cChars)
{
ERR("Number of Glyphs and Chars need to match at the beginning\n");
return;
}
input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
memcpy(input, pwcChars, cChars * sizeof(WCHAR));
/* Step 1: Compose Consonant and Nukta */
ComposeConsonants(hdc, input, &cCount, Devanagari_consonants);
TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
/* Step 2: Reorder within Syllables */
Indic_ReorderCharacters( input, cCount, devanagari_lex, Reorder_Like_Devanagari);
TRACE("reordered string %s\n",debugstr_wn(input,cCount));
GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
*pcGlyphs = cCount;
HeapFree(GetProcessHeap(),0,input);
}
static void ShapeCharGlyphProp_Default( 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)
{
int i,k;
@ -1962,6 +2166,61 @@ static void ShapeCharGlyphProp_Tibet( HDC hdc, ScriptCache* psc, SCRIPT_ANALYSIS
}
}
static void ShapeCharGlyphProp_BaseIndic( 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, lexical_function lexical)
{
int i,k;
for (i = 0; i < cGlyphs; i++)
{
int char_index[20];
int char_count = 0;
for (k = 0; k < cChars; k++)
{
if (pwLogClust[k] == i)
{
char_index[char_count] = k;
char_count++;
}
}
if (char_count == 0)
{
FIXME("No chars in this glyph? Must be an error\n");
continue;
}
if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
{
pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
pCharProp[char_index[0]].fCanGlyphAlone = 1;
}
else
pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
pGlyphProp[i].sva.fClusterStart = 0;
for (k = 0; k < char_count && !pGlyphProp[i].sva.fClusterStart; k++)
switch (lexical(pwcChars[char_index[k]]))
{
case lex_Mantra_pre:
case lex_Mantra_post:
case lex_Mantra_above:
case lex_Mantra_below:
case lex_Modifier:
break;
default:
pGlyphProp[i].sva.fClusterStart = 1;
break;
}
}
UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
}
static void ShapeCharGlyphProp_Devanagari( 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 )
{
ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, devanagari_lex);
}
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)
{
if (ShapingData[psa->eScript].charGlyphPropProc)

View File

@ -126,6 +126,7 @@ static inline void _test_items_ok(LPCWSTR string, DWORD cchString,
#define thai_tag MS_MAKE_TAG('t','h','a','i')
#define hebr_tag MS_MAKE_TAG('h','e','b','r')
#define syrc_tag MS_MAKE_TAG('s','y','r','c')
#define deva_tag MS_MAKE_TAG('d','e','v','a')
static void test_ScriptItemize( void )
{
@ -207,6 +208,11 @@ static void test_ScriptItemize( void )
static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
static const itemTest t101[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag},{{0,0,0,0,0},4,0,0,0,-1}};
/* Devanagari */
static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
static const itemTest t111[2] = {{{0,0,0,0,0},0,0,0,0,deva_tag},{{0,0,0,0,0},8,0,0,0,-1}};
static const itemTest t112[2] = {{{0,0,0,0,0},0,0,0,2,deva_tag},{{0,0,0,0,0},8,0,0,0,-1}};
SCRIPT_ITEM items[15];
SCRIPT_CONTROL Control;
SCRIPT_STATE State;
@ -249,6 +255,7 @@ static void test_ScriptItemize( void )
test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
State.uBidiLevel = 0;
test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
@ -265,6 +272,7 @@ static void test_ScriptItemize( void )
test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
State.uBidiLevel = 1;
test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
@ -281,6 +289,7 @@ static void test_ScriptItemize( void )
test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
State.uBidiLevel = 1;
Control.fMergeNeutralItems = TRUE;
@ -298,6 +307,7 @@ static void test_ScriptItemize( void )
test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
test_items_ok(test9,5,&Control,&State,1,t93,FALSE,2);
test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
}
static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,

View File

@ -77,6 +77,8 @@ static const scriptRange scriptRanges[] = {
{ Script_Arabic, 0x750, 0x77f, 0, 0},
/* Thaana: U+0780U+07BF */
{ Script_Thaana, 0x780, 0x7bf, 0, 0},
/* Devanagari: U+0900U+097F */
{ Script_Devanagari, 0x900, 0x97f, Script_Devanagari_Numeric, 0},
/* Sinhala: U+0D80U+0DFF */
{ Script_Sinhala, 0xd80, 0xdff, 0, 0},
/* Thai: U+0E00U+0E7F */
@ -87,6 +89,8 @@ static const scriptRange scriptRanges[] = {
{ Script_Tibetan, 0xf00, 0xfff, Script_Tibetan_Numeric, 0},
/* Georgian: U+10A0U+10FF */
{ Script_Georgian, 0x10a0, 0x10ff, 0, 0},
/* Vedic Extensions: U+1CD0-U+1CFF */
{ Script_Devanagari, 0x1cd0, 0x1cff, Script_Devanagari_Numeric, 0},
/* Phonetic Extensions: U+1D00U+1DBF */
{ Script_Latin, 0x1d00, 0x1dbf, 0, 0},
/* Latin Extended Additional: U+1E00U+1EFF */
@ -106,6 +110,8 @@ static const scriptRange scriptRanges[] = {
{ Script_Latin, 0xa700, 0xa7ff, 0, 0},
/* Phags-pa: U+A840U+A87F */
{ Script_Phags_pa, 0xa840, 0xa87f, 0, 0},
/* Devanagari Extended: U+A8E0-U+A8FF */
{ Script_Devanagari, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric, 0},
/* Latin Ligatures: U+FB00U+FB06 */
{ Script_Latin, 0xfb00, 0xfb06, 0, 0},
/* Armenian ligatures U+FB13..U+FB17 */
@ -201,6 +207,12 @@ static const scriptData scriptInformation[] = {
{{Script_Lao_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
{LANG_LAO, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
MS_MAKE_TAG('l','a','o',' ')},
{{Script_Devanagari, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
{LANG_HINDI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
MS_MAKE_TAG('d','e','v','a')},
{{Script_Devanagari_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
{LANG_HINDI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
MS_MAKE_TAG('d','e','v','a')},
};
static const SCRIPT_PROPERTIES *script_props[] =
@ -216,7 +228,8 @@ static const SCRIPT_PROPERTIES *script_props[] =
&scriptInformation[16].props, &scriptInformation[17].props,
&scriptInformation[18].props, &scriptInformation[19].props,
&scriptInformation[20].props, &scriptInformation[21].props,
&scriptInformation[22].props, &scriptInformation[23].props
&scriptInformation[22].props, &scriptInformation[23].props,
&scriptInformation[24].props, &scriptInformation[25].props
};
typedef struct {

View File

@ -50,6 +50,9 @@
#define Script_Thai_Numeric 21
#define Script_Lao 22
#define Script_Lao_Numeric 23
/* Unicode Chapter 9 */
#define Script_Devanagari 24
#define Script_Devanagari_Numeric 25
#define GLYPH_BLOCK_SHIFT 8
#define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)