[dali_2.3.42] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / dali-toolkit-test-utils / toolkit-text-utils.cpp
index e9d0ef0..088d5d8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -21,6 +21,7 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/text-abstraction/font-client.h>
 #include <limits>
+#include <cstring> ///< for memcpy
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/bidirectional-support.h>
 #include <dali-toolkit/internal/text/hyphenator.h>
 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
-#include <dali-toolkit/internal/text/markup-processor.h>
+#include <dali-toolkit/internal/text/markup-processor/markup-processor.h>
 #include <dali-toolkit/internal/text/multi-language-support.h>
 #include <dali-toolkit/internal/text/segmentation.h>
 #include <dali-toolkit/internal/text/shaper.h>
-#include <dali-toolkit/internal/text/text-controller-impl.h>
+#include <dali-toolkit/internal/text/controller/text-controller-impl.h>
 
 namespace Dali
 {
@@ -102,7 +103,8 @@ void CreateTextModel(const std::string&                text,
                      LineWrap::Mode                    wrapMode,
                      bool                              ellipsisEnabled,
                      DevelText::EllipsisPosition::Type ellipsisPosition,
-                     float                             lineSpacing)
+                     float                             lineSpacing,
+                     float                             characterSpacing)
 {
   textModel                    = Model::New(); ///< Pointer to the text's model.
   LogicalModelPtr logicalModel = textModel->mLogicalModel;
@@ -114,13 +116,17 @@ void CreateTextModel(const std::string&                text,
                                       logicalModel->mAnchors,
                                       logicalModel->mUnderlinedCharacterRuns,
                                       logicalModel->mBackgroundColorRuns,
-                                      logicalModel->mStrikethroughCharacterRuns);
+                                      logicalModel->mStrikethroughCharacterRuns,
+                                      logicalModel->mBoundedParagraphRuns,
+                                      logicalModel->mCharacterSpacingCharacterRuns);
 
   Length         textSize = 0u;
   const uint8_t* utf8     = NULL;
   if(markupProcessorEnabled)
   {
-    ProcessMarkupString(text, markupProcessData);
+    MarkupPropertyData markupPropertyData(Color::MEDIUM_BLUE, Color::DARK_MAGENTA);
+
+    ProcessMarkupString(text, markupPropertyData, markupProcessData);
     textSize = markupProcessData.markupProcessedText.size();
 
     // This is a bit horrible but std::string returns a (signed) char*
@@ -140,6 +146,10 @@ void CreateTextModel(const std::string&                text,
   textModel->mEllipsisPosition = ellipsisPosition;
   textModel->mVisualModel->SetEllipsisPosition(ellipsisPosition);
 
+  //Inset
+  textModel->mRemoveFrontInset = true;
+  textModel->mRemoveBackInset = true;
+
   // 1) Convert to utf32
   Vector<Character>& utf32Characters = logicalModel->mText;
   utf32Characters.Resize(textSize);
@@ -153,7 +163,9 @@ void CreateTextModel(const std::string&                text,
   Vector<LineBreakInfo>& lineBreakInfo = logicalModel->mLineBreakInfo;
   lineBreakInfo.Resize(characterCount);
 
-  SetLineBreakInfo(utf32Characters,
+  TextAbstraction::Segmentation segmentation = TextAbstraction::Segmentation::Get();
+  SetLineBreakInfo(segmentation,
+                   utf32Characters,
                    0u,
                    characterCount,
                    lineBreakInfo);
@@ -172,6 +184,8 @@ void CreateTextModel(const std::string&                text,
     CharacterIndex end                 = characterCount;
     LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin();
 
+    TextAbstraction::Hyphenation hyphenation = TextAbstraction::Hyphenation::Get();
+
     for(CharacterIndex index = 0; index < end; index++)
     {
       CharacterIndex wordEnd = index;
@@ -185,7 +199,7 @@ void CreateTextModel(const std::string&                text,
         wordEnd++;
       }
 
-      Vector<bool> hyphens = GetWordHyphens(utf32Characters.Begin() + index, wordEnd - index, nullptr);
+      Vector<bool> hyphens = GetWordHyphens(hyphenation, utf32Characters.Begin() + index, wordEnd - index, nullptr);
 
       for(CharacterIndex i = 0; i < (wordEnd - index); i++)
       {
@@ -221,11 +235,13 @@ void CreateTextModel(const std::string&                text,
 
   // Validates the fonts. If there is a character with no assigned font it sets a default one.
   // After this call, fonts are validated.
-  multilanguageSupport.ValidateFonts(utf32Characters,
+  multilanguageSupport.ValidateFonts(fontClient,
+                                     utf32Characters,
                                      scripts,
                                      fontDescriptionRuns,
                                      fontDescription,
                                      TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
+                                     1.0f,
                                      0u,
                                      characterCount,
                                      validFonts);
@@ -238,7 +254,11 @@ void CreateTextModel(const std::string&                text,
   Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo;
 
   // Calculates the bidirectional info for the whole paragraph if it contains right to left scripts.
-  SetBidirectionalInfo(utf32Characters,
+
+  TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get();
+
+  SetBidirectionalInfo(bidirectionalSupport,
+                       utf32Characters,
                        scripts,
                        lineBreakInfo,
                        0u,
@@ -254,14 +274,16 @@ void CreateTextModel(const std::string&                text,
   if(0u != bidirectionalInfo.Count())
   {
     // Only set the character directions if there is right to left characters.
-    GetCharactersDirection(bidirectionalInfo,
+    GetCharactersDirection(bidirectionalSupport,
+                           bidirectionalInfo,
                            characterCount,
                            0u,
                            characterCount,
                            characterDirections);
 
     // This paragraph has right to left text. Some characters may need to be mirrored.
-    textMirrored = GetMirroredText(utf32Characters,
+    textMirrored = GetMirroredText(bidirectionalSupport,
+                                   utf32Characters,
                                    characterDirections,
                                    bidirectionalInfo,
                                    0u,
@@ -283,7 +305,11 @@ void CreateTextModel(const std::string&                text,
 
   const Vector<Character>& textToShape = textMirrored ? mirroredUtf32Characters : utf32Characters;
 
-  ShapeText(textToShape,
+  TextAbstraction::Shaping shaping = TextAbstraction::Shaping::Get();
+
+  ShapeText(shaping,
+            fontClient,
+            textToShape,
             lineBreakInfo,
             scripts,
             validFonts,
@@ -299,6 +325,8 @@ void CreateTextModel(const std::string&                text,
   visualModel->CreateGlyphsPerCharacterTable(0u, 0u, characterCount);
   visualModel->CreateCharacterToGlyphTable(0u, 0u, characterCount);
 
+  visualModel->SetCharacterSpacing(characterSpacing);
+
   const Length numberOfGlyphs = glyphs.Count();
 
   // 8) Get the glyph metrics
@@ -331,7 +359,9 @@ void CreateTextModel(const std::string&                text,
   textModel->mHorizontalAlignment   = Text::HorizontalAlignment::BEGIN;
   textModel->mIgnoreSpacesAfterText = true;
   Layout::Parameters layoutParameters(textArea,
-                                      textModel);
+                                      textModel,
+                                      fontClient,
+                                      bidirectionalSupport);
 
   Vector<LineRun>& lines = visualModel->mLines;
 
@@ -346,11 +376,15 @@ void CreateTextModel(const std::string&                text,
   layoutParameters.startLineIndex         = 0u;
   layoutParameters.estimatedNumberOfLines = logicalModel->mParagraphInfo.Count();
 
-  bool isAutoScroll = false;
+  bool isAutoScroll                   = false;
+  bool isAutoScrollMaxTextureExceeded = false;
+  bool isHiddenInputEnabled           = false;
   layoutEngine.LayoutText(layoutParameters,
                           layoutSize,
                           false,
                           isAutoScroll,
+                          isAutoScrollMaxTextureExceeded,
+                          isHiddenInputEnabled,
                           ellipsisPosition);
 
   if(options.align)