From 404951ce1994183b50908037e954760bedfbb912 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Thu, 7 Jul 2022 20:15:53 +0900 Subject: [PATCH] Fix markup underline, strikethrough in overlay style Change-Id: Ib5352c423f558ca4ffc6be2c37d644eb02249151 Signed-off-by: Bowon Ryu --- .../internal/text/rendering/text-typesetter.cpp | 67 ++++++++++------------ .../internal/text/rendering/text-typesetter.h | 15 ----- .../internal/text/rendering/view-model.cpp | 10 ++++ dali-toolkit/internal/text/rendering/view-model.h | 19 ++++++ dali-toolkit/internal/text/text-model-interface.h | 14 +++++ dali-toolkit/internal/text/text-model.cpp | 10 ++++ dali-toolkit/internal/text/text-model.h | 20 +++++++ dali-toolkit/internal/text/text-view-interface.h | 14 +++++ dali-toolkit/internal/text/text-view.cpp | 10 ++++ dali-toolkit/internal/text/text-view.h | 10 ++++ dali-toolkit/internal/visuals/text/text-visual.cpp | 15 ++--- 11 files changed, 146 insertions(+), 58 deletions(-) diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.cpp b/dali-toolkit/internal/text/rendering/text-typesetter.cpp index 14f3da7..5543d79 100644 --- a/dali-toolkit/internal/text/rendering/text-typesetter.cpp +++ b/dali-toolkit/internal/text/rendering/text-typesetter.cpp @@ -983,7 +983,7 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect CombineImageBuffer(imageBuffer, outlineImageBuffer, bufferWidth, bufferHeight, true); } - // @todo. Support shadow and underline for partial text later on. + // @todo. Support shadow for partial text later on. // Generate the shadow if enabled const Vector2& shadowOffset = mModel->GetShadowOffset(); @@ -1004,17 +1004,6 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect CombineImageBuffer(imageBuffer, shadowImageBuffer, bufferWidth, bufferHeight, true); } - // Generate the underline if enabled - const bool underlineEnabled = mModel->IsUnderlineEnabled(); - 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); - - // Combine the two buffers - CombineImageBuffer(imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight, true); - } - // Generate the background if enabled const bool backgroundEnabled = mModel->IsBackgroundEnabled(); const bool backgroundMarkupSet = mModel->IsMarkupBackgroundColorSet(); @@ -1040,20 +1029,40 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect CombineImageBuffer(imageBuffer, backgroundImageBuffer, bufferWidth, bufferHeight, true); } - // Generate the strikethrough if enabled - const bool strikethroughEnabled = mModel->IsStrikethroughEnabled(); - if(strikethroughEnabled && RENDER_OVERLAY_STYLE == behaviour) + if(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); + if(mModel->IsUnderlineEnabled()) + { + // Create the image buffer for underline + Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs); - // Combine the two buffers - CombineImageBuffer(imageBuffer, strikethroughImageBuffer, bufferWidth, bufferHeight, true); - } + // Combine the two buffers + CombineImageBuffer(imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight, true); + } + + if(mModel->IsStrikethroughEnabled()) + { + // Create the image buffer for strikethrough + Devel::PixelBuffer strikethroughImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_STRIKETHROUGH, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, endIndexOfGlyphs); - // Markup-Processor + // Combine the two buffers + CombineImageBuffer(imageBuffer, strikethroughImageBuffer, bufferWidth, bufferHeight, true); + } + + // Markup-Processor for overlay styles + if(mModel->IsMarkupProcessorEnabled()) + { + if(mModel->IsMarkupUnderlineSet()) + { + imageBuffer = ApplyUnderlineMarkupImageBuffer(imageBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, penX, penY); + } - imageBuffer = ApplyMarkupProcessorOnPixelBuffer(imageBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, penX, penY); + if(mModel->IsMarkupStrikethroughSet()) + { + imageBuffer = ApplyStrikethroughMarkupImageBuffer(imageBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, penX, penY); + } + } + } } // Create the final PixelData for the combined image buffer @@ -1490,20 +1499,6 @@ Devel::PixelBuffer Typesetter::ApplyStrikethroughMarkupImageBuffer(Devel::PixelB return topPixelBuffer; } -Devel::PixelBuffer Typesetter::ApplyMarkupProcessorOnPixelBuffer(Devel::PixelBuffer topPixelBuffer, const uint32_t bufferWidth, const uint32_t bufferHeight, const bool ignoreHorizontalAlignment, const Pixel::Format pixelFormat, const int32_t horizontalOffset, const int32_t 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)) { diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.h b/dali-toolkit/internal/text/rendering/text-typesetter.h index 3a71c31..296126e 100644 --- a/dali-toolkit/internal/text/rendering/text-typesetter.h +++ b/dali-toolkit/internal/text/rendering/text-typesetter.h @@ -147,21 +147,6 @@ private: Devel::PixelBuffer CreateImageBuffer(const uint32_t bufferWidth, const uint32_t bufferHeight, const Typesetter::Style style, const bool ignoreHorizontalAlignment, const Pixel::Format pixelFormat, const int32_t horizontalOffset, const int32_t verticalOffset, const TextAbstraction::GlyphIndex fromGlyphIndex, const TextAbstraction::GlyphIndex toGlyphIndex); /** - * @brief Apply behaviour of tags if the markup-processor is enabled. - * - * @param[in] topPixelBuffer The top layer buffer. - * @param[in] bufferWidth The width of the image buffer. - * @param[in] bufferHeight The height of the image buffer. - * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment, not ignored by default. - * @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). - * @param[in] horizontalOffset The horizontal offset to be added to the glyph's position. - * @param[in] verticalOffset The vertical offset to be added to the glyph's position. - * - * @return The image buffer with the markup. - */ - Devel::PixelBuffer ApplyMarkupProcessorOnPixelBuffer(Devel::PixelBuffer topPixelBuffer, const uint32_t bufferWidth, const uint32_t bufferHeight, const bool ignoreHorizontalAlignment, const Pixel::Format pixelFormat, const int32_t horizontalOffset, const int32_t verticalOffset); - - /** * @brief Apply markup underline tags. * * The properties on TextLabel override the behavior of Markup. diff --git a/dali-toolkit/internal/text/rendering/view-model.cpp b/dali-toolkit/internal/text/rendering/view-model.cpp index 9cfba93..0c4aeb3 100644 --- a/dali-toolkit/internal/text/rendering/view-model.cpp +++ b/dali-toolkit/internal/text/rendering/view-model.cpp @@ -245,6 +245,11 @@ bool ViewModel::IsUnderlineEnabled() const return mModel->IsUnderlineEnabled(); } +bool const ViewModel::IsMarkupUnderlineSet() const +{ + return mModel->IsMarkupUnderlineSet(); +} + float ViewModel::GetUnderlineHeight() const { return mModel->GetUnderlineHeight(); @@ -699,6 +704,11 @@ bool ViewModel::IsStrikethroughEnabled() const return mModel->IsStrikethroughEnabled(); } +bool const ViewModel::IsMarkupStrikethroughSet() const +{ + return mModel->IsMarkupStrikethroughSet(); +} + Length ViewModel::GetNumberOfStrikethroughRuns() const { return mModel->GetNumberOfStrikethroughRuns(); diff --git a/dali-toolkit/internal/text/rendering/view-model.h b/dali-toolkit/internal/text/rendering/view-model.h index c7b0b18..c127ebb 100644 --- a/dali-toolkit/internal/text/rendering/view-model.h +++ b/dali-toolkit/internal/text/rendering/view-model.h @@ -207,6 +207,11 @@ public: bool IsUnderlineEnabled() const override; /** + * @copydoc ModelInterface::IsMarkupUnderlineSet() + */ + bool const IsMarkupUnderlineSet() const override; + + /** * @copydoc ModelInterface::GetUnderlineHeight() */ float GetUnderlineHeight() const override; @@ -303,13 +308,27 @@ public: */ void ElideGlyphs(); + /** + * @copydoc ModelInterface::GetStrikethroughHeight() + */ float GetStrikethroughHeight() const override; + /** + * @copydoc ModelInterface::GetStrikethroughColor() + */ const Vector4& GetStrikethroughColor() const override; + /** + * @copydoc ModelInterface::IsStrikethroughEnabled() + */ bool IsStrikethroughEnabled() const override; /** + * @copydoc ModelInterface::IsMarkupStrikethroughSet() + */ + bool const IsMarkupStrikethroughSet() const override; + + /** * @copydoc ModelInterface::GetNumberOfStrikethroughRuns() */ Length GetNumberOfStrikethroughRuns() const override; diff --git a/dali-toolkit/internal/text/text-model-interface.h b/dali-toolkit/internal/text/text-model-interface.h index 0f2bd7b..0ccbb45 100644 --- a/dali-toolkit/internal/text/text-model-interface.h +++ b/dali-toolkit/internal/text/text-model-interface.h @@ -262,6 +262,13 @@ public: virtual bool IsUnderlineEnabled() const = 0; /** + * @brief checks if there is underline set using markup. + * + * @return boolean if there is underline set using markup. + */ + virtual bool const IsMarkupUnderlineSet() const = 0; + + /** * @brief Retrieves the underline height override * * @return Returns the override height for an underline, 0 indicates that adaptor will determine the height @@ -376,6 +383,13 @@ public: virtual bool IsStrikethroughEnabled() const = 0; /** + * @brief checks if there is strikethrough set using markup. + * + * @return boolean if there is strikethrough set using markup. + */ + virtual bool const IsMarkupStrikethroughSet() const = 0; + + /** * @brief Retrieves the strikethrough height override * * @return Returns the override height for a strikethrough, 0 indicates that adaptor will determine the height diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index 0ac67ca..ba6dbcf 100644 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -187,6 +187,11 @@ bool Model::IsUnderlineEnabled() const return mVisualModel->IsUnderlineEnabled(); } +bool const Model::IsMarkupUnderlineSet() const +{ + return (mVisualModel->mUnderlineRuns.Count() > 0u); +} + float Model::GetUnderlineHeight() const { return mVisualModel->GetUnderlineHeight(); @@ -266,6 +271,11 @@ bool Model::IsStrikethroughEnabled() const return mVisualModel->IsStrikethroughEnabled(); } +bool const Model::IsMarkupStrikethroughSet() const +{ + return (mVisualModel->mStrikethroughRuns.Count() > 0u); +} + float Model::GetStrikethroughHeight() const { return mVisualModel->GetStrikethroughHeight(); diff --git a/dali-toolkit/internal/text/text-model.h b/dali-toolkit/internal/text/text-model.h index 416df17..a3a42a2 100644 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -205,6 +205,11 @@ public: bool IsUnderlineEnabled() const override; /** + * @copydoc ModelInterface::IsMarkupUnderlineSet() + */ + bool const IsMarkupUnderlineSet() const override; + + /** * @copydoc ModelInterface::GetUnderlineHeight() */ float GetUnderlineHeight() const override; @@ -274,11 +279,26 @@ public: */ Length GetHyphensCount() const override; + /** + * @copydoc ModelInterface::GetStrikethroughHeight() + */ float GetStrikethroughHeight() const override; + /** + * @copydoc ModelInterface::GetStrikethroughColor() + */ const Vector4& GetStrikethroughColor() const override; + /** + * @copydoc ModelInterface::IsStrikethroughEnabled() + */ bool IsStrikethroughEnabled() const override; + + /** + * @copydoc ModelInterface::IsMarkupStrikethroughSet() + */ + bool const IsMarkupStrikethroughSet() const override; + /** * @copydoc ModelInterface::GetCharacterSpacing() */ diff --git a/dali-toolkit/internal/text/text-view-interface.h b/dali-toolkit/internal/text/text-view-interface.h index 98b420d..2fcf548 100644 --- a/dali-toolkit/internal/text/text-view-interface.h +++ b/dali-toolkit/internal/text/text-view-interface.h @@ -175,6 +175,13 @@ public: virtual bool IsUnderlineEnabled() const = 0; /** + * @brief checks if there is underline set using markup. + * + * @return boolean if there is underline set using markup. + */ + virtual bool const IsMarkupUnderlineSet() const = 0; + + /** * @brief Returns the hyphens glyph info. * * @return hyphens glyph info. @@ -311,6 +318,13 @@ public: virtual bool IsStrikethroughEnabled() const = 0; /** + * @brief checks if there is strikethrough set using markup. + * + * @return boolean if there is strikethrough set using markup. + */ + virtual bool const IsMarkupStrikethroughSet() const = 0; + + /** * @brief Retrieves the strikethrough height override * * @return Returns the override height for a strikethrough, 0 indicates that adaptor will determine the height diff --git a/dali-toolkit/internal/text/text-view.cpp b/dali-toolkit/internal/text/text-view.cpp index 0be5ac6..0b81484 100644 --- a/dali-toolkit/internal/text/text-view.cpp +++ b/dali-toolkit/internal/text/text-view.cpp @@ -670,6 +670,11 @@ bool View::IsUnderlineEnabled() const return false; } +bool const View::IsMarkupUnderlineSet() const +{ + return (GetNumberOfUnderlineRuns() > 0u); +} + const GlyphInfo* View::GetHyphens() const { if(mImpl->mVisualModel) @@ -865,6 +870,11 @@ bool View::IsStrikethroughEnabled() const return (mImpl->mVisualModel) ? mImpl->mVisualModel->IsStrikethroughEnabled() : false; } +bool const View::IsMarkupStrikethroughSet() const +{ + return (GetNumberOfStrikethroughRuns() > 0u); +} + float View::GetStrikethroughHeight() const { return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetStrikethroughHeight() : 0.0f; diff --git a/dali-toolkit/internal/text/text-view.h b/dali-toolkit/internal/text/text-view.h index 93542cc..7cccf19 100644 --- a/dali-toolkit/internal/text/text-view.h +++ b/dali-toolkit/internal/text/text-view.h @@ -135,6 +135,11 @@ public: bool IsUnderlineEnabled() const override; /** + * @copydoc Dali::Toolkit::Text::ViewInterface::IsMarkupUnderlineSet() + */ + bool const IsMarkupUnderlineSet() const; + + /** * @copydoc Dali::Toolkit::Text::ViewInterface::GetHyphens() */ const GlyphInfo* GetHyphens() const override; @@ -232,6 +237,11 @@ public: bool IsStrikethroughEnabled() const override; /** + * @copydoc Dali::Toolkit::Text::ViewInterface::IsMarkupStrikethroughSet() + */ + bool const IsMarkupStrikethroughSet() const; + + /** * @copydoc Dali::Toolkit::Text::ViewInterface::GetStrikethroughHeight() */ float GetStrikethroughHeight() const override; diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 2106745..aa205cf 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -562,13 +562,14 @@ void TextVisual::UpdateRenderer() shadowEnabled = true; } - const bool underlineEnabled = mController->GetTextModel()->IsUnderlineEnabled(); - const bool outlineEnabled = (mController->GetTextModel()->GetOutlineWidth() > Math::MACHINE_EPSILON_1); - const bool backgroundEnabled = mController->GetTextModel()->IsBackgroundEnabled(); - const bool markupProcessorEnabled = mController->IsMarkupProcessorEnabled(); - const bool strikethroughEnabled = mController->GetTextModel()->IsStrikethroughEnabled(); - - const bool styleEnabled = (shadowEnabled || underlineEnabled || outlineEnabled || backgroundEnabled || markupProcessorEnabled || strikethroughEnabled); + const bool outlineEnabled = (mController->GetTextModel()->GetOutlineWidth() > Math::MACHINE_EPSILON_1); + const bool backgroundEnabled = mController->GetTextModel()->IsBackgroundEnabled(); + const bool markupProcessorEnabled = mController->IsMarkupProcessorEnabled(); + const bool markupUnderlineEnabled = markupProcessorEnabled && mController->GetTextModel()->IsMarkupUnderlineSet(); + const bool markupStrikethroughEnabled = markupProcessorEnabled && mController->GetTextModel()->IsMarkupStrikethroughSet(); + const bool underlineEnabled = mController->GetTextModel()->IsUnderlineEnabled() || markupUnderlineEnabled; + const bool strikethroughEnabled = mController->GetTextModel()->IsStrikethroughEnabled() || markupStrikethroughEnabled; + const bool styleEnabled = (shadowEnabled || outlineEnabled || backgroundEnabled || markupProcessorEnabled); const bool isOverlayStyle = underlineEnabled || strikethroughEnabled; AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle); -- 2.7.4