Character - Return the script which the character belongs. 29/28629/1
authorVictor Cebollada <v.cebollada@samsung.com>
Fri, 10 Oct 2014 13:33:01 +0000 (14:33 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Fri, 10 Oct 2014 14:26:18 +0000 (15:26 +0100)
Change-Id: Ib9fa04bb6bf62621681f85cb78c6b4b1b547fe94
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
automated-tests/src/dali/utc-Dali-Character.cpp
dali/internal/event/text/character-impl.cpp
dali/internal/event/text/character-impl.h
dali/public-api/text/character.cpp
dali/public-api/text/character.h

index 9f0a47c42d4cddcb802a6a2d33fc8de2fbc3b52c..e7b9523e3b3a046794a4d16a5fabb20a9b266567 100644 (file)
@@ -123,6 +123,59 @@ int UtcDaliGetCharacterDirection(void)
   END_TEST;
 }
 
+int UtcDaliGetScript(void)
+{
+  tet_infoline("UtcDaliGetScript ");
+  TestApplication application;
+
+  Text text( std::string("aᴆₘऄঅਅઅଅஅఅಅഅඅض") );
+
+  Character c0 = text[0];
+  Character c1 = text[1];
+  Character c2 = text[2];
+
+  DALI_TEST_EQUALS( c0.GetScript(), Character::LATIN, TEST_LOCATION );
+  DALI_TEST_EQUALS( c1.GetScript(), Character::LATIN, TEST_LOCATION );
+  DALI_TEST_EQUALS( c2.GetScript(), Character::LATIN, TEST_LOCATION );
+
+
+  Character c3 = text[3];
+  DALI_TEST_EQUALS( c3.GetScript(), Character::DEVANAGARI, TEST_LOCATION );
+
+  Character c4 = text[4];
+  DALI_TEST_EQUALS( c4.GetScript(), Character::BENGALI, TEST_LOCATION );
+
+  Character c5 = text[5];
+  DALI_TEST_EQUALS( c5.GetScript(), Character::GURMUKHI, TEST_LOCATION );
+
+  Character c6 = text[6];
+  DALI_TEST_EQUALS( c6.GetScript(), Character::GUJARATI, TEST_LOCATION );
+
+  Character c7 = text[7];
+  DALI_TEST_EQUALS( c7.GetScript(), Character::ORIYA, TEST_LOCATION );
+
+  Character c8 = text[8];
+  DALI_TEST_EQUALS( c8.GetScript(), Character::TAMIL, TEST_LOCATION );
+
+  Character c9 = text[9];
+  DALI_TEST_EQUALS( c9.GetScript(), Character::TELUGU, TEST_LOCATION );
+
+  Character c10 = text[10];
+  DALI_TEST_EQUALS( c10.GetScript(), Character::KANNADA, TEST_LOCATION );
+
+  Character c11 = text[11];
+  DALI_TEST_EQUALS( c11.GetScript(), Character::MALAYALAM, TEST_LOCATION );
+
+  Character c12 = text[12];
+  DALI_TEST_EQUALS( c12.GetScript(), Character::SINHALA, TEST_LOCATION );
+
+  Character c13 = text[13];
+  DALI_TEST_EQUALS( c13.GetScript(), Character::ARABIC, TEST_LOCATION );
+
+  // TODO : add more characters to cover all ranges.
+  END_TEST;
+}
+
 int UtcDaliCharacterIsWhiteSpace(void)
 {
   tet_infoline("UtcDaliCharacterIsWhiteSpace ");
index f03c377c02c41292421def7b7608fecc5d1e41a5..9b7df7fbaa523647277c299548e21808039a6687 100644 (file)
@@ -238,6 +238,196 @@ bool IsCharLeftToRight(uint32_t i)
   return true;
 }
 
+Dali::Character::Script GetCharacterScript( uint32_t character )
+{
+  // Latin script:
+  // 0x0000 - 0x007f C0 Controls and Basic Latin
+  // 0x0080 - 0x00ff C1 Controls and Latin-1 Supplement
+  // 0x0100 - 0x017f Latin Extended-A
+  // 0x0180 - 0x024f Latin Extended-B
+  // 0x0250 - 0x02af IPA Extensions
+  // 0x02b0 - 0x02ff Spacing Modifier Letters
+  // 0x1d00 - 0x1d7f Phonetic Extensions
+  // 0x1d80 - 0x1dbf Phonetic Extensions Supplement
+  // 0x1e00 - 0x1eff Latin Extended Additional
+  // 0x2070 - 0x209f Superscripts and Subscripts
+  // 0x2100 - 0x214f Letterlike symbols
+  // 0x2150 - 0x218f Number Forms
+  // 0x2c60 - 0x2c7f Latin Extended-C
+  // 0xa720 - 0xa7ff Latin Extended-D
+  // 0xab30 - 0xab6f Latin Extended-E
+  // 0xfb00 - 0xfb4f Alphabetic Presentation Forms
+  // 0xff00 - 0xffef Halfwidth and Fullwidth Forms
+
+  // Brahmic scripts:
+  // 0x0900 - 0x097f Devanagari
+  // 0x0980 - 0x09ff Bengali
+  // 0x0a00 - 0x0a7f Gurmukhi
+  // 0x0a80 - 0x0aff Gujarati
+  // 0x0b00 - 0x0b7f Oriya
+  // 0x0b80 - 0x0bff Tamil
+  // 0x0c00 - 0x0c7f Telugu
+  // 0x0c80 - 0x0cff Kannada
+  // 0x0d00 - 0x0d7f Malayalam
+
+  // Sinhala script.
+  // 0x0d80 - 0x0dff Sinhala
+
+  // Arabic script.
+  // 0x0600 - 0x06ff
+  // 0x0750 - 0x077f
+  // 0x08A0 - 0x08ff
+  // 0xfb50 - 0xfdff
+  // 0xfe70 - 0xfeff
+  // 0x1ee00 - 0x1eeff
+
+
+  if( character <= 0x0cff )
+  {
+    if( character <= 0x09ff )
+    {
+      if( character <= 0x077f )
+      {
+        if( character <= 0x02ff )
+        {
+          return Dali::Character::LATIN;
+        }
+        if( ( 0x0600 <= character ) && ( character <= 0x06ff ) )
+        {
+          return Dali::Character::ARABIC;
+        }
+        if( ( 0x0750 <= character ) && ( character <= 0x077f ) )
+        {
+          return Dali::Character::ARABIC;
+        }
+      }
+      else
+      {
+        if( ( 0x08A0 <= character ) && ( character <= 0x08ff ) )
+        {
+          return Dali::Character::ARABIC;
+        }
+        if( ( 0x0900 <= character ) && ( character <= 0x097f ) )
+        {
+          return Dali::Character::DEVANAGARI;
+        }
+        if( ( 0x0980 <= character ) && ( character <= 0x09ff ) )
+        {
+          return Dali::Character::BENGALI;
+        }
+      }
+    }
+    else
+    {
+      if( character <= 0x0b7f )
+      {
+        if( ( 0x0a00 <= character ) && ( character <= 0x0a7f ) )
+        {
+          return Dali::Character::GURMUKHI;
+        }
+        if( ( 0x0a80 <= character ) && ( character <= 0x0aff ) )
+        {
+          return Dali::Character::GUJARATI;
+        }
+        if( ( 0x0b00 <= character ) && ( character <= 0x0b7f ) )
+        {
+          return Dali::Character::ORIYA;
+        }
+      }
+      else
+      {
+        if( ( 0x0b80 <= character ) && ( character <= 0x0bff ) )
+        {
+          return Dali::Character::TAMIL;
+        }
+        if( ( 0x0c00 <= character ) && ( character <= 0x0c7f ) )
+        {
+          return Dali::Character::TELUGU;
+        }
+        if( ( 0x0c80 <= character ) && ( character <= 0x0cff ) )
+        {
+          return Dali::Character::KANNADA;
+        }
+      }
+    }
+  }
+  else
+  {
+    if( character <= 0x2c7f )
+    {
+      if( character <= 0x1eff )
+      {
+        if( ( 0x0d00 <= character ) && ( character <= 0x0d7f ) )
+        {
+          return Dali::Character::MALAYALAM;
+        }
+        if( ( 0x0d80 <= character ) && ( character <= 0x0dff ) )
+        {
+          return Dali::Character::SINHALA;
+        }
+        if( ( 0x1d00 <= character ) && ( character <= 0x1eff ) )
+        {
+          return Dali::Character::LATIN;
+        }
+      }
+      else
+      {
+        if( ( 0x2070 <= character ) && ( character <= 0x209f ) )
+        {
+          return Dali::Character::LATIN;
+        }
+        if( ( 0x2100 <= character ) && ( character <= 0x218f ) )
+        {
+          return Dali::Character::LATIN;
+        }
+        if( ( 0x2c60 <= character ) && ( character <= 0x2c7f ) )
+        {
+          return Dali::Character::LATIN;
+        }
+      }
+    }
+    else
+    {
+      if( character <= 0xfdff )
+      {
+        if( ( 0xa720 <= character ) && ( character <= 0xa7ff ) )
+        {
+          return Dali::Character::LATIN;
+        }
+        if( ( 0xab30 <= character ) && ( character <= 0xab6f ) )
+        {
+          return Dali::Character::LATIN;
+        }
+        if( ( 0xfb00 <= character ) && ( character <= 0xfb4f ) )
+        {
+          return Dali::Character::LATIN;
+        }
+        if( ( 0xfb50 <= character ) && ( character <= 0xfdff ) )
+        {
+          return Dali::Character::ARABIC;
+        }
+      }
+      else
+      {
+        if( ( 0xfe70 <= character ) && ( character <= 0xfeff ) )
+        {
+          return Dali::Character::ARABIC;
+        }
+        if( ( 0xff00 <= character ) && ( character <= 0xffef ) )
+        {
+          return Dali::Character::LATIN;
+        }
+        if( ( 0x1ee00 <= character ) && ( character <= 0x1eeff ) )
+        {
+          return Dali::Character::ARABIC;
+        }
+      }
+    }
+  }
+
+  return Dali::Character::UNKNOWN;
+}
+
 } // unnamed namespace
 
 namespace Dali
@@ -276,6 +466,16 @@ Character::CharacterDirection Character::GetCharacterDirection() const
   return GetCharacterDirection( mCharacter );
 }
 
+Dali::Character::Script Character::GetScript( uint32_t character )
+{
+  return GetCharacterScript( character );
+}
+
+Dali::Character::Script Character::GetScript() const
+{
+  return GetCharacterScript( mCharacter );
+}
+
 bool Character::IsLeftToRight() const
 {
   return GetCharacterDirection() != Dali::Character::RightToLeft;
index 370a75eac08ae4f33f6c424480e70db59df1a438..5fb2478013c7b4da5bc056ef0224680e84f7eb3f 100644 (file)
@@ -66,6 +66,20 @@ public:
    */
   CharacterDirection GetCharacterDirection() const;
 
+  /**
+   * Returns the character's script.
+   *
+   * @param[in] character The unicode value of the character.
+   *
+   * @return The script of the character.
+   */
+  static Dali::Character::Script GetScript( uint32_t character );
+
+  /**
+   * @copydoc Dali::Character::GetScript()
+   */
+  Dali::Character::Script GetScript() const;
+
   /**
    * @copydoc Dali::Character::IsLeftToRight()
    */
index a1d258b0dcfc742df21baf6bdec253d974d3e8d9..f85d13308f7011c1e82662ae84da6998e21a6860 100644 (file)
@@ -59,6 +59,11 @@ Character::CharacterDirection Character::GetCharacterDirection() const
   return mImpl->GetCharacterDirection();
 }
 
+Character::Script Character::GetScript() const
+{
+  return mImpl->GetScript();
+}
+
 bool Character::IsWhiteSpace() const
 {
   return mImpl->IsWhiteSpace();
index 1128d61ac192aafa540b18995a6a34430525deb1..7fa01086c1a56059499fb342f02b444c7a738667 100644 (file)
@@ -58,6 +58,31 @@ public:
     Neutral                                                 ///< Neutral characters follow the direction of characters surrounding them (e.g. whitespace ' ')
   };
 
+  /**
+   * @brief Script
+   *
+   * Script is the writing system used by a language.
+   * Typically one script can be used to write different languages although one language could be written in different scrips.
+   *
+   * i.e Many of the western languages like English, latin languages, etc use the latin script. Japanese uses the kanji, hiragana, katakana and latin scrips.
+   */
+  enum Script
+  {
+    LATIN,      ///< The latin script. Used by many western languages.
+    ARABIC,     ///< The arabic script. Used by Arab and Urdu among others.
+    DEVANAGARI, ///< The devanagari script. Used by Hindi, Marathi, Sindhi, Nepali and Sanskrit.
+    BENGALI,    ///< The Bengali script. Used by Bangla, Assamese, Bishnupriya Manipuri, Daphla, Garo, Hallam, Khasi, Mizo, Munda, Naga, Rian, and Santali.
+    GURMUKHI,   ///< The Gurmukhi script. Used by Punjabi.
+    GUJARATI,   ///< The Gujarati script. Used by Gujarati.
+    ORIYA,      ///< The Oriya script. Used by Oriya, Khondi, and Santali.
+    TAMIL,      ///< The Tamil script. Used by Tamil, Badaga, and Saurashtra.
+    TELUGU,     ///< The Telugu script. Used by Telugu, Gondi, and Lambadi.
+    KANNADA,    ///< The Kannada script. Used by Kannada and Tulu.
+    MALAYALAM,  ///< The Malayalam script. Used by Malayalam.
+    SINHALA,    ///< The Sinhala script. Used by Sinhala and Pali.
+    UNKNOWN     ///< The script is unknown.
+  };
+
 public:
 
   /**
@@ -103,6 +128,12 @@ public:
    */
   CharacterDirection GetCharacterDirection() const;
 
+
+  /**
+   * @brief Returs the script of this character.
+   */
+  Script GetScript() const;
+
   /**
    * @brief Returns whether this character is white space (true)
    * or not (false).