Support Markup Underline attributes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-impl.cpp
index f287daf..294b534 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
 #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;
 
@@ -672,11 +675,11 @@ float Controller::Impl::GetDefaultFontLineHeight()
   if(nullptr == mFontDefaults)
   {
     TextAbstraction::FontDescription fontDescription;
-    defaultFontId = mFontClient.GetFontId(fontDescription, TextAbstraction::FontClient::DEFAULT_POINT_SIZE * mFontSizeScale);
+    defaultFontId = mFontClient.GetFontId(fontDescription, TextAbstraction::FontClient::DEFAULT_POINT_SIZE * GetFontSizeScale());
   }
   else
   {
-    defaultFontId = mFontDefaults->GetFontId(mFontClient, mFontDefaults->mDefaultPointSize * mFontSizeScale);
+    defaultFontId = mFontDefaults->GetFontId(mFontClient, mFontDefaults->mDefaultPointSize * GetFontSizeScale());
   }
 
   Text::FontMetrics fontMetrics;
@@ -691,7 +694,7 @@ bool Controller::Impl::SetDefaultLineSpacing(float lineSpacing)
   {
     mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
 
-    RelayoutForNewLineSize();
+    RelayoutAllCharacters();
     return true;
   }
   return false;
@@ -703,7 +706,7 @@ bool Controller::Impl::SetDefaultLineSize(float lineSize)
   {
     mLayoutEngine.SetDefaultLineSize(lineSize);
 
-    RelayoutForNewLineSize();
+    RelayoutAllCharacters();
     return true;
   }
   return false;
@@ -1195,7 +1198,10 @@ void Controller::Impl::GetCursorPosition(CharacterIndex logical,
   parameters.logical      = logical;
   parameters.isMultiline  = isMultiLine;
 
+  float defaultFontLineHeight = GetDefaultFontLineHeight();
+
   Text::GetCursorPosition(parameters,
+                          defaultFontLineHeight,
                           cursorInfo);
 
   // Adds Outline offset.
@@ -1458,7 +1464,7 @@ void Controller::Impl::RequestRelayout()
   }
 }
 
-void Controller::Impl::RelayoutForNewLineSize()
+void Controller::Impl::RelayoutAllCharacters()
 {
   // relayout all characters
   mTextUpdateInfo.mCharacterIndex             = 0;
@@ -1615,14 +1621,61 @@ void Controller::Impl::CopyUnderlinedFromLogicalToVisualModels(bool shouldClearP
     Length         numberOfCharacters = it->characterRun.numberOfCharacters;
     for(Length index = 0u; index < numberOfCharacters; index++)
     {
-      GlyphRun underlineGlyphRun;
-      underlineGlyphRun.glyphIndex     = charactersToGlyph[characterIndex + index];
-      underlineGlyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex + index];
+      UnderlinedGlyphRun underlineGlyphRun;
+      underlineGlyphRun.glyphRun.glyphIndex     = charactersToGlyph[characterIndex + index];
+      underlineGlyphRun.glyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex + index];
+
+      //Copy properties (attributes)
+      underlineGlyphRun.properties.type             = it->properties.type;
+      underlineGlyphRun.properties.color            = it->properties.color;
+      underlineGlyphRun.properties.height           = it->properties.height;
+      underlineGlyphRun.properties.dashGap          = it->properties.dashGap;
+      underlineGlyphRun.properties.dashWidth        = it->properties.dashWidth;
+      underlineGlyphRun.properties.typeDefined      = it->properties.typeDefined;
+      underlineGlyphRun.properties.colorDefined     = it->properties.colorDefined;
+      underlineGlyphRun.properties.heightDefined    = it->properties.heightDefined;
+      underlineGlyphRun.properties.dashGapDefined   = it->properties.dashGapDefined;
+      underlineGlyphRun.properties.dashWidthDefined = it->properties.dashWidthDefined;
+
       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++)
+    {
+      strikethroughGlyphRun.glyphRun.numberOfGlyphs += glyphsPerCharacter[characterIndex + index];
+    }
+
+    mModel->mVisualModel->mStrikethroughRuns.PushBack(strikethroughGlyphRun);
+  }
+}
+
 void Controller::Impl::SetAutoScrollEnabled(bool enable)
 {
   if(mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)
@@ -1803,6 +1856,7 @@ void Controller::Impl::ClearStyleData()
 {
   mModel->mLogicalModel->mColorRuns.Clear();
   mModel->mLogicalModel->ClearFontDescriptionRuns();
+  mModel->mLogicalModel->ClearStrikethroughRuns();
 }
 
 void Controller::Impl::ResetScrollPosition()