From: abdullah Date: Mon, 5 Jul 2021 13:40:44 +0000 (+0300) Subject: Fix corrupted markup background X-Git-Tag: dali_2.0.34~3^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=c7c2401a9d5f40eba903e83962534c217c9e2682;hp=-c Fix corrupted markup background sometimes(random issue) when markup enabled for label, the background color is corrupted with random incorrect color pixels. because the background image was not initialized in some cases. plus made some code more clear. Change-Id: Iab93822addb9a790153df45a6f619ae93054ada6 --- c7c2401a9d5f40eba903e83962534c217c9e2682 diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.cpp b/dali-toolkit/internal/text/rendering/text-typesetter.cpp index 17a5c61..6fadaed 100644 --- a/dali-toolkit/internal/text/rendering/text-typesetter.cpp +++ b/dali-toolkit/internal/text/rendering/text-typesetter.cpp @@ -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; diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.h b/dali-toolkit/internal/text/rendering/text-typesetter.h index c9cd4cc..ee57e29 100644 --- a/dali-toolkit/internal/text/rendering/text-typesetter.h +++ b/dali-toolkit/internal/text/rendering/text-typesetter.h @@ -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: diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 12cdae7..76ba060 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -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; diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index 3868979..113051c 100644 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -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 diff --git a/dali-toolkit/internal/text/text-view.cpp b/dali-toolkit/internal/text/text-view.cpp index 74a83f5..8439927 100644 --- a/dali-toolkit/internal/text/text-view.cpp +++ b/dali-toolkit/internal/text/text-view.cpp @@ -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;