Merge "fix linespacing calculation in TextLabel" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / text-typesetter.cpp
index cea2a19..500a081 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.
 
 // 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/styles/character-spacing-helper-functions.h>
+#include <dali-toolkit/internal/text/rendering/styles/strikethrough-helper-functions.h>
+#include <dali-toolkit/internal/text/rendering/styles/underline-helper-functions.h>
 #include <dali-toolkit/internal/text/rendering/view-model.h>
 
 namespace Dali
@@ -35,6 +39,8 @@ namespace Text
 {
 namespace
 {
+const float HALF(0.5f);
+const float ONE_AND_A_HALF(1.5f);
 /**
  * @brief Data struct used to set the buffer of the glyph's bitmap into the final bitmap's buffer.
  */
@@ -255,76 +261,6 @@ void TypesetGlyph(GlyphData&           data,
   }
 }
 
-bool IsGlyphUnderlined(GlyphIndex              index,
-                       const Vector<GlyphRun>& underlineRuns)
-{
-  for(Vector<GlyphRun>::ConstIterator it    = underlineRuns.Begin(),
-                                      endIt = underlineRuns.End();
-      it != endIt;
-      ++it)
-  {
-    const GlyphRun& run = *it;
-
-    if((run.glyphIndex <= index) && (index < run.glyphIndex + run.numberOfGlyphs))
-    {
-      return true;
-    }
-  }
-
-  return false;
-}
-
-/// Helper method to fetch the underline metrics for the specified font glyph
-void FetchFontUnderlineMetrics(
-  TextAbstraction::FontClient& fontClient,
-  const GlyphInfo* const       glyphInfo,
-  float&                       currentUnderlinePosition,
-  const float                  underlineHeight,
-  float&                       currentUnderlineThickness,
-  float&                       maxUnderlineThickness,
-  FontId&                      lastUnderlinedFontId)
-{
-  FontMetrics fontMetrics;
-  fontClient.GetFontMetrics(glyphInfo->fontId, fontMetrics);
-  currentUnderlinePosition = ceil(fabsf(fontMetrics.underlinePosition));
-  const float descender    = ceil(fabsf(fontMetrics.descender));
-
-  if(fabsf(underlineHeight) < Math::MACHINE_EPSILON_1000)
-  {
-    currentUnderlineThickness = fontMetrics.underlineThickness;
-
-    // Ensure underline will be at least a pixel high
-    if(currentUnderlineThickness < 1.0f)
-    {
-      currentUnderlineThickness = 1.0f;
-    }
-    else
-    {
-      currentUnderlineThickness = ceil(currentUnderlineThickness);
-    }
-  }
-
-  // The underline thickness should be the max underline thickness of all glyphs of the line.
-  if(currentUnderlineThickness > maxUnderlineThickness)
-  {
-    maxUnderlineThickness = currentUnderlineThickness;
-  }
-
-  // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
-  if(currentUnderlinePosition > descender)
-  {
-    currentUnderlinePosition = descender;
-  }
-
-  if(fabsf(currentUnderlinePosition) < Math::MACHINE_EPSILON_1000)
-  {
-    // Move offset down by one ( EFL behavior )
-    currentUnderlinePosition = 1.0f;
-  }
-
-  lastUnderlinedFontId = glyphInfo->fontId;
-}
-
 /// Draws the specified color to the pixel buffer
 void WriteColorToPixelBuffer(
   GlyphData&         glyphData,
@@ -349,36 +285,94 @@ 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 unsigned int              bufferWidth,
+  const unsigned int              bufferHeight,
+  GlyphData&                      glyphData,
+  const float                     baseline,
+  const float                     currentUnderlinePosition,
+  const float                     maxUnderlineHeight,
+  const float                     lineExtentLeft,
+  const float                     lineExtentRight,
+  const UnderlineStyleProperties& commonUnderlineProperties,
+  const UnderlineStyleProperties& currentUnderlineProperties,
+  const LineRun&                  line)
 {
+  const Vector4&              underlineColor       = currentUnderlineProperties.colorDefined ? currentUnderlineProperties.color : commonUnderlineProperties.color;
+  const Text::Underline::Type underlineType        = currentUnderlineProperties.typeDefined ? currentUnderlineProperties.type : commonUnderlineProperties.type;
+  const float                 dashedUnderlineWidth = currentUnderlineProperties.dashWidthDefined ? currentUnderlineProperties.dashWidth : commonUnderlineProperties.dashWidth;
+  const float                 dashedUnderlineGap   = currentUnderlineProperties.dashGapDefined ? currentUnderlineProperties.dashGap : commonUnderlineProperties.dashGap;
+
   int       underlineYOffset = glyphData.verticalOffset + baseline + currentUnderlinePosition;
   uint32_t* bitmapBuffer     = reinterpret_cast<uint32_t*>(glyphData.bitmapBuffer.GetBuffer());
 
-  for(unsigned int y = underlineYOffset; y < underlineYOffset + maxUnderlineThickness; y++)
+  for(unsigned int y = underlineYOffset; y < underlineYOffset + maxUnderlineHeight; y++)
   {
     if(y > bufferHeight - 1)
     {
       // 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 = underlineYOffset - ONE_AND_A_HALF * maxUnderlineHeight;
+    for(unsigned int y = secondUnderlineYOffset; y < secondUnderlineYOffset + maxUnderlineHeight; 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);
+      }
     }
   }
 }
@@ -527,6 +521,44 @@ Devel::PixelBuffer DrawGlyphsBackground(const ViewModel* model, Devel::PixelBuff
   return glyphData.bitmapBuffer;
 }
 
+/// Draws the specified strikethrough color to the buffer
+void DrawStrikethrough(const unsigned int                  bufferWidth,
+                       const unsigned int                  bufferHeight,
+                       GlyphData&                          glyphData,
+                       const float                         baseline,
+                       const float                         strikethroughStartingYPosition,
+                       const float                         maxStrikethroughHeight,
+                       const float                         lineExtentLeft,
+                       const float                         lineExtentRight,
+                       const StrikethroughStyleProperties& commonStrikethroughProperties,
+                       const StrikethroughStyleProperties& currentStrikethroughProperties,
+                       const LineRun&                      line)
+{
+  const Vector4& strikethroughColor = currentStrikethroughProperties.colorDefined ? currentStrikethroughProperties.color : commonStrikethroughProperties.color;
+
+  uint32_t* bitmapBuffer = reinterpret_cast<uint32_t*>(glyphData.bitmapBuffer.GetBuffer());
+
+  for(unsigned int y = strikethroughStartingYPosition; y < strikethroughStartingYPosition + maxStrikethroughHeight; 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)
@@ -659,7 +691,7 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
     // Generate the image buffer as an alpha mask for color glyphs.
     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);
@@ -675,7 +707,7 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
   {
     // 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, startIndexOfGlyphs, endIndexOfGlyphs);
@@ -688,7 +720,7 @@ 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, startIndexOfGlyphs, endIndexOfGlyphs);
@@ -707,7 +739,7 @@ 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, startIndexOfGlyphs, endIndexOfGlyphs);
@@ -719,7 +751,7 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
     // Generate the background if enabled
     const bool backgroundEnabled   = mModel->IsBackgroundEnabled();
     const bool backgroundMarkupSet = mModel->IsMarkupBackgroundColorSet();
-    if(backgroundEnabled || backgroundMarkupSet)
+    if((backgroundEnabled || backgroundMarkupSet) && RENDER_OVERLAY_STYLE != behaviour)
     {
       Devel::PixelBuffer backgroundImageBuffer;
 
@@ -741,6 +773,17 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
       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);
@@ -788,6 +831,11 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
   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)
   {
@@ -800,12 +848,6 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
     // 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);
-    }
-
     // Retrieves the glyph's outline width
     float outlineWidth = static_cast<float>(mModel->GetOutlineWidth());
 
@@ -830,23 +872,57 @@ 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 bool  strikethroughEnabled  = mModel->IsStrikethroughEnabled();
+    const float modelCharacterSpacing = mModel->GetCharacterSpacing();
+
+    // Get the character-spacing runs.
+    const Vector<CharacterSpacingGlyphRun>& characterSpacingGlyphRuns = mModel->GetCharacterSpacingGlyphRuns();
+
+    // Aggregate underline-style-properties from mModel
+    const UnderlineStyleProperties modelUnderlineProperties{mModel->GetUnderlineType(),
+                                                            mModel->GetUnderlineColor(),
+                                                            mModel->GetUnderlineHeight(),
+                                                            mModel->GetDashedUnderlineGap(),
+                                                            mModel->GetDashedUnderlineWidth(),
+                                                            true,
+                                                            true,
+                                                            true,
+                                                            true,
+                                                            true};
+
+    // Aggregate strikethrough-style-properties from mModel
+    const StrikethroughStyleProperties modelStrikethroughProperties{mModel->GetStrikethroughColor(),
+                                                                    mModel->GetStrikethroughHeight(),
+                                                                    true,
+                                                                    true};
 
     // Get the underline runs.
-    const Length     numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns();
-    Vector<GlyphRun> underlineRuns;
+    const Length               numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns();
+    Vector<UnderlinedGlyphRun> underlineRuns;
     underlineRuns.Resize(numberOfUnderlineRuns);
     mModel->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
 
-    bool thereAreUnderlinedGlyphs = false;
+    // Get the strikethrough runs.
+    const Length                  numberOfStrikethroughRuns = mModel->GetNumberOfStrikethroughRuns();
+    Vector<StrikethroughGlyphRun> strikethroughRuns;
+    strikethroughRuns.Resize(numberOfStrikethroughRuns);
+    mModel->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
 
-    float currentUnderlinePosition  = 0.0f;
-    float currentUnderlineThickness = underlineHeight;
-    float maxUnderlineThickness     = currentUnderlineThickness;
+    bool thereAreUnderlinedGlyphs    = false;
+    bool thereAreStrikethroughGlyphs = false;
 
-    FontId lastUnderlinedFontId = 0;
+    float currentUnderlinePosition   = 0.0f;
+    float currentUnderlineHeight     = modelUnderlineProperties.height;
+    float maxUnderlineHeight         = currentUnderlineHeight;
+    auto  currentUnderlineProperties = modelUnderlineProperties;
+
+    float currentStrikethroughHeight     = modelStrikethroughProperties.height;
+    float maxStrikethroughHeight         = currentStrikethroughHeight;
+    auto  currentStrikethroughProperties = modelStrikethroughProperties;
+    float strikethroughStartingYPosition = 0.0f;
+
+    FontId lastFontId = 0;
 
     float lineExtentLeft  = bufferWidth;
     float lineExtentRight = 0.0f;
@@ -905,24 +981,52 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
         continue;
       }
 
-      const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined(glyphIndex, underlineRuns);
-      thereAreUnderlinedGlyphs  = thereAreUnderlinedGlyphs || underlineGlyph;
+      Vector<UnderlinedGlyphRun>::ConstIterator currentUnderlinedGlyphRunIt = underlineRuns.End();
+      const bool                                underlineGlyph              = underlineEnabled || IsGlyphUnderlined(glyphIndex, underlineRuns, currentUnderlinedGlyphRunIt);
+      currentUnderlineProperties                                            = GetCurrentUnderlineProperties(glyphIndex, underlineGlyph, underlineRuns, currentUnderlinedGlyphRunIt, modelUnderlineProperties);
+      currentUnderlineHeight                                                = currentUnderlineProperties.height;
+      thereAreUnderlinedGlyphs                                              = thereAreUnderlinedGlyphs || underlineGlyph;
+
+      Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt = strikethroughRuns.End();
+      const bool                                   strikethroughGlyph             = strikethroughEnabled || IsGlyphStrikethrough(glyphIndex, strikethroughRuns, currentStrikethroughGlyphRunIt);
+      currentStrikethroughProperties                                              = GetCurrentStrikethroughProperties(glyphIndex, strikethroughGlyph, strikethroughRuns, currentStrikethroughGlyphRunIt, modelStrikethroughProperties);
+      currentStrikethroughHeight                                                  = currentStrikethroughProperties.height;
+      thereAreStrikethroughGlyphs                                                 = thereAreStrikethroughGlyphs || strikethroughGlyph;
 
       // Are we still using the same fontId as previous
-      if(underlineGlyph && (glyphInfo->fontId != lastUnderlinedFontId))
+      if((glyphInfo->fontId != lastFontId) && (strikethroughGlyph || underlineGlyph))
       {
         // We need to fetch fresh font underline metrics
-        FetchFontUnderlineMetrics(fontClient, glyphInfo, currentUnderlinePosition, underlineHeight, currentUnderlineThickness, maxUnderlineThickness, lastUnderlinedFontId);
-      } // underline
+        FontMetrics fontMetrics;
+        fontClient.GetFontMetrics(glyphInfo->fontId, fontMetrics);
+
+        //The currentUnderlinePosition will be used for both Underline and/or Strikethrough
+        currentUnderlinePosition = FetchUnderlinePositionFromFontMetrics(fontMetrics);
+
+        if(underlineGlyph)
+        {
+          CalcualteUnderlineHeight(fontMetrics, currentUnderlineHeight, maxUnderlineHeight);
+        }
+
+        if(strikethroughGlyph)
+        {
+          CalcualteStrikethroughHeight(currentStrikethroughHeight, maxStrikethroughHeight);
+        }
+
+        // Update lastFontId because fontId is changed
+        lastFontId = glyphInfo->fontId; // Prevents searching for existing blocksizes when string of the same fontId.
+      }
 
       // Retrieves the glyph's position.
       Vector2 position = *(positionBuffer + elidedGlyphIndex);
 
       if(addHyphen)
       {
-        GlyphInfo tempInfo = *(glyphsBuffer + elidedGlyphIndex);
-        position.x         = position.x + tempInfo.advance - tempInfo.xBearing + glyphInfo->xBearing;
-        position.y         = -glyphInfo->yBearing;
+        GlyphInfo   tempInfo         = *(glyphsBuffer + elidedGlyphIndex);
+        const float characterSpacing = GetGlyphCharacterSpacing(glyphIndex, characterSpacingGlyphRuns, modelCharacterSpacing);
+        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)
@@ -974,7 +1078,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,
@@ -1031,7 +1135,7 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
     // 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(bufferWidth, bufferHeight, glyphData, baseline, currentUnderlinePosition, maxUnderlineHeight, lineExtentLeft, lineExtentRight, modelUnderlineProperties, currentUnderlineProperties, line);
     }
 
     // Draw the background color from the leftmost glyph to the rightmost glyph
@@ -1040,8 +1144,16 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
       DrawBackgroundColor(mModel->GetBackgroundColor(), bufferWidth, bufferHeight, glyphData, baseline, line, lineExtentLeft, lineExtentRight);
     }
 
-    // Increases the vertical offset with the line's descender.
-    glyphData.verticalOffset += static_cast<int>(-line.descender);
+    // Draw the strikethrough from the leftmost glyph to the rightmost glyph
+    if(thereAreStrikethroughGlyphs && 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(bufferWidth, bufferHeight, glyphData, baseline, strikethroughStartingYPosition, maxStrikethroughHeight, lineExtentLeft, lineExtentRight, modelStrikethroughProperties, currentStrikethroughProperties, line);
+    }
+
+    // Increases the vertical offset with the line's descender & line spacing.
+    glyphData.verticalOffset += static_cast<int>(-line.descender+line.lineSpacing);
   }
 
   return glyphData.bitmapBuffer;
@@ -1109,43 +1221,77 @@ 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<UnderlinedGlyphRun> 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<UnderlinedGlyphRun>::ConstIterator itGlyphRun    = underlineRuns.Begin();
+  Vector<UnderlinedGlyphRun>::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->glyphRun.glyphIndex;
+    endGlyphIndex   = startGlyphIndex + itGlyphRun->glyphRun.numberOfGlyphs - 1;
+
+    // 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(underlineImageBuffer, topPixelBuffer, bufferWidth, bufferHeight);
+
+    itGlyphRun++;
+  }
+
+  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)
   {
-    // 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);
+    topPixelBuffer = ApplyUnderlineMarkupImageBuffer(topPixelBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset);
 
-      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);
-    }
+    topPixelBuffer = ApplyStrikethroughMarkupImageBuffer(topPixelBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset);
   }
 
   return topPixelBuffer;