summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2017-07-03 16:33:36 +0200
committerMarco Cecchetti <mrcekets@gmail.com>2017-07-04 10:28:35 +0200
commitdd74a659c60c1f0e7733d4244e808865377c6316 (patch)
tree402e767710ede69c40de175d26b3e2e8d3f57ac1
parentabc440a691efb872afac385ce5ed28cd5db56c8c (diff)
support for saving a modified image instead of original version
Normally when you save an image through the "Save..." entry in the context menu for an image, the saved image is the original one more eventually applied filters (which are not removeable). Further applied transformations like rotations, cropping, color effects are not included in the saved image. This patch offers the user to choose if saving the original image (with filters) or the modified version through a pop-up dialog. The new feature is available in Writer, Draw and Calc. Change-Id: I4f983e3a5e8a6839fa5789a96c4d8c44477c1fd7 Reviewed-on: https://gerrit.libreoffice.org/39480 Reviewed-by: Marco Cecchetti <mrcekets@gmail.com> Tested-by: Marco Cecchetti <mrcekets@gmail.com>
-rw-r--r--include/svx/dialogs.hrc3
-rw-r--r--include/svx/graphichelper.hxx1
-rw-r--r--include/svx/svdograf.hxx2
-rw-r--r--sc/source/ui/drawfunc/graphsh.cxx26
-rw-r--r--sd/source/ui/view/drviews2.cxx22
-rw-r--r--svx/source/core/graphichelper.cxx9
-rw-r--r--svx/source/core/graphichelper.src5
-rw-r--r--svx/source/svdraw/svdograf.cxx35
-rw-r--r--sw/inc/editsh.hxx2
-rw-r--r--sw/source/core/edit/editsh.cxx7
-rw-r--r--sw/source/uibase/shells/grfsh.cxx38
11 files changed, 130 insertions, 20 deletions
diff --git a/include/svx/dialogs.hrc b/include/svx/dialogs.hrc
index 38680a96750c..9cb968dc7a17 100644
--- a/include/svx/dialogs.hrc
+++ b/include/svx/dialogs.hrc
@@ -750,6 +750,9 @@
#define RID_SVX_EXTRUSION_BAR (RID_SVX_START + 986)
#define RID_SVX_FONTWORK_BAR (RID_SVX_START + 987)
+// String for saving modified image (instead of original)
+#define RID_SVXSTR_SAVE_MODIFIED_IMAGE (RID_SVX_START + 988)
+
#define RID_SVXSTR_DEPTH_0 (RID_SVX_START + 992)
#define RID_SVXSTR_DEPTH_1 (RID_SVX_START + 993)
#define RID_SVXSTR_DEPTH_2 (RID_SVX_START + 994)
diff --git a/include/svx/graphichelper.hxx b/include/svx/graphichelper.hxx
index eca65563ef69..9056d92dedde 100644
--- a/include/svx/graphichelper.hxx
+++ b/include/svx/graphichelper.hxx
@@ -32,6 +32,7 @@ public:
static void GetPreferredExtension( OUString& rExtension, const Graphic& rGraphic );
static OUString ExportGraphic( const Graphic& rGraphic, const OUString& rGraphicName );
static void SaveShapeAsGraphic( const css::uno::Reference< css::drawing::XShape >& xShape );
+ static short HasToSaveTransformedImage(vcl::Window* pWin);
};
diff --git a/include/svx/svdograf.hxx b/include/svx/svdograf.hxx
index c748e3ad0ec1..dcf170099ea4 100644
--- a/include/svx/svdograf.hxx
+++ b/include/svx/svdograf.hxx
@@ -134,6 +134,8 @@ public:
GraphicType GetGraphicType() const;
+ GraphicAttr GetGraphicAttr( SdrGrafObjTransformsAttrs nTransformFlags = SdrGrafObjTransformsAttrs::ALL ) const;
+
// Keep ATM for SD.
bool IsAnimated() const;
bool IsEPS() const;
diff --git a/sc/source/ui/drawfunc/graphsh.cxx b/sc/source/ui/drawfunc/graphsh.cxx
index 75d45567bcf3..f0cd3b57da20 100644
--- a/sc/source/ui/drawfunc/graphsh.cxx
+++ b/sc/source/ui/drawfunc/graphsh.cxx
@@ -261,11 +261,31 @@ void ScGraphicShell::ExecuteSaveGraphic( SAL_UNUSED_PARAMETER SfxRequest& /*rReq
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
if( rMarkList.GetMarkCount() == 1 )
{
- SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
- if( pObj && dynamic_cast<const SdrGrafObj*>( pObj) != nullptr && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GraphicType::Bitmap )
+ const SdrGrafObj* pObj = dynamic_cast<const SdrGrafObj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
+ if( pObj && pObj->GetGraphicType() == GraphicType::Bitmap )
{
- GraphicObject aGraphicObject( static_cast<SdrGrafObj*>( pObj )->GetGraphicObject() );
+ GraphicAttr aGraphicAttr = pObj->GetGraphicAttr();
+ short nState = RET_CANCEL;
+ if (aGraphicAttr != GraphicAttr()) // the image has been modified
+ {
+ vcl::Window* pWin = GetViewData()->GetActiveWin();
+ if (pWin)
+ {
+ nState = GraphicHelper::HasToSaveTransformedImage(pWin);
+ }
+ }
+ else
+ {
+ nState = RET_NO;
+ }
+
+ if (nState == RET_YES)
+ {
+ GraphicHelper::ExportGraphic( pObj->GetTransformedGraphic(), "" );
+ }
+ else if (nState == RET_NO)
{
+ GraphicObject aGraphicObject(pObj->GetGraphicObject());
GraphicHelper::ExportGraphic( aGraphicObject.GetGraphic(), "" );
}
}
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index c960e4c4c7cb..c144cf9ea251 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -928,8 +928,28 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
const SdrGrafObj* pObj = dynamic_cast<const SdrGrafObj*>(rMarkList.GetMark(0)->GetMarkedSdrObj());
if (pObj && pObj->GetGraphicType() == GraphicType::Bitmap)
{
- GraphicObject aGraphicObject(pObj->GetGraphicObject());
+ GraphicAttr aGraphicAttr = pObj->GetGraphicAttr();
+ short nState = RET_CANCEL;
+ if (aGraphicAttr != GraphicAttr()) // the image has been modified
{
+ vcl::Window* pWin = GetActiveWindow();
+ if (pWin)
+ {
+ nState = GraphicHelper::HasToSaveTransformedImage(pWin);
+ }
+ }
+ else
+ {
+ nState = RET_NO;
+ }
+
+ if (nState == RET_YES)
+ {
+ GraphicHelper::ExportGraphic( pObj->GetTransformedGraphic(), "" );
+ }
+ else if (nState == RET_NO)
+ {
+ GraphicObject aGraphicObject(pObj->GetGraphicObject());
GraphicHelper::ExportGraphic( aGraphicObject.GetGraphic(), "" );
}
}
diff --git a/svx/source/core/graphichelper.cxx b/svx/source/core/graphichelper.cxx
index 86b1025e18f7..3a6df2b9e7f5 100644
--- a/svx/source/core/graphichelper.cxx
+++ b/svx/source/core/graphichelper.cxx
@@ -26,6 +26,8 @@
#include <svx/graphichelper.hxx>
#include <svx/dialogs.hrc>
+#include <vcl/layout.hxx>
+
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/anytostring.hxx>
#include <comphelper/processfactory.hxx>
@@ -284,4 +286,11 @@ void GraphicHelper::SaveShapeAsGraphic( const Reference< drawing::XShape >& xSha
}
}
+short GraphicHelper::HasToSaveTransformedImage(vcl::Window* pWin)
+{
+ OUString aMsg(SvxResId(RID_SVXSTR_SAVE_MODIFIED_IMAGE));
+ ScopedVclPtrInstance< MessageDialog > aBox(pWin, aMsg, VclMessageType::Question, VclButtonsType::YesNo);
+ return aBox->Execute();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/core/graphichelper.src b/svx/source/core/graphichelper.src
index 3432778c9cd9..c866076bed4d 100644
--- a/svx/source/core/graphichelper.src
+++ b/svx/source/core/graphichelper.src
@@ -28,4 +28,9 @@ String RID_SVXSTR_SAVEAS_IMAGE
{
Text [ en-US ] = "Save as Image" ;
};
+
+String RID_SVXSTR_SAVE_MODIFIED_IMAGE
+{
+ Text [ en-US ] = "The image has been modified. By default the original image will be saved.\nDo you want to save the modified version instead ?" ;
+};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx
index 8c8d584e9abe..59c5a57e9125 100644
--- a/svx/source/svdraw/svdograf.cxx
+++ b/svx/source/svdraw/svdograf.cxx
@@ -474,20 +474,35 @@ Graphic SdrGrafObj::GetTransformedGraphic( SdrGrafObjTransformsAttrs nTransformF
// Refactored most of the code to GraphicObject, where
// everybody can use e.g. the cropping functionality
- GraphicType eType = GetGraphicType();
MapMode aDestMap( pModel->GetScaleUnit(), Point(), pModel->GetScaleFraction(), pModel->GetScaleFraction() );
const Size aDestSize( GetLogicRect().GetSize() );
- const bool bMirror = bool( nTransformFlags & SdrGrafObjTransformsAttrs::MIRROR );
- const bool bRotate = bool( nTransformFlags & SdrGrafObjTransformsAttrs::ROTATE ) &&
- ( aGeo.nRotationAngle && aGeo.nRotationAngle != 18000 ) && ( GraphicType::NONE != eType );
- // Need cropping info earlier
- const_cast<SdrGrafObj*>(this)->ImpSetAttrToGrafInfo();
+ GraphicAttr aActAttr = GetGraphicAttr(nTransformFlags);
+
+ // Delegate to moved code in GraphicObject
+ return GetGraphicObject().GetTransformedGraphic( aDestSize, aDestMap, aActAttr );
+}
+
+GraphicType SdrGrafObj::GetGraphicType() const
+{
+ return pGraphic->GetType();
+}
+
+GraphicAttr SdrGrafObj::GetGraphicAttr( SdrGrafObjTransformsAttrs nTransformFlags ) const
+{
GraphicAttr aActAttr;
+ GraphicType eType = GetGraphicType();
if( SdrGrafObjTransformsAttrs::NONE != nTransformFlags &&
GraphicType::NONE != eType )
{
+ const bool bMirror = bool( nTransformFlags & SdrGrafObjTransformsAttrs::MIRROR );
+ const bool bRotate = bool( nTransformFlags & SdrGrafObjTransformsAttrs::ROTATE ) &&
+ ( aGeo.nRotationAngle && aGeo.nRotationAngle != 18000 ) && ( GraphicType::NONE != eType );
+
+ // Need cropping info earlier
+ const_cast<SdrGrafObj*>(this)->ImpSetAttrToGrafInfo();
+
// Actually transform the graphic only in this case.
// Cropping always happens, though.
aActAttr = aGrafInfo;
@@ -505,13 +520,7 @@ Graphic SdrGrafObj::GetTransformedGraphic( SdrGrafObjTransformsAttrs nTransformF
aActAttr.SetRotation( sal_uInt16(aGeo.nRotationAngle / 10) );
}
- // Delegate to moved code in GraphicObject
- return GetGraphicObject().GetTransformedGraphic( aDestSize, aDestMap, aActAttr );
-}
-
-GraphicType SdrGrafObj::GetGraphicType() const
-{
- return pGraphic->GetType();
+ return aActAttr;
}
bool SdrGrafObj::IsAnimated() const
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 1bc5c1b0eec5..7a0d2d85f2d9 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -78,6 +78,7 @@ class SwCharFormat;
class SwExtTextInput;
class Graphic;
class GraphicObject;
+class GraphicAttr;
class SwFormatINetFormat;
class SwTable;
class SwTextBlocks;
@@ -610,6 +611,7 @@ public:
const Graphic* GetGraphic( bool bWait = true ) const;
const GraphicObject* GetGraphicObj() const;
+ const GraphicAttr* GetGraphicAttr( GraphicAttr& rGA ) const;
bool IsLinkedGrfSwapOut() const;
GraphicType GetGraphicType() const;
diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx
index 3aef528a2fe8..46c5de7cfe8a 100644
--- a/sw/source/core/edit/editsh.cxx
+++ b/sw/source/core/edit/editsh.cxx
@@ -257,6 +257,13 @@ const GraphicObject* SwEditShell::GetGraphicObj() const
return pGrfNode ? &(pGrfNode->GetGrfObj()) : nullptr;
}
+const GraphicAttr* SwEditShell::GetGraphicAttr( GraphicAttr& rGA ) const
+{
+ SwGrfNode* pGrfNode = GetGrfNode_();
+ const SwFrame* pFrame = GetCurrFrame(false);
+ return pGrfNode ? &(pGrfNode->GetGraphicAttr( rGA, pFrame )) : nullptr;
+}
+
GraphicType SwEditShell::GetGraphicType() const
{
SwGrfNode *pGrfNode = GetGrfNode_();
diff --git a/sw/source/uibase/shells/grfsh.cxx b/sw/source/uibase/shells/grfsh.cxx
index b0f44cf62fbe..583a234443fe 100644
--- a/sw/source/uibase/shells/grfsh.cxx
+++ b/sw/source/uibase/shells/grfsh.cxx
@@ -131,13 +131,45 @@ void SwGrfShell::Execute(SfxRequest &rReq)
case SID_SAVE_GRAPHIC:
{
- const Graphic *pGraphic;
- if(nullptr != (pGraphic = rSh.GetGraphic()))
+ GraphicAttr aGraphicAttr;
+ const GraphicObject* pGraphicObj = rSh.GetGraphicObj();
+ if (pGraphicObj)
{
+ rSh.GetGraphicAttr(aGraphicAttr);
+ }
+
+ short nState = RET_CANCEL;
+ if (aGraphicAttr != GraphicAttr()) // the image has been modified
+ {
+ vcl::Window* pWin = GetView().GetWindow();
+ if (pWin)
+ {
+ nState = GraphicHelper::HasToSaveTransformedImage(pWin);
+ }
+ }
+ else
+ {
+ nState = RET_NO;
+ }
+
+ if (nState == RET_YES)
+ {
+ Graphic aGraphic = pGraphicObj->GetTransformedGraphic(pGraphicObj->GetPrefSize(), pGraphicObj->GetPrefMapMode(), aGraphicAttr);
OUString sGrfNm;
OUString sFilterNm;
rSh.GetGrfNms( &sGrfNm, &sFilterNm );
- GraphicHelper::ExportGraphic( *pGraphic, sGrfNm );
+ GraphicHelper::ExportGraphic( aGraphic, sGrfNm );
+ }
+ else if (nState == RET_NO)
+ {
+ const Graphic *pGraphic;
+ if(nullptr != (pGraphic = rSh.GetGraphic()))
+ {
+ OUString sGrfNm;
+ OUString sFilterNm;
+ rSh.GetGrfNms( &sGrfNm, &sFilterNm );
+ GraphicHelper::ExportGraphic( *pGraphic, sGrfNm );
+ }
}
}
break;