WebKit:
[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 #import <unicode/uchar.h>
9
10 static int _unicodeDigitValue(UChar32 c)
11 {
12     return u_charDigitValue(c);
13 }
14
15 static WebCoreUnicodeDirection _unicodeDirection(UChar32 c)
16 {
17     return u_charDirection(c);
18 }
19
20 static bool _unicodeMirrored(UChar32 c)
21 {
22     return u_isMirrored(c);
23 }
24
25 static UChar32 _unicodeMirroredChar(UChar32 c)
26 {
27     return u_charMirror(c);
28 }
29
30 static UChar32 _unicodeLower(UChar32 c)
31 {
32     return u_tolower(c);
33 }
34
35 static UChar32 _unicodeUpper(UChar32 c)
36 {
37     return u_toupper(c);
38 }
39
40 void WebKitInitializeUnicode(void)
41 {
42     WebCoreUnicodeDigitValueFunction = _unicodeDigitValue;
43     WebCoreUnicodeDirectionFunction = _unicodeDirection;
44     WebCoreUnicodeMirroredFunction = _unicodeMirrored;
45     WebCoreUnicodeMirroredCharFunction = _unicodeMirroredChar;
46     WebCoreUnicodeLowerFunction = _unicodeLower;
47     WebCoreUnicodeUpperFunction = _unicodeUpper;
48 }
49
50 bool hasShapeForNextCharacter (const CharacterShapeIterator *iterator)
51 {
52     if (iterator->currentCharacter - iterator->run->characters >= iterator->run->to)
53         return false;
54     return true;
55 }
56
57 UniChar shapeForNextCharacter (CharacterShapeIterator *iterator)
58 {
59     if (!hasShapeForNextCharacter(iterator))
60         return 0;
61     
62     UniChar currentCharacter = *iterator->currentCharacter;
63     iterator->currentCharacter++;
64
65     return currentCharacter;
66 }
67
68 // Assumes input characters are logically ordered.
69 bool initializeCharacterShapeIterator (CharacterShapeIterator *iterator, const WebCoreTextRun *run)
70 {        
71     iterator->currentCharacter = run->characters + run->from;
72     iterator->run = run;
73     
74     return true;
75 }