Modify to get the encoded offset in UTF8 61/223961/7
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Wed, 5 Feb 2020 07:46:25 +0000 (16:46 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Thu, 27 Feb 2020 08:16:28 +0000 (17:16 +0900)
- Get the number of bytes to figure out the length of utf8

Change-Id: I9c735ea888b2896f528e74b0c55d1b25fd2577a8
Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
dali/devel-api/adaptor-framework/input-method-context.cpp
dali/devel-api/adaptor-framework/input-method-context.h
dali/internal/input/common/input-method-context-impl.h
dali/internal/input/generic/input-method-context-impl-generic.cpp
dali/internal/input/generic/input-method-context-impl-generic.h
dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.cpp
dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h
dali/internal/input/ubuntu-x11/input-method-context-impl-x.cpp
dali/internal/input/ubuntu-x11/input-method-context-impl-x.h
dali/internal/input/windows/input-method-context-impl-win.cpp
dali/internal/input/windows/input-method-context-impl-win.h

index 4dbbcd3..ae4d1c6 100755 (executable)
@@ -221,7 +221,7 @@ void InputMethodContext::SetInputPanelPosition( unsigned int x, unsigned int y )
   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetInputPanelPosition( x, y );
 }
 
-void InputMethodContext::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const
+void InputMethodContext::GetPreeditStyle( PreEditAttributeDataContainer& attrs ) const
 {
   Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetPreeditStyle( attrs );
 }
index 1209d61..04a8e72 100755 (executable)
@@ -50,8 +50,8 @@ class DALI_ADAPTOR_API InputMethodContext : public BaseHandle
 public:
 
   /**
-  * @brief The direction of text.
-  */
+   * @brief The direction of text.
+   */
   enum TextDirection
   {
     LeftToRight,
@@ -120,9 +120,16 @@ public:
    */
   struct PreeditAttributeData
   {
-    PreeditStyle preeditType; /// The preedit style type
-    unsigned int startIndex;  /// The start index of preedit
-    unsigned int endIndex;    /// The end index of preedit
+    PreeditAttributeData()
+    : preeditType( PreeditStyle::NONE ),
+      startIndex( 0 ),
+      endIndex( 0 )
+    {
+    }
+
+    PreeditStyle preeditType;  /// The preedit style type
+    unsigned int startIndex;   /// The start index of preedit
+    unsigned int endIndex;     /// The end index of preedit
   };
 
   /**
@@ -210,6 +217,8 @@ public:
   typedef Signal< void ( int ) > LanguageChangedSignalType;  ///< Language changed signal
   typedef Signal< void ( const std::string&, const std::string&, const std::string& ) > ContentReceivedSignalType; ///< Content received signal
 
+  using PreEditAttributeDataContainer = Vector< Dali::InputMethodContext::PreeditAttributeData >;
+
 public:
 
   /**
@@ -491,11 +500,11 @@ public:
   void SetInputPanelPosition( unsigned int x, unsigned int y );
 
   /**
-   * @brief Gets the preedit attrs data.
+   * @brief Gets the preedit attributes data.
    *
-   * @param[out] attrs The preedit attrs data.
+   * @param[out] attrs The preedit attributes data.
    */
-  void GetPreeditStyle( Vector<PreeditAttributeData>& attrs ) const;
+  void GetPreeditStyle( PreEditAttributeDataContainer& attrs ) const;
 
 public:
 
index a923588..4125be2 100755 (executable)
@@ -276,7 +276,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  virtual void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const {}
+  virtual void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const {}
 
 public:  // Signals
 
index b84f58e..1da21dc 100644 (file)
@@ -298,7 +298,7 @@ void InputMethodContextGeneric::SetInputPanelPosition( unsigned int x, unsigned
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelPosition\n" );
 }
 
-void InputMethodContextGeneric::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs) const
+void InputMethodContextGeneric::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n" );
   // Do Nothing
index 2aa4b67..693d8de 100644 (file)
@@ -267,7 +267,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const override;
+  void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const override;
 
 public:
 
index ab7c78b..c351e8a 100755 (executable)
@@ -42,8 +42,6 @@
 #include <dali/internal/system/common/singleton-service-impl.h>
 #include <dali/internal/window-system/common/window-render-surface.h>
 
-#define TOKEN_STRING(x) #x
-
 Ecore_IMF_Input_Panel_Layout panelLayoutMap[] =
 {
    ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL,
@@ -105,22 +103,30 @@ size_t Utf8SequenceLength(const unsigned char leadByte)
 {
   size_t length = 0;
 
-  if ((leadByte & 0x80) == 0 )          //ASCII character (lead bit zero)
+  if( ( leadByte & 0x80 ) == 0 )         //ASCII character (lead bit zero)
   {
     length = 1;
   }
-  else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
+  else if( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
   {
     length = 2;
   }
-  else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
+  else if( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
   {
     length = 3;
   }
-  else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
+  else if( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
   {
     length = 4;
   }
+  else if( ( leadByte & 0xfc ) == 0xf8 ) //1111 10xx
+  {
+    length = 5;
+  }
+  else if( ( leadByte & 0xfe ) == 0xfc ) //1111 110x
+  {
+    length = 6;
+  }
 
   return length;
 }
@@ -521,16 +527,19 @@ void InputMethodContextEcoreWl::PreEditChanged( void*, ImfContext* imfContext, v
       size_t byteIndex = 0;
 
       // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
-      const char leadByte = preEditString[byteIndex];
+      char leadByte = preEditString[byteIndex];
+
       while( leadByte != '\0' )
       {
+        leadByte = preEditString[byteIndex]; // Update the character to get the number of its byte
+
         // attr->end_index is provided as a byte position not character and we need to know the character position.
         const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
         if( byteIndex <= attr->start_index )
         {
            data.startIndex = visualCharacterIndex;
         }
-        if ( byteIndex >= attr->end_index )
+        if( byteIndex >= attr->end_index )
         {
           data.endIndex = visualCharacterIndex;
           break;
@@ -1145,7 +1154,7 @@ void InputMethodContextEcoreWl::SetInputPanelPosition( unsigned int x, unsigned
   mBackupOperations[Operation::SET_INPUT_PANEL_POSITION] = std::bind( &InputMethodContextEcoreWl::SetInputPanelPosition, this, x, y );
 }
 
-void InputMethodContextEcoreWl::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const
+void InputMethodContextEcoreWl::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetPreeditStyle\n" );
   attrs = mPreeditAttrs;
index 4ffac3a..8a37100 100755 (executable)
@@ -265,7 +265,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const override;
+  void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const override;
 
 private:
   /**
@@ -345,7 +345,7 @@ private:
 
   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
   InputMethodOptions mOptions;
-  Vector< Dali::InputMethodContext::PreeditAttributeData > mPreeditAttrs; ///< Stores preedit attr data
+  Dali::InputMethodContext::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data
 
   int mWindowId;
 };
index ce6a57c..16d9e69 100755 (executable)
@@ -56,22 +56,30 @@ size_t Utf8SequenceLength(const unsigned char leadByte)
 {
   size_t length = 0;
 
-  if ((leadByte & 0x80) == 0 )          //ASCII character (lead bit zero)
+  if( ( leadByte & 0x80 ) == 0 )         //ASCII character (lead bit zero)
   {
     length = 1;
   }
-  else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
+  else if( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
   {
     length = 2;
   }
-  else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
+  else if( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
   {
     length = 3;
   }
-  else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
+  else if( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
   {
     length = 4;
   }
+  else if( ( leadByte & 0xfc ) == 0xf8 ) //1111 10xx
+  {
+    length = 5;
+  }
+  else if( ( leadByte & 0xfe ) == 0xfc ) //1111 110x
+  {
+    length = 6;
+  }
 
   return length;
 }
@@ -332,16 +340,19 @@ void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* e
       size_t byteIndex = 0;
 
       // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
-      const char leadByte = preEditString[byteIndex];
+      char leadByte = preEditString[byteIndex];
+
       while( leadByte != '\0' )
       {
+        leadByte = preEditString[byteIndex]; // Update the character to get the number of its byte
+
         // attr->end_index is provided as a byte position not character and we need to know the character position.
         const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
         if( byteIndex <= attr->start_index )
         {
            data.startIndex = visualCharacterIndex;
         }
-        if ( byteIndex >= attr->end_index )
+        if( byteIndex >= attr->end_index )
         {
           data.endIndex = visualCharacterIndex;
           break;
@@ -840,7 +851,7 @@ void InputMethodContextX::SetInputPanelPosition( unsigned int x, unsigned int y
   // ecore_imf_context_input_panel_position_set() is supported from ecore-imf 1.21.0 version.
 }
 
-void InputMethodContextX::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const
+void InputMethodContextX::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n" );
   attrs = mPreeditAttrs;
index f4de117..e707386 100755 (executable)
@@ -271,7 +271,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const override;
+  void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const override;
 
 private:
   /**
@@ -346,7 +346,7 @@ private:
   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
   InputMethodOptions        mOptions;
-  Vector< Dali::InputMethodContext::PreeditAttributeData > mPreeditAttrs; ///< Stores preedit attr data
+  Dali::InputMethodContext::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data
 };
 
 } // namespace Adaptor
index 1061aec..b673e4b 100755 (executable)
@@ -371,7 +371,7 @@ void InputMethodContextWin::SetInputPanelPosition( unsigned int x, unsigned int
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelPosition\n" );\r
 }\r
 \r
-void InputMethodContextWin::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const\r
+void InputMethodContextWin::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const\r
 {\r
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetPreeditStyle\n" );\r
   attrs = mPreeditAttrs;\r
index 1af29ef..253bc02 100755 (executable)
@@ -259,7 +259,7 @@ public:
   /**\r
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()\r
    */\r
-  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const override;\r
+  void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const override;\r
 \r
 private:\r
   /**\r
@@ -319,7 +319,7 @@ private:
   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.\r
   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.\r
   InputMethodOptions        mOptions;\r
-  Vector< Dali::InputMethodContext::PreeditAttributeData > mPreeditAttrs;\r
+  Dali::InputMethodContext::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data\r
 };\r
 \r
 } // namespace Adaptor\r