Merge "Improve the underline markup" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-impl.cpp
index 6ffa715..cf49df5 100644 (file)
 #include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/actors/layer.h>
+#include <dali/public-api/rendering/renderer.h>
 #include <cmath>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/character-set-conversion.h>
 #include <dali-toolkit/internal/text/cursor-helper-functions.h>
+#include <dali-toolkit/internal/text/glyph-metrics-helper.h>
 #include <dali-toolkit/internal/text/text-control-interface.h>
 #include <dali-toolkit/internal/text/text-controller-impl-data-clearer.h>
 #include <dali-toolkit/internal/text/text-controller-impl-event-handler.h>
@@ -37,6 +39,7 @@
 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
 #include <dali-toolkit/internal/text/text-run-container.h>
 #include <dali-toolkit/internal/text/text-selection-handle-controller.h>
+#include <dali-toolkit/internal/text/underlined-glyph-run.h>
 
 using namespace Dali;
 
@@ -691,7 +694,7 @@ bool Controller::Impl::SetDefaultLineSpacing(float lineSpacing)
   {
     mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
 
-    RelayoutForNewLineSize();
+    RelayoutAllCharacters();
     return true;
   }
   return false;
@@ -703,12 +706,29 @@ bool Controller::Impl::SetDefaultLineSize(float lineSize)
   {
     mLayoutEngine.SetDefaultLineSize(lineSize);
 
-    RelayoutForNewLineSize();
+    RelayoutAllCharacters();
     return true;
   }
   return false;
 }
 
+bool Controller::Impl::SetRelativeLineSize(float relativeLineSize)
+{
+  if(std::fabs(relativeLineSize - GetRelativeLineSize()) > Math::MACHINE_EPSILON_1000)
+  {
+    mLayoutEngine.SetRelativeLineSize(relativeLineSize);
+
+    RelayoutAllCharacters();
+    return true;
+  }
+  return false;
+}
+
+float Controller::Impl::GetRelativeLineSize()
+{
+  return mLayoutEngine.GetRelativeLineSize();
+}
+
 string Controller::Impl::GetSelectedText()
 {
   string text;
@@ -1461,7 +1481,7 @@ void Controller::Impl::RequestRelayout()
   }
 }
 
-void Controller::Impl::RelayoutForNewLineSize()
+void Controller::Impl::RelayoutAllCharacters()
 {
   // relayout all characters
   mTextUpdateInfo.mCharacterIndex             = 0;
@@ -1616,13 +1636,60 @@ void Controller::Impl::CopyUnderlinedFromLogicalToVisualModels(bool shouldClearP
   {
     CharacterIndex characterIndex     = it->characterRun.characterIndex;
     Length         numberOfCharacters = it->characterRun.numberOfCharacters;
-    for(Length index = 0u; index < numberOfCharacters; index++)
+
+    if(numberOfCharacters == 0)
+    {
+      continue;
+    }
+
+    // Create one run for all glyphs of all run's characters that has same properties
+    // This enhance performance and reduce the needed memory to store glyphs-runs
+    UnderlinedGlyphRun underlineGlyphRun;
+    underlineGlyphRun.glyphRun.glyphIndex     = charactersToGlyph[characterIndex];
+    underlineGlyphRun.glyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex];
+    //Copy properties (attributes)
+    underlineGlyphRun.properties = it->properties;
+
+    for(Length index = 1u; index < numberOfCharacters; index++)
+    {
+      underlineGlyphRun.glyphRun.numberOfGlyphs += glyphsPerCharacter[characterIndex + index];
+    }
+
+    mModel->mVisualModel->mUnderlineRuns.PushBack(underlineGlyphRun);
+  }
+}
+
+void Controller::Impl::CopyStrikethroughFromLogicalToVisualModels()
+{
+  //Strikethrough character runs from markup-processor
+  const Vector<StrikethroughCharacterRun>& strikethroughCharacterRuns = mModel->mLogicalModel->mStrikethroughCharacterRuns;
+  const Vector<GlyphIndex>&                charactersToGlyph          = mModel->mVisualModel->mCharactersToGlyph;
+  const Vector<Length>&                    glyphsPerCharacter         = mModel->mVisualModel->mGlyphsPerCharacter;
+
+  mModel->mVisualModel->mStrikethroughRuns.Clear();
+
+  for(Vector<StrikethroughCharacterRun>::ConstIterator it = strikethroughCharacterRuns.Begin(), endIt = strikethroughCharacterRuns.End(); it != endIt; ++it)
+  {
+    CharacterIndex characterIndex     = it->characterRun.characterIndex;
+    Length         numberOfCharacters = it->characterRun.numberOfCharacters;
+
+    if(numberOfCharacters == 0)
+    {
+      continue;
+    }
+
+    StrikethroughGlyphRun strikethroughGlyphRun;
+    strikethroughGlyphRun.color                   = it->color;
+    strikethroughGlyphRun.isColorSet              = it->isColorSet;
+    strikethroughGlyphRun.glyphRun.glyphIndex     = charactersToGlyph[characterIndex];
+    strikethroughGlyphRun.glyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex];
+
+    for(Length index = 1u; index < numberOfCharacters; index++)
     {
-      GlyphRun underlineGlyphRun;
-      underlineGlyphRun.glyphIndex     = charactersToGlyph[characterIndex + index];
-      underlineGlyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex + index];
-      mModel->mVisualModel->mUnderlineRuns.PushBack(underlineGlyphRun);
+      strikethroughGlyphRun.glyphRun.numberOfGlyphs += glyphsPerCharacter[characterIndex + index];
     }
+
+    mModel->mVisualModel->mStrikethroughRuns.PushBack(strikethroughGlyphRun);
   }
 }
 
@@ -1806,6 +1873,7 @@ void Controller::Impl::ClearStyleData()
 {
   mModel->mLogicalModel->mColorRuns.Clear();
   mModel->mLogicalModel->ClearFontDescriptionRuns();
+  mModel->mLogicalModel->ClearStrikethroughRuns();
 }
 
 void Controller::Impl::ResetScrollPosition()