Merge "Fix corrupted markup background" into devel/master
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 8 Jul 2021 07:25:25 +0000 (07:25 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 8 Jul 2021 07:25:25 +0000 (07:25 +0000)
dali-toolkit/internal/text/rendering/text-typesetter.cpp
dali-toolkit/internal/text/rendering/text-typesetter.h
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-model.cpp
dali-toolkit/internal/text/text-view.cpp

index 17a5c61..6fadaed 100644 (file)
@@ -539,6 +539,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.
@@ -709,7 +727,7 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
       }
       else
       {
-        backgroundImageBuffer = Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat);
+        backgroundImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, pixelFormat);
       }
 
       if(backgroundMarkupSet)
@@ -755,20 +773,9 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth,
   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();
   Length                      hyphenIndex = 0;
index c9cd4cc..ee57e29 100644 (file)
@@ -123,7 +123,7 @@ private:
   Typesetter& operator=(const Typesetter& handle);
 
   /**
-   * @brief Create the image buffer for the given range of the glyphs in the given style.
+   * @brief Create & draw the image buffer for the given range of the glyphs in the given style.
    *
    * Does the following operations:
    * - Retrieves the data buffers from the text model.
@@ -145,6 +145,19 @@ private:
   Devel::PixelBuffer CreateImageBuffer(const unsigned int bufferWidth, const unsigned int bufferHeight, Typesetter::Style style, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset, TextAbstraction::GlyphIndex fromGlyphIndex, TextAbstraction::GlyphIndex toGlyphIndex);
 
   /**
+   * @brief Create an initialized image buffer.
+   *
+   * Creates the pixel data used to generate the final image with the given size.
+   *
+   * @param[in] bufferWidth The width of the image buffer.
+   * @param[in] bufferHeight The height of the image buffer.
+   * @param[in] pixelFormat The format of the pixel in the image that the text is rendered as (i.e. either Pixel::BGRA8888 or Pixel::L8).
+   *
+   * @return An image buffer.
+   */
+  Devel::PixelBuffer CreateImageBuffer(const unsigned int bufferWidth, const unsigned int bufferHeight, Pixel::Format pixelFormat);
+
+  /**
    * @brief Combine the two RGBA image buffers together.
    *
    * The top layer buffer will blend over the bottom layer buffer:
index 12cdae7..76ba060 100644 (file)
@@ -2106,8 +2106,10 @@ Actor Controller::Impl::CreateBackgroundActor()
 
       // Get the background color of the character.
       // The color index zero is reserved for the default background color (i.e. Color::TRANSPARENT)
-      const ColorIndex backgroundColorIndex = (nullptr == backgroundColorsBuffer) ? 0u : *(backgroundColorIndicesBuffer + i);
-      const Vector4&   backgroundColor      = (0u == backgroundColorIndex) ? defaultBackgroundColor : *(backgroundColorsBuffer + backgroundColorIndex - 1u);
+      const bool       isMarkupBackground       = mView.IsMarkupBackgroundColorSet();
+      const ColorIndex backgroundColorIndex     = isMarkupBackground ? *(backgroundColorIndicesBuffer + i) : 0u;
+      const bool       isDefaultBackgroundColor = (0u == backgroundColorIndex);
+      const Vector4&   backgroundColor          = isDefaultBackgroundColor ? defaultBackgroundColor : *(backgroundColorsBuffer + backgroundColorIndex - 1u);
 
       mModel->mVisualModel->GetNumberOfLines(i, 1, lineIndex, numberOfLines);
       Length lineHeight = lineRun[lineIndex].ascender + -(lineRun[lineIndex].descender) + lineRun[lineIndex].lineSpacing;
index 3868979..113051c 100644 (file)
@@ -129,7 +129,7 @@ const ColorIndex* const Model::GetBackgroundColorIndices() const
 
 bool const Model::IsMarkupBackgroundColorSet() const
 {
-  return (mVisualModel->mBackgroundColorIndices.Count() > 0);
+  return (mVisualModel->mBackgroundColors.Count() > 0);
 }
 
 const Vector4& Model::GetDefaultColor() const
index 74a83f5..8439927 100644 (file)
@@ -347,7 +347,7 @@ bool const View::IsMarkupBackgroundColorSet() const
 {
   if(mImpl->mVisualModel)
   {
-    return (mImpl->mVisualModel->mBackgroundColorIndices.Count() > 0);
+    return (mImpl->mVisualModel->mBackgroundColors.Count() > 0);
   }
 
   return false;