2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/text/character-impl.h>
24 const unsigned char CHAR_WHITE_SPACE(32); ///< Unsigned characters 0-32 (' ') are white space, 33-127 are standard ASCII, 128+ are UTF-8.
25 const unsigned char CHAR_NEW_LINE( 0x0A ); ///< New Line character (LF)
27 bool IsCharBidirectional(uint32_t i)
29 //TODO: Cover the entire table.
31 http://www.ietf.org/rfc/rfc3454.txt
32 D. Bidirectional tables
33 D.1 Characters with bidirectional property "R" or "AL"
34 D.2 Characters with bidirectional property "L"
36 bidirectional characters are those characters which are neither R (D.1) or L (D.2)
42 if( i > 0x005a && i < 0x0061 )
46 if( i > 0x007a && i < 0x00aa )
54 bool IsCharLeftToRight(uint32_t i)
56 //TODO: This method could be optimized. Performance notes: 1400us for 64k calls (80us for first if statement, 40us for each subsequent if statement)
57 //TODO: This table could be parsed from internet (http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt) or a config file.
59 http://www.ietf.org/rfc/rfc3454.txt
60 D. Bidirectional tables
61 D.1 Characters with bidirectional property "R" or "AL"
63 ----- Start Table D.1 -----
98 ----- End Table D.1 -----
113 if( ( 0x05D0 <= i ) && ( 0x05EA >= i ) )
117 if( ( 0x05F0 <= i ) && ( 0x05F4 >= i ) )
129 if( ( 0x0621 <= i ) && ( 0x063A >= i ) )
133 if( ( 0x0640 <= i ) && ( 0x064A >= i ) )
137 if( ( 0x066D <= i ) && ( 0x066F >= i ) )
141 if( ( 0x0671 <= i ) && ( 0x06D5 >= i ) )
149 if( ( 0x06E5 <= i ) && ( 0x06E6 >= i ) )
153 if( ( 0x06FA <= i ) && ( 0x06FE >= i ) )
157 if( ( 0x0700 <= i ) && ( 0x070D >= i ) )
165 if( ( 0x0712 <= i ) && ( 0x072C >= i ) )
169 if( ( 0x0780 <= i ) && ( 0x07A5 >= i ) )
185 if( ( 0xFB1F <= i ) && ( 0xFB28 >= i ) )
189 if( ( 0xFB2A <= i ) && ( 0xFB36 >= i ) )
193 if( ( 0xFB38 <= i ) && ( 0xFB3C >= i ) )
201 if( ( 0xFB40 <= i ) && ( 0xFB41 >= i ) )
205 if( ( 0xFB43 <= i ) && ( 0xFB44 >= i ) )
209 if( ( 0xFB46 <= i ) && ( 0xFBB1 >= i ) )
213 if( ( 0xFBD3 <= i ) && ( 0xFD3D >= i ) )
217 if( ( 0xFD50 <= i ) && ( 0xFD8F >= i ) )
221 if( ( 0xFD92 <= i ) && ( 0xFDC7 >= i ) )
225 if( ( 0xFDF0 <= i ) && ( 0xFDFC >= i ) )
229 if( ( 0xFE70 <= i ) && ( 0xFE74 >= i ) )
233 if( ( 0xFE76 <= i ) && ( 0xFEFC >= i ) )
241 Dali::Character::Script GetCharacterScript( uint32_t character )
244 // 0x0000 - 0x007f C0 Controls and Basic Latin
245 // 0x0080 - 0x00ff C1 Controls and Latin-1 Supplement
246 // 0x0100 - 0x017f Latin Extended-A
247 // 0x0180 - 0x024f Latin Extended-B
248 // 0x0250 - 0x02af IPA Extensions
249 // 0x02b0 - 0x02ff Spacing Modifier Letters
250 // 0x1d00 - 0x1d7f Phonetic Extensions
251 // 0x1d80 - 0x1dbf Phonetic Extensions Supplement
252 // 0x1e00 - 0x1eff Latin Extended Additional
253 // 0x2070 - 0x209f Superscripts and Subscripts
254 // 0x2100 - 0x214f Letterlike symbols
255 // 0x2150 - 0x218f Number Forms
256 // 0x2c60 - 0x2c7f Latin Extended-C
257 // 0xa720 - 0xa7ff Latin Extended-D
258 // 0xab30 - 0xab6f Latin Extended-E
259 // 0xfb00 - 0xfb4f Alphabetic Presentation Forms
260 // 0xff00 - 0xffef Halfwidth and Fullwidth Forms
263 // 0x0900 - 0x097f Devanagari
264 // 0x0980 - 0x09ff Bengali
265 // 0x0a00 - 0x0a7f Gurmukhi
266 // 0x0a80 - 0x0aff Gujarati
267 // 0x0b00 - 0x0b7f Oriya
268 // 0x0b80 - 0x0bff Tamil
269 // 0x0c00 - 0x0c7f Telugu
270 // 0x0c80 - 0x0cff Kannada
271 // 0x0d00 - 0x0d7f Malayalam
274 // 0x0d80 - 0x0dff Sinhala
285 if( character <= 0x0cff )
287 if( character <= 0x09ff )
289 if( character <= 0x077f )
291 if( character <= 0x02ff )
293 return Dali::Character::LATIN;
295 if( ( 0x0600 <= character ) && ( character <= 0x06ff ) )
297 return Dali::Character::ARABIC;
299 if( ( 0x0750 <= character ) && ( character <= 0x077f ) )
301 return Dali::Character::ARABIC;
306 if( ( 0x08A0 <= character ) && ( character <= 0x08ff ) )
308 return Dali::Character::ARABIC;
310 if( ( 0x0900 <= character ) && ( character <= 0x097f ) )
312 return Dali::Character::DEVANAGARI;
314 if( ( 0x0980 <= character ) && ( character <= 0x09ff ) )
316 return Dali::Character::BENGALI;
322 if( character <= 0x0b7f )
324 if( ( 0x0a00 <= character ) && ( character <= 0x0a7f ) )
326 return Dali::Character::GURMUKHI;
328 if( ( 0x0a80 <= character ) && ( character <= 0x0aff ) )
330 return Dali::Character::GUJARATI;
332 if( ( 0x0b00 <= character ) && ( character <= 0x0b7f ) )
334 return Dali::Character::ORIYA;
339 if( ( 0x0b80 <= character ) && ( character <= 0x0bff ) )
341 return Dali::Character::TAMIL;
343 if( ( 0x0c00 <= character ) && ( character <= 0x0c7f ) )
345 return Dali::Character::TELUGU;
347 if( ( 0x0c80 <= character ) && ( character <= 0x0cff ) )
349 return Dali::Character::KANNADA;
356 if( character <= 0x2c7f )
358 if( character <= 0x1eff )
360 if( ( 0x0d00 <= character ) && ( character <= 0x0d7f ) )
362 return Dali::Character::MALAYALAM;
364 if( ( 0x0d80 <= character ) && ( character <= 0x0dff ) )
366 return Dali::Character::SINHALA;
368 if( ( 0x1d00 <= character ) && ( character <= 0x1eff ) )
370 return Dali::Character::LATIN;
375 if( ( 0x2070 <= character ) && ( character <= 0x209f ) )
377 return Dali::Character::LATIN;
379 if( ( 0x2100 <= character ) && ( character <= 0x218f ) )
381 return Dali::Character::LATIN;
383 if( ( 0x2c60 <= character ) && ( character <= 0x2c7f ) )
385 return Dali::Character::LATIN;
391 if( character <= 0xfdff )
393 if( ( 0xa720 <= character ) && ( character <= 0xa7ff ) )
395 return Dali::Character::LATIN;
397 if( ( 0xab30 <= character ) && ( character <= 0xab6f ) )
399 return Dali::Character::LATIN;
401 if( ( 0xfb00 <= character ) && ( character <= 0xfb4f ) )
403 return Dali::Character::LATIN;
405 if( ( 0xfb50 <= character ) && ( character <= 0xfdff ) )
407 return Dali::Character::ARABIC;
412 if( ( 0xfe70 <= character ) && ( character <= 0xfeff ) )
414 return Dali::Character::ARABIC;
416 if( ( 0xff00 <= character ) && ( character <= 0xffef ) )
418 return Dali::Character::LATIN;
420 if( ( 0x1ee00 <= character ) && ( character <= 0x1eeff ) )
422 return Dali::Character::ARABIC;
428 return Dali::Character::UNKNOWN;
431 } // unnamed namespace
439 Character::Character( uint32_t character )
440 : mCharacter( character )
444 Character::~Character()
448 Character::CharacterDirection Character::GetCharacterDirection(uint32_t character)
450 //TODO: This method could be optimized, and should cover all 5 types of characters.
451 if( IsCharBidirectional(character) )
453 return Dali::Character::Neutral;
456 if( IsCharLeftToRight(character) )
458 return Dali::Character::LeftToRight;
461 return Dali::Character::RightToLeft;
464 Character::CharacterDirection Character::GetCharacterDirection() const
466 return GetCharacterDirection( mCharacter );
469 Dali::Character::Script Character::GetScript( uint32_t character )
471 return GetCharacterScript( character );
474 Dali::Character::Script Character::GetScript() const
476 return GetCharacterScript( mCharacter );
479 bool Character::IsLeftToRight() const
481 return GetCharacterDirection() != Dali::Character::RightToLeft;
484 bool Character::IsWhiteSpace() const
486 return Character::IsWhiteSpace( mCharacter );
489 bool Character::IsNewLine() const
491 return Character::IsNewLine( mCharacter );
494 uint32_t Character::GetCharacter() const
499 void Character::SetCharacter( uint32_t character )
501 mCharacter = character;
504 bool Character::IsWhiteSpace( uint32_t character )
506 // TODO: It should cover unicode characters: http://en.wikipedia.org/wiki/Whitespace_character
507 return character <= CHAR_WHITE_SPACE;
510 bool Character::IsNewLine( uint32_t character )
512 return character == CHAR_NEW_LINE;
515 } // namespace Internal