[3.0] Text - Fix for placement actor.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / layouts / layout-engine.cpp
index a5da5a4..a3ceee2 100644 (file)
@@ -25,6 +25,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/bidirectional-line-info-run.h>
+#include <dali-toolkit/internal/text/cursor-helper-functions.h>
 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
 
@@ -47,6 +48,7 @@ namespace
 const float MAX_FLOAT = std::numeric_limits<float>::max();
 const bool RTL = true;
 const float CURSOR_WIDTH = 1.f;
+const float LINE_SPACING= 0.f;
 
 } //namespace
 
@@ -104,6 +106,7 @@ struct LayoutEngine::Impl
     mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ),
     mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP ),
     mCursorWidth( CURSOR_WIDTH ),
+    mDefaultLineSpacing( LINE_SPACING ),
     mEllipsisEnabled( false )
   {
   }
@@ -464,34 +467,6 @@ struct LayoutEngine::Impl
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox\n" );
   }
 
-  /**
-   * @brief Calculates the vertical offset to add to the new laid-out glyphs.
-   *
-   * @pre @p lineIndex must be between 0 and the number of lines (both inclusive).
-   *
-   * @param[in] lines The previously laid-out lines.
-   * @param[in] lineIndex Index to the line where the new laid-out lines are inserted.
-   *
-   * @return The vertical offset of the lines starting from the beginning to the line @p lineIndex.
-   */
-  float SetParagraphOffset( const Vector<LineRun>& lines,
-                            LineIndex lineIndex )
-  {
-    float offset = 0.f;
-
-    for( Vector<LineRun>::ConstIterator it = lines.Begin(),
-           endIt = lines.Begin() + lineIndex;
-         it != endIt;
-         ++it )
-    {
-      const LineRun& line = *it;
-
-      offset += line.ascender + -line.descender;
-    }
-
-    return offset;
-  }
-
   void SetGlyphPositions( const GlyphInfo* const glyphsBuffer,
                           Length numberOfGlyphs,
                           Vector2* glyphPositionsBuffer )
@@ -621,7 +596,10 @@ struct LayoutEngine::Impl
       lineRun->ellipsis = true;
 
       layoutSize.width = layoutParameters.boundingBox.width;
-      layoutSize.height += ( lineRun->ascender + -lineRun->descender );
+      if( layoutSize.height < Math::MACHINE_EPSILON_1000 )
+      {
+        layoutSize.height += ( lineRun->ascender + -lineRun->descender );
+      }
 
       SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun->glyphRun.glyphIndex,
                          ellipsisLayout.numberOfGlyphs,
@@ -820,6 +798,10 @@ struct LayoutEngine::Impl
         }
       }
 
+      // Calculates the layout size.
+      UpdateLayoutSize( lines,
+                        layoutSize );
+
       // Nothing else do if there are no glyphs to layout.
       return false;
     }
@@ -871,8 +853,8 @@ struct LayoutEngine::Impl
       linesBuffer = lines.Begin();
     }
 
-    float penY = SetParagraphOffset( lines,
-                                     layoutParameters.startLineIndex );
+    float penY = CalculateLineOffset( lines,
+                                      layoutParameters.startLineIndex );
 
     for( GlyphIndex index = layoutParameters.startGlyphIndex; index < lastGlyphPlusOne; )
     {
@@ -1094,10 +1076,12 @@ struct LayoutEngine::Impl
   void Align( const Size& size,
               CharacterIndex startIndex,
               Length numberOfCharacters,
-              Vector<LineRun>& lines )
+              Vector<LineRun>& lines,
+              float& alignmentOffset )
   {
     const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters;
 
+    alignmentOffset = MAX_FLOAT;
     // Traverse all lines and align the glyphs.
     for( Vector<LineRun>::Iterator it = lines.Begin(), endIt = lines.End();
          it != endIt;
@@ -1121,6 +1105,9 @@ struct LayoutEngine::Impl
       // the box width, line length, and the paragraph's direction.
       CalculateHorizontalAlignment( size.width,
                                     line );
+
+      // Updates the alignment offset.
+      alignmentOffset = std::min( alignmentOffset, line.alignmentOffset );
     }
   }
 
@@ -1213,6 +1200,7 @@ struct LayoutEngine::Impl
   LayoutEngine::HorizontalAlignment mHorizontalAlignment;
   LayoutEngine::VerticalAlignment mVerticalAlignment;
   float mCursorWidth;
+  float mDefaultLineSpacing;
 
   IntrusivePtr<Metrics> mMetrics;
 
@@ -1242,11 +1230,13 @@ void LayoutEngine::SetLayout( Layout layout )
 
 LayoutEngine::Layout LayoutEngine::GetLayout() const
 {
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetLayout[%d]\n", mImpl->mLayout);
   return mImpl->mLayout;
 }
 
 void LayoutEngine::SetTextEllipsisEnabled( bool enabled )
 {
+  DALI_LOG_INFO( gLogFilter, Debug::General, "-->LayoutEngine::SetTextEllipsisEnabled[%s]\n", (enabled)?"true":"false" );
   mImpl->mEllipsisEnabled = enabled;
 }
 
@@ -1310,12 +1300,24 @@ void LayoutEngine::ReLayoutRightToLeftLines( const LayoutParameters& layoutParam
 void LayoutEngine::Align( const Size& size,
                           CharacterIndex startIndex,
                           Length numberOfCharacters,
-                          Vector<LineRun>& lines )
+                          Vector<LineRun>& lines,
+                          float& alignmentOffset )
 {
   mImpl->Align( size,
                 startIndex,
                 numberOfCharacters,
-                lines );
+                lines,
+                alignmentOffset );
+}
+
+void LayoutEngine::SetDefaultLineSpacing( float lineSpacing )
+{
+  mImpl->mDefaultLineSpacing = lineSpacing;
+}
+
+float LayoutEngine::GetDefaultLineSpacing() const
+{
+  return mImpl->mDefaultLineSpacing;
 }
 
 } // namespace Text