summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-08-19 20:51:18 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-11-19 12:54:55 +0100
commit540ac6933be3ffc7585631aea12c86cfe326f462 (patch)
tree98d8652693cf00d2601cd99f485f49ccceef1afc
parent10d6a5d62ea8fbeb390714bb8e765664f8613556 (diff)
intruduce RenderContext, RenderOptions to remove code duplication
To remove code duplication when rendering main and master slide, it is needed to put them into common code, so add RenderContext and RenderOptions classes to put the common code into those. Change-Id: Icf4039f85e0aa5bf4d43e6fe5efb725c90504173 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176762 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sd/source/ui/inc/SlideshowLayerRenderer.hxx8
-rw-r--r--sd/source/ui/tools/SlideshowLayerRenderer.cxx150
2 files changed, 80 insertions, 78 deletions
diff --git a/sd/source/ui/inc/SlideshowLayerRenderer.hxx b/sd/source/ui/inc/SlideshowLayerRenderer.hxx
index 33c2ca69d502..2f51c6e39b76 100644
--- a/sd/source/ui/inc/SlideshowLayerRenderer.hxx
+++ b/sd/source/ui/inc/SlideshowLayerRenderer.hxx
@@ -21,6 +21,9 @@ class Size;
namespace sd
{
+struct RenderContext;
+struct RenderOptions;
+
enum class SlideRenderStage
{
Master,
@@ -31,11 +34,14 @@ class SD_DLLPUBLIC SlideshowLayerRenderer
{
SdrPage& mrPage;
SdrModel& mrModel;
-
Size maSlideSize;
std::deque<SlideRenderStage> maRenderStages;
+ void cleanupRendering(RenderContext& rRenderContext);
+ void setupRendering(unsigned char* pBuffer, RenderContext& rRenderContext);
+ void createViewAndDraw(RenderContext& rRenderContext, RenderOptions const& rRenderOptions);
+
public:
SlideshowLayerRenderer(SdrPage& rPage);
Size calculateAndSetSizePixel(Size const& rDesiredSizePixel);
diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx b/sd/source/ui/tools/SlideshowLayerRenderer.cxx
index ec238d3a139f..486823b0aa9c 100644
--- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx
+++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx
@@ -20,24 +20,70 @@
#include <vcl/virdev.hxx>
#include <tools/helpers.hxx>
#include <tools/json_writer.hxx>
+#include <editeng/editeng.hxx>
namespace sd
{
-namespace
-{
-struct RedirectorOptions
+struct RenderOptions
{
+ bool mbIncludeBackground = true;
bool mbSkipMainPageObjects = false;
bool mbSkipMasterPageObjects = false;
};
+struct RenderContext
+{
+ SdrModel& mrModel;
+ SdrPage& mrPage;
+
+ EEControlBits mnSavedControlBits;
+ ScopedVclPtrInstance<VirtualDevice> maVirtualDevice;
+
+ RenderContext(unsigned char* pBuffer, SdrModel& rModel, SdrPage& rPage, Size const& rSlideSize)
+ : mrModel(rModel)
+ , mrPage(rPage)
+ , maVirtualDevice(DeviceFormat::WITHOUT_ALPHA)
+ {
+ // Turn of spelling
+ SdrOutliner& rOutliner = mrModel.GetDrawOutliner();
+ mnSavedControlBits = rOutliner.GetControlWord();
+ rOutliner.SetControlWord(mnSavedControlBits & ~EEControlBits::ONLINESPELLING);
+
+ maVirtualDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+
+ maVirtualDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(rSlideSize, Fraction(1.0),
+ Point(), pBuffer);
+ Size aPageSize(mrPage.GetSize());
+
+ MapMode aMapMode(MapUnit::Map100thMM);
+ const Fraction aFracX(rSlideSize.Width(),
+ maVirtualDevice->LogicToPixel(aPageSize, aMapMode).Width());
+ aMapMode.SetScaleX(aFracX);
+
+ const Fraction aFracY(rSlideSize.Height(),
+ maVirtualDevice->LogicToPixel(aPageSize, aMapMode).Height());
+ aMapMode.SetScaleY(aFracY);
+
+ maVirtualDevice->SetMapMode(aMapMode);
+ }
+
+ ~RenderContext()
+ {
+ // Restore spelling
+ SdrOutliner& rOutliner = mrModel.GetDrawOutliner();
+ rOutliner.SetControlWord(mnSavedControlBits);
+ }
+};
+
+namespace
+{
class ObjectRedirector : public sdr::contact::ViewObjectContactRedirector
{
protected:
- RedirectorOptions maOptions;
+ RenderOptions maOptions;
public:
- ObjectRedirector(RedirectorOptions const& rOptions)
+ ObjectRedirector(RenderOptions const& rOptions)
: maOptions(rOptions)
{
}
@@ -115,34 +161,10 @@ Size SlideshowLayerRenderer::calculateAndSetSizePixel(Size const& rDesiredSizePi
return maSlideSize;
}
-bool SlideshowLayerRenderer::renderMaster(unsigned char* pBuffer, OString& rJsonMsg)
+void SlideshowLayerRenderer::createViewAndDraw(RenderContext& rRenderContext,
+ RenderOptions const& rRenderOptions)
{
- SdrOutliner& rOutliner = mrModel.GetDrawOutliner();
- const EEControlBits nOldControlBits(rOutliner.GetControlWord());
- EEControlBits nControlBits = nOldControlBits & ~EEControlBits::ONLINESPELLING;
- rOutliner.SetControlWord(nControlBits);
-
- ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::WITHOUT_ALPHA);
- pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
-
- pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(maSlideSize, Fraction(1.0), Point(),
- pBuffer);
-
- Point aPoint;
- Size aPageSize(mrPage.GetSize());
-
- MapMode aMapMode(MapUnit::Map100thMM);
- const Fraction aFracX(maSlideSize.Width(), pDevice->LogicToPixel(aPageSize, aMapMode).Width());
- aMapMode.SetScaleX(aFracX);
-
- const Fraction aFracY(maSlideSize.Height(),
- pDevice->LogicToPixel(aPageSize, aMapMode).Height());
- aMapMode.SetScaleY(aFracY);
-
- pDevice->SetMapMode(aMapMode);
-
- SdrView aView(mrModel, pDevice);
-
+ SdrView aView(mrModel, rRenderContext.maVirtualDevice);
aView.SetPageVisible(false);
aView.SetPageShadowVisible(false);
aView.SetPageBorderVisible(false);
@@ -150,12 +172,24 @@ bool SlideshowLayerRenderer::renderMaster(unsigned char* pBuffer, OString& rJson
aView.SetGridVisible(false);
aView.SetHlplVisible(false);
aView.SetGlueVisible(false);
- aView.setHideBackground(false);
+ aView.setHideBackground(!rRenderOptions.mbIncludeBackground);
aView.ShowSdrPage(&mrPage);
+ Size aPageSize(mrPage.GetSize());
+ Point aPoint;
+
vcl::Region aRegion(::tools::Rectangle(aPoint, aPageSize));
- ObjectRedirector aRedirector({ .mbSkipMainPageObjects = true });
- aView.CompleteRedraw(pDevice, aRegion, &aRedirector);
+ ObjectRedirector aRedirector(rRenderOptions);
+ aView.CompleteRedraw(rRenderContext.maVirtualDevice, aRegion, &aRedirector);
+}
+
+bool SlideshowLayerRenderer::renderMaster(unsigned char* pBuffer, OString& rJsonMsg)
+{
+ RenderOptions aRenderOptions;
+ aRenderOptions.mbSkipMainPageObjects = true;
+
+ RenderContext aRenderContext(pBuffer, mrModel, mrPage, maSlideSize);
+ createViewAndDraw(aRenderContext, aRenderOptions);
::tools::JsonWriter aJsonWriter;
aJsonWriter.put("group", "MasterPage");
@@ -169,52 +203,16 @@ bool SlideshowLayerRenderer::renderMaster(unsigned char* pBuffer, OString& rJson
}
rJsonMsg = aJsonWriter.finishAndGetAsOString();
- rOutliner.SetControlWord(nOldControlBits);
-
return true;
}
bool SlideshowLayerRenderer::renderSlide(unsigned char* pBuffer, OString& rJsonMsg)
{
- SdrOutliner& rOutliner = mrModel.GetDrawOutliner();
- const EEControlBits nOldControlBits(rOutliner.GetControlWord());
- EEControlBits nControlBits = nOldControlBits & ~EEControlBits::ONLINESPELLING;
- rOutliner.SetControlWord(nControlBits);
-
- ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::WITHOUT_ALPHA);
- pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
-
- pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(maSlideSize, Fraction(1.0), Point(),
- pBuffer);
-
- Point aPoint;
- Size aPageSize(mrPage.GetSize());
-
- MapMode aMapMode(MapUnit::Map100thMM);
- const Fraction aFracX(maSlideSize.Width(), pDevice->LogicToPixel(aPageSize, aMapMode).Width());
- aMapMode.SetScaleX(aFracX);
+ RenderOptions aRenderOptions;
+ aRenderOptions.mbSkipMasterPageObjects = true;
- const Fraction aFracY(maSlideSize.Height(),
- pDevice->LogicToPixel(aPageSize, aMapMode).Height());
- aMapMode.SetScaleY(aFracY);
-
- pDevice->SetMapMode(aMapMode);
-
- SdrView aView(mrModel, pDevice);
-
- aView.SetPageVisible(false);
- aView.SetPageShadowVisible(false);
- aView.SetPageBorderVisible(false);
- aView.SetBordVisible(false);
- aView.SetGridVisible(false);
- aView.SetHlplVisible(false);
- aView.SetGlueVisible(false);
- aView.setHideBackground(true);
- aView.ShowSdrPage(&mrPage);
-
- vcl::Region aRegion(::tools::Rectangle(aPoint, aPageSize));
- ObjectRedirector aRedirector({ .mbSkipMasterPageObjects = true });
- aView.CompleteRedraw(pDevice, aRegion, &aRedirector);
+ RenderContext aRenderContext(pBuffer, mrModel, mrPage, maSlideSize);
+ createViewAndDraw(aRenderContext, aRenderOptions);
::tools::JsonWriter aJsonWriter;
aJsonWriter.put("group", "DrawPage");
@@ -228,8 +226,6 @@ bool SlideshowLayerRenderer::renderSlide(unsigned char* pBuffer, OString& rJsonM
}
rJsonMsg = aJsonWriter.finishAndGetAsOString();
- rOutliner.SetControlWord(nOldControlBits);
-
return true;
}