summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2022-01-31 17:15:21 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2022-02-02 18:25:29 +0100
commitc5833988681caa30b612105bb1eb3a362de9b0f9 (patch)
treeb328acfda6d468559f366c6141f59d95fe90cc9a
parentUse unique id for FN_UNO_TRANSFORMED_GRAPHIC (diff)
downloadcore-c5833988681caa30b612105bb1eb3a362de9b0f9.tar.gz
core-c5833988681caa30b612105bb1eb3a362de9b0f9.zip
lok: render image preview with lower resolution
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/+/129230 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Mert Tumer <mert.tumer@collabora.com>
-rw-r--r--desktop/source/lib/init.cxx1
-rw-r--r--filter/source/svg/svgexport.cxx6
-rw-r--r--filter/source/svg/svgfilter.cxx10
-rw-r--r--filter/source/svg/svgfilter.hxx1
-rw-r--r--filter/source/svg/svgwriter.cxx22
-rw-r--r--filter/source/svg/svgwriter.hxx2
-rw-r--r--sfx2/source/doc/objstor.cxx15
-rw-r--r--sw/inc/cmdid.h1
-rw-r--r--sw/inc/unoprnms.hxx1
-rw-r--r--sw/source/core/unocore/unoframe.cxx16
-rw-r--r--sw/source/core/unocore/unomap1.cxx1
11 files changed, 73 insertions, 3 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0c93a7f9d626..5721b56573d6 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3839,6 +3839,7 @@ static size_t doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOu
}
aMediaDescriptor["SelectionOnly"] <<= true;
aMediaDescriptor["OutputStream"] <<= xOut;
+ aMediaDescriptor["IsPreview"] <<= true; // will down-scale graphics
xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList());
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index f5ab1a67b94a..b0110e71c297 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -797,7 +797,9 @@ bool SVGFilter::implExportWriterTextGraphic( const Reference< view::XSelectionSu
const Graphic aOriginalGraphic(xOriginalGraphic);
uno::Reference<graphic::XGraphic> xTransformedGraphic;
- xPropertySet->getPropertyValue("TransformedGraphic") >>= xTransformedGraphic;
+ xPropertySet->getPropertyValue(
+ mbIsPreview ? OUString("GraphicPreview") : OUString("TransformedGraphic"))
+ >>= xTransformedGraphic;
if (!xTransformedGraphic.is())
return false;
@@ -973,6 +975,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 5677d63fcc6c..25c96c3d1848 100644
--- a/filter/source/svg/svgfilter.cxx
+++ b/filter/source/svg/svgfilter.cxx
@@ -90,6 +90,7 @@ SVGFilter::SVGFilter( const Reference< XComponentContext >& rxCtx ) :
mbExportShapeSelection(false),
maFilterData(),
mxDefaultPage(),
+ mbIsPreview(false),
mbWriterFilter(false),
mbCalcFilter(false),
mbImpressFilter(false),
@@ -121,6 +122,15 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto
{
for (sal_Int32 nInd = 0; nInd < rDescriptor.getLength(); nInd++)
{
+ if (rDescriptor[nInd].Name == "IsPreview")
+ {
+ rDescriptor[nInd].Value >>= mbIsPreview;
+ break;
+ }
+ }
+
+ for (sal_Int32 nInd = 0; nInd < rDescriptor.getLength(); nInd++)
+ {
if (rDescriptor[nInd].Name == "FilterName")
{
OUString sFilterName;
diff --git a/filter/source/svg/svgfilter.hxx b/filter/source/svg/svgfilter.hxx
index ae9418ea49c5..d95710ca3e40 100644
--- a/filter/source/svg/svgfilter.hxx
+++ b/filter/source/svg/svgfilter.hxx
@@ -218,6 +218,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 694cc073a81c..006a2ca48073 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -2867,7 +2867,27 @@ void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx,
}
}
- if( bCached || GraphicConverter::Export( aOStm, rBmpEx, ConvertDataFormat::PNG ) == ERRCODE_NONE )
+ const BitmapEx* pBitmap = &rBmpEx;
+ std::unique_ptr<BitmapEx> pNewBitmap;
+
+ // for preview we generate downscaled images (1280x720 max)
+ if (mbIsPreview)
+ {
+ Size aSize = rBmpEx.GetSizePixel();
+ double fX = static_cast<double>(aSize.getWidth()) / 1280;
+ double fY = static_cast<double>(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<BitmapEx>(rBmpEx);
+ pNewBitmap->Scale(aSize);
+ pBitmap = pNewBitmap.get();
+ }
+ }
+
+ if( bCached || GraphicConverter::Export( aOStm, *pBitmap, ConvertDataFormat::PNG ) == ERRCODE_NONE )
{
Point aPt;
Size aSz;
diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx
index d7458d053120..0be1e5ba1bdb 100644
--- a/filter/source/svg/svgwriter.hxx
+++ b/filter/source/svg/svgwriter.hxx
@@ -337,6 +337,7 @@ private:
bool mbClipAttrChanged;
bool mbIsPlaceholderShape;
const MetaBitmapActionMap* mpEmbeddedBitmapsMap;
+ bool mbIsPreview;
long ImplMap( sal_Int32 nVal ) const;
@@ -394,6 +395,7 @@ public:
const GDIMetaFile* pTextEmbeddedBitmapMtf = nullptr );
void SetEmbeddedBitmapRefs( const MetaBitmapActionMap* pEmbeddedBitmapsMap );
+ void SetPreviewMode(bool bState = true) { mbIsPreview = bState; }
};
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index abdb402e507e..8d101e8aac04 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2431,6 +2431,7 @@ bool SfxObjectShell::ExportTo( SfxMedium& rMedium )
bool bHasBaseURL = false;
bool bHasFilterName = false;
bool bIsRedactMode = false;
+ bool bIsPreview = false;
sal_Int32 nEnd = aOldArgs.getLength();
for ( sal_Int32 i = 0; i < nEnd; i++ )
@@ -2448,6 +2449,13 @@ bool SfxObjectShell::ExportTo( SfxMedium& rMedium )
bHasFilterName = true;
}
+ const css::uno::Sequence<css::beans::PropertyValue>& rMediumArgs = rMedium.GetArgs();
+ for ( sal_Int32 i = 0; i < rMediumArgs.getLength(); i++ )
+ {
+ if( rMediumArgs[i].Name == "IsPreview" )
+ rMediumArgs[i].Value >>= bIsPreview;
+ }
+
// FIXME: Handle this inside TransformItems()
if (pItems->GetItemState(SID_IS_REDACT_MODE) == SfxItemState::SET)
bIsRedactMode = true;
@@ -2488,6 +2496,13 @@ bool SfxObjectShell::ExportTo( SfxMedium& rMedium )
aArgs[nEnd-1].Value <<= bIsRedactMode;
}
+ if (bIsPreview)
+ {
+ aArgs.realloc( ++nEnd );
+ aArgs[nEnd-1].Name = "IsPreview";
+ aArgs[nEnd-1].Value <<= bIsPreview;
+ }
+
return xFilter->filter( aArgs );
}catch(...)
{}
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index ff229e1672db..6380d58c7124 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -621,6 +621,7 @@
#define FN_UNO_VISIBLE_AREA_HEIGHT (FN_EXTRA2 + 126)
#define FN_UNO_TRANSFORMED_GRAPHIC (FN_EXTRA2 + 127)
+#define FN_UNO_GRAPHIC_PREVIEW (FN_EXTRA2 + 128)
// Area: Help
// Region: Traveling & Selection
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index 1100a72508fb..fcd0b4029a58 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -166,6 +166,7 @@
#define UNO_NAME_FILE_LINK "FileLink"
#define UNO_NAME_GRAPHIC "Graphic"
#define UNO_NAME_TRANSFORMED_GRAPHIC "TransformedGraphic"
+#define UNO_NAME_GRAPHIC_PREVIEW "GraphicPreview"
#define UNO_NAME_IS_PROTECTED "IsProtected"
#define UNO_NAME_PARA_KEEP_TOGETHER "ParaKeepTogether"
#define UNO_NAME_KEEP_TOGETHER "KeepTogether"
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index e2e5c9411715..60dc135caa3f 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2078,7 +2078,8 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName)
aAny <<= pGrfNode->GetGrf().GetXGraphic();
}
}
- else if( FN_UNO_TRANSFORMED_GRAPHIC == pEntry->nWID )
+ else if( FN_UNO_TRANSFORMED_GRAPHIC == pEntry->nWID
+ || FN_UNO_GRAPHIC_PREVIEW == pEntry->nWID )
{
const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
if(pIdx)
@@ -2102,6 +2103,19 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName)
awt::Size aFrameSize = getSize();
Size aSize100thmm(aFrameSize.Width, aFrameSize.Height);
Size aSize = OutputDevice::LogicToLogic(aSize100thmm, MapMode(MapUnit::Map100thMM), aGraphicObj.GetPrefMapMode());
+
+ if (FN_UNO_GRAPHIC_PREVIEW == pEntry->nWID)
+ {
+ double fX = static_cast<double>(aSize.getWidth()) / 1280;
+ double fY = static_cast<double>(aSize.getHeight()) / 720;
+ double fFactor = fX > fY ? fX : fY;
+ if (fFactor > 1.0)
+ {
+ aSize.setWidth(aSize.getWidth() / fFactor);
+ aSize.setHeight(aSize.getHeight() / fFactor);
+ }
+ }
+
Graphic aGraphic = aGraphicObj.GetTransformedGraphic(aSize, aGraphicObj.GetPrefMapMode(), aGraphicAttr);
aAny <<= aGraphic.GetXGraphic();
}
diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx
index 08c97f878703..5ee500c17776 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -858,6 +858,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetGraphicPropertyMap(
{ OUString(UNO_NAME_GRAPHIC), FN_UNO_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0 },
{ OUString(UNO_NAME_GRAPHIC_URL), FN_UNO_GRAPHIC_URL, cppu::UnoType<css::uno::Any>::get(), 0, 0 },
{ OUString(UNO_NAME_TRANSFORMED_GRAPHIC), FN_UNO_TRANSFORMED_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0 },
+ { OUString(UNO_NAME_GRAPHIC_PREVIEW), FN_UNO_GRAPHIC_PREVIEW, cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0 },
{ OUString(UNO_NAME_ACTUAL_SIZE), FN_UNO_ACTUAL_SIZE, cppu::UnoType<css::awt::Size>::get(), PropertyAttribute::READONLY, CONVERT_TWIPS},
{ OUString(UNO_NAME_CONTOUR_POLY_POLYGON), FN_PARAM_CONTOUR_PP, cppu::UnoType<css::drawing::PointSequenceSequence>::get(), PropertyAttribute::MAYBEVOID, 0 },
{ OUString(UNO_NAME_IS_PIXEL_CONTOUR), FN_UNO_IS_PIXEL_CONTOUR, cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },