Added script value for Emoji
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / 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/internal/text/script.h>
20
21 namespace Dali
22 {
23
24 namespace Toolkit
25 {
26
27 namespace Text
28 {
29
30 namespace
31 {
32 const unsigned int WHITE_SPACE_THRESHOLD  = 0x21; ///< All characters below 0x21 are considered white spaces.
33 const unsigned int CHAR_FL   = 0x000A; ///< NL Line feed, new line.
34 const unsigned int CHAR_VT   = 0x000B; ///< Vertical tab.
35 const unsigned int CHAR_FF   = 0x000C; ///< NP Form feed, new page.
36 const unsigned int CHAR_NEL  = 0x0085; ///< Next line.
37 const unsigned int CHAR_LS   = 0x2028; ///< Line separator.
38 const unsigned int CHAR_PS   = 0x2029; ///< Paragraph separator
39
40 const unsigned int CHAR_ZWS  = 0x200B; ///< Zero width space.
41 const unsigned int CHAR_ZWNJ = 0x200C; ///< Zero width non joiner.
42 const unsigned int CHAR_ZWJ  = 0x200D; ///< Zero width joiner.
43 const unsigned int CHAR_LTRM = 0x200E; ///< Left to Right Mark.
44 const unsigned int CHAR_RTLM = 0x200F; ///< Right to Left Mark.
45 const unsigned int CHAR_TS   = 0x2009; ///< Thin Space.
46 } // namespace
47
48 Script GetCharacterScript( Character character )
49 {
50   // Latin script:
51   // 0x0000 - 0x007f C0 Controls and Basic Latin
52   // 0x0080 - 0x00ff C1 Controls and Latin-1 Supplement
53   // 0x0100 - 0x017f Latin Extended-A
54   // 0x0180 - 0x024f Latin Extended-B
55   // 0x0250 - 0x02af IPA Extensions
56   // 0x02b0 - 0x02ff Spacing Modifier Letters
57   // 0x1d00 - 0x1d7f Phonetic Extensions
58   // 0x1d80 - 0x1dbf Phonetic Extensions Supplement
59   // 0x1e00 - 0x1eff Latin Extended Additional
60   // 0x2070 - 0x209f Superscripts and Subscripts
61   // 0x2100 - 0x214f Letterlike symbols
62   // 0x2150 - 0x218f Number Forms
63   // 0x2c60 - 0x2c7f Latin Extended-C
64   // 0xa720 - 0xa7ff Latin Extended-D
65   // 0xab30 - 0xab6f Latin Extended-E
66   // 0xfb00 - 0xfb4f Alphabetic Presentation Forms
67   // 0xff00 - 0xffef Halfwidth and Fullwidth Forms
68
69   // Brahmic scripts:
70   // 0x0900 - 0x097f Devanagari
71   // 0x0980 - 0x09ff Bengali
72   // 0x0a00 - 0x0a7f Gurmukhi
73   // 0x0a80 - 0x0aff Gujarati
74   // 0x0b00 - 0x0b7f Oriya
75   // 0x0b80 - 0x0bff Tamil
76   // 0x0c00 - 0x0c7f Telugu
77   // 0x0c80 - 0x0cff Kannada
78   // 0x0d00 - 0x0d7f Malayalam
79
80   // Sinhala script.
81   // 0x0d80 - 0x0dff Sinhala
82
83   // Arabic script.
84   // 0x0600 - 0x06ff Arabic
85   // 0x0750 - 0x077f Arabic Supplement
86   // 0x08A0 - 0x08ff Arabic Extended-A
87   // 0xfb50 - 0xfdff Arabic Presentation Forms-A
88   // 0xfe70 - 0xfeff Arabic Presentation Forms-B
89   // 0x1ee00 - 0x1eeff Arabic Mathematical Alphabetic Symbols
90
91   // CJK and Vietnamese script.
92   // 0x2E80 - 0x2eff CJK Radicals Supplement
93   // 0x3000 - 0x303f CJK Symbols and Punctuation
94   // 0x3200 - 0x32ff Enclosed CJK Letters and Months
95   // 0x3400 - 0x4dbf CJK Unified Ideographs Extension A
96   // 0x4e00 - 0x62ff CJK Unified Ideographs
97   // 0x6300 - 0x77ff CJK Unified Ideographs
98   // 0x7800 - 0x8cff CJK Unified Ideographs
99   // 0x8d00 - 0x9fff CJK Unified Ideographs
100   // 0x20000 - 0x215ff CJK Unified Ideographs Extension B
101   // 0x21600 - 0x230ff CJK Unified Ideographs Extension B
102   // 0x23100 - 0x245ff CJK Unified Ideographs Extension B
103   // 0x24600 - 0x260ff CJK Unified Ideographs Extension B
104   // 0x26100 - 0x275ff CJK Unified Ideographs Extension B
105   // 0x27600 - 0x290ff CJK Unified Ideographs Extension B
106   // 0x29100 - 0x2a6df CJK Unified Ideographs Extension B
107   // 2a700-2b73f. CJK Unified Ideographs Extension C
108   // 2b740-2b81f. CJK Unified Ideographs Extension D
109
110   // Hangul script
111   // 0x1100 - 0x11ff Hangul jamo
112   // 0x3130 - 0x318f Hangul Compatibility Jamo
113   // 0xa960 - 0xa97f Hangul Jamo Extended-A
114   // 0xac00 - 0xd7af Hangul Syllables
115   // 0xd7b0 - 0xd7ff Hangul Jamo Extended-B
116
117   // Khmer script
118   // 0x1780 - 0x17ff Khmer
119   // 0x19e0 - 0x19ff Khmer Symbols
120
121   // Lao script
122   // 0x0e80 - 0x0eff Lao
123
124   // Thai script
125   // 0x0e00 - 0x0e7f Thai
126
127   // Burmese script
128   // 0x1000 - 0x109f Myanmar
129
130   // The Emoji which map to standardized Unicode characters
131   // 1. Emoticons ( 1F601 - 1F64F )
132   // 2. Dingbats ( 2702 - 27B0 )
133   // 3. Transport and map symbols ( 1F680 - 1F6C0 )
134   // 4. Enclosed characters ( 24C2 - 1F251 )
135   // 5. Uncategorized :-S
136   // 6. Additional Emoticons ( 1F600 - 1F636 )
137   // 6b. Additional transport and map symbols ( 1F681 - 1F6C5 )
138   // 6c. Other additional symbols ( 1F30D - 1F567 )
139
140   if( character <= 0x0cff )
141   {
142     if( character <= 0x09ff )
143     {
144       if( character <= 0x077f )
145       {
146         if( character == 0x00A9 )
147         {
148           return TextAbstraction::EMOJI; // 5. Uncategorized: copyright sign
149         }
150         if( character == 0x00AE )
151         {
152           return TextAbstraction::EMOJI; // 5. Uncategorized: registered sign
153         }
154         if( character <= 0x02ff )
155         {
156           return TextAbstraction::LATIN;
157         }
158         if( ( 0x0600 <= character ) && ( character <= 0x06ff ) )
159         {
160           return TextAbstraction::ARABIC;
161         }
162         if( ( 0x0750 <= character ) && ( character <= 0x077f ) )
163         {
164           return TextAbstraction::ARABIC;
165         }
166       }
167       else // > 0x077f
168       {
169         if( ( 0x08A0 <= character ) && ( character <= 0x08ff ) )
170         {
171           return TextAbstraction::ARABIC;
172         }
173         if( ( 0x0900 <= character ) && ( character <= 0x097f ) )
174         {
175           return TextAbstraction::DEVANAGARI;
176         }
177         if( ( 0x0980 <= character ) && ( character <= 0x09ff ) )
178         {
179           return TextAbstraction::BENGALI;
180         }
181       }
182     }
183     else // > 0x09ff
184     {
185       if( character <= 0x0b7f )
186       {
187         if( ( 0x0a00 <= character ) && ( character <= 0x0a7f ) )
188         {
189           return TextAbstraction::GURMUKHI;
190         }
191         if( ( 0x0a80 <= character ) && ( character <= 0x0aff ) )
192         {
193           return TextAbstraction::GUJARATI;
194         }
195         if( ( 0x0b00 <= character ) && ( character <= 0x0b7f ) )
196         {
197           return TextAbstraction::ORIYA;
198         }
199       }
200       else // > 0x0b7f
201       {
202         if( ( 0x0b80 <= character ) && ( character <= 0x0bff ) )
203         {
204           return TextAbstraction::TAMIL;
205         }
206         if( ( 0x0c00 <= character ) && ( character <= 0x0c7f ) )
207         {
208           return TextAbstraction::TELUGU;
209         }
210         if( ( 0x0c80 <= character ) && ( character <= 0x0cff ) )
211         {
212           return TextAbstraction::KANNADA;
213         }
214       }
215     }
216   }
217   else // > 0x0cff
218   {
219     if( character <= 0x2c7f )
220     {
221       if( character <= 0x1eff )
222       {
223         if( ( 0x0d00 <= character ) && ( character <= 0x0d7f ) )
224         {
225           return TextAbstraction::MALAYALAM;
226         }
227         if( ( 0x0d80 <= character ) && ( character <= 0x0dff ) )
228         {
229           return TextAbstraction::SINHALA;
230         }
231         if( ( 0x0e00 <= character ) && ( character <= 0x0e7f ) )
232         {
233           return TextAbstraction::THAI;
234         }
235         if( ( 0x0e80 <= character ) && ( character <= 0x0eff ) )
236         {
237           return TextAbstraction::LAO;
238         }
239         if( ( 0x1000 <= character ) && ( character <= 0x109f ) )
240         {
241           return TextAbstraction::BURMESE;
242         }
243         if( ( 0x1100 <= character ) && ( character <= 0x11ff ) )
244         {
245           return TextAbstraction::HANGUL;
246         }
247         if( ( 0x1780 <= character ) && ( character <= 0x17ff ) )
248         {
249           return TextAbstraction::KHMER;
250         }
251         if( ( 0x19e0 <= character ) && ( character <= 0x19ff ) )
252         {
253           return TextAbstraction::KHMER;
254         }
255         if( ( 0x1d00 <= character ) && ( character <= 0x1eff ) )
256         {
257           return TextAbstraction::LATIN;
258         }
259       }
260       else // > 0x1eff
261       {
262         if( character == 0x203c )
263         {
264           return TextAbstraction::EMOJI; // 5. Uncategorized: double exclamation mark
265         }
266         if( character == 0x2049 )
267         {
268           return TextAbstraction::EMOJI; // 5. Uncategorized: exclamation question mark
269         }
270         if( ( 0x2070 <= character ) && ( character <= 0x209f ) )
271         {
272           return TextAbstraction::LATIN;
273         }
274         if( character == 0x20e3 )
275         {
276           return TextAbstraction::EMOJI; // 5. Uncategorized: combining enclosing keycap
277         }
278         if( character == 0x2122 )
279         {
280           return TextAbstraction::EMOJI; // 5. Uncategorized: trade mark sign
281         }
282         if( character == 0x2139 )
283         {
284           return TextAbstraction::EMOJI; // 5. Uncategorized: information source
285         }
286         if( ( 0x2100 <= character ) && ( character <= 0x218f ) )
287         {
288           return TextAbstraction::LATIN;
289         }
290         // U+2194 5. Uncategorized: left right arrow
291         // U+2B55 5. Uncategorized: heavy large circle
292         if( ( 0x2194 <= character ) && ( character <= 0x2B55 ) )
293         {
294           return TextAbstraction::EMOJI;
295         }
296         if( ( 0x2c60 <= character ) && ( character <= 0x2c7f ) )
297         {
298           return TextAbstraction::LATIN;
299         }
300       }
301     }
302     else // > 0x2c7f
303     {
304       if( character <= 0xfdff )
305       {
306         if( ( 0x2e80 <= character ) && ( character <= 0x2eff ) )
307         {
308           return TextAbstraction::CJK;
309         }
310         if( ( 0x3000 <= character ) && ( character <= 0x303f ) )
311         {
312           return TextAbstraction::CJK;
313         }
314         if( ( 0x3130 <= character ) && ( character <= 0x318f ) )
315         {
316           return TextAbstraction::HANGUL;
317         }
318         if( ( 0x3200 <= character ) && ( character <= 0x32ff ) )
319         {
320           return TextAbstraction::CJK;
321         }
322         if( ( 0x3400 <= character ) && ( character <= 0x4dbf ) )
323         {
324           return TextAbstraction::CJK;
325         }
326         if( ( 0x4e00 <= character ) && ( character <= 0x62ff ) )
327         {
328           return TextAbstraction::CJK;
329         }
330         if( ( 0x6300 <= character ) && ( character <= 0x77ff ) )
331         {
332           return TextAbstraction::CJK;
333         }
334         if( ( 0x7800 <= character ) && ( character <= 0x8cff ) )
335         {
336           return TextAbstraction::CJK;
337         }
338         if( ( 0x8d00 <= character ) && ( character <= 0x9fff ) )
339         {
340           return TextAbstraction::CJK;
341         }
342         if( ( 0xa720 <= character ) && ( character <= 0xa7ff ) )
343         {
344           return TextAbstraction::LATIN;
345         }
346         if( ( 0xa960 <= character ) && ( character <= 0xa97f ) )
347         {
348           return TextAbstraction::HANGUL;
349         }
350         if( ( 0xab30 <= character ) && ( character <= 0xab6f ) )
351         {
352           return TextAbstraction::LATIN;
353         }
354         if( ( 0xac00 <= character ) && ( character <= 0xd7af ) )
355         {
356           return TextAbstraction::HANGUL;
357         }
358         if( ( 0xd7b0 <= character ) && ( character <= 0xd7ff ) )
359         {
360           return TextAbstraction::HANGUL;
361         }
362         if( ( 0xfb00 <= character ) && ( character <= 0xfb4f ) )
363         {
364           return TextAbstraction::LATIN;
365         }
366         if( ( 0xfb50 <= character ) && ( character <= 0xfdff ) )
367         {
368           return TextAbstraction::ARABIC;
369         }
370       }
371       else // > 0xfdff
372       {
373         if( ( 0xfe70 <= character ) && ( character <= 0xfeff ) )
374         {
375           return TextAbstraction::ARABIC;
376         }
377         if( ( 0xff00 <= character ) && ( character <= 0xffef ) )
378         {
379           return TextAbstraction::LATIN;
380         }
381         if( ( 0x1ee00 <= character ) && ( character <= 0x1eeff ) )
382         {
383           return TextAbstraction::ARABIC;
384         }
385         // U+1f170 4. Enclosed characters: negative squared latin capital letter A
386         // U+1f6c5 6b. Additional transport and map symbols
387         if( ( 0x1f170 <= character ) && ( character <= 0x1f6c5 ) )
388         {
389           return TextAbstraction::EMOJI;
390         }
391         if( ( 0x20000 <= character ) && ( character <= 0x215ff ) )
392         {
393           return TextAbstraction::CJK;
394         }
395         if( ( 0x21600 <= character ) && ( character <= 0x230ff ) )
396         {
397           return TextAbstraction::CJK;
398         }
399         if( ( 0x23100 <= character ) && ( character <= 0x245ff ) )
400         {
401           return TextAbstraction::CJK;
402         }
403         if( ( 0x24600 <= character ) && ( character <= 0x260ff ) )
404         {
405           return TextAbstraction::CJK;
406         }
407         if( ( 0x26100 <= character ) && ( character <= 0x275ff ) )
408         {
409           return TextAbstraction::CJK;
410         }
411         if( ( 0x27600 <= character ) && ( character <= 0x290ff ) )
412         {
413           return TextAbstraction::CJK;
414         }
415         if( ( 0x29100 <= character ) && ( character <= 0x2a6df ) )
416         {
417           return TextAbstraction::CJK;
418         }
419         if( ( 0x2a700 <= character ) && ( character <= 0x2b73f ) )
420         {
421           return TextAbstraction::CJK;
422         }
423         if( ( 0x2b740 <= character ) && ( character <= 0x2b81f ) )
424         {
425           return TextAbstraction::CJK;
426         }
427       }
428     }
429   }
430
431   return TextAbstraction::UNKNOWN;
432 }
433
434 bool IsWhiteSpace( Character character )
435 {
436   return character < WHITE_SPACE_THRESHOLD;
437 }
438
439 bool IsNewParagraph( Character character )
440 {
441   return ( ( CHAR_FL == character )  ||
442            ( CHAR_VT == character )  ||
443            ( CHAR_FF == character )  ||
444            ( CHAR_NEL == character ) ||
445            ( CHAR_LS == character )  ||
446            ( CHAR_PS == character ) );
447 }
448
449 bool IsZeroWidthNonJoiner( Character character )
450 {
451   return CHAR_ZWNJ == character;
452 }
453
454 bool IsZeroWidthJoiner( Character character )
455 {
456   return CHAR_ZWJ == character;
457 }
458
459 bool IsZeroWidthSpace( Character character )
460 {
461   return CHAR_ZWS == character;
462 }
463
464 bool IsLeftToRightMark( Character character )
465 {
466   return CHAR_LTRM == character;
467 }
468
469 bool IsRightToLeftMark( Character character )
470 {
471   return CHAR_RTLM == character;
472 }
473
474 bool IsThinSpace( Character character )
475 {
476   return CHAR_TS == character;
477 }
478
479 } // namespace Text
480
481 } // namespace Toolkit
482
483 } // namespace Dali