include/svx/dialogs.hrc | 3 +++ include/svx/graphichelper.hxx | 1 + include/svx/svdograf.hxx | 2 ++ sc/source/ui/drawfunc/graphsh.cxx | 26 +++++++++++++++++++++++--- sd/source/ui/view/drviews2.cxx | 22 +++++++++++++++++++++- svx/source/core/graphichelper.cxx | 9 +++++++++ svx/source/core/graphichelper.src | 5 +++++ svx/source/svdraw/svdograf.cxx | 35 ++++++++++++++++++++++------------- sw/inc/editsh.hxx | 2 ++ sw/source/core/edit/editsh.cxx | 7 +++++++ sw/source/uibase/shells/grfsh.cxx | 38 +++++++++++++++++++++++++++++++++++--- 11 files changed, 130 insertions(+), 20 deletions(-)
New commits: commit 970a2517d27336deb8b140f31371f37ea1c890f6 Author: Marco Cecchetti <marco.cecche...@collabora.com> Date: Mon Jul 3 16:33:36 2017 +0200 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 rotation, 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/39487 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/include/svx/dialogs.hrc b/include/svx/dialogs.hrc index 1c320896368d..e6176b1e2a19 100644 --- a/include/svx/dialogs.hrc +++ b/include/svx/dialogs.hrc @@ -862,6 +862,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_EXTRUSION_COLOR (RID_SVX_START + 991) #define RID_SVXSTR_DEPTH_0 (RID_SVX_START + 992) 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 77183c301de2..e8cb176ad10b 100644 --- a/include/svx/svdograf.hxx +++ b/include/svx/svdograf.hxx @@ -133,6 +133,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 254cb0649a4d..8c11655da76a 100644 --- a/sc/source/ui/drawfunc/graphsh.cxx +++ b/sc/source/ui/drawfunc/graphsh.cxx @@ -261,11 +261,31 @@ void ScGraphicShell::ExecuteSaveGraphic(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 7a5ef99fe9f3..1ceae1cf2f19 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -929,8 +929,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 5be57e8a8c2a..0e2497fa072a 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(SVX_RESSTR(RID_SVXSTR_SAVE_MODIFIED_IMAGE)); + ScopedVclPtrInstance< MessageDialog > aBox(pWin, aMsg, VclMessageType::Question, VCL_BUTTONS_YES_NO); + 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 7234d08e8f8d..60104fe90d50 100644 --- a/svx/source/core/graphichelper.src +++ b/svx/source/core/graphichelper.src @@ -24,4 +24,9 @@ String RID_SVXSTR_EXPORT_GRAPHIC_TITLE Text [ en-US ] = "Image Export" ; }; + +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 002ac8f77db2..cc14814fc7dc 100644 --- a/svx/source/svdraw/svdograf.cxx +++ b/svx/source/svdraw/svdograf.cxx @@ -479,20 +479,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; @@ -510,13 +525,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 e031303b6aae..888ee55c26ce 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; @@ -609,6 +610,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 0a0057a17dc5..ddabe6bc4fa7 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -258,6 +258,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 8553c3ed8f38..c269f75ba66a 100644 --- a/sw/source/uibase/shells/grfsh.cxx +++ b/sw/source/uibase/shells/grfsh.cxx @@ -132,13 +132,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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits