From 107347fd130dda8102d6eb23d0fa9fc72dcd886d Mon Sep 17 00:00:00 2001 From: Seoyeon Kim Date: Wed, 5 Feb 2020 16:46:25 +0900 Subject: [PATCH] Modify to get the encoded offset in UTF8 - Get the number of bytes to figure out the length of utf8 Change-Id: I9c735ea888b2896f528e74b0c55d1b25fd2577a8 Signed-off-by: Seoyeon Kim --- .../adaptor-framework/input-method-context.cpp | 2 +- .../adaptor-framework/input-method-context.h | 25 +++++++++++++------- .../input/common/input-method-context-impl.h | 2 +- .../generic/input-method-context-impl-generic.cpp | 2 +- .../generic/input-method-context-impl-generic.h | 2 +- .../input-method-context-impl-ecore-wl.cpp | 27 ++++++++++++++-------- .../input-method-context-impl-ecore-wl.h | 4 ++-- .../ubuntu-x11/input-method-context-impl-x.cpp | 25 ++++++++++++++------ .../input/ubuntu-x11/input-method-context-impl-x.h | 4 ++-- .../windows/input-method-context-impl-win.cpp | 2 +- .../input/windows/input-method-context-impl-win.h | 4 ++-- 11 files changed, 64 insertions(+), 35 deletions(-) diff --git a/dali/devel-api/adaptor-framework/input-method-context.cpp b/dali/devel-api/adaptor-framework/input-method-context.cpp index 4dbbcd3..ae4d1c6 100755 --- a/dali/devel-api/adaptor-framework/input-method-context.cpp +++ b/dali/devel-api/adaptor-framework/input-method-context.cpp @@ -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 ); } diff --git a/dali/devel-api/adaptor-framework/input-method-context.h b/dali/devel-api/adaptor-framework/input-method-context.h index 1209d61..04a8e72 100755 --- a/dali/devel-api/adaptor-framework/input-method-context.h +++ b/dali/devel-api/adaptor-framework/input-method-context.h @@ -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& attrs ) const; + void GetPreeditStyle( PreEditAttributeDataContainer& attrs ) const; public: diff --git a/dali/internal/input/common/input-method-context-impl.h b/dali/internal/input/common/input-method-context-impl.h index a923588..4125be2 100755 --- a/dali/internal/input/common/input-method-context-impl.h +++ b/dali/internal/input/common/input-method-context-impl.h @@ -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 diff --git a/dali/internal/input/generic/input-method-context-impl-generic.cpp b/dali/internal/input/generic/input-method-context-impl-generic.cpp index b84f58e..1da21dc 100644 --- a/dali/internal/input/generic/input-method-context-impl-generic.cpp +++ b/dali/internal/input/generic/input-method-context-impl-generic.cpp @@ -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 diff --git a/dali/internal/input/generic/input-method-context-impl-generic.h b/dali/internal/input/generic/input-method-context-impl-generic.h index 2aa4b67..693d8de 100644 --- a/dali/internal/input/generic/input-method-context-impl-generic.h +++ b/dali/internal/input/generic/input-method-context-impl-generic.h @@ -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: diff --git a/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.cpp b/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.cpp index ab7c78b..c351e8a 100755 --- a/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.cpp +++ b/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.cpp @@ -42,8 +42,6 @@ #include #include -#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; diff --git a/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h b/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h index 4ffac3a..8a37100 100755 --- a/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h +++ b/dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h @@ -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 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; }; diff --git a/dali/internal/input/ubuntu-x11/input-method-context-impl-x.cpp b/dali/internal/input/ubuntu-x11/input-method-context-impl-x.cpp index ce6a57c..16d9e69 100755 --- a/dali/internal/input/ubuntu-x11/input-method-context-impl-x.cpp +++ b/dali/internal/input/ubuntu-x11/input-method-context-impl-x.cpp @@ -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; diff --git a/dali/internal/input/ubuntu-x11/input-method-context-impl-x.h b/dali/internal/input/ubuntu-x11/input-method-context-impl-x.h index f4de117..e707386 100755 --- a/dali/internal/input/ubuntu-x11/input-method-context-impl-x.h +++ b/dali/internal/input/ubuntu-x11/input-method-context-impl-x.h @@ -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 diff --git a/dali/internal/input/windows/input-method-context-impl-win.cpp b/dali/internal/input/windows/input-method-context-impl-win.cpp index 1061aec..b673e4b 100755 --- a/dali/internal/input/windows/input-method-context-impl-win.cpp +++ b/dali/internal/input/windows/input-method-context-impl-win.cpp @@ -371,7 +371,7 @@ void InputMethodContextWin::SetInputPanelPosition( unsigned int x, unsigned int DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelPosition\n" ); } -void InputMethodContextWin::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const +void InputMethodContextWin::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const { DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetPreeditStyle\n" ); attrs = mPreeditAttrs; diff --git a/dali/internal/input/windows/input-method-context-impl-win.h b/dali/internal/input/windows/input-method-context-impl-win.h index 1af29ef..253bc02 100755 --- a/dali/internal/input/windows/input-method-context-impl-win.h +++ b/dali/internal/input/windows/input-method-context-impl-win.h @@ -259,7 +259,7 @@ public: /** * @copydoc Dali::InputMethodContext::GetPreeditStyle() */ - void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const override; + void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const override; private: /** @@ -319,7 +319,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; + Dali::InputMethodContext::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data }; } // namespace Adaptor -- 2.7.4