Merge "Makes the LTR/RTL alignment of text follow the system language by default...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-model.cpp
old mode 100755 (executable)
new mode 100644 (file)
index da87e0c..afc9ed0
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // CLASS HEADER
 #include <dali-toolkit/internal/text/text-model.h>
 
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/environment-variable.h>
+
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Text
 {
+namespace
+{
+const char* DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION("DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION");
+}
 
 ModelPtr Model::New()
 {
-  return ModelPtr( new Model() );
+  return ModelPtr(new Model());
 }
 
 const Size& Model::GetControlSize() const
@@ -112,6 +117,21 @@ const ColorIndex* const Model::GetColorIndices() const
   return mVisualModel->mColorIndices.Begin();
 }
 
+const Vector4* const Model::GetBackgroundColors() const
+{
+  return mVisualModel->mBackgroundColors.Begin();
+}
+
+const ColorIndex* const Model::GetBackgroundColorIndices() const
+{
+  return mVisualModel->mBackgroundColorIndices.Begin();
+}
+
+bool const Model::IsMarkupBackgroundColorSet() const
+{
+  return (mVisualModel->mBackgroundColors.Count() > 0);
+}
+
 const Vector4& Model::GetDefaultColor() const
 {
   return mVisualModel->mTextColor;
@@ -152,9 +172,9 @@ Length Model::GetNumberOfUnderlineRuns() const
   return mVisualModel->GetNumberOfUnderlineRuns();
 }
 
-void Model::GetUnderlineRuns( GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns ) const
+void Model::GetUnderlineRuns(GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
 {
-  mVisualModel->GetUnderlineRuns( underlineRuns, index, numberOfRuns );
+  mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
 }
 
 const Vector4& Model::GetOutlineColor() const
@@ -177,22 +197,49 @@ bool Model::IsBackgroundEnabled() const
   return mVisualModel->IsBackgroundEnabled();
 }
 
+bool Model::IsMarkupProcessorEnabled() const
+{
+  return mVisualModel->IsMarkupProcessorEnabled();
+}
+
+const GlyphInfo* Model::GetHyphens() const
+{
+  return mVisualModel->mHyphen.glyph.Begin();
+}
+
+const Length* Model::GetHyphenIndices() const
+{
+  return mVisualModel->mHyphen.index.Begin();
+}
+
+Length Model::GetHyphensCount() const
+{
+  return mVisualModel->mHyphen.glyph.Size();
+}
+
 Model::Model()
 : mLogicalModel(),
   mVisualModel(),
   mScrollPosition(),
   mScrollPositionLast(),
-  mHorizontalAlignment( Text::HorizontalAlignment::BEGIN ),
-  mVerticalAlignment( Text::VerticalAlignment::TOP ),
-  mVerticalLineAlignment( DevelText::VerticalLineAlignment::TOP ),
-  mLineWrapMode( Text::LineWrap::WORD ),
-  mAlignmentOffset( 0.0f ),
-  mElideEnabled( false ),
-  mIgnoreSpacesAfterText( true ),
-  mMatchSystemLanguageDirection( false )
+  mHorizontalAlignment(Text::HorizontalAlignment::BEGIN),
+  mVerticalAlignment(Text::VerticalAlignment::TOP),
+  mVerticalLineAlignment(DevelText::VerticalLineAlignment::TOP),
+  mLineWrapMode(Text::LineWrap::WORD),
+  mAlignmentOffset(0.0f),
+  mElideEnabled(false),
+  mIgnoreSpacesAfterText(true),
+  mMatchLayoutDirection(DevelText::MatchLayoutDirection::INHERIT)
 {
   mLogicalModel = LogicalModel::New();
-  mVisualModel = VisualModel::New();
+  mVisualModel  = VisualModel::New();
+
+  // Check environment variable for DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION
+  auto match = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION);
+  if(match && (std::atoi(match) == 0))
+  {
+    mMatchLayoutDirection = DevelText::MatchLayoutDirection::CONTENTS;
+  }
 }
 
 Model::~Model()