[dali_1.1.9] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / layouts / layout-engine.cpp
index 5a28904..ad513a8 100644 (file)
@@ -45,6 +45,7 @@ namespace
 
 const float MAX_FLOAT = std::numeric_limits<float>::max();
 const bool RTL = true;
+const float CURSOR_WIDTH = 1.f;
 
 } //namespace
 
@@ -101,9 +102,9 @@ struct LayoutEngine::Impl
   : mLayout( LayoutEngine::SINGLE_LINE_BOX ),
     mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ),
     mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP ),
+    mCursorWidth( CURSOR_WIDTH ),
     mEllipsisEnabled( false )
   {
-    mFontClient = TextAbstraction::FontClient::Get();
   }
 
   /**
@@ -115,7 +116,7 @@ struct LayoutEngine::Impl
   void UpdateLineHeight( FontId fontId, LineLayout& lineLayout )
   {
     Text::FontMetrics fontMetrics;
-    mFontClient.GetFontMetrics( fontId, fontMetrics );
+    mMetrics->GetFontMetrics( fontId, fontMetrics );
 
     // Sets the maximum ascender.
     if( fontMetrics.ascender > lineLayout.ascender )
@@ -210,7 +211,7 @@ struct LayoutEngine::Impl
 
     float tmpExtraBearing = ( 0.f > glyphInfo.xBearing ) ? -glyphInfo.xBearing : 0.f;
 
-    tmpLineLayout.length += 1.f; // Added one unit to give some space to the cursor.
+    tmpLineLayout.length += mCursorWidth; // Added to give some space to the cursor.
 
     // Calculate the line height if there is no characters.
     FontId lastFontId = glyphInfo.fontId;
@@ -450,7 +451,6 @@ struct LayoutEngine::Impl
 
     const GlyphInfo& glyph = *glyphsBuffer;
     float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f;
-    penX += 1.f; // Added one unit to give some space to the cursor.
 
     for( GlyphIndex i = 0u; i < numberOfGlyphs; ++i )
     {
@@ -632,7 +632,7 @@ struct LayoutEngine::Impl
           const GlyphInfo& glyphInfo = *( layoutParameters.glyphsBuffer + layoutParameters.totalNumberOfGlyphs - 1u );
 
           Text::FontMetrics fontMetrics;
-          mFontClient.GetFontMetrics( glyphInfo.fontId, fontMetrics );
+          mMetrics->GetFontMetrics( glyphInfo.fontId, fontMetrics );
 
           LineRun lineRun;
           lineRun.glyphRun.glyphIndex = 0u;
@@ -671,7 +671,6 @@ struct LayoutEngine::Impl
       const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) );
 
       float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f;
-      penX += 1.f; // Added one unit to give some space to the cursor.
 
       Vector2* glyphPositionsBuffer = glyphPositions.Begin();
 
@@ -767,10 +766,12 @@ struct LayoutEngine::Impl
       {
         if( isLastLine && !isRTL )
         {
+          // Add the length of the white saces at the end of the line.
           lineLength += line.extraLength;
           if( lineLength > boxWidth )
           {
-            lineLength = boxWidth;
+            // The line's length is longer than the box's width.
+            // Set the line's offset to 0 and nothing else to do.
             line.alignmentOffset = 0.f;
             break;
           }
@@ -817,8 +818,9 @@ struct LayoutEngine::Impl
   LayoutEngine::Layout mLayout;
   LayoutEngine::HorizontalAlignment mHorizontalAlignment;
   LayoutEngine::VerticalAlignment mVerticalAlignment;
+  float mCursorWidth;
 
-  TextAbstraction::FontClient mFontClient;
+  IntrusivePtr<Metrics> mMetrics;
 
   bool mEllipsisEnabled:1;
 };
@@ -834,6 +836,11 @@ LayoutEngine::~LayoutEngine()
   delete mImpl;
 }
 
+void LayoutEngine::SetMetrics( MetricsPtr& metrics )
+{
+  mImpl->mMetrics = metrics;
+}
+
 void LayoutEngine::SetLayout( Layout layout )
 {
   mImpl->mLayout = layout;
@@ -874,6 +881,16 @@ LayoutEngine::VerticalAlignment LayoutEngine::GetVerticalAlignment() const
   return mImpl->mVerticalAlignment;
 }
 
+void LayoutEngine::SetCursorWidth( int width )
+{
+  mImpl->mCursorWidth = static_cast<float>( width );
+}
+
+int LayoutEngine::GetCursorWidth() const
+{
+  return static_cast<int>( mImpl->mCursorWidth );
+}
+
 bool LayoutEngine::LayoutText( const LayoutParameters& layoutParameters,
                                Vector<Vector2>& glyphPositions,
                                Vector<LineRun>& lines,