Adding Character Spacing
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / text-typesetter.cpp
index abf7325..2e01c18 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.
@@ -25,6 +25,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
+#include <dali-toolkit/internal/text/glyph-metrics-helper.h>
 #include <dali-toolkit/internal/text/rendering/view-model.h>
 
 namespace Dali
@@ -35,6 +36,7 @@ namespace Text
 {
 namespace
 {
+const float HALF(0.5f);
 /**
  * @brief Data struct used to set the buffer of the glyph's bitmap into the final bitmap's buffer.
  */
@@ -274,15 +276,43 @@ bool IsGlyphUnderlined(GlyphIndex              index,
   return false;
 }
 
+bool doGlyphHaveStrikethrough(GlyphIndex                           index,
+                              const Vector<StrikethroughGlyphRun>& strikethroughRuns,
+                              Vector4&                             strikethroughColor)
+{
+  for(Vector<StrikethroughGlyphRun>::ConstIterator it    = strikethroughRuns.Begin(),
+                                                   endIt = strikethroughRuns.End();
+      it != endIt;
+      ++it)
+  {
+    const StrikethroughGlyphRun& run = *it;
+
+    if((run.glyphRun.glyphIndex <= index) && (index < run.glyphRun.glyphIndex + run.glyphRun.numberOfGlyphs))
+    {
+      if(run.isColorSet)
+      {
+        strikethroughColor = run.color;
+      }
+
+      return true;
+    }
+  }
+
+  return false;
+}
+
 /// Helper method to fetch the underline metrics for the specified font glyph
-void FetchFontUnderlineMetrics(
+void FetchFontDecorationlinesMetrics(
   TextAbstraction::FontClient& fontClient,
   const GlyphInfo* const       glyphInfo,
   float&                       currentUnderlinePosition,
   const float                  underlineHeight,
   float&                       currentUnderlineThickness,
   float&                       maxUnderlineThickness,
-  FontId&                      lastUnderlinedFontId)
+  FontId&                      lastlinedFontId,
+  const float                  strikethroughHeight,
+  float&                       currentStrikethroughThickness,
+  float&                       maxStrikethroughThickness)
 {
   FontMetrics fontMetrics;
   fontClient.GetFontMetrics(glyphInfo->fontId, fontMetrics);
@@ -304,12 +334,31 @@ void FetchFontUnderlineMetrics(
     }
   }
 
+  if(fabsf(strikethroughHeight) < Math::MACHINE_EPSILON_1000)
+  {
+    // Ensure strikethrough will be at least a pixel high
+    if(currentStrikethroughThickness < 1.0f)
+    {
+      currentStrikethroughThickness = 1.0f;
+    }
+    else
+    {
+      currentStrikethroughThickness = ceil(currentStrikethroughThickness);
+    }
+  }
+
   // The underline thickness should be the max underline thickness of all glyphs of the line.
   if(currentUnderlineThickness > maxUnderlineThickness)
   {
     maxUnderlineThickness = currentUnderlineThickness;
   }
 
+  // The strikethrough thickness should be the max strikethrough thickness of all glyphs of the line.
+  if(currentStrikethroughThickness > maxStrikethroughThickness)
+  {
+    maxStrikethroughThickness = currentStrikethroughThickness;
+  }
+
   // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
   if(currentUnderlinePosition > descender)
   {
@@ -322,7 +371,7 @@ void FetchFontUnderlineMetrics(
     currentUnderlinePosition = 1.0f;
   }
 
-  lastUnderlinedFontId = glyphInfo->fontId;
+  lastlinedFontId = glyphInfo->fontId;
 }
 
 /// Draws the specified color to the pixel buffer
@@ -349,15 +398,19 @@ void WriteColorToPixelBuffer(
 
 /// Draws the specified underline color to the buffer
 void DrawUnderline(
-  const Vector4&     underlineColor,
-  const unsigned int bufferWidth,
-  const unsigned int bufferHeight,
-  GlyphData&         glyphData,
-  const float        baseline,
-  const float        currentUnderlinePosition,
-  const float        maxUnderlineThickness,
-  const float        lineExtentLeft,
-  const float        lineExtentRight)
+  const Vector4&              underlineColor,
+  const unsigned int          bufferWidth,
+  const unsigned int          bufferHeight,
+  GlyphData&                  glyphData,
+  const float                 baseline,
+  const float                 currentUnderlinePosition,
+  const float                 maxUnderlineThickness,
+  const float                 lineExtentLeft,
+  const float                 lineExtentRight,
+  const Text::Underline::Type underlineType,
+  const float                 dashedUnderlineWidth,
+  const float                 dashedUnderlineGap,
+  const LineRun&              line)
 {
   int       underlineYOffset = glyphData.verticalOffset + baseline + currentUnderlinePosition;
   uint32_t* bitmapBuffer     = reinterpret_cast<uint32_t*>(glyphData.bitmapBuffer.GetBuffer());
@@ -369,16 +422,67 @@ void DrawUnderline(
       // Do not write out of bounds.
       break;
     }
+    if(underlineType == Text::Underline::DASHED)
+    {
+      float dashWidth = dashedUnderlineWidth;
+      float dashGap   = 0;
 
-    for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++)
+      for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++)
+      {
+        if(x > bufferWidth - 1)
+        {
+          // Do not write out of bounds.
+          break;
+        }
+        if(dashGap == 0 && dashWidth > 0)
+        {
+          WriteColorToPixelBuffer(glyphData, bitmapBuffer, underlineColor, x, y);
+          dashWidth--;
+        }
+        else if(dashGap < dashedUnderlineGap)
+        {
+          dashGap++;
+        }
+        else
+        {
+          //reset
+          dashWidth = dashedUnderlineWidth;
+          dashGap   = 0;
+        }
+      }
+    }
+    else
     {
-      if(x > bufferWidth - 1)
+      for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++)
+      {
+        if(x > bufferWidth - 1)
+        {
+          // Do not write out of bounds.
+          break;
+        }
+        WriteColorToPixelBuffer(glyphData, bitmapBuffer, underlineColor, x, y);
+      }
+    }
+  }
+  if(underlineType == Text::Underline::DOUBLE)
+  {
+    int secondUnderlineYOffset = glyphData.verticalOffset - line.descender - maxUnderlineThickness;
+    for(unsigned int y = secondUnderlineYOffset; y < secondUnderlineYOffset + maxUnderlineThickness; y++)
+    {
+      if(y > bufferHeight - 1)
       {
         // Do not write out of bounds.
         break;
       }
-
-      WriteColorToPixelBuffer(glyphData, bitmapBuffer, underlineColor, x, y);
+      for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++)
+      {
+        if(x > bufferWidth - 1)
+        {
+          // Do not write out of bounds.
+          break;
+        }
+        WriteColorToPixelBuffer(glyphData, bitmapBuffer, underlineColor, x, y);
+      }
     }
   }
 }
@@ -417,6 +521,152 @@ void DrawBackgroundColor(
   }
 }
 
+Devel::PixelBuffer DrawGlyphsBackground(const ViewModel* model, Devel::PixelBuffer& buffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, int horizontalOffset, int verticalOffset)
+{
+  // Retrieve lines, glyphs, positions and colors from the view model.
+  const Length            modelNumberOfLines           = model->GetNumberOfLines();
+  const LineRun* const    modelLinesBuffer             = model->GetLines();
+  const Length            numberOfGlyphs               = model->GetNumberOfGlyphs();
+  const GlyphInfo* const  glyphsBuffer                 = model->GetGlyphs();
+  const Vector2* const    positionBuffer               = model->GetLayout();
+  const Vector4* const    backgroundColorsBuffer       = model->GetBackgroundColors();
+  const ColorIndex* const backgroundColorIndicesBuffer = model->GetBackgroundColorIndices();
+
+  // Create and initialize the pixel buffer.
+  GlyphData glyphData;
+  glyphData.verticalOffset   = verticalOffset;
+  glyphData.width            = bufferWidth;
+  glyphData.height           = bufferHeight;
+  glyphData.bitmapBuffer     = buffer;
+  glyphData.horizontalOffset = 0;
+
+  ColorIndex prevBackgroundColorIndex = 0;
+  ColorIndex backgroundColorIndex     = 0;
+
+  // Traverses the lines of the text.
+  for(LineIndex lineIndex = 0u; lineIndex < modelNumberOfLines; ++lineIndex)
+  {
+    const LineRun& line = *(modelLinesBuffer + lineIndex);
+
+    // Sets the horizontal offset of the line.
+    glyphData.horizontalOffset = ignoreHorizontalAlignment ? 0 : static_cast<int>(line.alignmentOffset);
+    glyphData.horizontalOffset += horizontalOffset;
+
+    // Increases the vertical offset with the line's ascender.
+    glyphData.verticalOffset += static_cast<int>(line.ascender);
+
+    // Include line spacing after first line
+    if(lineIndex > 0u)
+    {
+      glyphData.verticalOffset += static_cast<int>(line.lineSpacing);
+    }
+
+    float left     = bufferWidth;
+    float right    = 0.0f;
+    float baseline = 0.0f;
+
+    // Traverses the glyphs of the line.
+    const GlyphIndex endGlyphIndex = std::min(numberOfGlyphs, line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs);
+    for(GlyphIndex glyphIndex = line.glyphRun.glyphIndex; glyphIndex < endGlyphIndex; ++glyphIndex)
+    {
+      // Retrieve the glyph's info.
+      const GlyphInfo* const glyphInfo = glyphsBuffer + glyphIndex;
+
+      if((glyphInfo->width < Math::MACHINE_EPSILON_1000) ||
+         (glyphInfo->height < Math::MACHINE_EPSILON_1000))
+      {
+        // Nothing to do if default background color, the glyph's width or height is zero.
+        continue;
+      }
+
+      backgroundColorIndex = (nullptr == backgroundColorsBuffer) ? 0u : *(backgroundColorIndicesBuffer + glyphIndex);
+
+      if((backgroundColorIndex != prevBackgroundColorIndex) &&
+         (prevBackgroundColorIndex != 0u))
+      {
+        const Vector4& backgroundColor = *(backgroundColorsBuffer + prevBackgroundColorIndex - 1u);
+        DrawBackgroundColor(backgroundColor, bufferWidth, bufferHeight, glyphData, baseline, line, left, right);
+      }
+
+      if(backgroundColorIndex == 0u)
+      {
+        prevBackgroundColorIndex = backgroundColorIndex;
+        //if background color is the default do nothing
+        continue;
+      }
+
+      // Retrieves the glyph's position.
+      const Vector2* const position = positionBuffer + glyphIndex;
+
+      if(baseline < position->y + glyphInfo->yBearing)
+      {
+        baseline = position->y + glyphInfo->yBearing;
+      }
+
+      // Calculate the positions of leftmost and rightmost glyphs in the current line
+      if((position->x < left) || (backgroundColorIndex != prevBackgroundColorIndex))
+      {
+        left = position->x - glyphInfo->xBearing;
+      }
+
+      if(position->x + glyphInfo->width > right)
+      {
+        right = position->x - glyphInfo->xBearing + glyphInfo->advance;
+      }
+
+      prevBackgroundColorIndex = backgroundColorIndex;
+    }
+
+    //draw last background at line end if not default
+    if(backgroundColorIndex != 0u)
+    {
+      const Vector4& backgroundColor = *(backgroundColorsBuffer + backgroundColorIndex - 1u);
+      DrawBackgroundColor(backgroundColor, bufferWidth, bufferHeight, glyphData, baseline, line, left, right);
+    }
+
+    // Increases the vertical offset with the line's descender.
+    glyphData.verticalOffset += static_cast<int>(-line.descender);
+  }
+
+  return glyphData.bitmapBuffer;
+}
+
+/// Draws the specified strikethrough color to the buffer
+void DrawStrikethrough(
+  const Vector4&     strikethroughColor,
+  const unsigned int bufferWidth,
+  const unsigned int bufferHeight,
+  GlyphData&         glyphData,
+  const float        baseline,
+  const LineRun&     line,
+  const float        maxStrikethroughThickness,
+  const float        lineExtentLeft,
+  const float        lineExtentRight,
+  float              strikethroughStartingYPosition)
+{
+  uint32_t* bitmapBuffer = reinterpret_cast<uint32_t*>(glyphData.bitmapBuffer.GetBuffer());
+
+  for(unsigned int y = strikethroughStartingYPosition; y < strikethroughStartingYPosition + maxStrikethroughThickness; y++)
+  {
+    if(y > bufferHeight - 1)
+    {
+      // Do not write out of bounds.
+      break;
+    }
+
+    for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++)
+    {
+      if(x > bufferWidth - 1)
+      {
+        // Do not write out of bounds.
+        break;
+      }
+
+      WriteColorToPixelBuffer(glyphData, bitmapBuffer, strikethroughColor, x, y);
+    }
+  }
+}
+
 } // namespace
 
 TypesetterPtr Typesetter::New(const ModelInterface* const model)
@@ -429,6 +679,24 @@ ViewModel* Typesetter::GetViewModel()
   return mModel;
 }
 
+Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth, const unsigned int bufferHeight, Pixel::Format pixelFormat)
+{
+  Devel::PixelBuffer imageBuffer = Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat);
+
+  if(Pixel::RGBA8888 == pixelFormat)
+  {
+    const unsigned int bufferSizeInt  = bufferWidth * bufferHeight;
+    const unsigned int bufferSizeChar = 4u * bufferSizeInt;
+    memset(imageBuffer.GetBuffer(), 0u, bufferSizeChar);
+  }
+  else
+  {
+    memset(imageBuffer.GetBuffer(), 0, bufferWidth * bufferHeight);
+  }
+
+  return imageBuffer;
+}
+
 PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirection::Type textDirection, RenderBehaviour behaviour, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat)
 {
   // @todo. This initial implementation for a TextLabel has only one visible page.
@@ -520,16 +788,18 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
   const unsigned int bufferSizeInt  = bufferWidth * bufferHeight;
   const unsigned int bufferSizeChar = 4u * bufferSizeInt;
 
-  Length numberOfGlyphs = mModel->GetNumberOfGlyphs();
+  //Elided text in ellipsis at START could start on index greater than 0
+  auto startIndexOfGlyphs = mModel->GetStartIndexOfElidedGlyphs();
+  auto endIndexOfGlyphs   = mModel->GetEndIndexOfElidedGlyphs();
 
   Devel::PixelBuffer imageBuffer;
 
   if(RENDER_MASK == behaviour)
   {
     // Generate the image buffer as an alpha mask for color glyphs.
-    imageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_MASK, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1);
+    imageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_MASK, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs);
   }
-  else if(RENDER_NO_TEXT == behaviour)
+  else if(RENDER_NO_TEXT == behaviour || RENDER_OVERLAY_STYLE == behaviour)
   {
     // Generate an empty image buffer so that it can been combined with the image buffers for styles
     imageBuffer = Devel::PixelBuffer::New(bufferWidth, bufferHeight, Pixel::RGBA8888);
@@ -538,17 +808,17 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
   else
   {
     // Generate the image buffer for the text with no style.
-    imageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_NONE, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1);
+    imageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_NONE, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs);
   }
 
   if((RENDER_NO_STYLES != behaviour) && (RENDER_MASK != behaviour))
   {
     // Generate the outline if enabled
     const uint16_t outlineWidth = mModel->GetOutlineWidth();
-    if(outlineWidth != 0u)
+    if(outlineWidth != 0u && RENDER_OVERLAY_STYLE != behaviour)
     {
       // Create the image buffer for outline
-      Devel::PixelBuffer outlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_OUTLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1);
+      Devel::PixelBuffer outlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_OUTLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs);
 
       // Combine the two buffers
       imageBuffer = CombineImageBuffer(imageBuffer, outlineImageBuffer, bufferWidth, bufferHeight);
@@ -558,10 +828,10 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
 
     // Generate the shadow if enabled
     const Vector2& shadowOffset = mModel->GetShadowOffset();
-    if(fabsf(shadowOffset.x) > Math::MACHINE_EPSILON_1 || fabsf(shadowOffset.y) > Math::MACHINE_EPSILON_1)
+    if(RENDER_OVERLAY_STYLE != behaviour && (fabsf(shadowOffset.x) > Math::MACHINE_EPSILON_1 || fabsf(shadowOffset.y) > Math::MACHINE_EPSILON_1))
     {
       // Create the image buffer for shadow
-      Devel::PixelBuffer shadowImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_SHADOW, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1);
+      Devel::PixelBuffer shadowImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_SHADOW, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs);
 
       // Check whether it will be a soft shadow
       const float& blurRadius = mModel->GetShadowBlurRadius();
@@ -577,24 +847,54 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
 
     // Generate the underline if enabled
     const bool underlineEnabled = mModel->IsUnderlineEnabled();
-    if(underlineEnabled)
+    if(underlineEnabled && RENDER_OVERLAY_STYLE == behaviour)
     {
       // Create the image buffer for underline
-      Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1);
+      Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs);
 
       // Combine the two buffers
       imageBuffer = CombineImageBuffer(imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight);
     }
 
     // Generate the background if enabled
-    const bool backgroundEnabled = mModel->IsBackgroundEnabled();
-    if(backgroundEnabled)
+    const bool backgroundEnabled   = mModel->IsBackgroundEnabled();
+    const bool backgroundMarkupSet = mModel->IsMarkupBackgroundColorSet();
+    if((backgroundEnabled || backgroundMarkupSet) && RENDER_OVERLAY_STYLE != behaviour)
     {
-      Devel::PixelBuffer backgroundImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_BACKGROUND, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1);
+      Devel::PixelBuffer backgroundImageBuffer;
+
+      if(backgroundEnabled)
+      {
+        backgroundImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_BACKGROUND, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs);
+      }
+      else
+      {
+        backgroundImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, pixelFormat);
+      }
+
+      if(backgroundMarkupSet)
+      {
+        DrawGlyphsBackground(mModel, backgroundImageBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, penX, penY);
+      }
 
       // Combine the two buffers
       imageBuffer = CombineImageBuffer(imageBuffer, backgroundImageBuffer, bufferWidth, bufferHeight);
     }
+
+    // Generate the strikethrough if enabled
+    const bool strikethroughEnabled = mModel->IsStrikethroughEnabled();
+    if(strikethroughEnabled && RENDER_OVERLAY_STYLE == behaviour)
+    {
+      // Create the image buffer for strikethrough
+      Devel::PixelBuffer strikethroughImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_STRIKETHROUGH, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, endIndexOfGlyphs);
+
+      // Combine the two buffers
+      imageBuffer = CombineImageBuffer(imageBuffer, strikethroughImageBuffer, bufferWidth, bufferHeight);
+    }
+
+    // Markup-Processor
+
+    imageBuffer = ApplyMarkupProcessorOnPixelBuffer(imageBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, penX, penY);
   }
 
   // Create the final PixelData for the combined image buffer
@@ -608,37 +908,42 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
   // Retrieve lines, glyphs, positions and colors from the view model.
   const Length            modelNumberOfLines = mModel->GetNumberOfLines();
   const LineRun* const    modelLinesBuffer   = mModel->GetLines();
-  const Length            numberOfGlyphs     = mModel->GetNumberOfGlyphs();
   const GlyphInfo* const  glyphsBuffer       = mModel->GetGlyphs();
   const Vector2* const    positionBuffer     = mModel->GetLayout();
   const Vector4* const    colorsBuffer       = mModel->GetColors();
   const ColorIndex* const colorIndexBuffer   = mModel->GetColorIndices();
+  const GlyphInfo*        hyphens            = mModel->GetHyphens();
+  const Length*           hyphenIndices      = mModel->GetHyphenIndices();
+  const Length            hyphensCount       = mModel->GetHyphensCount();
+
+  // Elided text info. Indices according to elided text and Ellipsis position.
+  const auto startIndexOfGlyphs              = mModel->GetStartIndexOfElidedGlyphs();
+  const auto endIndexOfGlyphs                = mModel->GetEndIndexOfElidedGlyphs();
+  const auto firstMiddleIndexOfElidedGlyphs  = mModel->GetFirstMiddleIndexOfElidedGlyphs();
+  const auto secondMiddleIndexOfElidedGlyphs = mModel->GetSecondMiddleIndexOfElidedGlyphs();
+  const auto ellipsisPosition                = mModel->GetEllipsisPosition();
 
   // Whether to use the default color.
   const bool     useDefaultColor = (NULL == colorsBuffer);
   const Vector4& defaultColor    = mModel->GetDefaultColor();
+  Vector4        currentStrikethroughColor;
 
   // Create and initialize the pixel buffer.
   GlyphData glyphData;
   glyphData.verticalOffset   = verticalOffset;
   glyphData.width            = bufferWidth;
   glyphData.height           = bufferHeight;
-  glyphData.bitmapBuffer     = Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat);
+  glyphData.bitmapBuffer     = CreateImageBuffer(bufferWidth, bufferHeight, pixelFormat);
   glyphData.horizontalOffset = 0;
 
-  if(Pixel::RGBA8888 == pixelFormat)
-  {
-    const unsigned int bufferSizeInt  = bufferWidth * bufferHeight;
-    const unsigned int bufferSizeChar = 4u * bufferSizeInt;
-    memset(glyphData.bitmapBuffer.GetBuffer(), 0u, bufferSizeChar);
-  }
-  else
-  {
-    memset(glyphData.bitmapBuffer.GetBuffer(), 0, bufferWidth * bufferHeight);
-  }
-
   // Get a handle of the font client. Used to retrieve the bitmaps of the glyphs.
-  TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+  TextAbstraction::FontClient fontClient  = TextAbstraction::FontClient::Get();
+  Length                      hyphenIndex = 0;
+
+  const Character*              textBuffer                = mModel->GetTextBuffer();
+  float                         calculatedAdvance         = 0.f;
+  const Vector<CharacterIndex>& glyphToCharacterMap       = mModel->GetGlyphsToCharacters();
+  const CharacterIndex*         glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
 
   // Traverses the lines of the text.
   for(LineIndex lineIndex = 0u; lineIndex < modelNumberOfLines; ++lineIndex)
@@ -682,9 +987,16 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
       }
     }
 
-    const bool     underlineEnabled = mModel->IsUnderlineEnabled();
-    const Vector4& underlineColor   = mModel->GetUnderlineColor();
-    const float    underlineHeight  = mModel->GetUnderlineHeight();
+    const bool                  underlineEnabled     = mModel->IsUnderlineEnabled();
+    const Vector4&              underlineColor       = mModel->GetUnderlineColor();
+    const float                 underlineHeight      = mModel->GetUnderlineHeight();
+    const Text::Underline::Type underlineType        = mModel->GetUnderlineType();
+    const float                 dashedUnderlineWidth = mModel->GetDashedUnderlineWidth();
+    const float                 dashedUnderlineGap   = mModel->GetDashedUnderlineGap();
+    const bool                  strikethroughEnabled = mModel->IsStrikethroughEnabled();
+    const Vector4&              strikethroughColor   = mModel->GetStrikethroughColor();
+    const float                 strikethroughHeight  = mModel->GetStrikethroughHeight();
+    const float                 characterSpacing     = mModel->GetCharacterSpacing();
 
     // Get the underline runs.
     const Length     numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns();
@@ -692,21 +1004,35 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
     underlineRuns.Resize(numberOfUnderlineRuns);
     mModel->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
 
+    // Get the strikethrough runs.
+    const Length                  numberOfStrikethroughRuns = mModel->GetNumberOfStrikethroughRuns();
+    Vector<StrikethroughGlyphRun> strikethroughRuns;
+    strikethroughRuns.Resize(numberOfStrikethroughRuns);
+    mModel->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
+
     bool thereAreUnderlinedGlyphs = false;
+    bool strikethroughGlyphsExist = false;
 
-    float currentUnderlinePosition  = 0.0f;
-    float currentUnderlineThickness = underlineHeight;
-    float maxUnderlineThickness     = currentUnderlineThickness;
+    float currentUnderlinePosition       = 0.0f;
+    float currentUnderlineThickness      = underlineHeight;
+    float maxUnderlineThickness          = currentUnderlineThickness;
+    float currentStrikethroughThickness  = strikethroughHeight;
+    float maxStrikethroughThickness      = currentStrikethroughThickness;
+    float strikethroughStartingYPosition = 0.0f;
 
     FontId lastUnderlinedFontId = 0;
 
     float lineExtentLeft  = bufferWidth;
     float lineExtentRight = 0.0f;
     float baseline        = 0.0f;
+    bool  addHyphen       = false;
 
     // Traverses the glyphs of the line.
-    const GlyphIndex endGlyphIndex = std::min(numberOfGlyphs, line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs);
-    for(GlyphIndex glyphIndex = line.glyphRun.glyphIndex; glyphIndex < endGlyphIndex; ++glyphIndex)
+    const GlyphIndex startGlyphIndex = std::max(line.glyphRun.glyphIndex, startIndexOfGlyphs);
+    GlyphIndex       endGlyphIndex   = (line.isSplitToTwoHalves ? line.glyphRunSecondHalf.glyphIndex + line.glyphRunSecondHalf.numberOfGlyphs : line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs) - 1u;
+    endGlyphIndex                    = std::min(endGlyphIndex, endIndexOfGlyphs);
+
+    for(GlyphIndex glyphIndex = startGlyphIndex; glyphIndex <= endGlyphIndex; ++glyphIndex)
     {
       if(glyphIndex < fromGlyphIndex || glyphIndex > toGlyphIndex)
       {
@@ -714,8 +1040,37 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
         continue;
       }
 
+      //To handle START case of ellipsis, the first glyph has been shifted
+      //glyphIndex represent indices in whole glyphs but elidedGlyphIndex represents indices in elided Glyphs
+      GlyphIndex elidedGlyphIndex = glyphIndex - startIndexOfGlyphs;
+
+      //To handle MIDDLE case of ellipsis, the first glyph in the second half of line has been shifted and skip the removed glyph from middle.
+      if(ellipsisPosition == DevelText::EllipsisPosition::MIDDLE)
+      {
+        if(glyphIndex > firstMiddleIndexOfElidedGlyphs &&
+           glyphIndex < secondMiddleIndexOfElidedGlyphs)
+        {
+          // Ignore any glyph that removed for MIDDLE ellipsis
+          continue;
+        }
+        if(glyphIndex >= secondMiddleIndexOfElidedGlyphs)
+        {
+          elidedGlyphIndex -= (secondMiddleIndexOfElidedGlyphs - firstMiddleIndexOfElidedGlyphs - 1u);
+        }
+      }
+
       // Retrieve the glyph's info.
-      const GlyphInfo* const glyphInfo = glyphsBuffer + glyphIndex;
+      const GlyphInfo* glyphInfo;
+
+      if(addHyphen && hyphens)
+      {
+        glyphInfo = hyphens + hyphenIndex;
+        hyphenIndex++;
+      }
+      else
+      {
+        glyphInfo = glyphsBuffer + elidedGlyphIndex;
+      }
 
       if((glyphInfo->width < Math::MACHINE_EPSILON_1000) ||
          (glyphInfo->height < Math::MACHINE_EPSILON_1000))
@@ -727,29 +1082,42 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
       const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined(glyphIndex, underlineRuns);
       thereAreUnderlinedGlyphs  = thereAreUnderlinedGlyphs || underlineGlyph;
 
+      currentStrikethroughColor     = strikethroughColor;
+      const bool strikethroughGlyph = strikethroughEnabled || doGlyphHaveStrikethrough(glyphIndex, strikethroughRuns, currentStrikethroughColor);
+      strikethroughGlyphsExist      = strikethroughGlyphsExist || strikethroughGlyph;
+
       // Are we still using the same fontId as previous
-      if(underlineGlyph && (glyphInfo->fontId != lastUnderlinedFontId))
+      if((strikethroughGlyph || underlineGlyph) && (glyphInfo->fontId != lastUnderlinedFontId))
       {
         // We need to fetch fresh font underline metrics
-        FetchFontUnderlineMetrics(fontClient, glyphInfo, currentUnderlinePosition, underlineHeight, currentUnderlineThickness, maxUnderlineThickness, lastUnderlinedFontId);
+        FetchFontDecorationlinesMetrics(fontClient, glyphInfo, currentUnderlinePosition, underlineHeight, currentUnderlineThickness, maxUnderlineThickness, lastUnderlinedFontId, strikethroughHeight, currentStrikethroughThickness, maxStrikethroughThickness);
       } // underline
 
       // Retrieves the glyph's position.
-      const Vector2* const position = positionBuffer + glyphIndex;
-      if(baseline < position->y + glyphInfo->yBearing)
+      Vector2 position = *(positionBuffer + elidedGlyphIndex);
+
+      if(addHyphen)
       {
-        baseline = position->y + glyphInfo->yBearing;
+        GlyphInfo tempInfo = *(glyphsBuffer + elidedGlyphIndex);
+        calculatedAdvance  = GetCalculatedAdvance(*(textBuffer + (*(glyphToCharacterMapBuffer + elidedGlyphIndex))), characterSpacing, tempInfo.advance);
+        position.x         = position.x + calculatedAdvance - tempInfo.xBearing + glyphInfo->xBearing;
+        position.y         = -glyphInfo->yBearing;
+      }
+
+      if(baseline < position.y + glyphInfo->yBearing)
+      {
+        baseline = position.y + glyphInfo->yBearing;
       }
 
       // Calculate the positions of leftmost and rightmost glyphs in the current line
-      if(position->x < lineExtentLeft)
+      if(position.x < lineExtentLeft)
       {
-        lineExtentLeft = position->x;
+        lineExtentLeft = position.x;
       }
 
-      if(position->x + glyphInfo->width > lineExtentRight)
+      if(position.x + glyphInfo->width > lineExtentRight)
       {
-        lineExtentRight = position->x + glyphInfo->width;
+        lineExtentRight = position.x + glyphInfo->width;
       }
 
       // Retrieves the glyph's color.
@@ -785,7 +1153,7 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
         outlineWidth = 0.0f;
       }
 
-      if(style != Typesetter::STYLE_UNDERLINE)
+      if(style != Typesetter::STYLE_UNDERLINE && style != Typesetter::STYLE_STRIKETHROUGH)
       {
         fontClient.CreateBitmap(glyphInfo->fontId,
                                 glyphInfo->index,
@@ -807,7 +1175,7 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
 
         // Set the buffer of the glyph's bitmap into the final bitmap's buffer
         TypesetGlyph(glyphData,
-                     position,
+                     &position,
                      &color,
                      style,
                      pixelFormat);
@@ -823,12 +1191,26 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
         delete[] glyphData.glyphBitmap.buffer;
         glyphData.glyphBitmap.buffer = NULL;
       }
+
+      if(hyphenIndices)
+      {
+        while((hyphenIndex < hyphensCount) && (glyphIndex > hyphenIndices[hyphenIndex]))
+        {
+          hyphenIndex++;
+        }
+
+        addHyphen = ((hyphenIndex < hyphensCount) && ((glyphIndex + 1) == hyphenIndices[hyphenIndex]));
+        if(addHyphen)
+        {
+          glyphIndex--;
+        }
+      }
     }
 
     // Draw the underline from the leftmost glyph to the rightmost glyph
     if(thereAreUnderlinedGlyphs && style == Typesetter::STYLE_UNDERLINE)
     {
-      DrawUnderline(underlineColor, bufferWidth, bufferHeight, glyphData, baseline, currentUnderlinePosition, maxUnderlineThickness, lineExtentLeft, lineExtentRight);
+      DrawUnderline(underlineColor, bufferWidth, bufferHeight, glyphData, baseline, currentUnderlinePosition, maxUnderlineThickness, lineExtentLeft, lineExtentRight, underlineType, dashedUnderlineWidth, dashedUnderlineGap, line);
     }
 
     // Draw the background color from the leftmost glyph to the rightmost glyph
@@ -837,6 +1219,14 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
       DrawBackgroundColor(mModel->GetBackgroundColor(), bufferWidth, bufferHeight, glyphData, baseline, line, lineExtentLeft, lineExtentRight);
     }
 
+    // Draw the strikethrough from the leftmost glyph to the rightmost glyph
+    if(strikethroughGlyphsExist && style == Typesetter::STYLE_STRIKETHROUGH)
+    {
+      //TODO : The currently implemented strikethrough creates a strikethrough on the line level. We need to create different strikethroughs the case of glyphs with different sizes.
+      strikethroughStartingYPosition = (glyphData.verticalOffset + baseline + currentUnderlinePosition) - ((line.ascender) * HALF); // Since Free Type font doesn't contain the strikethrough-position property, strikethrough position will be calculated by moving the underline position upwards by half the value of the line height.
+      DrawStrikethrough(strikethroughColor, bufferWidth, bufferHeight, glyphData, baseline, line, maxStrikethroughThickness, lineExtentLeft, lineExtentRight, strikethroughStartingYPosition);
+    }
+
     // Increases the vertical offset with the line's descender.
     glyphData.verticalOffset += static_cast<int>(-line.descender);
   }
@@ -906,6 +1296,88 @@ Devel::PixelBuffer Typesetter::CombineImageBuffer(Devel::PixelBuffer topPixelBuf
   return combinedPixelBuffer;
 }
 
+Devel::PixelBuffer Typesetter::ApplyUnderlineMarkupImageBuffer(Devel::PixelBuffer topPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset)
+{
+  // Underline-tags (this is for Markup case)
+  // Get the underline runs.
+  const Length     numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns();
+  Vector<GlyphRun> underlineRuns;
+  underlineRuns.Resize(numberOfUnderlineRuns);
+  mModel->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
+
+  // Iterate on the consecutive underlined glyph run and connect them into one chunk of underlined characters.
+  Vector<GlyphRun>::ConstIterator itGlyphRun    = underlineRuns.Begin();
+  Vector<GlyphRun>::ConstIterator endItGlyphRun = underlineRuns.End();
+  GlyphIndex                      startGlyphIndex, endGlyphIndex;
+
+  //The outer loop to iterate on the separated chunks of underlined glyph runs
+  while(itGlyphRun != endItGlyphRun)
+  {
+    startGlyphIndex = itGlyphRun->glyphIndex;
+    endGlyphIndex   = startGlyphIndex;
+    //The inner loop to make a connected underline for the consecutive characters
+    do
+    {
+      endGlyphIndex += itGlyphRun->numberOfGlyphs;
+      itGlyphRun++;
+    } while(itGlyphRun != endItGlyphRun && itGlyphRun->glyphIndex == endGlyphIndex);
+
+    endGlyphIndex--;
+
+    // Create the image buffer for underline
+    Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset, startGlyphIndex, endGlyphIndex);
+    // Combine the two buffers
+    topPixelBuffer = CombineImageBuffer(topPixelBuffer, underlineImageBuffer, bufferWidth, bufferHeight);
+  }
+
+  return topPixelBuffer;
+}
+
+Devel::PixelBuffer Typesetter::ApplyStrikethroughMarkupImageBuffer(Devel::PixelBuffer topPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset)
+{
+  // strikethrough-tags (this is for Markup case)
+  // Get the strikethrough runs.
+  const Length                  numberOfStrikethroughRuns = mModel->GetNumberOfStrikethroughRuns();
+  Vector<StrikethroughGlyphRun> strikethroughRuns;
+  strikethroughRuns.Resize(numberOfStrikethroughRuns);
+  mModel->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
+
+  // Iterate on the consecutive strikethrough glyph run and connect them into one chunk of strikethrough characters.
+  Vector<StrikethroughGlyphRun>::ConstIterator itGlyphRun    = strikethroughRuns.Begin();
+  Vector<StrikethroughGlyphRun>::ConstIterator endItGlyphRun = strikethroughRuns.End();
+  GlyphIndex                                   startGlyphIndex, endGlyphIndex;
+
+  //The outer loop to iterate on the separated chunks of strikethrough glyph runs
+  while(itGlyphRun != endItGlyphRun)
+  {
+    startGlyphIndex = itGlyphRun->glyphRun.glyphIndex;
+    endGlyphIndex   = startGlyphIndex + itGlyphRun->glyphRun.numberOfGlyphs - 1;
+
+    // Create the image buffer for strikethrough
+    Devel::PixelBuffer strikethroughImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_STRIKETHROUGH, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset, startGlyphIndex, endGlyphIndex);
+    // Combine the two buffers
+    topPixelBuffer = CombineImageBuffer(strikethroughImageBuffer, topPixelBuffer, bufferWidth, bufferHeight);
+
+    itGlyphRun++;
+  }
+
+  return topPixelBuffer;
+}
+
+Devel::PixelBuffer Typesetter::ApplyMarkupProcessorOnPixelBuffer(Devel::PixelBuffer topPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset)
+{
+  // Apply the markup-Processor if enabled
+  const bool markupProcessorEnabled = mModel->IsMarkupProcessorEnabled();
+  if(markupProcessorEnabled)
+  {
+    topPixelBuffer = ApplyUnderlineMarkupImageBuffer(topPixelBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset);
+
+    topPixelBuffer = ApplyStrikethroughMarkupImageBuffer(topPixelBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset);
+  }
+
+  return topPixelBuffer;
+}
+
 Typesetter::Typesetter(const ModelInterface* const model)
 : mModel(new ViewModel(model))
 {