i Implemented rendering of diacriticals.
[WebKit-https.git] / WebKit / Misc.subproj / WebUnicode.m
1 /*      
2         WebUnicode.m
3         Copyright 2001, 2002, Apple Computer, Inc.
4 */
5 #import <WebKit/WebUnicode.h>
6 #import <WebCore/WebCoreUnicode.h>
7
8
9 static int _unicodeDigitValue(UniChar c)
10 {
11     const char *dec_row = decimal_info[WK_ROW(c)];
12     if( !dec_row )
13         return -1;
14     return dec_row[WK_CELL(c)];
15 }
16
17 static WebCoreUnicodeCategory _unicodeCategory(UniChar c)
18 {
19     return (WebCoreUnicodeCategory)(unicode_info[WK_ROW(c)][WK_CELL(c)]);
20 }
21
22 static WebCoreUnicodeDirection _unicodeDirection(UniChar c)
23 {
24     const unsigned char *rowp = direction_info[WK_ROW(c)];
25     
26     if(!rowp) 
27         return DirectionL;
28     return (WebCoreUnicodeDirection) ( *(rowp+WK_CELL(c)) &0x1f );
29 }
30
31 static WebCoreUnicodeJoining _unicodeJoining(UniChar c)
32 {
33     const unsigned char *rowp = direction_info[WK_ROW(c)];
34     if ( !rowp )
35         return JoiningOther;
36     return (WebCoreUnicodeJoining) ((*(rowp+WK_CELL(c)) >> 5) &0x3);
37 }
38
39 static WebCoreUnicodeDecomposition _unicodeDecompositionTag(UniChar c)
40 {
41     const unsigned short *r = decomposition_info[WK_ROW(c)];
42     if(!r)
43         return DecompositionSingle;
44
45     unsigned short pos = r[WK_CELL(c)];
46     if(!pos)
47         return DecompositionSingle;
48
49     return (WebCoreUnicodeDecomposition) decomposition_map[pos];
50 }
51
52 static bool _unicodeMirrored(UniChar c)
53 {
54     const unsigned char *rowp = direction_info[WK_ROW(c)];
55     if ( !rowp )
56         return FALSE;
57     return *(rowp+WK_CELL(c))>128;
58 }
59
60 static UniChar _unicodeMirroredChar(UniChar c)
61 {
62     if(!_unicodeMirrored(c))
63         return c;
64
65     int i;
66     for (i = 0; i < symmetricPairsSize; i ++) {
67         if (symmetricPairs[i] == c)
68           return symmetricPairs[(i%2) ? (i-1) : (i+1)];
69     }
70     return c;
71 }
72
73 static WebCoreUnicodeCombiningClass _unicodeCombiningClass (UniChar c)
74 {
75     const unsigned char *rowp = combining_info[WK_ROW(c)];
76     if ( !rowp )
77         return 0;
78     return *(rowp+WK_CELL(c));
79 }
80
81 static UniChar _unicodeLower(UniChar c)
82 {
83     if ( _unicodeCategory(c) != Letter_Uppercase )
84         return c;
85     unsigned short lower = *( case_info[WK_ROW(c)] + WK_CELL(c) );
86     if ( lower == 0 )
87         return c;
88     return lower;
89 }
90
91 static UniChar _unicodeUpper(UniChar c)
92 {
93     if ( _unicodeCategory(c) != Letter_Lowercase )
94         return c;
95     unsigned short upper = *(case_info[WK_ROW(c)]+WK_CELL(c));
96     if ( upper == 0 )
97         return c;
98     return upper;
99 }
100
101 void WebKitInitializeUnicode(void)
102 {
103     WebCoreUnicodeDigitValueFunction = _unicodeDigitValue;
104     WebCoreUnicodeCategoryFunction = _unicodeCategory;
105     WebCoreUnicodeDirectionFunction = _unicodeDirection;
106     WebCoreUnicodeJoiningFunction = _unicodeJoining;
107     WebCoreUnicodeDecompositionTagFunction = _unicodeDecompositionTag;
108     WebCoreUnicodeMirroredFunction = _unicodeMirrored;
109     WebCoreUnicodeMirroredCharFunction = _unicodeMirroredChar;
110     WebCoreUnicodeCombiningClassFunction = _unicodeCombiningClass;
111     WebCoreUnicodeLowerFunction = _unicodeLower;
112     WebCoreUnicodeUpperFunction = _unicodeUpper;
113 }
114