Makes the LTR/RTL alignment of text follow the system language by default. 58/259858/17
authorJoogab Yun <joogab.yun@samsung.com>
Wed, 16 Jun 2021 05:19:35 +0000 (14:19 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Tue, 6 Jul 2021 01:55:25 +0000 (10:55 +0900)
The MATCH_SYSTEM_LANGUAGE_DIRECTION property defaults to true.

When the layout direction of TextLabel, TextField, or TextEditor is changed,
LTR/RTL alignment of text follows the layout direction of each control.

If you set MATCH_SYSTEM_LANGUAGE_DIRECTION to false
As before, LTR/RTL is determined according to the language of the text.

Change-Id: Ie97654a2309ffd4c30bec2c1b95d6337d8f4c674

25 files changed:
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/devel-api/controls/text-controls/text-field-devel.h
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/devel-api/text/text-enumerations-devel.h
dali-toolkit/devel-api/text/text-utils-devel.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.h
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/controls/text-controls/text-field-impl.h
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.h
dali-toolkit/internal/text/bidirectional-support.cpp
dali-toolkit/internal/text/bidirectional-support.h
dali-toolkit/internal/text/layouts/layout-engine.cpp
dali-toolkit/internal/text/layouts/layout-engine.h
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller-relayouter.cpp
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h
dali-toolkit/internal/text/text-model.cpp
dali-toolkit/internal/text/text-model.h
dali-toolkit/internal/visuals/text/text-visual.cpp

index 6028e02..b2a6f5a 100755 (executable)
@@ -323,7 +323,6 @@ void CreateTextModel( const std::string& text,
   // Set the layout parameters.
   textModel->mHorizontalAlignment = Text::HorizontalAlignment::BEGIN;
   textModel->mIgnoreSpacesAfterText = true;
-  textModel->mMatchSystemLanguageDirection = false;
   Layout::Parameters layoutParameters( textArea,
                                        textModel );
 
@@ -385,7 +384,7 @@ void ConfigureTextLabel( ControllerPtr controller )
   controller->SetTextElideEnabled( true );
 
   // Disable match system language direction
-  controller->SetMatchSystemLanguageDirection(false);
+  controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS);
 }
 
 void ConfigureTextField( ControllerPtr controller )
@@ -417,7 +416,7 @@ void ConfigureTextField( ControllerPtr controller )
   controller->SetTextElideEnabled( false );
 
   // Disable match system language direction
-  controller->SetMatchSystemLanguageDirection(false);
+  controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS);
 }
 
 void ConfigureTextEditor( ControllerPtr controller )
@@ -449,7 +448,7 @@ void ConfigureTextEditor( ControllerPtr controller )
   controller->SetTextElideEnabled( false );
 
   // Disable match system language direction
-  controller->SetMatchSystemLanguageDirection(false);
+  controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS);
 }
 
 } // namespace Text
index 8bdecaa..ed8d620 100755 (executable)
@@ -162,7 +162,6 @@ bool LayoutTextTest( const LayoutTextData& data )
   textModel->mHorizontalAlignment = Text::HorizontalAlignment::BEGIN;
   textModel->mLineWrapMode = LineWrap::WORD;
   textModel->mIgnoreSpacesAfterText = true;
-  textModel->mMatchSystemLanguageDirection = false;
   Layout::Parameters layoutParameters( data.textArea,
                                        textModel );
 
index baa872f..fb96330 100644 (file)
@@ -112,7 +112,7 @@ enum Type
   /**
    * @brief Modifies the default text alignment to match the direction of the system language.
    * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write
-   * @note The default value is false
+   * @note The default value is true
    */
   MATCH_SYSTEM_LANGUAGE_DIRECTION,
 
index e1c18f0..f9f13dd 100644 (file)
@@ -100,7 +100,7 @@ enum
   /**
    * @brief Modifies the default text alignment to match the direction of the system language.
    * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write
-   * @note The default value is false
+   * @note The default value is true
    */
   MATCH_SYSTEM_LANGUAGE_DIRECTION = ELLIPSIS + 3,
 
index efdad10..eed77fd 100644 (file)
@@ -95,7 +95,7 @@ enum Type
   /**
      * @brief Modifies the default text alignment to match the direction of the system language.
      * @details Name "matchSystemLanguageDirection", type (Property::BOLEAN), Read/Write
-     * @note The default value is false
+     * @note The default value is true
      *
      * If MATCH_SYSTEM_LANGUAGE_DIRECTION property set true, the default text alignment to match the direction of the system language.
      *
@@ -105,10 +105,10 @@ enum Type
      *
      * | TextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION                 |
      * |-----------------------------------------------------------------------
-     * |        false (default)            |                true              |
+     * |               false               |          true (default)          |
      * |-----------------------------------|----------------------------------|
      * |                     Hello world   |                  Hello world     |
-     * |   ﻡﺮﺤﺑﺍ.                          |                      ﻡﺮﺤﺑﺍ.      |
+     * |   ﻡﺮﺤﺑﺍ.                     |                          ﻡﺮﺤﺑﺍ.      |
      *
      */
   MATCH_SYSTEM_LANGUAGE_DIRECTION,
@@ -154,6 +154,7 @@ enum Type
    *  - fontSize: 10pt, fontSizeScale: 1.5
    */
   FONT_SIZE_SCALE,
+
 };
 
 } // namespace Property
index a74af43..9eb668f 100644 (file)
@@ -56,6 +56,18 @@ enum Mode
 
 } // namespace LineWrap
 
+/**
+ * A enum for defining text layout directions.
+ * It can also be inherited (from a parent) or deduced from the default language script of a locale.
+ * And it can be the direction of the text ifself.
+ */
+enum class MatchLayoutDirection
+{
+  INHERIT, // The text layout direction is inherited. If you change the layout direction, it will be aligned with the changed layout direction.
+  LOCALE,  // The text layout direction is determined by the locale of the system language.
+  CONTENTS // The text layout direction is determined by the text itself.
+};
+
 } // namespace DevelText
 
 } // namespace Toolkit
index 99ff139..046d014 100644 (file)
@@ -1031,9 +1031,8 @@ Size LayoutText(const RendererParameters& textParameters, TextAbstraction::TextR
   // Resize the vector of positions to have the same size than the vector of glyphs.
   rendererParameters.positions.Resize(numberOfGlyphs);
 
-  textModel->mLineWrapMode                 = Text::LineWrap::WORD;
-  textModel->mIgnoreSpacesAfterText        = false;
-  textModel->mMatchSystemLanguageDirection = false;
+  textModel->mLineWrapMode          = Text::LineWrap::WORD;
+  textModel->mIgnoreSpacesAfterText = false;
   Text::Layout::Parameters layoutParameters(internalDataModel.textLayoutArea,
                                             textModel);
 
index af27bd1..220e63e 100644 (file)
@@ -20,7 +20,6 @@
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/actors/actor-devel.h>
-#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/object/property-helper-devel.h>
 #include <dali/integration-api/adaptor-framework/adaptor.h>
@@ -698,7 +697,7 @@ void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Pr
       }
       case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
       {
-        impl.mController->SetMatchSystemLanguageDirection(value.Get<bool>());
+        impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
         break;
       }
       case Toolkit::DevelTextEditor::Property::MAX_LENGTH:
@@ -1119,7 +1118,7 @@ Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index inde
       }
       case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
       {
-        value = impl.mController->IsMatchSystemLanguageDirection();
+        value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
         break;
       }
       case Toolkit::DevelTextEditor::Property::MAX_LENGTH:
@@ -1376,6 +1375,8 @@ void TextEditor::OnInitialize()
   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
   mController->SetLayoutDirection(layoutDirection);
 
+  self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
+
   // Forward input events to controller
   EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
   GetTapGestureDetector().SetMaximumTapsRequired(2);
@@ -1501,15 +1502,8 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
 
   // Support Right-To-Left of padding
-  Dali::LayoutDirection::Type layoutDirection;
-  if(mController->IsMatchSystemLanguageDirection())
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(self).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
-  else
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(self.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
+  Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
+
   if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
   {
     std::swap(padding.start, padding.end);
@@ -2172,6 +2166,11 @@ void TextEditor::SetEditable(bool editable)
   }
 }
 
+void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
+{
+  mController->ChangedLayoutDirection();
+}
+
 TextEditor::TextEditor()
 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
   mAnimationPeriod(0.0f, 0.0f),
index 9a034a1..a39ccfa 100644 (file)
@@ -377,6 +377,13 @@ private: // Implementation
   void OnScrollIndicatorAnimationFinished(Animation& animation);
 
   /**
+  * @brief Callback function for when the layout is changed.
+  * @param[in] actor The actor whose layoutDirection is changed.
+  * @param[in] type  The layoutDirection.
+  */
+  void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
+
+  /**
    * Construct a new TextEditor.
    */
   TextEditor();
index 27eae92..e466063 100644 (file)
@@ -21,7 +21,6 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/adaptor-framework/key-devel.h>
-#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/object/property-helper-devel.h>
 #include <dali/integration-api/debug.h>
@@ -696,7 +695,7 @@ void TextField::SetProperty(BaseObject* object, Property::Index index, const Pro
       }
       case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
       {
-        impl.mController->SetMatchSystemLanguageDirection(value.Get<bool>());
+        impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
         break;
       }
       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
@@ -1081,7 +1080,7 @@ Property::Value TextField::GetProperty(BaseObject* object, Property::Index index
       }
       case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
       {
-        value = impl.mController->IsMatchSystemLanguageDirection();
+        value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
         break;
       }
       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
@@ -1301,6 +1300,8 @@ void TextField::OnInitialize()
   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
   mController->SetLayoutDirection(layoutDirection);
 
+  self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
+
   // Forward input events to controller
   EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
   GetTapGestureDetector().SetMaximumTapsRequired(2);
@@ -1413,15 +1414,8 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
 
   // Support Right-To-Left of padding
-  Dali::LayoutDirection::Type layoutDirection;
-  if(mController->IsMatchSystemLanguageDirection())
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(self).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
-  else
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(self.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
+  Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
+
   if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
   {
     std::swap(padding.start, padding.end);
@@ -1956,6 +1950,11 @@ bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
   return false;
 }
 
+void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
+{
+  mController->ChangedLayoutDirection();
+}
+
 void TextField::OnIdleSignal()
 {
   // Emits the change of input style signals.
index ae73c30..7eb5852 100644 (file)
@@ -333,6 +333,13 @@ private: // Implementation
   void EmitTextChangedSignal();
 
   /**
+   * @brief Callback function for when the layout is changed.
+   * @param[in] actor The actor whose layoutDirection is changed.
+   * @param[in] type  The layoutDirection.
+   */
+  void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
+
+  /**
    * Construct a new TextField.
    */
   TextField();
index 52f9c29..af0f85e 100644 (file)
@@ -21,7 +21,6 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
-#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/object/property-helper-devel.h>
 #include <dali/integration-api/debug.h>
@@ -457,7 +456,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
       }
       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
       {
-        impl.mController->SetMatchSystemLanguageDirection(value.Get<bool>());
+        impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
         break;
       }
       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
@@ -688,7 +687,7 @@ Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index
       }
       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
       {
-        value = impl.mController->IsMatchSystemLanguageDirection();
+        value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
         break;
       }
       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
@@ -786,6 +785,8 @@ void TextLabel::OnInitialize()
   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
   mController->SetLayoutDirection(layoutDirection);
 
+  self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
+
   // Forward input events to controller
   EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
   GetTapGestureDetector().SetMaximumTapsRequired(1);
@@ -899,8 +900,10 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
 {
   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n");
 
+  Actor self = Self();
+
   Extents padding;
-  padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+  padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
 
   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
 
@@ -911,15 +914,8 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
   }
 
   // Support Right-To-Left
-  Dali::LayoutDirection::Type layoutDirection;
-  if(mController->IsMatchSystemLanguageDirection())
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(Self()).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
-  else
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
+  Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
+
   const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
 
   if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded)
@@ -1048,6 +1044,11 @@ void TextLabel::ScrollingFinished()
   RequestTextRelayout();
 }
 
+void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
+{
+  mController->ChangedLayoutDirection();
+}
+
 TextLabel::TextLabel()
 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
index a204be6..2606011 100644 (file)
@@ -177,6 +177,13 @@ private:
     return mTextScroller;
   }
 
+  /**
+   * @brief Callback function for when the layout is changed.
+   * @param[in] actor The actor whose layoutDirection is changed.
+   * @param[in] type  The layoutDirection.
+   */
+  void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
+
 private: // Data
   Text::ControllerPtr   mController;
   Text::TextScrollerPtr mTextScroller;
index da8f961..90e8caf 100644 (file)
@@ -34,7 +34,7 @@ void SetBidirectionalInfo(const Vector<Character>&               text,
                           CharacterIndex                         startIndex,
                           Length                                 numberOfCharacters,
                           Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
-                          bool                                   matchSystemLanguageDirection,
+                          bool                                   matchLayoutDirection,
                           Dali::LayoutDirection::Type            layoutDirection)
 {
   // Find where to insert the new paragraphs.
@@ -113,7 +113,7 @@ void SetBidirectionalInfo(const Vector<Character>&               text,
         // Create the bidirectional info for the whole paragraph and store the index to the table with this info in the run.
         bidirectionalRun.bidirectionalInfoIndex = bidirectionalSupport.CreateInfo(textBuffer + bidirectionalRun.characterRun.characterIndex,
                                                                                   bidirectionalRun.characterRun.numberOfCharacters,
-                                                                                  matchSystemLanguageDirection,
+                                                                                  matchLayoutDirection,
                                                                                   layoutDirection);
 
         bidirectionalRun.direction = bidirectionalSupport.GetParagraphDirection(bidirectionalRun.bidirectionalInfoIndex);
index 46c368e..864f6a3 100644 (file)
@@ -43,8 +43,8 @@ namespace Text
  * @param[in] startIndex The character from where the bidirectional info is set.
  * @param[in] numberOfCharacters The number of characters.
  * @param[out] bidirectionalInfo Vector with the bidirectional infor for each paragraph.
- * @param[in] matchSystemLanguageDirection Whether match for system language direction or not.
- * @param[in] layoutDirection The direction of the system language.
+ * @param[in] matchLayoutDirection Whether match for layout direction or not.
+ * @param[in] layoutDirection The direction of the layout.
  */
 void SetBidirectionalInfo(const Vector<Character>&               text,
                           const Vector<ScriptRun>&               scripts,
@@ -52,8 +52,8 @@ void SetBidirectionalInfo(const Vector<Character>&               text,
                           CharacterIndex                         startIndex,
                           Length                                 numberOfCharacters,
                           Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
-                          bool                                   matchSystemLanguageDirection = false,
-                          Dali::LayoutDirection::Type            layoutDirection              = LayoutDirection::LEFT_TO_RIGHT);
+                          bool                                   matchLayoutDirection = false,
+                          Dali::LayoutDirection::Type            layoutDirection      = LayoutDirection::LEFT_TO_RIGHT);
 
 /**
  * @brief Sets the visual to logical map table for a given line.
index 25f83d1..6baed98 100644 (file)
@@ -1474,7 +1474,7 @@ struct Engine::Impl
              Vector<LineRun>&                lines,
              float&                          alignmentOffset,
              Dali::LayoutDirection::Type     layoutDirection,
-             bool                            matchSystemLanguageDirection)
+             bool                            matchLayoutDirection)
   {
     const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters;
 
@@ -1510,7 +1510,7 @@ struct Engine::Impl
                                    horizontalAlignment,
                                    line,
                                    layoutDirection,
-                                   matchSystemLanguageDirection);
+                                   matchLayoutDirection);
 
       // Updates the alignment offset.
       alignmentOffset = std::min(alignmentOffset, line.alignmentOffset);
@@ -1521,7 +1521,7 @@ struct Engine::Impl
                                     HorizontalAlignment::Type   horizontalAlignment,
                                     LineRun&                    line,
                                     Dali::LayoutDirection::Type layoutDirection,
-                                    bool                        matchSystemLanguageDirection)
+                                    bool                        matchLayoutDirection)
   {
     line.alignmentOffset = 0.f;
     const bool isLineRTL = RTL == line.direction;
@@ -1532,7 +1532,7 @@ struct Engine::Impl
     float lineLength  = line.width;
 
     // match align for system language direction
-    if(matchSystemLanguageDirection)
+    if(matchLayoutDirection)
     {
       // Swap the alignment type if the line is right to left.
       isLayoutRTL = layoutDirection == LayoutDirection::RIGHT_TO_LEFT;
@@ -1680,7 +1680,7 @@ void Engine::Align(const Size&                     size,
                    Vector<LineRun>&                lines,
                    float&                          alignmentOffset,
                    Dali::LayoutDirection::Type     layoutDirection,
-                   bool                            matchSystemLanguageDirection)
+                   bool                            matchLayoutDirection)
 {
   mImpl->Align(size,
                startIndex,
@@ -1689,7 +1689,7 @@ void Engine::Align(const Size&                     size,
                lines,
                alignmentOffset,
                layoutDirection,
-               matchSystemLanguageDirection);
+               matchLayoutDirection);
 }
 
 void Engine::SetDefaultLineSpacing(float lineSpacing)
index 28e987c..46cc972 100644 (file)
@@ -121,8 +121,8 @@ public:
    * @param[in] horizontalAlignment The horizontal alignment.
    * @param[in,out] lines The laid-out lines.
    * @param[out] alignmentOffset The alignment offset.
-   * @param[in] layoutDirection The direction of the system language.
-   * @param[in] matchSystemLanguageDirection Whether match align for system language direction or not.
+   * @param[in] layoutDirection The direction of the layout.
+   * @param[in] matchLayoutDirection Whether match align for layout direction or not.
    */
   void Align(const Size&                     size,
              CharacterIndex                  startIndex,
@@ -131,7 +131,7 @@ public:
              Vector<LineRun>&                lines,
              float&                          alignmentOffset,
              Dali::LayoutDirection::Type     layoutDirection,
-             bool                            matchSystemLanguageDirection);
+             bool                            matchLayoutDirection);
 
   /**
    * @brief Sets the default line spacing.
index 12cdae7..80b8756 100644 (file)
@@ -797,7 +797,7 @@ bool Controller::Impl::UpdateModel(OperationsMask operationsRequired)
                          startIndex,
                          requestedNumberOfCharacters,
                          bidirectionalInfo,
-                         mModel->mMatchSystemLanguageDirection,
+                         (mModel->mMatchLayoutDirection != DevelText::MatchLayoutDirection::CONTENTS),
                          mLayoutDirection);
 
     if(0u != bidirectionalInfo.Count())
@@ -1737,7 +1737,7 @@ void Controller::Impl::GetCursorPosition(CharacterIndex logical,
     cursorInfo.primaryCursorHeight = cursorInfo.lineHeight;
 
     bool isRTL = false;
-    if(mModel->mMatchSystemLanguageDirection)
+    if(mModel->mMatchLayoutDirection != DevelText::MatchLayoutDirection::CONTENTS)
     {
       isRTL = mLayoutDirection == LayoutDirection::RIGHT_TO_LEFT;
     }
index 55184ef..f6681bd 100644 (file)
@@ -355,7 +355,8 @@ struct Controller::Impl
     mTextFitMaxSize(DEFAULT_TEXTFIT_MAX),
     mTextFitStepSize(DEFAULT_TEXTFIT_STEP),
     mTextFitEnabled(false),
-    mFontSizeScale(DEFAULT_FONT_SIZE_SCALE)
+    mFontSizeScale(DEFAULT_FONT_SIZE_SCALE),
+    mIsLayoutDirectionChanged(false)
   {
     mModel = Model::New();
 
@@ -834,11 +835,12 @@ public:
 
   Shader mShaderBackground; ///< The shader for text background.
 
-  float mTextFitMinSize;     ///< Minimum Font Size for text fit. Default 10
-  float mTextFitMaxSize;     ///< Maximum Font Size for text fit. Default 100
-  float mTextFitStepSize;    ///< Step Size for font intervalse. Default 1
-  bool  mTextFitEnabled : 1; ///< Whether the text's fit is enabled.
-  float mFontSizeScale;      ///< Scale value for Font Size. Default 1.0
+  float mTextFitMinSize;               ///< Minimum Font Size for text fit. Default 10
+  float mTextFitMaxSize;               ///< Maximum Font Size for text fit. Default 100
+  float mTextFitStepSize;              ///< Step Size for font intervalse. Default 1
+  bool  mTextFitEnabled : 1;           ///< Whether the text's fit is enabled.
+  float mFontSizeScale;                ///< Scale value for Font Size. Default 1.0
+  bool  mIsLayoutDirectionChanged : 1; ///< Whether the layout has changed.
 
 private:
   friend ControllerImplEventHandler;
index 062153d..decbfc1 100644 (file)
@@ -384,7 +384,7 @@ Controller::UpdateTextType Controller::Relayouter::Relayout(Controller& controll
     textUpdateInfo.mCharacterIndex     = 0u;
   }
 
-  if(model->mMatchSystemLanguageDirection && impl.mLayoutDirection != layoutDirection)
+  if(impl.mLayoutDirection != layoutDirection)
   {
     // Clear the update info. This info will be set the next time the text is updated.
     textUpdateInfo.mClearAll = true;
@@ -394,6 +394,7 @@ Controller::UpdateTextType Controller::Relayouter::Relayout(Controller& controll
                                                     GET_GLYPH_METRICS |
                                                     SHAPE_TEXT |
                                                     UPDATE_DIRECTION |
+                                                    ALIGN |
                                                     LAYOUT |
                                                     BIDI_INFO |
                                                     REORDER);
@@ -622,7 +623,7 @@ bool Controller::Relayouter::DoRelayout(Controller& controller, const Size& size
                              lines,
                              impl.mModel->mAlignmentOffset,
                              impl.mLayoutDirection,
-                             impl.mModel->mMatchSystemLanguageDirection);
+                             (impl.mModel->mMatchLayoutDirection != DevelText::MatchLayoutDirection::CONTENTS));
 
     viewUpdated = true;
   }
index b2b6550..d78f275 100644 (file)
@@ -19,6 +19,8 @@
 #include <dali-toolkit/internal/text/text-controller.h>
 
 // EXTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/integration-api/debug.h>
 #include <memory.h>
 #include <cmath>
@@ -382,14 +384,19 @@ void Controller::SetIgnoreSpacesAfterText(bool ignore)
   mImpl->mModel->mIgnoreSpacesAfterText = ignore;
 }
 
-bool Controller::IsMatchSystemLanguageDirection() const
+void Controller::ChangedLayoutDirection()
 {
-  return mImpl->mModel->mMatchSystemLanguageDirection;
+  mImpl->mIsLayoutDirectionChanged = true;
 }
 
-void Controller::SetMatchSystemLanguageDirection(bool match)
+void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
 {
-  mImpl->mModel->mMatchSystemLanguageDirection = match;
+  mImpl->mModel->mMatchLayoutDirection = type;
+}
+
+DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
+{
+  return mImpl->mModel->mMatchLayoutDirection;
 }
 
 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
@@ -397,6 +404,19 @@ void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
   mImpl->mLayoutDirection = layoutDirection;
 }
 
+Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const
+{
+  if(mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE ||
+     (mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mImpl->mIsLayoutDirectionChanged))
+  {
+    return static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+  }
+  else
+  {
+    return static_cast<Dali::LayoutDirection::Type>(actor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+  }
+}
+
 bool Controller::IsShowingRealText() const
 {
   return mImpl->IsShowingRealText();
index 0802a77..5c1c9e2 100644 (file)
@@ -1441,24 +1441,36 @@ public: // Queries & retrieves.
   void SetIgnoreSpacesAfterText(bool ignore);
 
   /**
-   * @brief Retrieves matchSystemLanguageDirection value from model
-   * @return The value of matchSystemLanguageDirection
+   * @brief Sets SetMatchLayoutDirection value to model
+   * @param[in] match The value of matchLayoutDirection for the text
    */
-  bool IsMatchSystemLanguageDirection() const;
+  void SetMatchLayoutDirection(DevelText::MatchLayoutDirection type);
 
   /**
-   * @brief Sets matchSystemLanguageDirection value to model
-   * @param[in] match The value of matchSystemLanguageDirection for the text
+   * @brief Retrieves matchLayoutDirection value from model
+   * @return The value of matchLayoutDirection
    */
-  void SetMatchSystemLanguageDirection(bool match);
+  DevelText::MatchLayoutDirection GetMatchLayoutDirection() const;
 
   /**
-   * @brief Sets layoutDirection value
-   * @param[in] layoutDirection The value of system language direction
+   * @brief Sets layoutDirection type value.
+   * @param[in] layoutDirection The value of the layout direction type.
    */
   void SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection);
 
   /**
+   * @brief Gets layoutDirection type value.
+   * @param[in] actor The actor which will get the layout direction type.
+   * @return The value of the layout direction type.
+   */
+  Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const;
+
+  /**
+   * @brief Sets the layout direction changed.
+   */
+  void ChangedLayoutDirection();
+
+  /**
    * @brief Retrieves if showing real text or not.
    * @return The value of showing real text.
    */
index 3868979..62ee89a 100644 (file)
@@ -229,14 +229,17 @@ Model::Model()
   mAlignmentOffset(0.0f),
   mElideEnabled(false),
   mIgnoreSpacesAfterText(true),
-  mMatchSystemLanguageDirection(true)
+  mMatchLayoutDirection(DevelText::MatchLayoutDirection::INHERIT)
 {
   mLogicalModel = LogicalModel::New();
   mVisualModel  = VisualModel::New();
 
   // Check environment variable for DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION
-  auto match                    = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION);
-  mMatchSystemLanguageDirection = match ? (std::atoi(match) == 0 ? false : true) : mMatchSystemLanguageDirection;
+  auto match = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION);
+  if(match && (std::atoi(match) == 0))
+  {
+    mMatchLayoutDirection = DevelText::MatchLayoutDirection::CONTENTS;
+  }
 }
 
 Model::~Model()
index 751f230..139b8a3 100644 (file)
@@ -257,16 +257,16 @@ public:
    * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control.
    * Typically this will have a negative value with scrolling occurs.
    */
-  Vector2                                mScrollPosition;                   ///< The text is offset by this position when scrolling.
-  Vector2                                mScrollPositionLast;               ///< The last offset value of mScrollPosition
-  HorizontalAlignment::Type              mHorizontalAlignment;              ///< The layout's horizontal alignment.
-  VerticalAlignment::Type                mVerticalAlignment;                ///< The layout's vertical alignment.
-  DevelText::VerticalLineAlignment::Type mVerticalLineAlignment;            ///< The layout's vertical line alignment.
-  Text::LineWrap::Mode                   mLineWrapMode;                     ///< The text wrap mode
-  float                                  mAlignmentOffset;                  ///< The alignment offset.
-  bool                                   mElideEnabled : 1;                 ///< Whether the text's elide is enabled.
-  bool                                   mIgnoreSpacesAfterText : 1;        ///< Whether ignoring spaces after text or not. Default is true.
-  bool                                   mMatchSystemLanguageDirection : 1; ///< Whether match align for system language direction or not. Default is false.
+  Vector2                                mScrollPosition;            ///< The text is offset by this position when scrolling.
+  Vector2                                mScrollPositionLast;        ///< The last offset value of mScrollPosition
+  HorizontalAlignment::Type              mHorizontalAlignment;       ///< The layout's horizontal alignment.
+  VerticalAlignment::Type                mVerticalAlignment;         ///< The layout's vertical alignment.
+  DevelText::VerticalLineAlignment::Type mVerticalLineAlignment;     ///< The layout's vertical line alignment.
+  Text::LineWrap::Mode                   mLineWrapMode;              ///< The text wrap mode
+  float                                  mAlignmentOffset;           ///< The alignment offset.
+  bool                                   mElideEnabled : 1;          ///< Whether the text's elide is enabled.
+  bool                                   mIgnoreSpacesAfterText : 1; ///< Whether ignoring spaces after text or not. Default is true.
+  DevelText::MatchLayoutDirection        mMatchLayoutDirection;      ///< Whether to match text alignment with layout direction or not.
 };
 
 } // namespace Text
index 870ac09..19ecb5c 100644 (file)
@@ -20,7 +20,6 @@
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/image-loading.h>
-#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/images/pixel-data-devel.h>
 #include <dali/devel-api/rendering/renderer-devel.h>
 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
@@ -474,15 +473,7 @@ void TextVisual::UpdateRenderer()
     return;
   }
 
-  Dali::LayoutDirection::Type layoutDirection;
-  if(mController->IsMatchSystemLanguageDirection())
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(control).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
-  else
-  {
-    layoutDirection = static_cast<Dali::LayoutDirection::Type>(control.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  }
+  Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(control);
 
   const Text::Controller::UpdateTextType updateTextType = mController->Relayout(relayoutSize, layoutDirection);