[dali_2.1.31] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-view.cpp
index 9b34dd4..0b81484 100644 (file)
 #include <dali/public-api/math/vector2.h>
 #include <memory.h>
 
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/glyph-metrics-helper.h>
+#include <dali-toolkit/internal/text/rendering/styles/character-spacing-helper-functions.h>
+
 namespace Dali
 {
 namespace Toolkit
@@ -32,6 +36,7 @@ namespace Text
 struct View::Impl
 {
   VisualModelPtr              mVisualModel;
+  LogicalModelPtr             mLogicalModel;
   TextAbstraction::FontClient mFontClient; ///< Handle to the font client.
 };
 
@@ -53,6 +58,11 @@ void View::SetVisualModel(VisualModelPtr visualModel)
   mImpl->mVisualModel = visualModel;
 }
 
+void View::SetLogicalModel(LogicalModelPtr logicalModel)
+{
+  mImpl->mLogicalModel = logicalModel;
+}
+
 const Vector2& View::GetControlSize() const
 {
   if(mImpl->mVisualModel)
@@ -96,17 +106,25 @@ Length View::GetGlyphs(GlyphInfo* glyphs,
                        GlyphIndex glyphIndex,
                        Length     numberOfGlyphs) const
 {
-  Length numberOfLaidOutGlyphs       = 0u;
-  Length numberOfActualLaidOutGlyphs = 0u;
+  Length                  numberOfLaidOutGlyphs       = 0u;
+  Length                  numberOfActualLaidOutGlyphs = 0u;
+  const float             modelCharacterSpacing       = mImpl->mVisualModel->GetCharacterSpacing();
+  Vector<CharacterIndex>& glyphToCharacterMap         = mImpl->mVisualModel->mGlyphsToCharacters;
+  const CharacterIndex*   glyphToCharacterMapBuffer   = glyphToCharacterMap.Begin();
+  float                   calculatedAdvance           = 0.f;
+  const Character*        textBuffer                  = mImpl->mLogicalModel->mText.Begin();
 
   if(mImpl->mVisualModel)
   {
+    // Get the character-spacing runs.
+    const Vector<CharacterSpacingGlyphRun>& characterSpacingGlyphRuns = mImpl->mVisualModel->GetCharacterSpacingGlyphRuns();
+
     bool                              textElided       = false;
     DevelText::EllipsisPosition::Type ellipsisPosition = GetEllipsisPosition();
 
     //Reset indices of ElidedGlyphs
     mImpl->mVisualModel->SetStartIndexOfElidedGlyphs(0u);
-    mImpl->mVisualModel->SetEndIndexOfElidedGlyphs(numberOfGlyphs);
+    mImpl->mVisualModel->SetEndIndexOfElidedGlyphs(numberOfGlyphs - 1u); // Initialization is the last index of Glyphs
     mImpl->mVisualModel->SetFirstMiddleIndexOfElidedGlyphs(0u);
     mImpl->mVisualModel->SetSecondMiddleIndexOfElidedGlyphs(0u);
 
@@ -265,7 +283,7 @@ Length View::GetGlyphs(GlyphInfo* glyphs,
           const LineRun& elidedLine = *ellipsisLine;
 
           if((1u == numberOfLines) &&
-             (GetLineHeight(elidedLine) > mImpl->mVisualModel->mControlSize.height))
+             (GetLineHeight(elidedLine, true) > mImpl->mVisualModel->mControlSize.height))
           {
             // Replace the first glyph with ellipsis glyph
             auto indexOfFirstGlyph = (ellipsisPosition == DevelText::EllipsisPosition::START) ? startIndexOfEllipsis : 0u;
@@ -342,7 +360,9 @@ Length View::GetGlyphs(GlyphInfo* glyphs,
                 firstPenSet = true;
               }
 
-              removedGlypsWidth += std::min(glyphToRemove.advance, (glyphToRemove.xBearing + glyphToRemove.width));
+              const float characterSpacing = GetGlyphCharacterSpacing(indexOfEllipsis, characterSpacingGlyphRuns, modelCharacterSpacing);
+              calculatedAdvance            = GetCalculatedAdvance(*(textBuffer + (*(glyphToCharacterMapBuffer + indexOfEllipsis))), characterSpacing, glyphToRemove.advance);
+              removedGlypsWidth += std::min(calculatedAdvance, (glyphToRemove.xBearing + glyphToRemove.width));
 
               // Calculate the width of the ellipsis glyph and check if it fits.
               const float ellipsisGlyphWidth = ellipsisGlyph.width + ellipsisGlyph.xBearing;
@@ -356,10 +376,73 @@ Length View::GetGlyphs(GlyphInfo* glyphs,
                 glyphInfo = ellipsisGlyph;
 
                 // Change the 'x' and 'y' position of the ellipsis glyph.
-
                 if(position.x > firstPenX)
                 {
-                  position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
+                  if(isTailMode)
+                  {
+                    // To handle case of the mixed languages (LTR then RTL) with
+                    // EllipsisPosition::END and the LayoutDirection::RIGHT_TO_LEFT
+                    float nextXPositions = ellipsisLine->width;
+                    if(indexOfEllipsis + 1u < numberOfGlyphs)
+                    {
+                      Vector2& positionOfNextGlyph = *(glyphPositions + indexOfEllipsis + 1u);
+                      nextXPositions               = positionOfNextGlyph.x;
+                    }
+
+                    if(position.x > nextXPositions) // RTL language
+                    {
+                      if((indexOfEllipsis > 0u) && ((position.x - nextXPositions) > removedGlypsWidth))
+                      {
+                        // To handle mixed directions
+                        // Re-calculates the first penX which will be used if rtl text is elided.
+                        firstPenX = position.x - glyphToRemove.xBearing;
+                        if(firstPenX < -ellipsisGlyph.xBearing)
+                        {
+                          // Avoids to exceed the bounding box when rtl text is elided.
+                          firstPenX = -ellipsisGlyph.xBearing;
+                        }
+                        //Reset the width of removed glyphs
+                        removedGlypsWidth = std::min(calculatedAdvance, (glyphToRemove.xBearing + glyphToRemove.width)) - ellipsisGlyph.xBearing;
+
+                        --indexOfEllipsis;
+                        continue;
+                      }
+                      else
+                      {
+                        // To handle the case of RTL language with EllipsisPosition::END
+                        position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
+                      }
+                    }
+                  }
+                  else
+                  {
+                    // To handle the case of LTR language with EllipsisPosition::START
+                    position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
+                  }
+                }
+                else
+                {
+                  if(!isTailMode)
+                  {
+                    // To handle case of the mixed languages (RTL then LTR) with
+                    // EllipsisPosition::START and the LayoutDirection::RIGHT_TO_LEFT
+                    float nextXPositions = ellipsisLine->width;
+                    if(indexOfEllipsis + 1u < numberOfGlyphs)
+                    {
+                      Vector2& positionOfNextGlyph = *(glyphPositions + indexOfEllipsis + 1u);
+                      nextXPositions               = positionOfNextGlyph.x;
+                    }
+
+                    if(position.x < nextXPositions) // LTR language
+                    {
+                      position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
+
+                      if((position.x + ellipsisGlyphWidth + ellipsisGlyph.xBearing) > nextXPositions)
+                      {
+                        position.x -= (position.x + ellipsisGlyphWidth + ellipsisGlyph.xBearing) - nextXPositions;
+                      }
+                    }
+                  }
                 }
 
                 position.x += ellipsisGlyph.xBearing;
@@ -587,6 +670,11 @@ bool View::IsUnderlineEnabled() const
   return false;
 }
 
+bool const View::IsMarkupUnderlineSet() const
+{
+  return (GetNumberOfUnderlineRuns() > 0u);
+}
+
 const GlyphInfo* View::GetHyphens() const
 {
   if(mImpl->mVisualModel)
@@ -665,9 +753,9 @@ Length View::GetNumberOfUnderlineRuns() const
   return 0u;
 }
 
-void View::GetUnderlineRuns(GlyphRun*         underlineRuns,
-                            UnderlineRunIndex index,
-                            Length            numberOfRuns) const
+void View::GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns,
+                            UnderlineRunIndex   index,
+                            Length              numberOfRuns) const
 {
   if(mImpl->mVisualModel)
   {
@@ -782,6 +870,11 @@ bool View::IsStrikethroughEnabled() const
   return (mImpl->mVisualModel) ? mImpl->mVisualModel->IsStrikethroughEnabled() : false;
 }
 
+bool const View::IsMarkupStrikethroughSet() const
+{
+  return (GetNumberOfStrikethroughRuns() > 0u);
+}
+
 float View::GetStrikethroughHeight() const
 {
   return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetStrikethroughHeight() : 0.0f;
@@ -809,6 +902,46 @@ void View::GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns,
   }
 }
 
+Length View::GetNumberOfBoundedParagraphRuns() const
+{
+  if(mImpl->mLogicalModel)
+  {
+    return mImpl->mLogicalModel->GetNumberOfBoundedParagraphRuns();
+  }
+
+  return 0u;
+}
+
+const Vector<BoundedParagraphRun>& View::GetBoundedParagraphRuns() const
+{
+  return mImpl->mLogicalModel->GetBoundedParagraphRuns();
+}
+
+Length View::GetNumberOfCharacterSpacingGlyphRuns() const
+{
+  return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetNumberOfCharacterSpacingGlyphRuns() : 0u;
+}
+
+const Vector<CharacterSpacingGlyphRun>& View::GetCharacterSpacingGlyphRuns() const
+{
+  return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetCharacterSpacingGlyphRuns() : GetEmptyCharacterSpacingGlyphRuns();
+}
+
+const float View::GetCharacterSpacing() const
+{
+  return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetCharacterSpacing() : 0.f;
+}
+
+const Character* View::GetTextBuffer() const
+{
+  return (mImpl->mVisualModel) ? mImpl->mLogicalModel->mText.Begin() : nullptr;
+}
+
+const Vector<CharacterIndex>& View::GetGlyphsToCharacters() const
+{
+  return mImpl->mVisualModel->GetGlyphsToCharacters();
+}
+
 } // namespace Text
 
 } // namespace Toolkit