[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / layouts / layout-engine.cpp
index 39af47c..e78a544 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.
@@ -449,7 +449,16 @@ struct Engine::Impl
           {
             whiteSpaceLengthEndOfLine = 0.f;
           }
-          length = std::max(length, penX + glyphMetrics.xBearing + glyphMetrics.width);
+
+          if(parameters.textModel->mRemoveBackInset)
+          {
+            length = std::max(length, penX + glyphMetrics.xBearing + glyphMetrics.width);
+          }
+          else
+          {
+            length = std::max(length, penX + glyphMetrics.advance);
+          }
+
           penX += (glyphMetrics.advance + parameters.interGlyphExtraAdvance);
         }
       }
@@ -512,7 +521,15 @@ struct Engine::Impl
         {
           whiteSpaceLengthEndOfLine = 0.f;
         }
-        length = std::max(length, penX + glyphMetrics.xBearing + glyphMetrics.width);
+
+        if(parameters.textModel->mRemoveBackInset)
+        {
+          length = std::max(length, penX + glyphMetrics.xBearing + glyphMetrics.width);
+        }
+        else
+        {
+          length = std::max(length, penX + glyphMetrics.advance);
+        }
         penX += (glyphMetrics.advance + parameters.interGlyphExtraAdvance);
       }
     }
@@ -667,6 +684,7 @@ struct Engine::Impl
    * @param[out] lineLayout The line layout.
    * @param[in] completelyFill Whether to completely fill the line ( even if the last word exceeds the boundaries ).
    * @param[in] ellipsisPosition Where is the location the text elide
+   * @param[in] hiddenInputEnabled Whether the hidden input is enabled.
    */
   void GetLineLayoutForBox(const Parameters&                 parameters,
                            LayoutBidiParameters&             bidiParameters,
@@ -674,7 +692,8 @@ struct Engine::Impl
                            bool                              completelyFill,
                            DevelText::EllipsisPosition::Type ellipsisPosition,
                            bool                              enforceEllipsisInSingleLine,
-                           bool                              elideTextEnabled)
+                           bool                              elideTextEnabled,
+                           bool                              hiddenInputEnabled)
   {
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "-->GetLineLayoutForBox\n");
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "  initial glyph index : %d\n", lineLayout.glyphIndex);
@@ -743,7 +762,12 @@ struct Engine::Impl
     // The initial start point is zero. However it needs a correction according the 'x' bearing of the first glyph.
     // i.e. if the bearing of the first glyph is negative it may exceed the boundaries of the text area.
     // It needs to add as well space for the cursor if the text is in edit mode and extra space in case the text is outlined.
-    tmpLineLayout.penX = -glyphMetrics.xBearing + mCursorWidth + outlineWidth;
+
+    tmpLineLayout.penX = mCursorWidth + outlineWidth;
+    if(parameters.textModel->mRemoveFrontInset)
+    {
+      tmpLineLayout.penX -= glyphMetrics.xBearing;
+    }
 
     tmpLineLayout.relativeLineSize = lineLayout.relativeLineSize;
 
@@ -826,7 +850,10 @@ struct Engine::Impl
       const float previousTmpLength                    = tmpLineLayout.length;
       const float previousTmpWhiteSpaceLengthEndOfLine = tmpLineLayout.whiteSpaceLengthEndOfLine;
 
-      if(isWhiteSpace)
+      // The calculated text size is used in atlas renderer.
+      // When the text is all white space, partial render issue occurs because the width is 0.
+      // To avoid issue, do not remove the white space size in hidden input mode.
+      if(isWhiteSpace && !hiddenInputEnabled)
       {
         // Add the length to the length of white spaces at the end of the line.
         tmpLineLayout.whiteSpaceLengthEndOfLine += glyphMetrics.advance;
@@ -837,7 +864,14 @@ struct Engine::Impl
         tmpLineLayout.penX += tmpLineLayout.previousAdvance + tmpLineLayout.whiteSpaceLengthEndOfLine;
         tmpLineLayout.previousAdvance = (glyphMetrics.advance + parameters.interGlyphExtraAdvance);
 
-        tmpLineLayout.length = std::max(tmpLineLayout.length, tmpLineLayout.penX + glyphMetrics.xBearing + glyphMetrics.width);
+        if(parameters.textModel->mRemoveBackInset)
+        {
+          tmpLineLayout.length = std::max(tmpLineLayout.length, tmpLineLayout.penX + glyphMetrics.xBearing + glyphMetrics.width);
+        }
+        else
+        {
+          tmpLineLayout.length = std::max(tmpLineLayout.length, tmpLineLayout.penX + glyphMetrics.advance);
+        }
 
         // Clear the white space length at the end of the line.
         tmpLineLayout.whiteSpaceLengthEndOfLine = 0.f;
@@ -907,7 +941,7 @@ struct Engine::Impl
             tmpLineLayout.numberOfGlyphs -= numberOfGLyphsInGroup;
           }
 
-          if(isRemovedGlyphWhiteSpace)
+          if(isRemovedGlyphWhiteSpace && !hiddenInputEnabled)
           {
             tmpLineLayout.penX -= glyphMetrics.advance;
             tmpLineLayout.length -= glyphMetrics.advance;
@@ -1100,7 +1134,12 @@ struct Engine::Impl
     // If it has a negative x bearing, it will exceed the boundaries of the actor,
     // so the penX position needs to be moved to the right.
     const GlyphInfo& glyph = *(glyphsBuffer + startIndexForGlyph);
-    float            penX  = -glyph.xBearing + mCursorWidth + outlineWidth; //
+    float            penX  = mCursorWidth + outlineWidth; //
+
+    if(layoutParameters.textModel->mRemoveFrontInset)
+    {
+      penX -= glyph.xBearing;
+    }
 
     CalculateGlyphPositionsLTR(layoutParameters.textModel->mVisualModel,
                                layoutParameters.textModel->mLogicalModel,
@@ -1247,6 +1286,7 @@ struct Engine::Impl
    * @param[in] penY The vertical layout position.
    * @param[in] currentParagraphDirection The current paragraph's direction.
    * @param[in,out] isAutoScrollEnabled If the isAutoScrollEnabled is true and the height of the text exceeds the boundaries of the control the text is elided and the isAutoScrollEnabled is set to false to disable the autoscroll
+   * @param[in] isHiddenInputEnabled Whether the hidden input is enabled.
    * @param[in] ellipsisPosition Where is the location the text elide
    *
    * return Whether the line is ellipsized.
@@ -1261,6 +1301,7 @@ struct Engine::Impl
                     float                             penY,
                     bool&                             isAutoScrollEnabled,
                     bool                              isAutoScrollMaxTextureExceeded,
+                    bool                              isHiddenInputEnabled,
                     DevelText::EllipsisPosition::Type ellipsisPosition,
                     bool                              enforceEllipsisInSingleLine)
   {
@@ -1310,7 +1351,8 @@ struct Engine::Impl
                           true,
                           ellipsisPosition,
                           enforceEllipsisInSingleLine,
-                          true);
+                          true,
+                          isHiddenInputEnabled);
 
       if(ellipsisPosition == DevelText::EllipsisPosition::START && !isMultiline)
       {
@@ -1470,6 +1512,12 @@ struct Engine::Impl
   {
     const Vector<GlyphInfo>& glyphs = layoutParameters.textModel->mVisualModel->mGlyphs;
 
+    if(glyphs.Size() == 0u)
+    {
+      // Do nothing.
+      return;
+    }
+
     // Need to add a new line with no characters but with height to increase the layoutSize.height
     const GlyphInfo& glyphInfo = glyphs[glyphs.Count() - 1u];
 
@@ -1608,6 +1656,7 @@ struct Engine::Impl
                   bool                              elideTextEnabled,
                   bool&                             isAutoScrollEnabled,
                   bool                              isAutoScrollMaxTextureExceeded,
+                  bool                              isHiddenInputEnabled,
                   DevelText::EllipsisPosition::Type ellipsisPosition)
   {
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "-->LayoutText\n");
@@ -1797,7 +1846,8 @@ struct Engine::Impl
                           false,
                           ellipsisPosition,
                           false,
-                          elideTextEnabled);
+                          elideTextEnabled,
+                          isHiddenInputEnabled);
 
       DALI_LOG_INFO(gLogFilter, Debug::Verbose, "           glyph index %d\n", layout.glyphIndex);
       DALI_LOG_INFO(gLogFilter, Debug::Verbose, "       character index %d\n", layout.characterIndex);
@@ -1848,6 +1898,7 @@ struct Engine::Impl
                                 penY,
                                 isAutoScrollEnabled,
                                 isAutoScrollMaxTextureExceeded,
+                                isHiddenInputEnabled,
                                 ellipsisPosition,
                                 false);
       }
@@ -1867,6 +1918,7 @@ struct Engine::Impl
                                   penY,
                                   isAutoScrollEnabled,
                                   isAutoScrollMaxTextureExceeded,
+                                  isHiddenInputEnabled,
                                   ellipsisPosition,
                                   true);
         }
@@ -2262,6 +2314,7 @@ bool Engine::LayoutText(Parameters&                       layoutParameters,
                         bool                              elideTextEnabled,
                         bool&                             isAutoScrollEnabled,
                         bool                              isAutoScrollMaxTextureExceeded,
+                        bool                              isHiddenInputEnabled,
                         DevelText::EllipsisPosition::Type ellipsisPosition)
 {
   return mImpl->LayoutText(layoutParameters,
@@ -2269,6 +2322,7 @@ bool Engine::LayoutText(Parameters&                       layoutParameters,
                            elideTextEnabled,
                            isAutoScrollEnabled,
                            isAutoScrollMaxTextureExceeded,
+                           isHiddenInputEnabled,
                            ellipsisPosition);
 }