slideshow/source/engine/slide/slideimpl.cxx | 162 ++++++++++++++++++++-------- 1 file changed, 117 insertions(+), 45 deletions(-)
New commits: commit 6481ab40e4dc1729d5d04c8226541efc3b9974cc Author: Marco Cecchetti <marco.cecche...@collabora.com> AuthorDate: Sun Jul 7 22:59:07 2024 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Jul 16 12:59:18 2024 +0200 lok: sd: slideshow render improvements Changed the slide layer message layout. Sometime some text field layer was missing. Try to skip empty layers. Change-Id: I52f00e637da7ab705a1fcb52a70af88cf619c8f7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170156 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/slideshow/source/engine/slide/slideimpl.cxx b/slideshow/source/engine/slide/slideimpl.cxx index ea943033a8c3..e8df227e7fa2 100644 --- a/slideshow/source/engine/slide/slideimpl.cxx +++ b/slideshow/source/engine/slide/slideimpl.cxx @@ -140,6 +140,13 @@ OUString getPlaceholderType(std::u16string_view sShapeType) return aType; } +void appendImageInfoPlaceholder(tools::JsonWriter& rJsonWriter) +{ + ::tools::ScopedJsonWriterNode aContentNode = rJsonWriter.startNode("content"); + rJsonWriter.put("type", "%IMAGETYPE%"); + rJsonWriter.put("checksum", "%IMAGECHECKSUM%"); +} + class LOKSlideRenderer { public: @@ -218,6 +225,9 @@ private: bool mbMasterPageRenderingDone; bool mbDrawPageRenderingDone; bool mbSlideRenderingDone; + bool mbIsPageNumberVisible; + bool mbIsDateTimeVisible; + bool mbIsFooterVisible; ShapeSharedPtr mpDPLastAnimatedShape; OUString msLastPlaceholder; @@ -249,6 +259,9 @@ LOKSlideRenderer::LOKSlideRenderer(const Size& rViewSize, const Size& rSlideSize mbMasterPageRenderingDone(false), mbDrawPageRenderingDone(false), mbSlideRenderingDone(false), + mbIsPageNumberVisible(true), + mbIsDateTimeVisible(true), + mbIsFooterVisible(true), mbIsBitmapLayer(false) { uno::Reference< drawing::XMasterPageTarget > xMasterPageTarget( mxDrawPage, uno::UNO_QUERY ); @@ -269,6 +282,34 @@ LOKSlideRenderer::LOKSlideRenderer(const Size& rViewSize, const Size& rSlideSize xPropSet->getPropertyValue("IsBackgroundObjectsVisible") >>= bBackgroundObjectsVisibility; mbTextFieldsRenderingDone = mbMasterPageRenderingDone = !bBackgroundObjectsVisibility; + // try to skip empty layer + if (bBackgroundObjectsVisibility) + { + xPropSet->getPropertyValue("IsPageNumberVisible") >>= mbIsPageNumberVisible; + xPropSet->getPropertyValue("IsDateTimeVisible") >>= mbIsDateTimeVisible; + xPropSet->getPropertyValue("IsFooterVisible") >>= mbIsFooterVisible; + if (mbIsDateTimeVisible) + { + bool bDateTimeFixed = true; // default: fixed + xPropSet->getPropertyValue("IsDateTimeFixed") >>= bDateTimeFixed; + if (bDateTimeFixed) + { + OUString sDateTimeText; + xPropSet->getPropertyValue("DateTimeText") >>= sDateTimeText; + mbIsDateTimeVisible = !sDateTimeText.isEmpty(); + } + } + if (mbIsFooterVisible) + { + OUString sFooterText; + xPropSet->getPropertyValue("FooterText") >>= sFooterText; + mbIsFooterVisible = !sFooterText.isEmpty(); + } + + mbTextFieldsRenderingDone = + !mbIsPageNumberVisible && !mbIsDateTimeVisible && !mbIsFooterVisible; + } + if (!mbTextFieldsRenderingDone) { mpTFShapesFunctor @@ -286,11 +327,22 @@ LOKSlideRenderer::LOKSlideRenderer(const Size& rViewSize, const Size& rSlideSize mpMPShapesFunctor->setMasterPageObjectsOnly(true); } - mpShapesFunctor = std::make_shared<ShapeImporter>(mxDrawPage, mxDrawPage, mxDrawPagesSupplier, - mrContext, 0, /* shape num starts at 0 */ - false); + uno::Reference<drawing::XShapes> const xShapes(mxDrawPage, uno::UNO_QUERY_THROW); + if (xShapes.is()) + { + mbDrawPageRenderingDone = xShapes->getCount() == 0; + } + + if (!mbDrawPageRenderingDone) + { + mpShapesFunctor + = std::make_shared<ShapeImporter>(mxDrawPage, mxDrawPage, mxDrawPagesSupplier, + mrContext, 0, /* shape num starts at 0 */ + false); + } } - collectAnimatedShapes(); + if (!mbDrawPageRenderingDone) + collectAnimatedShapes(); } void LOKSlideRenderer::renderBackground(unsigned char* pBuffer) @@ -348,8 +400,8 @@ void LOKSlideRenderer::renderBackgroundImpl(VirtualDevice& rDevice) tools::JsonWriter aJsonWriter; aJsonWriter.put("group", "Background"); - std::string sLayerId = GetInterfaceHash(mxDrawPage) + ".0"; - aJsonWriter.put("id", sLayerId); + std::string sSlideHash = GetInterfaceHash(mxDrawPage); + aJsonWriter.put("slideHash", sSlideHash); ShapeSharedPtr const& rBGShape(mpMPShapesFunctor->importBackgroundShape()); mpLayerManager->addShape(rBGShape); @@ -364,7 +416,7 @@ void LOKSlideRenderer::renderBackgroundImpl(VirtualDevice& rDevice) // json mbIsBitmapLayer = true; aJsonWriter.put("type", "bitmap"); - aJsonWriter.put("checksum", std::to_string(nChecksum)); + appendImageInfoPlaceholder(aJsonWriter); msLastJsonMessage = aJsonWriter.finishAndGetAsOString(); maJsonMsgList.push_back(msLastJsonMessage); @@ -378,21 +430,19 @@ void LOKSlideRenderer::renderBackgroundImpl(VirtualDevice& rDevice) void LOKSlideRenderer::renderMasterPageImpl(VirtualDevice& rDevice) { - if (mpMPShapesFunctor->isImportDone()) - mbMasterPageRenderingDone = true; - - if (mbMasterPageRenderingDone) - return; - - tools::JsonWriter aJsonWriter; - aJsonWriter.put("group", "MasterPage"); - std::string sLayerId = GetInterfaceHash(mxMasterPage) + "." + std::to_string(mnMPLayerIndex); - aJsonWriter.put("id", sLayerId); - if (!msLastPlaceholder.isEmpty()) { + tools::JsonWriter aJsonWriter; + aJsonWriter.put("group", "MasterPage"); + aJsonWriter.put("slideHash", GetInterfaceHash(mxDrawPage)); + aJsonWriter.put("index", mnMPLayerIndex); + aJsonWriter.put("type", "placeholder"); - aJsonWriter.put("placeholderId", msLastPlaceholder); + { + ::tools::ScopedJsonWriterNode aContentNode = aJsonWriter.startNode("content"); + aJsonWriter.put("type", msLastPlaceholder); + } + msLastPlaceholder = ""; msLastJsonMessage = aJsonWriter.finishAndGetAsOString(); maJsonMsgList.push_back(msLastJsonMessage); @@ -400,6 +450,17 @@ void LOKSlideRenderer::renderMasterPageImpl(VirtualDevice& rDevice) return; } + if (mpMPShapesFunctor->isImportDone()) + mbMasterPageRenderingDone = true; + + if (mbMasterPageRenderingDone) + return; + + tools::JsonWriter aJsonWriter; + aJsonWriter.put("group", "MasterPage"); + aJsonWriter.put("slideHash", GetInterfaceHash(mxDrawPage)); + aJsonWriter.put("index", mnMPLayerIndex); + bool bDoRendering = false; while (!mpMPShapesFunctor->isImportDone()) { @@ -427,7 +488,10 @@ void LOKSlideRenderer::renderMasterPageImpl(VirtualDevice& rDevice) else { aJsonWriter.put("type", "placeholder"); - aJsonWriter.put("placeholderId", sPlaceholderType); + { + ::tools::ScopedJsonWriterNode aContentNode = aJsonWriter.startNode("content"); + aJsonWriter.put("type", sPlaceholderType); + } } bDoRendering = false; msLastJsonMessage = aJsonWriter.finishAndGetAsOString(); @@ -462,6 +526,11 @@ void LOKSlideRenderer::renderTextFieldsImpl(VirtualDevice& rDevice) OUString sPlaceholderType = getPlaceholderType(sShapeType); if (!sPlaceholderType.isEmpty()) { + if ((!mbIsPageNumberVisible && sPlaceholderType == "SlideNumber") || + (!mbIsDateTimeVisible && sPlaceholderType == "DateTime") || + (!mbIsFooterVisible && sPlaceholderType == "Footer")) + continue; + mpLayerManager->addShape(rShape); // render and collect bitmap @@ -469,16 +538,17 @@ void LOKSlideRenderer::renderTextFieldsImpl(VirtualDevice& rDevice) BitmapEx aBitmapEx(rDevice.GetBitmapEx(Point(0, 0), rDevice.GetOutputSizePixel())); BitmapChecksum nChecksum = aBitmapEx.GetChecksum(); maBitmapMap[nChecksum] = aBitmapEx; + mbIsBitmapLayer = true; // json - OUString sLayerId = OUString::fromUtf8(GetInterfaceHash(mxMasterPage)) + "." + sPlaceholderType; tools::JsonWriter aJsonWriter; aJsonWriter.put("group", "TextFields"); - aJsonWriter.put("id", sLayerId); - mbIsBitmapLayer = true; - aJsonWriter.put("type", "bitmap"); - aJsonWriter.put("checksum", std::to_string(nChecksum)); - + aJsonWriter.put("slideHash", GetInterfaceHash(mxDrawPage)); + { + ::tools::ScopedJsonWriterNode aContentNode = aJsonWriter.startNode("content"); + aJsonWriter.put("type", sPlaceholderType); + appendImageInfoPlaceholder(aJsonWriter); + } msLastJsonMessage = aJsonWriter.finishAndGetAsOString(); maJsonMsgList.push_back(msLastJsonMessage); @@ -503,7 +573,7 @@ void LOKSlideRenderer::renderLayerImpl(VirtualDevice& rDevice, tools::JsonWriter // json mbIsBitmapLayer = true; rJsonWriter.put("type", "bitmap"); - rJsonWriter.put("checksum", std::to_string(nChecksum)); + appendImageInfoPlaceholder(rJsonWriter); // clean up rDevice.Erase(); @@ -512,19 +582,13 @@ void LOKSlideRenderer::renderLayerImpl(VirtualDevice& rDevice, tools::JsonWriter void LOKSlideRenderer::renderDrawPageImpl(VirtualDevice& rDevice) { - if (mpShapesFunctor->isImportDone()) - mbDrawPageRenderingDone = true; - - if (mbDrawPageRenderingDone) - return; - - tools::JsonWriter aJsonWriter; - aJsonWriter.put("group", "DrawPage"); - std::string sLayerId = GetInterfaceHash(mxDrawPage) + "." + std::to_string(mnDPLayerIndex); - aJsonWriter.put("id", sLayerId); - if (mpDPLastAnimatedShape) { + tools::JsonWriter aJsonWriter; + aJsonWriter.put("group", "DrawPage"); + aJsonWriter.put("slideHash", GetInterfaceHash(mxDrawPage)); + aJsonWriter.put("index", mnDPLayerIndex); + renderAnimatedShapeImpl(rDevice, mpDPLastAnimatedShape, aJsonWriter); mpDPLastAnimatedShape.reset(); msLastJsonMessage = aJsonWriter.finishAndGetAsOString(); @@ -533,6 +597,17 @@ void LOKSlideRenderer::renderDrawPageImpl(VirtualDevice& rDevice) return; } + if (mpShapesFunctor->isImportDone()) + mbDrawPageRenderingDone = true; + + if (mbDrawPageRenderingDone) + return; + + tools::JsonWriter aJsonWriter; + aJsonWriter.put("group", "DrawPage"); + aJsonWriter.put("slideHash", GetInterfaceHash(mxDrawPage)); + aJsonWriter.put("index", mnDPLayerIndex); + bool bDoRendering = false; while (!mpShapesFunctor->isImportDone()) { @@ -581,17 +656,14 @@ void LOKSlideRenderer::renderAnimatedShapeImpl(VirtualDevice& rDevice, { rJsonWriter.put("type", "animated"); + ::tools::ScopedJsonWriterNode aContentNode = rJsonWriter.startNode("content"); std::string sShapeId = GetInterfaceHash(pShape->getXShape()); - rJsonWriter.put("shapeHash", sShapeId); + rJsonWriter.put("hash", sShapeId); bool bIsInitVisible = maAnimatedShapeVisibilityMap.at(sShapeId); rJsonWriter.put("initVisible", bIsInitVisible); - tools::ScopedJsonWriterNode aData = rJsonWriter.startNode("data"); - if (bIsInitVisible) - { - mpLayerManager->addShape(pShape); - renderLayerImpl(rDevice, rJsonWriter); - } + mpLayerManager->addShape(pShape); + renderLayerImpl(rDevice, rJsonWriter); } void LOKSlideRenderer::renderImpl(LayerGroupType eLayersSet, unsigned char* pBuffer)