8860a142b0622f4865bd56313ef634579b748d33
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / script.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // FILE HEADER
19 #include <dali-toolkit/public-api/text/script.h>
20
21 namespace Dali
22 {
23
24 namespace Toolkit
25 {
26
27 namespace Text
28 {
29
30 Script GetCharacterScript( Character character )
31 {
32   // Latin script:
33   // 0x0000 - 0x007f C0 Controls and Basic Latin
34   // 0x0080 - 0x00ff C1 Controls and Latin-1 Supplement
35   // 0x0100 - 0x017f Latin Extended-A
36   // 0x0180 - 0x024f Latin Extended-B
37   // 0x0250 - 0x02af IPA Extensions
38   // 0x02b0 - 0x02ff Spacing Modifier Letters
39   // 0x1d00 - 0x1d7f Phonetic Extensions
40   // 0x1d80 - 0x1dbf Phonetic Extensions Supplement
41   // 0x1e00 - 0x1eff Latin Extended Additional
42   // 0x2070 - 0x209f Superscripts and Subscripts
43   // 0x2100 - 0x214f Letterlike symbols
44   // 0x2150 - 0x218f Number Forms
45   // 0x2c60 - 0x2c7f Latin Extended-C
46   // 0xa720 - 0xa7ff Latin Extended-D
47   // 0xab30 - 0xab6f Latin Extended-E
48   // 0xfb00 - 0xfb4f Alphabetic Presentation Forms
49   // 0xff00 - 0xffef Halfwidth and Fullwidth Forms
50
51   // Brahmic scripts:
52   // 0x0900 - 0x097f Devanagari
53   // 0x0980 - 0x09ff Bengali
54   // 0x0a00 - 0x0a7f Gurmukhi
55   // 0x0a80 - 0x0aff Gujarati
56   // 0x0b00 - 0x0b7f Oriya
57   // 0x0b80 - 0x0bff Tamil
58   // 0x0c00 - 0x0c7f Telugu
59   // 0x0c80 - 0x0cff Kannada
60   // 0x0d00 - 0x0d7f Malayalam
61
62   // Sinhala script.
63   // 0x0d80 - 0x0dff Sinhala
64
65   // Arabic script.
66   // 0x0600 - 0x06ff Arabic
67   // 0x0750 - 0x077f Arabic Supplement
68   // 0x08A0 - 0x08ff Arabic Extended-A
69   // 0xfb50 - 0xfdff Arabic Presentation Forms-A
70   // 0xfe70 - 0xfeff Arabic Presentation Forms-B
71   // 0x1ee00 - 0x1eeff Arabic Mathematical Alphabetic Symbols
72
73   // CJK and Vietnamese script.
74   // 0x2E80 - 0x2eff CJK Radicals Supplement
75   // 0x3000 - 0x303f CJK Symbols and Punctuation
76   // 0x3200 - 0x32ff Enclosed CJK Letters and Months
77   // 0x3400 - 0x4dbf CJK Unified Ideographs Extension A
78   // 0x4e00 - 0x62ff CJK Unified Ideographs
79   // 0x6300 - 0x77ff CJK Unified Ideographs
80   // 0x7800 - 0x8cff CJK Unified Ideographs
81   // 0x8d00 - 0x9fff CJK Unified Ideographs
82   // 0x20000 - 0x215ff CJK Unified Ideographs Extension B
83   // 0x21600 - 0x230ff CJK Unified Ideographs Extension B
84   // 0x23100 - 0x245ff CJK Unified Ideographs Extension B
85   // 0x24600 - 0x260ff CJK Unified Ideographs Extension B
86   // 0x26100 - 0x275ff CJK Unified Ideographs Extension B
87   // 0x27600 - 0x290ff CJK Unified Ideographs Extension B
88   // 0x29100 - 0x2a6df CJK Unified Ideographs Extension B
89   // 2a700-2b73f. CJK Unified Ideographs Extension C
90   // 2b740-2b81f. CJK Unified Ideographs Extension D
91
92   // Hangul script
93   // 0x1100 - 0x11ff Hangul jamo
94   // 0x3130 - 0x318f Hangul Compatibility Jamo
95   // 0xa960 - 0xa97f Hangul Jamo Extended-A
96   // 0xac00 - 0xd7af Hangul Syllables
97   // 0xd7b0 - 0xd7ff Hangul Jamo Extended-B
98
99   // Khmer script
100   // 0x1780 - 0x17ff Khmer
101   // 0x19e0 - 0x19ff Khmer Symbols
102
103   // Lao script
104   // 0x0e80 - 0x0eff Lao
105
106   // Thai script
107   // 0x0e00 - 0x0e7f Thai
108
109   // Burmese script
110   // 0x1000 - 0x104f Myanmar
111
112
113   if( character <= 0x0cff )
114   {
115     if( character <= 0x09ff )
116     {
117       if( character <= 0x077f )
118       {
119         if( character <= 0x02ff )
120         {
121           return TextAbstraction::LATIN;
122         }
123         if( ( 0x0600 <= character ) && ( character <= 0x06ff ) )
124         {
125           return TextAbstraction::ARABIC;
126         }
127         if( ( 0x0750 <= character ) && ( character <= 0x077f ) )
128         {
129           return TextAbstraction::ARABIC;
130         }
131       }
132       else // > 0x077f
133       {
134         if( ( 0x08A0 <= character ) && ( character <= 0x08ff ) )
135         {
136           return TextAbstraction::ARABIC;
137         }
138         if( ( 0x0900 <= character ) && ( character <= 0x097f ) )
139         {
140           return TextAbstraction::DEVANAGARI;
141         }
142         if( ( 0x0980 <= character ) && ( character <= 0x09ff ) )
143         {
144           return TextAbstraction::BENGALI;
145         }
146       }
147     }
148     else // > 0x09ff
149     {
150       if( character <= 0x0b7f )
151       {
152         if( ( 0x0a00 <= character ) && ( character <= 0x0a7f ) )
153         {
154           return TextAbstraction::GURMUKHI;
155         }
156         if( ( 0x0a80 <= character ) && ( character <= 0x0aff ) )
157         {
158           return TextAbstraction::GUJARATI;
159         }
160         if( ( 0x0b00 <= character ) && ( character <= 0x0b7f ) )
161         {
162           return TextAbstraction::ORIYA;
163         }
164       }
165       else // > 0x0b7f
166       {
167         if( ( 0x0b80 <= character ) && ( character <= 0x0bff ) )
168         {
169           return TextAbstraction::TAMIL;
170         }
171         if( ( 0x0c00 <= character ) && ( character <= 0x0c7f ) )
172         {
173           return TextAbstraction::TELUGU;
174         }
175         if( ( 0x0c80 <= character ) && ( character <= 0x0cff ) )
176         {
177           return TextAbstraction::KANNADA;
178         }
179       }
180     }
181   }
182   else // > 0x0cff
183   {
184     if( character <= 0x2c7f )
185     {
186       if( character <= 0x1eff )
187       {
188         if( ( 0x0d00 <= character ) && ( character <= 0x0d7f ) )
189         {
190           return TextAbstraction::MALAYALAM;
191         }
192         if( ( 0x0d80 <= character ) && ( character <= 0x0dff ) )
193         {
194           return TextAbstraction::SINHALA;
195         }
196         if( ( 0x0e00 <= character ) && ( character <= 0x0e7f ) )
197         {
198           return TextAbstraction::THAI;
199         }
200         if( ( 0x0e80 <= character ) && ( character <= 0x0eff ) )
201         {
202           return TextAbstraction::LAO;
203         }
204         if( ( 0x1000 <= character ) && ( character <= 0x104f ) )
205         {
206           return TextAbstraction::BURMESE;
207         }
208         if( ( 0x1100 <= character ) && ( character <= 0x11ff ) )
209         {
210           return TextAbstraction::HANGUL;
211         }
212         if( ( 0x1780 <= character ) && ( character <= 0x17ff ) )
213         {
214           return TextAbstraction::KHMER;
215         }
216         if( ( 0x19e0 <= character ) && ( character <= 0x19ff ) )
217         {
218           return TextAbstraction::KHMER;
219         }
220         if( ( 0x1d00 <= character ) && ( character <= 0x1eff ) )
221         {
222           return TextAbstraction::LATIN;
223         }
224       }
225       else // > 0x1eff
226       {
227         if( ( 0x2070 <= character ) && ( character <= 0x209f ) )
228         {
229           return TextAbstraction::LATIN;
230         }
231         if( ( 0x2100 <= character ) && ( character <= 0x218f ) )
232         {
233           return TextAbstraction::LATIN;
234         }
235         if( ( 0x2c60 <= character ) && ( character <= 0x2c7f ) )
236         {
237           return TextAbstraction::LATIN;
238         }
239       }
240     }
241     else // > 0x2c7f
242     {
243       if( character <= 0xfdff )
244       {
245         if( ( 0x2e80 <= character ) && ( character <= 0x2eff ) )
246         {
247           return TextAbstraction::CJK;
248         }
249         if( ( 0x3000 <= character ) && ( character <= 0x303f ) )
250         {
251           return TextAbstraction::CJK;
252         }
253         if( ( 0x3130 <= character ) && ( character <= 0x318f ) )
254         {
255           return TextAbstraction::HANGUL;
256         }
257         if( ( 0x3200 <= character ) && ( character <= 0x32ff ) )
258         {
259           return TextAbstraction::CJK;
260         }
261         if( ( 0x3400 <= character ) && ( character <= 0x4dbf ) )
262         {
263           return TextAbstraction::CJK;
264         }
265         if( ( 0x4e00 <= character ) && ( character <= 0x62ff ) )
266         {
267           return TextAbstraction::CJK;
268         }
269         if( ( 0x6300 <= character ) && ( character <= 0x77ff ) )
270         {
271           return TextAbstraction::CJK;
272         }
273         if( ( 0x7800 <= character ) && ( character <= 0x8cff ) )
274         {
275           return TextAbstraction::CJK;
276         }
277         if( ( 0x8d00 <= character ) && ( character <= 0x9fff ) )
278         {
279           return TextAbstraction::CJK;
280         }
281         if( ( 0xa720 <= character ) && ( character <= 0xa7ff ) )
282         {
283           return TextAbstraction::LATIN;
284         }
285         if( ( 0xa960 <= character ) && ( character <= 0xa97f ) )
286         {
287           return TextAbstraction::HANGUL;
288         }
289         if( ( 0xab30 <= character ) && ( character <= 0xab6f ) )
290         {
291           return TextAbstraction::LATIN;
292         }
293         if( ( 0xac00 <= character ) && ( character <= 0xd7af ) )
294         {
295           return TextAbstraction::HANGUL;
296         }
297         if( ( 0xd7b0 <= character ) && ( character <= 0xd7ff ) )
298         {
299           return TextAbstraction::HANGUL;
300         }
301         if( ( 0xfb00 <= character ) && ( character <= 0xfb4f ) )
302         {
303           return TextAbstraction::LATIN;
304         }
305         if( ( 0xfb50 <= character ) && ( character <= 0xfdff ) )
306         {
307           return TextAbstraction::ARABIC;
308         }
309       }
310       else // > 0xfdff
311       {
312         if( ( 0xfe70 <= character ) && ( character <= 0xfeff ) )
313         {
314           return TextAbstraction::ARABIC;
315         }
316         if( ( 0xff00 <= character ) && ( character <= 0xffef ) )
317         {
318           return TextAbstraction::LATIN;
319         }
320         if( ( 0x1ee00 <= character ) && ( character <= 0x1eeff ) )
321         {
322           return TextAbstraction::ARABIC;
323         }
324         if( ( 0x20000 <= character ) && ( character <= 0x215ff ) )
325         {
326           return TextAbstraction::CJK;
327         }
328         if( ( 0x21600 <= character ) && ( character <= 0x230ff ) )
329         {
330           return TextAbstraction::CJK;
331         }
332         if( ( 0x23100 <= character ) && ( character <= 0x245ff ) )
333         {
334           return TextAbstraction::CJK;
335         }
336         if( ( 0x24600 <= character ) && ( character <= 0x260ff ) )
337         {
338           return TextAbstraction::CJK;
339         }
340         if( ( 0x26100 <= character ) && ( character <= 0x275ff ) )
341         {
342           return TextAbstraction::CJK;
343         }
344         if( ( 0x27600 <= character ) && ( character <= 0x290ff ) )
345         {
346           return TextAbstraction::CJK;
347         }
348         if( ( 0x29100 <= character ) && ( character <= 0x2a6df ) )
349         {
350           return TextAbstraction::CJK;
351         }
352         if( ( 0x2a700 <= character ) && ( character <= 0x2b73f ) )
353         {
354           return TextAbstraction::CJK;
355         }
356         if( ( 0x2b740 <= character ) && ( character <= 0x2b81f ) )
357         {
358           return TextAbstraction::CJK;
359         }
360       }
361     }
362   }
363
364   return TextAbstraction::UNKNOWN;
365 }
366
367 } // namespace Text
368
369 } // namespace Toolkit
370
371 } // namespace Dali