Merge branch 'upstream'
[profile/ivi/org.tizen.video-player.git] / src / harfbuzz.c
1 /*
2  * Copyright (C) 2006  Behdad Esfahbod
3  *
4  * This is part of HarfBuzz, an OpenType Layout engine library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  */
24
25 #include "harfbuzz.h"
26 #include "hb_unicode_tables.h"
27
28 #include "harfbuzz-buffer.c"
29 #include "harfbuzz-gdef.c"
30 #include "harfbuzz-gsub.c"
31 #include "harfbuzz-gpos.c"
32 #include "harfbuzz-impl.c"
33 #include "harfbuzz-open.c"
34 #include "harfbuzz-stream.c"
35
36
37 HB_Error hb_getScriptID(HB_UShort value, HB_Script *scriptID)
38 {
39         HB_Error error = HB_Err_Ok;
40         hb_uint8 script = value>>8;
41
42         *scriptID = HB_Script_Common;
43
44         if(0 == scriptTableStruct[script].pSubTable)
45         {
46                 *scriptID = (HB_Script)scriptTableStruct[script].scriptID;
47         }
48         else if(scriptTableStruct[script].pSubTable != 0)
49         {
50                 if((value&0xFF) < scriptTableStruct[script].scriptID)//check the size of the sub table array
51                 {
52                         *scriptID = scriptTableStruct[script].pSubTable[(value&0xFF)];
53                 }
54                 else
55                 {
56                         error = HB_Err_Not_Covered;
57                 }
58         }
59         else
60         {
61                 error = HB_Err_Invalid_SubTable;
62         }
63
64         return error;
65 }
66
67 HB_Error hb_getTextWithScriptID(HB_UShort *text, int textLen, HB_Script *scriptID, int *scriptLen)
68 {
69       HB_Script cur_script_id;
70       HB_Error error = HB_Err_Ok;
71       HB_UShort *curText = text ; 
72
73       *scriptID = HB_Script_Common;
74       *scriptLen = 0 ;
75  
76       if((NULL == curText) || (0 == textLen))
77       {
78             return HB_Err_Invalid_Argument;
79       }
80
81       hb_getScriptID(*curText, scriptID);   
82           
83       curText++;
84       textLen--; 
85
86       while(textLen)
87       {
88             if(HB_DOTTED_CIRCLE == *curText     || HB_ZWJ == *curText || HB_ZWNJ == *curText)
89             {
90                   curText++;
91                   textLen--;
92                   continue;
93             } 
94
95             hb_getScriptID(*curText, &cur_script_id); 
96
97             if(*scriptID != cur_script_id)
98             {
99                   break;
100             } 
101
102             curText++;
103             textLen--;
104       } 
105
106       *scriptLen = curText -text ;
107       return error;
108
109 }
110
111
112 int hb_getSyllableLength(HB_UShort *text, int textLen, HB_Script *scriptID)
113 {
114         int len = 0 ;
115         HB_Bool invalid ;
116         switch (*scriptID)
117         {
118         case HB_Script_Devanagari:
119         case HB_Script_Bengali:
120         case HB_Script_Gurmukhi:
121         case HB_Script_Gujarati:
122         case HB_Script_Oriya:
123         case HB_Script_Tamil:
124         case HB_Script_Telugu:
125         case HB_Script_Kannada:
126         case HB_Script_Malayalam:
127         case HB_Script_Sinhala:
128                 len = indic_nextSyllableBoundary(*scriptID, (const HB_UChar16*)text, 0, textLen, &invalid); 
129                 break ;
130         case HB_Script_Khmer:
131                 len = khmer_nextSyllableBoundary(text, 0, textLen, &invalid);
132                 break ;
133         case HB_Script_Myanmar:
134                 len = myanmar_nextSyllableBoundary(text, 0, textLen, &invalid);
135                 break ;
136         case HB_Script_Tibetan:
137                 len = tibetan_nextSyllableBoundary(text, 0, textLen, &invalid);
138                 break ;
139         default:
140                 len = 1 ;
141         }
142
143         return len ;
144 }
145