sd/source/ui/inc/SlideshowLayerRenderer.hxx | 3 sd/source/ui/tools/SlideshowLayerRenderer.cxx | 103 +++++++++++++------------- 2 files changed, 55 insertions(+), 51 deletions(-)
New commits: commit 8bf2e3f60fd6efff435137a798d25c58168bd69c Author: Marco Cecchetti <marco.cecche...@collabora.com> AuthorDate: Mon Dec 16 19:20:10 2024 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Dec 17 13:38:20 2024 +0100 lok: slideshow: effect for paragraph with auto font color can be wrong Color animations applied to a paragraph with font color set to auto didn't work. Here we implement a new way for retrieving the real paragraph font color. Change-Id: I72540964a6eddb75188c21f22b110a7e5007bcac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178626 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sd/source/ui/inc/SlideshowLayerRenderer.hxx b/sd/source/ui/inc/SlideshowLayerRenderer.hxx index 21962d1ee5b4..0804dd78edc9 100644 --- a/sd/source/ui/inc/SlideshowLayerRenderer.hxx +++ b/sd/source/ui/inc/SlideshowLayerRenderer.hxx @@ -28,6 +28,7 @@ #include <frozen/bits/defines.h> #include <frozen/bits/elsa_std.h> #include <frozen/unordered_set.h> +#include <tools/color.hxx> class SdrPage; class SdrModel; @@ -97,6 +98,8 @@ struct RenderPass bool mbPlaceholder = false; OUString maFieldType; + Color maFontColor = COL_AUTO; + bool isEmpty() { return maObjectsAndParagraphs.empty(); } }; diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx b/sd/source/ui/tools/SlideshowLayerRenderer.cxx index e123b2af6841..f447aa84f2c3 100644 --- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx +++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx @@ -44,6 +44,7 @@ #include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx> #include <drawinglayer/primitive2d/Tools.hxx> #include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx> +#include <drawinglayer/primitive2d/textprimitive2d.hxx> #include <drawinglayer/tools/primitive2dxmldump.hxx> @@ -257,11 +258,45 @@ findTextBlock(drawinglayer::primitive2d::Primitive2DContainer const& rContainer, return nullptr; } +/// Retrieve paragraph font color to be used in the json message attached to the animated layer +Color getParagraphFontColor( + const drawinglayer::primitive2d::TextHierarchyParagraphPrimitive2D& pParagraphPrimitive2d) +{ + auto& rLinesContainer = const_cast<drawinglayer::primitive2d::Primitive2DContainer&>( + pParagraphPrimitive2d.getChildren()); + for (auto& pLine : rLinesContainer) + { + if (pLine->getPrimitive2DID() == PRIMITIVE2D_ID_TEXTHIERARCHYLINEPRIMITIVE2D) + { + auto& rLinePrimitive2d + = static_cast<drawinglayer::primitive2d::TextHierarchyLinePrimitive2D&>(*pLine); + auto& rPortionsContainer = const_cast<drawinglayer::primitive2d::Primitive2DContainer&>( + rLinePrimitive2d.getChildren()); + for (auto& pPortion : rPortionsContainer) + { + if (pPortion->getPrimitive2DID() == PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D) + { + auto& rPortionPrimitive2d + = static_cast<drawinglayer::primitive2d::TextSimplePortionPrimitive2D&>( + *pPortion); + Color aColor(rPortionPrimitive2d.getFontColor()); + SAL_INFO("sd", "SlideshowLayerRenderer: modifyParagraphs: " + "text: " + << rPortionPrimitive2d.getText() + << ", color: " << aColor.AsRGBHEXString()); + return aColor; + } + } + } + } + return COL_AUTO; +} + /// show/hide paragraphs in the container void modifyParagraphs( drawinglayer::primitive2d::Primitive2DContainer& rContainer, drawinglayer::geometry::ViewInformation2D const& rViewInformation2D, - std::deque<sal_Int32> const& rPreserveIndices, bool bRenderObject, + std::deque<sal_Int32> const& rPreserveIndices, bool bRenderObject, Color& rFontColor, std::vector<drawinglayer::primitive2d::Primitive2DReference>& rPrimitivesToUnhide) { auto* pTextBlock = findTextBlock(rContainer, rViewInformation2D); @@ -279,6 +314,8 @@ void modifyParagraphs( = static_cast<drawinglayer::primitive2d::TextHierarchyParagraphPrimitive2D&>( *pPrimitive); + rFontColor = getParagraphFontColor(pParagraphPrimitive2d); + // find the index auto aIterator = std::find(rPreserveIndices.begin(), rPreserveIndices.end(), nIndex); @@ -532,10 +569,10 @@ class RenderPassObjectRedirector : public sdr::contact::ViewObjectContactRedirec { protected: RenderState& mrRenderState; - RenderPass const& mrRenderPass; + RenderPass& mrRenderPass; public: - RenderPassObjectRedirector(RenderState& rRenderState, RenderPass const& rRenderPass) + RenderPassObjectRedirector(RenderState& rRenderState, RenderPass& rRenderPass) : mrRenderState(rRenderState) , mrRenderPass(rRenderPass) { @@ -572,7 +609,7 @@ public: = static_cast<drawinglayer::primitive2d::Primitive2DContainer&>(rVisitor); modifyParagraphs(rContainer, rViewInformation2D, rParagraphs, - mrRenderPass.mbRenderObjectBackground, + mrRenderPass.mbRenderObjectBackground, mrRenderPass.maFontColor, mrRenderState.maPrimitivesToUnhide); } } @@ -809,51 +846,9 @@ void writeBoundingBox(::tools::JsonWriter& aJsonWriter, SdrObject* pObject) aJsonWriter.put("height", aRect.GetHeight()); } -uno::Reference<text::XTextRange> -getParagraphFromShape(int nPara, uno::Reference<beans::XPropertySet> const& xShape) -{ - uno::Reference<text::XText> xText - = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY_THROW)->getText(); - if (!xText.is()) - return {}; - - uno::Reference<container::XEnumerationAccess> paraEnumAccess(xText, uno::UNO_QUERY); - if (!paraEnumAccess.is()) - return {}; - uno::Reference<container::XEnumeration> paraEnum(paraEnumAccess->createEnumeration()); - if (!paraEnum.is()) - return {}; - - for (int i = 0; i < nPara; ++i) - paraEnum->nextElement(); - - uno::Reference<text::XTextRange> xParagraph(paraEnum->nextElement(), uno::UNO_QUERY_THROW); - - return xParagraph; -} - -void writeFontColor(::tools::JsonWriter& aJsonWriter, SdrObject* pObject, sal_Int32 nParagraph) -{ - uno::Reference<drawing::XShape> xShape = GetXShapeForSdrObject(pObject); - uno::Reference<beans::XPropertySet> xShapePropSet(xShape, uno::UNO_QUERY_THROW); - if (!xShapePropSet.is()) - return; - - uno::Reference<text::XTextRange> xParagraph = getParagraphFromShape(nParagraph, xShapePropSet); - if (!xParagraph.is()) - return; - - uno::Reference<beans::XPropertySet> xPropSet(xParagraph->getStart(), uno::UNO_QUERY_THROW); - if (!xPropSet) - return; - - Color aCharColor; - xPropSet->getPropertyValue("CharColor") >>= aCharColor; - aJsonWriter.put("fontColor", "#" + aCharColor.AsRGBHEXString()); -} - void writeAnimated(::tools::JsonWriter& aJsonWriter, AnimationLayerInfo const& rLayerInfo, - SdrObject* pObject, sal_Int32 nParagraph = -1) + SdrObject* pObject, sal_Int32 nParagraph = -1, + const Color& rFontColor = COL_AUTO) { aJsonWriter.put("type", "animated"); { @@ -892,7 +887,12 @@ void writeAnimated(::tools::JsonWriter& aJsonWriter, AnimationLayerInfo const& r } else { - writeFontColor(aJsonWriter, pObject, nParagraph); + if (rFontColor == COL_AUTO) + { + SAL_WARN("sd", "SlideshowLayerRenderer: on writing JSON info for an animated " + "paragraph layer: font color is set to auto."); + } + aJsonWriter.put("fontColor", "#" + rFontColor.AsRGBHEXString()); } } } @@ -933,7 +933,8 @@ void SlideshowLayerRenderer::writeJSON(OString& rJsonMsg, RenderPass const& rRen auto aParagraphInfoIterator = rInfo.maParagraphInfos.find(nParagraph); if (aParagraphInfoIterator != rInfo.maParagraphInfos.end()) { - writeAnimated(aJsonWriter, aParagraphInfoIterator->second, pObject, nParagraph); + writeAnimated(aJsonWriter, aParagraphInfoIterator->second, pObject, nParagraph, + rRenderPass.maFontColor); } } else if (rInfo.moObjectInfo) @@ -1017,7 +1018,7 @@ bool SlideshowLayerRenderer::render(unsigned char* pBuffer, bool& bIsBitmapLayer cleanup(); return false; } - auto const& rRenderPass = maRenderState.maRenderPasses.front(); + auto& rRenderPass = maRenderState.maRenderPasses.front(); maRenderState.meStage = rRenderPass.meStage; bIsBitmapLayer = !rRenderPass.mbPlaceholder;