Refactor script.cpp
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / script.cpp
1 /*
2  * Copyright (c) 2020 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/devel-api/text-abstraction/script.h>
20
21 namespace Dali
22 {
23
24 namespace TextAbstraction
25 {
26
27 namespace
28 {
29 constexpr unsigned int WHITE_SPACE_THRESHOLD  = 0x21; ///< All characters below 0x21 are considered white spaces.
30 constexpr unsigned int CHAR_LF   = 0x000A; ///< NL Line feed, new line.
31 constexpr unsigned int CHAR_VT   = 0x000B; ///< Vertical tab.
32 constexpr unsigned int CHAR_FF   = 0x000C; ///< NP Form feed, new page.
33 constexpr unsigned int CHAR_CR   = 0x000D; ///< Carriage return, new line.
34 constexpr unsigned int CHAR_NEL  = 0x0085; ///< Next line.
35 constexpr unsigned int CHAR_LS   = 0x2028; ///< Line separator.
36 constexpr unsigned int CHAR_PS   = 0x2029; ///< Paragraph separator
37
38 constexpr unsigned int CHAR_ZWS  = 0x200B; ///< Zero width space.
39 constexpr unsigned int CHAR_ZWNJ = 0x200C; ///< Zero width non joiner.
40 constexpr unsigned int CHAR_ZWJ  = 0x200D; ///< Zero width joiner.
41 constexpr unsigned int CHAR_LTRM = 0x200E; ///< Left to Right Mark.
42 constexpr unsigned int CHAR_RTLM = 0x200F; ///< Right to Left Mark.
43 constexpr unsigned int CHAR_TS   = 0x2009; ///< Thin Space.
44
45 // Latin script:   It contains punctuation characters and symbols which are not part of the latin script. https://en.wikipedia.org/wiki/Latin_script_in_Unicode
46 // 0x0000 - 0x007f C0 Controls and Basic Latin
47 //
48 //                 ASCII digits (not part of LATIN script):
49 //                 0x0030 - 0x0039
50 //
51 //                 ASCII punctuation and symbols (not part of LATIN script):
52 //                 0x0020 - 0x002F
53 //                 0x003A - 0x0040
54 //                 0x005B - 0x0060
55 //                 0x007B - 0x007E
56 //
57 //                 Controls (not part of LATIN script):
58 //                 0x007F
59 //
60 // 0x0080 - 0x00ff C1 Controls and Latin-1 Supplement
61 //
62 //                 Controls (not part of LATIN script):
63 //                 0x0080 - 0x009F
64 //
65 //                 Punctuations and symbols (not part of LATIN script):
66 //                 0x00A0 - 0x00BF
67 //
68 //                 Mathematical operators (not part of LATIN script):
69 //                 0x00D7
70 //                 0x00F7
71 //
72 // 0x0100 - 0x017f Latin Extended-A
73 // 0x0180 - 0x024f Latin Extended-B
74 // 0x0250 - 0x02af IPA Extensions
75 // 0x02b0 - 0x02ff Spacing Modifier Letters
76 //
77 //                 Punctuation (not part of LATIN script):
78 //                 0x02B9 - 0x02BF
79 //
80 // 0x1d00 - 0x1d7f Phonetic Extensions
81 //
82 //                 Uralic Phonetic (not part of LATIN script):
83 //                 0x1D26 - 0x1D2B
84 //
85 //                 Subscripts and superscripts
86 //                 0x1D5D - 0x1D61
87 //                 0x1D66 - 0x1D6A
88 //                 0x1D78
89 //
90 // 0x1d80 - 0x1dbf Phonetic Extensions Supplement
91 //
92 //                 0x1DBF (subscript or superscript. Not part of LATIN script )
93 //
94 // 0x1e00 - 0x1eff Latin Extended Additional
95 // 0x2070 - 0x209f Superscripts and Subscripts
96 //
97 //                 0x2070          (not part of LATIN script)
98 //                 0x2074 - 0x207E (not part of LATIN script)
99 //
100 // 0x2100 - 0x214f Letterlike symbols (not part of LATIN script)
101 //
102 //                 0x212A - 0x212B (are part of LATIN script)
103 //                 0x2132          (are part of LATIN script)
104 //                 0x214E          (are part of LATIN script)
105 //
106 // 0x2150 - 0x2189 Number Forms
107 //
108 //                 0x2150 - 0x215F Fractions (not part of LATIN script)
109 //                 0x2189          Fractions (not part of LATIN script)
110 //
111 // 0x2c60 - 0x2c7f Latin Extended-C
112 // 0xa720 - 0xa7ff Latin Extended-D
113 //
114 //                 0xA720 - 0xA721 Uralic Phonetic (not part of LATIN script)
115 //                 0xA788          (not part of LATIN script)
116 //                 0xA789 - 0xA78A Budu (not part of LATIN script)
117 //
118 // 0xab30 - 0xab6f Latin Extended-E
119 //
120 // 0xfb00 - 0xfb06 Latin Alphabetic Presentation Forms
121 // 0xff00 - 0xffef Halfwidth and Fullwidth Forms
122 //
123 //                 0xFF00 - 0xFF20 HWFW Symbols (not part of LATIN script)
124 //                 0xFF3B - 0xFF40 HWFW Symbols (not part of LATIN script)
125 //                 0xFF5B - 0xFFEF HWFW Symbols (not part of LATIN script)
126
127 // Brahmic scripts:
128 // 0x0900 - 0x097f Devanagari
129 // 0x0980 - 0x09ff Bengali
130 // 0x0a00 - 0x0a7f Gurmukhi
131 // 0x0a80 - 0x0aff Gujarati
132 // 0x0b00 - 0x0b7f Oriya
133 // 0x0b80 - 0x0bff Tamil
134 // 0x0c00 - 0x0c7f Telugu
135 // 0x0c80 - 0x0cff Kannada
136 // 0x0d00 - 0x0d7f Malayalam
137
138 // Sinhala script.
139 // 0x0d80 - 0x0dff Sinhala
140
141 // Arabic script.
142 // 0x0600 - 0x06ff Arabic
143 // 0x0750 - 0x077f Arabic Supplement
144 // 0x08A0 - 0x08ff Arabic Extended-A
145 // 0xfb50 - 0xfdff Arabic Presentation Forms-A
146 // 0xfe70 - 0xfeff Arabic Presentation Forms-B
147 // 0x1ee00 - 0x1eeff Arabic Mathematical Alphabetic Symbols
148
149 // CJK (Chinese, Japanese and Korean) and Vietnamese script.
150 // 0x2e80 - 0x2eff CJK Radicals Supplement
151 // 0x2f00 - 0x2fdf Kangxi Radicals
152 // 0x3000 - 0x303f CJK Symbols and Punctuation
153 // 0x3200 - 0x32ff Enclosed CJK Letters and Months
154 // 0x3400 - 0x4dbf CJK Unified Ideographs Extension A
155 // 0x4e00 - 0x62ff CJK Unified Ideographs
156 // 0x6300 - 0x77ff CJK Unified Ideographs
157 // 0x7800 - 0x8cff CJK Unified Ideographs
158 // 0x8d00 - 0x9fff CJK Unified Ideographs
159 // 0x20000 - 0x215ff CJK Unified Ideographs Extension B
160 // 0x21600 - 0x230ff CJK Unified Ideographs Extension B
161 // 0x23100 - 0x245ff CJK Unified Ideographs Extension B
162 // 0x24600 - 0x260ff CJK Unified Ideographs Extension B
163 // 0x26100 - 0x275ff CJK Unified Ideographs Extension B
164 // 0x27600 - 0x290ff CJK Unified Ideographs Extension B
165 // 0x29100 - 0x2a6df CJK Unified Ideographs Extension B
166 // 0x2a700 - 0x2b73f CJK Unified Ideographs Extension C
167 // 0x2b740 - 0x2b81f CJK Unified Ideographs Extension D
168
169 // Japanese scripts.
170 // 0x3040 - 0x309f Hiragana
171 // 0x30a0 - 0x30ff Katakana
172
173 // Hangul script
174 // 0x1100 - 0x11ff Hangul jamo
175 // 0x3130 - 0x318f Hangul Compatibility Jamo
176 // 0xa960 - 0xa97f Hangul Jamo Extended-A
177 // 0xac00 - 0xd7af Hangul Syllables
178 // 0xd7b0 - 0xd7ff Hangul Jamo Extended-B
179
180 // Bopomofo script
181 // 0x3100 - 0x312f Bopomofo
182 // 0x31a0 - 0x31bf Bopomofo Extended
183
184 // Khmer script
185 // 0x1780 - 0x17ff Khmer
186 // 0x19e0 - 0x19ff Khmer Symbols
187
188 // Lao script
189 // 0x0e80 - 0x0eff Lao
190
191 // Thai script
192 // 0x0e00 - 0x0e7f Thai
193
194 // Burmese script
195 // 0x1000 - 0x109f Myanmar
196
197 // Hebrew script
198 // 0x0591 - 0x05f4 Hebrew
199 // 0xfb1d - 0xfb4f Hebrew subset of Alphabetic Presentation Forms
200
201 // Cyrillic script
202 // 0x0400 - 0x04ff Cyrillic
203 // 0x0500 - 0x052f Cyrillic suplement
204 // 0x2de0 - 0x2dff Cyrillic Extended-A
205 // 0xa640 - 0xa69f Cyrillic Extended-B
206
207 // Georgian script
208 // 0x10a0 - 0x10ff Georgian
209 // 0x2d00 - 0x2d2f Georgian suplement
210
211 // Greek script
212 // 0x0370 - 0x03ff Greek & Coptic
213 // 0x1f00 - 0x1fff Greek Extended
214
215 // Armenian script
216 // 0x0530 - 0x058f Armenian
217 // 0xfb13 - 0xfb17 Armenian subset of Alphabetic prefentation forms
218
219 // Javanese script
220 // 0xa980 - 0xa9fd Javanese
221
222 // Sundanese script
223 // 0x1b80 - 0x1bbf Sundanese
224 // 0x1cc0 - 0x1ccf Sundanese supplement
225
226 // Ge'ez script (Ethiopic)
227 // 0x1200 - 0x137f Ethiopic
228 // 0x1380 - 0x139f Ethiopic supplement
229 // 0x2d80 - 0x2ddf Ethiopic Extended
230 // 0xab00 - 0xab2f Ethiopic Extended-A
231
232 // Baybayin Script
233 // 0x1700 - 0x171f Baybayin
234
235 // Ol Chiki Script
236 // 0x1c50 - 0x1c7f Ol Chiki
237
238 // Meitei Script
239 // 0xabc0 - 0xabff Meetei Mayek
240 // 0xaae0 - 0xaaff Meetei Mayek Extensions
241
242 // The Emoji which map to standardized Unicode characters
243 // 1. Emoticons ( 1F601 - 1F64F )
244 // 2. Dingbats ( 2700 - 27BF )
245 // 3. Transport and map symbols ( 1F680 - 1F6C0 )
246 // 4. Enclosed characters ( 24C2 - 1F251 )
247 // 5. Uncategorized :-S
248 // 6. Additional Emoticons ( 1F600 - 1F636 )
249 // 6b. Additional transport and map symbols ( 1F680 - 1F6FF ): http://unicode.org/charts/PDF/U1F680.pdf
250 // 6c. Other additional symbols ( 1F30D - 1F567 )
251 // 7. Supplemental Symbols and Pictographs ( 1F900–1F9FF ): http://unicode.org/charts/PDF/U1F900.pdf
252
253 // Symbols. Work around for these symbols.
254 // 0x25cb
255 // 0x25cf
256 // 0x25a1
257 // 0x25a0
258 // 0x2664
259 // 0x2661
260 // 0x2662
261 // 0x2667
262 // 0x2606
263 // 0x25aa
264 // 0x262a
265
266
267 /// character <= 0x077f
268 inline Script GetScriptTillArabicSupplement(Character character)
269 {
270   Script script = UNKNOWN;
271
272   if( ( 0x0030 <= character ) && ( character <= 0x0039 ) )
273   {
274     script = ASCII_DIGITS;
275   }
276   else if( character <= 0x007E )
277   {
278     if( ( 0x0020 <= character ) && ( character <= 0x002F ) )
279     {
280       script = ASCII_PS;
281     }
282     else if( ( 0x003A <= character ) && ( character <= 0x0040 ) )
283     {
284       script = ASCII_PS;
285     }
286     else if( ( 0x005B <= character ) && ( character <= 0x0060 ) )
287     {
288       script = ASCII_PS;
289     }
290     else if( ( 0x007B <= character ) && ( character <= 0x007E ) )
291     {
292       script = ASCII_PS;
293     }
294     else
295     {
296       script = LATIN;
297     }
298   }
299   else if( ( 0x007F <= character ) && ( character <= 0x009F ) )
300   {
301     // 0x007F is actually part of C0 Controls and Basic Latin. However, is the last and only control character of its block
302     // and the following characters of the next block are consecutive.
303     script = C1_CONTROLS;
304   }
305   else if( ( 0x00A0 <= character ) && ( character <= 0x00BF ) )
306   {
307     if( character == 0x00A9 )
308     {
309       script = EMOJI; // 5. Uncategorized: copyright sign
310     }
311     else if( character == 0x00AE )
312     {
313       script = EMOJI; // 5. Uncategorized: registered sign
314     }
315     else
316     {
317       script = C1_PS;
318     }
319   }
320   else if( character == 0x00D7 )
321   {
322     script = C1_MATH;
323   }
324   else if( character == 0x00F7 )
325   {
326     script = C1_MATH;
327   }
328   else if( ( 0x00C0 <= character ) && ( character <= 0x02ff ) )
329   {
330     if( ( 0x02B9 <= character ) && ( character <= 0x02BF ) )
331     {
332       script = SML_P;
333     }
334     else
335     {
336       script = LATIN;
337     }
338   }
339   else if( ( 0x0370 <= character ) && ( character <= 0x03ff ) )
340   {
341     script = GREEK;
342   }
343   else if( ( 0x0400 <= character ) && ( character <= 0x04ff ) )
344   {
345     script = CYRILLIC;
346   }
347   else if( ( 0x0500 <= character ) && ( character <= 0x052f ) )
348   {
349     script = CYRILLIC;
350   }
351   else if( ( 0x0530 <= character ) && ( character <= 0x058f ) )
352   {
353     script = ARMENIAN;
354   }
355   else if( ( 0x0591 <= character ) && ( character <= 0x05f4 ) )
356   {
357     script = HEBREW;
358   }
359   else if( ( 0x0600 <= character ) && ( character <= 0x06ff ) )
360   {
361     script = ARABIC;
362   }
363   else if( ( 0x0750 <= character ) && ( character <= 0x077f ) )
364   {
365     script = ARABIC;
366   }
367
368   return script;
369 }
370
371 /// character <= 0x09ff
372 inline Script GetScriptTillBengali(Character character)
373 {
374   Script script = UNKNOWN;
375
376   if( character <= 0x077f )
377   {
378     script = GetScriptTillArabicSupplement(character);
379   }
380   else // > 0x077f
381   {
382     if( ( 0x08A0 <= character ) && ( character <= 0x08ff ) )
383     {
384       script = ARABIC;
385     }
386     else if( ( 0x0900 <= character ) && ( character <= 0x097f ) )
387     {
388       script = DEVANAGARI;
389     }
390     else if( ( 0x0980 <= character ) && ( character <= 0x09ff ) )
391     {
392       script = BENGALI;
393     }
394   }
395
396   return script;
397 }
398
399 /// 0x09ff < character <= 0x0cff
400 inline Script GetScriptBetweenBengaliAndKannada( Character character )
401 {
402   Script script = UNKNOWN;
403
404   if( character <= 0x0b7f )
405   {
406     if( ( 0x0a00 <= character ) && ( character <= 0x0a7f ) )
407     {
408       script = GURMUKHI;
409     }
410     else if( ( 0x0a80 <= character ) && ( character <= 0x0aff ) )
411     {
412       script = GUJARATI;
413     }
414     else if( ( 0x0b00 <= character ) && ( character <= 0x0b7f ) )
415     {
416       script = ORIYA;
417     }
418   }
419   else // > 0x0b7f
420   {
421     if( ( 0x0b80 <= character ) && ( character <= 0x0bff ) )
422     {
423       script = TAMIL;
424     }
425     else if( ( 0x0c00 <= character ) && ( character <= 0x0c7f ) )
426     {
427       script = TELUGU;
428     }
429     else if( ( 0x0c80 <= character ) && ( character <= 0x0cff ) )
430     {
431       script = KANNADA;
432     }
433   }
434
435   return script;
436 }
437
438 /// 0x0cff < character <= 0x1eff
439 inline Script GetScriptBetweenKannadaAndLatinExtendedAdditional(Character character)
440 {
441   Script script = UNKNOWN;
442
443   if( ( 0x0d00 <= character ) && ( character <= 0x0d7f ) )
444   {
445     script = MALAYALAM;
446   }
447   else if( ( 0x0d80 <= character ) && ( character <= 0x0dff ) )
448   {
449     script = SINHALA;
450   }
451   else if( ( 0x0e00 <= character ) && ( character <= 0x0e7f ) )
452   {
453     script = THAI;
454   }
455   else if( ( 0x0e80 <= character ) && ( character <= 0x0eff ) )
456   {
457     script = LAO;
458   }
459   else if( ( 0x1000 <= character ) && ( character <= 0x109f ) )
460   {
461     script = BURMESE;
462   }
463   else if( ( 0x10a0 <= character ) && ( character <= 0x10ff ) )
464   {
465     script = GEORGIAN;
466   }
467   else if( ( 0x1100 <= character ) && ( character <= 0x11ff ) )
468   {
469     script = HANGUL;
470   }
471   else if( ( 0x1200 <= character ) && ( character <= 0x137f ) )
472   {
473     script = GEEZ;
474   }
475   else if( ( 0x1380 <= character ) && ( character <= 0x139f ) )
476   {
477     script = GEEZ;
478   }
479   else if( ( 0x1700 <= character ) && ( character <= 0x171f ) )
480   {
481     script = BAYBAYIN;
482   }
483   else if( ( 0x1780 <= character ) && ( character <= 0x17ff ) )
484   {
485     script = KHMER;
486   }
487   else if( ( 0x19e0 <= character ) && ( character <= 0x19ff ) )
488   {
489     script = KHMER;
490   }
491   else if( ( 0x1b80 <= character ) && ( character <= 0x1bbf ) )
492   {
493     script = SUNDANESE;
494   }
495   else if( ( 0x1c50 <= character ) && ( character <= 0x1c7f ) )
496   {
497     script = OL_CHIKI;
498   }
499   else if( ( 0x1cc0 <= character ) && ( character <= 0x1ccf ) )
500   {
501     script = SUNDANESE;
502   }
503   else if( ( 0x1d00 <= character ) && ( character <= 0x1eff ) )
504   {
505     if( ( 0x1D26 <= character ) && ( character <= 0x1D2B ) )
506     {
507       script = PHONETIC_U;
508     }
509     else if( ( 0x1D5D <= character ) && ( character <= 0x1D61 ) )
510     {
511       script = PHONETIC_SS;
512     }
513     else if( ( 0x1D66 <= character ) && ( character <= 0x1D6A ) )
514     {
515       script = PHONETIC_SS;
516     }
517     else if( character == 0x1D78 )
518     {
519       script = PHONETIC_SS;
520     }
521     else if( character == 0x1DBF)
522     {
523       script = PHONETIC_SS;
524     }
525     else
526     {
527       script = LATIN;
528     }
529   }
530
531   return script;
532 }
533
534 /// 0x1eff < character <= 0x2c7f
535 inline Script GetScriptBetweenLatinExtendedAdditionalAndLatinExtendedC(Character character)
536 {
537   Script script = UNKNOWN;
538
539   if( ( 0x1f00 <= character ) && ( character <= 0x1fff ) )
540   {
541     script = GREEK;
542   }
543   else if( character == 0x203c )
544   {
545     script = EMOJI; // 5. Uncategorized: double exclamation mark
546   }
547   else if( character == 0x2049 )
548   {
549     script = EMOJI; // 5. Uncategorized: exclamation question mark
550   }
551   else if( ( 0x2070 <= character ) && ( character <= 0x209f ) )
552   {
553     if( character == 0x2070 )
554     {
555       script = NUMERIC_SS;
556     }
557     else if( ( 0x2074 <= character ) && ( character <= 0x207E ) )
558     {
559       script = NUMERIC_SS;
560     }
561     else
562     {
563       script = LATIN;
564     }
565   }
566   else if( character == 0x20e3 )
567   {
568     script = EMOJI; // 5. Uncategorized: combining enclosing keycap
569   }
570   else if( character == 0x2122 )
571   {
572     script = EMOJI; // 5. Uncategorized: trade mark sign
573   }
574   else if( character == 0x2139 )
575   {
576     script = EMOJI; // 5. Uncategorized: information source
577   }
578   else if( ( 0x2100 <= character ) && ( character <= 0x2189 ) )
579   {
580     if( ( 0x2100 <= character ) && ( character <= 0x214f ) )
581     {
582       if( ( 0x212A <= character ) && ( character <= 0x212B ) )
583       {
584         script = LATIN;
585       }
586       else if( character == 0x2132 )
587       {
588         script = LATIN;
589       }
590       else if( character == 0x214E )
591       {
592         script = LATIN;
593       }
594       else
595       {
596         script = LETTER_LIKE;
597       }
598     }
599     else if( ( 0x2150 <= character ) && ( character <= 0x215F ) )
600     {
601       script = FRACTIONS_NF;
602     }
603     else if( character == 0x2189 )
604     {
605       script = FRACTIONS_NF;
606     }
607     else
608     {
609       script = LATIN;
610     }
611   }
612   // Symbols
613   else if( ( 0x25cb == character ) ||
614            ( 0x25cf == character ) ||
615            ( 0x25a1 == character ) )
616   {
617     script = SYMBOLS1;
618   }
619   else if( 0x25a0 == character )
620   {
621     script = SYMBOLS2;
622   }
623   else if( ( 0x2664 == character ) ||
624            ( 0x2661 == character ) ||
625            ( 0x2662 == character ) ||
626            ( 0x2667 == character ) )
627   {
628     script = SYMBOLS3;
629   }
630   else if( ( 0x2606 == character ) ||
631            ( 0x25aa == character ) )
632   {
633     script = SYMBOLS4;
634   }
635   else if( 0x262a == character )
636   {
637     script = SYMBOLS5;
638   }
639   // U+2194 5. Uncategorized: left right arrow
640   // U+2B55 5. Uncategorized: heavy large circle
641   else if( ( 0x2194 <= character ) && ( character <= 0x2B55 ) )
642   {
643     script = EMOJI;
644   }
645   else if( ( 0x2c60 <= character ) && ( character <= 0x2c7f ) )
646   {
647     script = LATIN;
648   }
649
650   return script;
651 }
652
653 /// 0x0cff < character <= 0x2c7f
654 inline Script GetScriptBetweenKannadaAndLatinExtendedC(Character character)
655 {
656   Script script = UNKNOWN;
657
658   if( character <= 0x1eff )
659   {
660     script = GetScriptBetweenKannadaAndLatinExtendedAdditional(character);
661   }
662   else // > 0x1eff
663   {
664     script = GetScriptBetweenLatinExtendedAdditionalAndLatinExtendedC(character);
665   }
666
667   return script;
668 }
669
670 /// 0x2c7f < character <= 0xa7ff
671 inline Script GetScriptBetweenLatinExtendedCAndLatinExtendedD(Character character)
672 {
673   Script script = UNKNOWN;
674
675   if( ( 0x2d00 <= character ) && ( character <= 0x2d2f ) )
676   {
677     script = GEORGIAN;
678   }
679   else if( ( 0x2d80 <= character ) && ( character <= 0x2ddf ) )
680   {
681     script = GEEZ;
682   }
683   else if( ( 0x2de0 <= character ) && ( character <= 0x2dff ) )
684   {
685     script = CYRILLIC;
686   }
687   else if( ( 0x2e80 <= character ) && ( character <= 0x2eff ) )
688   {
689     script = CJK;
690   }
691   else if( ( 0x2f00 <= character ) && ( character <= 0x2fdf ) )
692   {
693     script = CJK;
694   }
695   else if( ( 0x3000 <= character ) && ( character <= 0x303f ) )
696   {
697     script = CJK;
698   }
699   else if( ( 0x3040 <= character ) && ( character <= 0x309f ) )
700   {
701     script = HIRAGANA;
702   }
703   else if( ( 0x30a0 <= character ) && ( character <= 0x30ff ) )
704   {
705     script = KATAKANA;
706   }
707   else if( ( 0x3100 <= character ) && ( character <= 0x312f ) )
708   {
709     script = BOPOMOFO;
710   }
711   else if( ( 0x3130 <= character ) && ( character <= 0x318f ) )
712   {
713     script = HANGUL;
714   }
715   else if( ( 0x31a0 <= character ) && ( character <= 0x31bf ) )
716   {
717     script = BOPOMOFO;
718   }
719   else if( ( 0x3200 <= character ) && ( character <= 0x32ff ) )
720   {
721     script = CJK;
722   }
723   else if( ( 0x3400 <= character ) && ( character <= 0x4dbf ) )
724   {
725     script = CJK;
726   }
727   else if( ( 0x4e00 <= character ) && ( character <= 0x62ff ) )
728   {
729     script = CJK;
730   }
731   else if( ( 0x6300 <= character ) && ( character <= 0x77ff ) )
732   {
733     script = CJK;
734   }
735   else if( ( 0x7800 <= character ) && ( character <= 0x8cff ) )
736   {
737     script = CJK;
738   }
739   else if( ( 0x8d00 <= character ) && ( character <= 0x9fff ) )
740   {
741     script = CJK;
742   }
743   else if( ( 0xa640 <= character ) && ( character <= 0xa69f ) )
744   {
745     script = CYRILLIC;
746   }
747   else if( ( 0xa720 <= character ) && ( character <= 0xa7ff ) )
748   {
749     if( character == 0xA720 )
750     {
751       script = PHONETIC_U;
752     }
753     else if( character == 0xA721 )
754     {
755       script = PHONETIC_U;
756     }
757     else if( character == 0xA788 )
758     {
759       script = NON_LATIN_LED;
760     }
761     else if( character == 0xA789 )
762     {
763       script = NON_LATIN_LED;
764     }
765     else if( character == 0xA78A )
766     {
767       script = NON_LATIN_LED;
768     }
769     else
770     {
771       script = LATIN;
772     }
773   }
774
775   return script;
776 }
777
778 /// 0x2c7f < character <= 0xfdff
779 inline Script GetScriptBetweenLatinExtendedCAndArabicPresentationFormsA(Character character)
780 {
781   Script script = GetScriptBetweenLatinExtendedCAndLatinExtendedD(character);
782
783   if( ( 0xa960 <= character ) && ( character <= 0xa97f ) )
784   {
785     script = HANGUL;
786   }
787   else if( ( 0xa980 <= character ) && ( character <= 0xa9fd ) )
788   {
789     script = JAVANESE;
790   }
791   else if( ( 0xab00 <= character ) && ( character <= 0xab2f ) )
792   {
793     script = GEEZ;
794   }
795   else if( ( 0xab30 <= character ) && ( character <= 0xab6f ) )
796   {
797     script = LATIN;
798   }
799   else if( ( 0xaae0 <= character ) && ( character <= 0xaaff ) )
800   {
801     script = MEITEI;
802   }
803   else if( ( 0xabc0 <= character ) && ( character <= 0xabff ) )
804   {
805     script = MEITEI;
806   }
807   else if( ( 0xac00 <= character ) && ( character <= 0xd7af ) )
808   {
809     script = HANGUL;
810   }
811   else if( ( 0xd7b0 <= character ) && ( character <= 0xd7ff ) )
812   {
813     script = HANGUL;
814   }
815   else if( ( 0xfb00 <= character ) && ( character <= 0xfb06 ) )
816   {
817     script = LATIN;
818   }
819   else if( ( 0xfb13 <= character ) && ( character <= 0xfb17 ) )
820   {
821     script = ARMENIAN;
822   }
823   else if( ( 0xfb1d <= character ) && ( character <= 0xfb4f ) )
824   {
825     script = HEBREW;
826   }
827   else if( ( 0xfb50 <= character ) && ( character <= 0xfdff ) )
828   {
829     script = ARABIC;
830   }
831
832   return script;
833 }
834
835 /// character > 0xfdff
836 inline Script GetScriptAboveArabicPresentationFormsA(Character character)
837 {
838   Script script = UNKNOWN;
839
840   if( ( 0xfe70 <= character ) && ( character <= 0xfeff ) )
841   {
842     script = ARABIC;
843   }
844   else if( ( 0xff00 <= character ) && ( character <= 0xffef ) )
845   {
846     if( ( 0xFF00 <= character ) && ( character <= 0xFF20 ) )
847     {
848       script = HWFW_S;
849     }
850     else if( ( 0xFF3B <= character ) && ( character <= 0xFF40 ) )
851     {
852       script = HWFW_S;
853     }
854     else if( ( 0xFF5B <= character ) && ( character <= 0xFFEF ) )
855     {
856       script = HWFW_S;
857     }
858     else
859     {
860       script = LATIN;
861     }
862   }
863   else if( ( 0x1ee00 <= character ) && ( character <= 0x1eeff ) )
864   {
865     script = ARABIC;
866   }
867   // U+1f170 4. Enclosed characters: negative squared latin capital letter A
868   // U+1f6ff 6b. Additional transport and map symbols
869   else if( ( 0x1f170 <= character ) && ( character <= 0x1f6ff ) )
870   {
871     script = EMOJI;
872   }
873   // 7. Supplemental Symbols and Pictographs
874   else if( ( 0x1f900 <= character ) && ( character <= 0x1f9ff ) )
875   {
876     script = EMOJI;
877   }
878   else if( ( 0x20000 <= character ) && ( character <= 0x215ff ) )
879   {
880     script = CJK;
881   }
882   else if( ( 0x21600 <= character ) && ( character <= 0x230ff ) )
883   {
884     script = CJK;
885   }
886   else if( ( 0x23100 <= character ) && ( character <= 0x245ff ) )
887   {
888     script = CJK;
889   }
890   else if( ( 0x24600 <= character ) && ( character <= 0x260ff ) )
891   {
892     script = CJK;
893   }
894   else if( ( 0x26100 <= character ) && ( character <= 0x275ff ) )
895   {
896     script = CJK;
897   }
898   else if( ( 0x27600 <= character ) && ( character <= 0x290ff ) )
899   {
900     script = CJK;
901   }
902   else if( ( 0x29100 <= character ) && ( character <= 0x2a6df ) )
903   {
904     script = CJK;
905   }
906   else if( ( 0x2a700 <= character ) && ( character <= 0x2b73f ) )
907   {
908     script = CJK;
909   }
910   else if( ( 0x2b740 <= character ) && ( character <= 0x2b81f ) )
911   {
912     script = CJK;
913   }
914
915   return script;
916 }
917
918 /// character > 0x2c7f
919 inline Script GetScriptAboveLatinExtendedC(Character character)
920 {
921   Script script = UNKNOWN;
922
923   if( character <= 0xfdff )
924   {
925     script = GetScriptBetweenLatinExtendedCAndArabicPresentationFormsA(character);
926   }
927   else // > 0xfdff
928   {
929     script = GetScriptAboveArabicPresentationFormsA(character);
930   }
931
932   return script;
933 }
934
935 } // namespace
936
937 bool IsRightToLeftScript( Script script )
938 {
939   return ( ( ARABIC == script ) ||
940            ( HEBREW == script ) );
941 }
942
943 Script GetCharacterScript( Character character )
944 {
945   Script script = UNKNOWN;
946
947   if( IsCommonScript( character ) )
948   {
949     script = COMMON;
950   }
951   else if( character <= 0x0cff )
952   {
953     if( character <= 0x09ff )
954     {
955       script = GetScriptTillBengali(character);
956     }
957     else // > 0x09ff
958     {
959       script = GetScriptBetweenBengaliAndKannada(character);
960     }
961   }
962   else // > 0x0cff
963   {
964     if( character <= 0x2c7f )
965     {
966        script = GetScriptBetweenKannadaAndLatinExtendedC(character);
967     }
968     else // > 0x2c7f
969     {
970       script = GetScriptAboveLatinExtendedC(character);
971     }
972   }
973
974   return script;
975 }
976
977 bool IsWhiteSpace(Character character)
978 {
979   return character < WHITE_SPACE_THRESHOLD;
980 }
981
982 bool IsNewParagraph(Character character)
983 {
984   return ((CHAR_LF == character) ||
985           (CHAR_VT == character) ||
986           (CHAR_FF == character) ||
987           (CHAR_CR == character) ||
988           (CHAR_NEL == character) ||
989           (CHAR_LS == character) ||
990           (CHAR_PS == character));
991 }
992
993 bool IsZeroWidthNonJoiner(Character character)
994 {
995   return CHAR_ZWNJ == character;
996 }
997
998 bool IsZeroWidthJoiner(Character character)
999 {
1000   return CHAR_ZWJ == character;
1001 }
1002
1003 bool IsZeroWidthSpace(Character character)
1004 {
1005   return CHAR_ZWS == character;
1006 }
1007
1008 bool IsLeftToRightMark(Character character)
1009 {
1010   return CHAR_LTRM == character;
1011 }
1012
1013 bool IsRightToLeftMark(Character character)
1014 {
1015   return CHAR_RTLM == character;
1016 }
1017
1018 bool IsThinSpace(Character character)
1019 {
1020   return CHAR_TS == character;
1021 }
1022
1023 bool IsCommonScript(Character character)
1024 {
1025   return (IsWhiteSpace(character) ||
1026           IsZeroWidthNonJoiner(character) ||
1027           IsZeroWidthJoiner(character) ||
1028           IsZeroWidthSpace(character) ||
1029           IsLeftToRightMark(character) ||
1030           IsRightToLeftMark(character) ||
1031           IsThinSpace(character) ||
1032           IsNewParagraph(character));
1033 }
1034
1035 bool HasLigatureMustBreak(Script script)
1036 {
1037   return ((LATIN == script) ||
1038           (ARABIC == script));
1039 }
1040
1041 } // namespace TextAbstraction
1042
1043 } // namespace Dali