Multiple text background color support for left-to-right text only in TextField
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-view.cpp
old mode 100644 (file)
new mode 100755 (executable)
index d57b2ec..9d9f991
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -94,7 +94,7 @@ Length View::GetNumberOfGlyphs() const
 
 Length View::GetGlyphs( GlyphInfo* glyphs,
                         Vector2* glyphPositions,
-                        Vector4* glyphColors,
+                        float& minLineOffset,
                         GlyphIndex glyphIndex,
                         Length numberOfGlyphs ) const
 {
@@ -132,30 +132,6 @@ Length View::GetGlyphs( GlyphInfo* glyphs,
                                                 glyphIndex,
                                                 numberOfLaidOutGlyphs );
 
-        // Set the colors.
-        const GlyphIndex lastLaidOutGlyphIndex = glyphIndex + numberOfLaidOutGlyphs;
-
-        for( Vector<ColorGlyphRun>::ConstIterator it = mImpl->mVisualModel->mColorRuns.Begin(),
-               endIt = mImpl->mVisualModel->mColorRuns.End();
-             it != endIt;
-             ++it )
-        {
-          const ColorGlyphRun& colorGlyphRun = *it;
-          const GlyphIndex lastGlyphIndex = colorGlyphRun.glyphRun.glyphIndex + colorGlyphRun.glyphRun.numberOfGlyphs;
-
-          if( ( colorGlyphRun.glyphRun.glyphIndex < lastLaidOutGlyphIndex ) &&
-              ( glyphIndex < lastGlyphIndex ) )
-          {
-            for( GlyphIndex index = glyphIndex < colorGlyphRun.glyphRun.glyphIndex ? colorGlyphRun.glyphRun.glyphIndex : glyphIndex,
-                   endIndex = lastLaidOutGlyphIndex < lastGlyphIndex ? lastLaidOutGlyphIndex : lastGlyphIndex;
-                 index < endIndex;
-                 ++index )
-            {
-              *( glyphColors + index - glyphIndex ) = colorGlyphRun.color;
-            }
-          }
-        }
-
         // Get the lines for the given range of glyphs.
         // The lines contain the alignment offset which needs to be added to the glyph's position.
         LineIndex firstLine = 0u;
@@ -181,19 +157,30 @@ Length View::GetGlyphs( GlyphInfo* glyphs,
         GlyphIndex lastGlyphIndexOfLine = line->glyphRun.glyphIndex + line->glyphRun.numberOfGlyphs - 1u;
 
         // Add the alignment offset to the glyph's position.
+
+        minLineOffset = line->alignmentOffset;
+        float penY = line->ascender;
         for( Length index = 0u; index < numberOfLaidOutGlyphs; ++index )
         {
-          ( *( glyphPositions + index ) ).x += line->alignmentOffset;
+          Vector2& position =  *( glyphPositions + index );
+          position.x += line->alignmentOffset;
+          position.y += penY;
 
           if( lastGlyphIndexOfLine == index )
           {
+            penY += -line->descender;
+
             // Get the next line.
             ++lineIndex;
 
             if( lineIndex < numberOfLines )
             {
               line = lineBuffer + lineIndex;
+              minLineOffset = std::min( minLineOffset, line->alignmentOffset );
+
               lastGlyphIndexOfLine = line->glyphRun.glyphIndex + line->glyphRun.numberOfGlyphs - 1u;
+
+              penY += line->ascender;
             }
           }
         }
@@ -206,6 +193,24 @@ Length View::GetGlyphs( GlyphInfo* glyphs,
 
         if( lastLine.ellipsis )
         {
+          if( ( 1u == numberOfLines ) &&
+              ( lastLine.ascender - lastLine.descender > mImpl->mVisualModel->mControlSize.height ) )
+          {
+            // Get the first glyph which is going to be replaced and the ellipsis glyph.
+            GlyphInfo& glyphInfo = *glyphs;
+            const GlyphInfo& ellipsisGlyph = mImpl->mFontClient.GetEllipsisGlyph( mImpl->mFontClient.GetPointSize( glyphInfo.fontId ) );
+
+            // Change the 'x' and 'y' position of the ellipsis glyph.
+            Vector2& position = *glyphPositions;
+            position.x = ellipsisGlyph.xBearing;
+            position.y = mImpl->mVisualModel->mControlSize.height - ellipsisGlyph.yBearing;
+
+            // Replace the glyph by the ellipsis glyph.
+            glyphInfo = ellipsisGlyph;
+
+             return 1u;
+          }
+
           // firstPenX, penY and firstPenSet are used to position the ellipsis glyph if needed.
           float firstPenX = 0.f; // Used if rtl text is elided.
           float penY = 0.f;
@@ -301,6 +306,46 @@ Length View::GetGlyphs( GlyphInfo* glyphs,
   return numberOfLaidOutGlyphs;
 }
 
+const Vector4* const View::GetColors() const
+{
+  if( mImpl->mVisualModel )
+  {
+    return mImpl->mVisualModel->mColors.Begin();
+  }
+
+  return NULL;
+}
+
+const ColorIndex* const View::GetColorIndices() const
+{
+  if( mImpl->mVisualModel )
+  {
+    return mImpl->mVisualModel->mColorIndices.Begin();
+  }
+
+  return NULL;
+}
+
+const Vector4* const View::GetBackgroundColors() const
+{
+  if( mImpl->mVisualModel )
+  {
+    return mImpl->mVisualModel->mBackgroundColors.Begin();
+  }
+
+  return nullptr;
+}
+
+const ColorIndex* const View::GetBackgroundColorIndices() const
+{
+  if( mImpl->mVisualModel )
+  {
+    return mImpl->mVisualModel->mBackgroundColorIndices.Begin();
+  }
+
+  return nullptr;
+}
+
 const Vector4& View::GetTextColor() const
 {
   if( mImpl->mVisualModel )
@@ -359,7 +404,7 @@ Length View::GetNumberOfUnderlineRuns() const
 {
   if( mImpl->mVisualModel )
   {
-    return mImpl->mVisualModel->mUnderlineRuns.Count();
+    return mImpl->mVisualModel->GetNumberOfUnderlineRuns();
   }
 
   return 0u;
@@ -377,6 +422,24 @@ void View::GetUnderlineRuns( GlyphRun* underlineRuns,
   }
 }
 
+const Vector4& View::GetOutlineColor() const
+{
+  if( mImpl->mVisualModel )
+  {
+    return mImpl->mVisualModel->GetOutlineColor();
+  }
+  return Vector4::ZERO;
+}
+
+uint16_t View::GetOutlineWidth() const
+{
+  if( mImpl->mVisualModel )
+  {
+    return mImpl->mVisualModel->GetOutlineWidth();
+  }
+  return 0u;
+}
+
 } // namespace Text
 
 } // namespace Toolkit