Kaydet (Commit) dd74a659 authored tarafından Marco Cecchetti's avatar Marco Cecchetti Kaydeden (comit) Marco Cecchetti

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/39480Reviewed-by: 's avatarMarco Cecchetti <mrcekets@gmail.com>
Tested-by: 's avatarMarco Cecchetti <mrcekets@gmail.com>
üst abc440a6
......@@ -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)
......
......@@ -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);
};
......
......@@ -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;
......
......@@ -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(), "" );
}
}
......
......@@ -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(), "" );
}
}
......
......@@ -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: */
......@@ -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: */
......@@ -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
......
......@@ -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;
......
......@@ -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_();
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment