From d01b1b174f4e18b8bef23f7409d4e9cf4f07d232 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Mon, 31 Jan 2022 17:15:21 +0100 Subject: lok: render image preview with lower resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renderShapeSelection callback is used to render image previews which are later used during eg. rotation. Do not render preview with original size which slows down app a lot. Use 1280x720 max. Change-Id: Ia8365a67d87cea869ef74cb70ce4830439a523b6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129376 Tested-by: Jenkins CollaboraOffice Reviewed-by: Szymon Kłos --- filter/source/svg/svgexport.cxx | 6 +++++- filter/source/svg/svgfilter.cxx | 10 ++++++++++ filter/source/svg/svgfilter.hxx | 1 + filter/source/svg/svgwriter.cxx | 22 +++++++++++++++++++++- filter/source/svg/svgwriter.hxx | 2 ++ 5 files changed, 39 insertions(+), 2 deletions(-) (limited to 'filter') diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx index fc8de3b18f68..d0eb6b9c6a8c 100644 --- a/filter/source/svg/svgexport.cxx +++ b/filter/source/svg/svgexport.cxx @@ -802,7 +802,9 @@ bool SVGFilter::implExportWriterTextGraphic( const Reference< view::XSelectionSu const Graphic aOriginalGraphic(xOriginalGraphic); uno::Reference xTransformedGraphic; - xPropertySet->getPropertyValue("TransformedGraphic") >>= xTransformedGraphic; + xPropertySet->getPropertyValue( + mbIsPreview ? OUString("GraphicPreview") : OUString("TransformedGraphic")) + >>= xTransformedGraphic; if (!xTransformedGraphic.is()) return false; @@ -978,6 +980,8 @@ bool SVGFilter::implExportDocument() mpSVGWriter->SetEmbeddedBitmapRefs( &maBitmapActionMap ); implExportTiledBackground(); } + if( mbIsPreview ) + mpSVGWriter->SetPreviewMode(); // #i124608# export a given object selection, so no MasterPage export at all if (!mbExportShapeSelection) diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx index 8025550b5837..67ff2dd80680 100644 --- a/filter/source/svg/svgfilter.cxx +++ b/filter/source/svg/svgfilter.cxx @@ -82,6 +82,7 @@ SVGFilter::SVGFilter( const Reference< XComponentContext >& rxCtx ) : mbExportShapeSelection(false), maFilterData(), mxDefaultPage(), + mbIsPreview(false), mbWriterFilter(false), mbCalcFilter(false), mbImpressFilter(false), @@ -111,6 +112,15 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto if(mxSrcDoc.is()) { + for (const PropertyValue& rProp : rDescriptor) + { + if (rProp.Name == "IsPreview") + { + rProp.Value >>= mbIsPreview; + break; + } + } + for (const PropertyValue& rProp : rDescriptor) { if (rProp.Name == "FilterName") diff --git a/filter/source/svg/svgfilter.hxx b/filter/source/svg/svgfilter.hxx index aab158971e0b..975eb4ae2d02 100644 --- a/filter/source/svg/svgfilter.hxx +++ b/filter/source/svg/svgfilter.hxx @@ -209,6 +209,7 @@ private: Sequence< PropertyValue > maFilterData; Reference< css::drawing::XDrawPage > mxDefaultPage; std::vector< Reference< css::drawing::XDrawPage > > mSelectedPages; + bool mbIsPreview; bool mbWriterFilter; bool mbCalcFilter; diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index f5c96878d4f4..9677c9e092fd 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -2949,7 +2949,27 @@ void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx, } } - if( !(bCached || GraphicConverter::Export( aOStm, rBmpEx, ConvertDataFormat::PNG ) == ERRCODE_NONE) ) + const BitmapEx* pBitmap = &rBmpEx; + std::unique_ptr pNewBitmap; + + // for preview we generate downscaled images (1280x720 max) + if (mbIsPreview) + { + Size aSize = rBmpEx.GetSizePixel(); + double fX = static_cast(aSize.getWidth()) / 1280; + double fY = static_cast(aSize.getHeight()) / 720; + double fFactor = fX > fY ? fX : fY; + if (fFactor > 1.0) + { + aSize.setWidth(aSize.getWidth() / fFactor); + aSize.setHeight(aSize.getHeight() / fFactor); + pNewBitmap = std::make_unique(rBmpEx); + pNewBitmap->Scale(aSize); + pBitmap = pNewBitmap.get(); + } + } + + if( !(bCached || GraphicConverter::Export( aOStm, *pBitmap, ConvertDataFormat::PNG ) == ERRCODE_NONE) ) return; Point aPt; diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx index a052fba16e87..57c261fad7a5 100644 --- a/filter/source/svg/svgwriter.hxx +++ b/filter/source/svg/svgwriter.hxx @@ -319,6 +319,7 @@ private: bool mbClipAttrChanged; bool mbIsPlaceholderShape; const MetaBitmapActionMap* mpEmbeddedBitmapsMap; + bool mbIsPreview; tools::Long ImplMap( sal_Int32 nVal ) const; @@ -378,6 +379,7 @@ public: void SetEmbeddedBitmapRefs( const MetaBitmapActionMap* pEmbeddedBitmapsMap ); void StartMask(const Point& rDestPt, const Size& rDestSize, const Gradient& rGradient, sal_uInt32 nWriteFlags, OUString* pTextStyle = nullptr); + void SetPreviewMode(bool bState = true) { mbIsPreview = bState; } }; -- cgit