Kaydet (Commit) 44faceac authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

Add "Compress Graphic Dialog" to Writer.

Change-Id: Icff16a86d217b2648ce588ca2b90abefcd1634d9
üst bd502f4d
...@@ -80,9 +80,14 @@ private: ...@@ -80,9 +80,14 @@ private:
public: public:
CompressGraphicsDialog( Window* pParent, SdrGrafObj* pGraphicObj, SfxBindings& rBindings ); CompressGraphicsDialog( Window* pParent, SdrGrafObj* pGraphicObj, SfxBindings& rBindings );
CompressGraphicsDialog( Window* pParent, Graphic& rGraphic, Size rViewSize100mm, Rectangle& rCropRectangle, SfxBindings& rBindings );
virtual ~CompressGraphicsDialog(); virtual ~CompressGraphicsDialog();
SdrGrafObj* GetCompressedSdrGrafObj(); SdrGrafObj* GetCompressedSdrGrafObj();
Graphic GetCompressedGraphic();
Rectangle GetScaledCropRectangle();
}; };
#endif #endif
......
...@@ -43,7 +43,21 @@ CompressGraphicsDialog::CompressGraphicsDialog( Window* pParent, SdrGrafObj* pGr ...@@ -43,7 +43,21 @@ CompressGraphicsDialog::CompressGraphicsDialog( Window* pParent, SdrGrafObj* pGr
m_pGraphicObj ( pGraphicObj ), m_pGraphicObj ( pGraphicObj ),
m_aGraphic ( pGraphicObj->GetGraphicObject().GetGraphic() ), m_aGraphic ( pGraphicObj->GetGraphicObject().GetGraphic() ),
m_aViewSize100mm ( pGraphicObj->GetLogicRect().GetSize() ), m_aViewSize100mm ( pGraphicObj->GetLogicRect().GetSize() ),
m_aCropRectangle ( Rectangle() ), m_rBindings ( rBindings ),
m_dResolution ( 96.0 )
{
const SdrGrafCropItem& rCrop = (const SdrGrafCropItem&) m_pGraphicObj->GetMergedItem(SDRATTR_GRAFCROP);
m_aCropRectangle = Rectangle(rCrop.GetLeft(), rCrop.GetTop(), rCrop.GetRight(), rCrop.GetBottom());
Initialize();
}
CompressGraphicsDialog::CompressGraphicsDialog( Window* pParent, Graphic& rGraphic, Size rViewSize100mm, Rectangle& rCropRectangle, SfxBindings& rBindings ) :
ModalDialog ( pParent, "CompressGraphicDialog", "svx/ui/compressgraphicdialog.ui" ),
m_pGraphicObj ( NULL ),
m_aGraphic ( rGraphic ),
m_aViewSize100mm ( rViewSize100mm ),
m_aCropRectangle ( rCropRectangle ),
m_rBindings ( rBindings ), m_rBindings ( rBindings ),
m_dResolution ( 96.0 ) m_dResolution ( 96.0 )
{ {
...@@ -184,15 +198,15 @@ sal_uLong CompressGraphicsDialog::GetSelectedInterpolationType() ...@@ -184,15 +198,15 @@ sal_uLong CompressGraphicsDialog::GetSelectedInterpolationType()
void CompressGraphicsDialog::Compress(SvStream& aStream) void CompressGraphicsDialog::Compress(SvStream& aStream)
{ {
BitmapEx bitmap = m_aGraphic.GetBitmapEx(); BitmapEx aBitmap = m_aGraphic.GetBitmapEx();
if ( m_pReduceResolutionCB->IsChecked() ) if ( m_pReduceResolutionCB->IsChecked() )
{ {
long nPixelX = (long)( GetViewWidthInch() * m_dResolution ); long nPixelX = (long)( GetViewWidthInch() * m_dResolution );
long nPixelY = (long)( GetViewHeightInch() * m_dResolution ); long nPixelY = (long)( GetViewHeightInch() * m_dResolution );
bitmap.Scale( Size( nPixelX, nPixelY ), GetSelectedInterpolationType() ); aBitmap.Scale( Size( nPixelX, nPixelY ), GetSelectedInterpolationType() );
} }
Graphic aScaledGraphic = Graphic( bitmap ); Graphic aScaledGraphic( aBitmap );
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
Sequence< PropertyValue > aFilterData( 3 ); Sequence< PropertyValue > aFilterData( 3 );
...@@ -206,7 +220,7 @@ void CompressGraphicsDialog::Compress(SvStream& aStream) ...@@ -206,7 +220,7 @@ void CompressGraphicsDialog::Compress(SvStream& aStream)
String aGraphicFormatName = m_pLosslessRB->IsChecked() ? String( "png" ) : String( "jpg" ); String aGraphicFormatName = m_pLosslessRB->IsChecked() ? String( "png" ) : String( "jpg" );
sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( aGraphicFormatName ); sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( aGraphicFormatName );
rFilter.ExportGraphic( aScaledGraphic, String( "test" ), aStream, nFilterFormat, &aFilterData ); rFilter.ExportGraphic( aScaledGraphic, OUString( "none" ), aStream, nFilterFormat, &aFilterData );
} }
IMPL_LINK_NOARG( CompressGraphicsDialog, NewWidthModifiedHdl ) IMPL_LINK_NOARG( CompressGraphicsDialog, NewWidthModifiedHdl )
...@@ -266,7 +280,7 @@ IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl ) ...@@ -266,7 +280,7 @@ IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl )
{ {
sal_Int32 aSize = 0; sal_Int32 aSize = 0;
if ( m_dResolution > 0 ) if ( m_dResolution > 0.0 )
{ {
SvMemoryStream aMemStream; SvMemoryStream aMemStream;
aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
...@@ -286,38 +300,63 @@ IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl ) ...@@ -286,38 +300,63 @@ IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl )
return 0L; return 0L;
} }
SdrGrafObj* CompressGraphicsDialog::GetCompressedSdrGrafObj() Rectangle CompressGraphicsDialog::GetScaledCropRectangle()
{ {
if ( m_dResolution > 0 ) if ( m_pReduceResolutionCB->IsChecked() )
{ {
SdrGrafObj* pNewObject = (SdrGrafObj*) m_pGraphicObj->Clone(); long nPixelX = (long)( GetViewWidthInch() * m_dResolution );
long nPixelY = (long)( GetViewHeightInch() * m_dResolution );
if ( m_pReduceResolutionCB->IsChecked() ) Size aSize = m_aGraphic.GetBitmapEx().GetSizePixel();
{ double aScaleX = nPixelX / (double) aSize.Width();
const SdrGrafCropItem& rCrop = (const SdrGrafCropItem&) m_pGraphicObj->GetMergedItem(SDRATTR_GRAFCROP); double aScaleY = nPixelY / (double) aSize.Height();
long nPixelX = (long)( GetViewWidthInch() * m_dResolution );
long nPixelY = (long)( GetViewHeightInch() * m_dResolution ); return Rectangle(
Size size = m_aGraphic.GetBitmapEx().GetSizePixel(); m_aCropRectangle.Left() * aScaleX,
double aScaleX = nPixelX / (double) size.Width(); m_aCropRectangle.Top() * aScaleY,
double aScaleY = nPixelY / (double) size.Height(); m_aCropRectangle.Right() * aScaleX,
m_aCropRectangle.Bottom()* aScaleY);
SdrGrafCropItem aNewCrop( }
rCrop.GetLeft() * aScaleX, else
rCrop.GetTop() * aScaleY, {
rCrop.GetRight() * aScaleX, return m_aCropRectangle;
rCrop.GetBottom()* aScaleY); }
pNewObject->SetMergedItem(aNewCrop); }
}
Graphic CompressGraphicsDialog::GetCompressedGraphic()
{
if ( m_dResolution > 0.0 )
{
SvMemoryStream aMemStream; SvMemoryStream aMemStream;
aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
Compress( aMemStream ); Compress( aMemStream );
aMemStream.Seek( STREAM_SEEK_TO_BEGIN ); aMemStream.Seek( STREAM_SEEK_TO_BEGIN );
Graphic aResultGraphic; Graphic aResultGraphic;
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
rFilter.ImportGraphic( aResultGraphic, String("import"), aMemStream ); rFilter.ImportGraphic( aResultGraphic, OUString("import"), aMemStream );
pNewObject->SetGraphic( aResultGraphic ); return aResultGraphic;
}
return Graphic();
}
SdrGrafObj* CompressGraphicsDialog::GetCompressedSdrGrafObj()
{
if ( m_dResolution > 0.0 )
{
SdrGrafObj* pNewObject = (SdrGrafObj*) m_pGraphicObj->Clone();
if ( m_pReduceResolutionCB->IsChecked() )
{
Rectangle aScaledCropedRectangle = GetScaledCropRectangle();
SdrGrafCropItem aNewCrop(
aScaledCropedRectangle.Left(),
aScaledCropedRectangle.Top(),
aScaledCropedRectangle.Right(),
aScaledCropedRectangle.Bottom());
pNewObject->SetMergedItem(aNewCrop);
}
pNewObject->SetGraphic( GetCompressedGraphic() );
return pNewObject; return pNewObject;
} }
......
...@@ -42,13 +42,18 @@ interface BaseTextGraphic ...@@ -42,13 +42,18 @@ interface BaseTextGraphic
DisableFlags="SW_DISABLE_ON_PROTECTED_CURSOR"; DisableFlags="SW_DISABLE_ON_PROTECTED_CURSOR";
] ]
SID_SAVE_GRAPHIC SID_SAVE_GRAPHIC
[ [
ExecMethod = Execute ; ExecMethod = Execute ;
StateMethod = GetAttrState ; StateMethod = GetAttrState ;
] ]
SID_COMPRESS_GRAPHIC
[
ExecMethod = Execute ;
StateMethod = GetAttrState ;
]
SID_EXTERNAL_EDIT SID_EXTERNAL_EDIT
[ [
ExecMethod = Execute ; ExecMethod = Execute ;
......
...@@ -1286,6 +1286,7 @@ Menu MN_GRF_POPUPMENU ...@@ -1286,6 +1286,7 @@ Menu MN_GRF_POPUPMENU
MN_FRM_CAPTION_ITEM MN_FRM_CAPTION_ITEM
SEPARATOR; SEPARATOR;
MenuItem { ITEM_SAVE_GRAPHIC }; MenuItem { ITEM_SAVE_GRAPHIC };
MenuItem { ITEM_COMPRESS_GRAPHIC };
MenuItem { ITEM_EXTERNAL_EDIT }; MenuItem { ITEM_EXTERNAL_EDIT };
SEPARATOR; SEPARATOR;
MenuItem MenuItem
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <svx/sdgmoitm.hxx> #include <svx/sdgmoitm.hxx>
#include <editeng/brushitem.hxx> #include <editeng/brushitem.hxx>
#include <svx/grfflt.hxx> #include <svx/grfflt.hxx>
#include <svx/compressgraphicdialog.hxx>
#include <svx/tbxcolor.hxx> #include <svx/tbxcolor.hxx>
#include <fmturl.hxx> #include <fmturl.hxx>
#include <view.hxx> #include <view.hxx>
...@@ -115,6 +116,50 @@ void SwGrfShell::Execute(SfxRequest &rReq) ...@@ -115,6 +116,50 @@ void SwGrfShell::Execute(SfxRequest &rReq)
} }
} }
break; break;
case SID_COMPRESS_GRAPHIC:
{
const Graphic* pGraphic = rSh.GetGraphic();
if( pGraphic )
{
Size aSize (
TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width()),
TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height()));
SfxItemSet aSet( rSh.GetAttrPool(), RES_GRFATR_CROPGRF, RES_GRFATR_CROPGRF );
rSh.GetCurAttr( aSet );
SwCropGrf aCrop( (const SwCropGrf&) aSet.Get(RES_GRFATR_CROPGRF) );
Rectangle aCropRectangle(
TWIP_TO_MM100(aCrop.GetLeft()),
TWIP_TO_MM100(aCrop.GetTop()),
TWIP_TO_MM100(aCrop.GetRight()),
TWIP_TO_MM100(aCrop.GetBottom()) );
Graphic aGraphic = Graphic( *pGraphic );
CompressGraphicsDialog aDialog( GetView().GetWindow(), aGraphic, aSize, aCropRectangle, GetView().GetViewFrame()->GetBindings() );
if( aDialog.Execute() == RET_OK )
{
rSh.StartAllAction();
rSh.StartUndo(UNDO_START);
Rectangle aScaledCropedRectangle = aDialog.GetScaledCropRectangle();
aCrop.SetLeft( MM100_TO_TWIP( aScaledCropedRectangle.Left() ));
aCrop.SetTop( MM100_TO_TWIP( aScaledCropedRectangle.Top() ));
aCrop.SetRight( MM100_TO_TWIP( aScaledCropedRectangle.Right() ));
aCrop.SetBottom( MM100_TO_TWIP( aScaledCropedRectangle.Bottom() ));
Graphic aCompressedGraphic( aDialog.GetCompressedGraphic() );
rSh.ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &aCompressedGraphic);
rSh.SetAttr(aCrop);
rSh.EndUndo(UNDO_END);
rSh.EndAllAction();
}
}
}
break;
case SID_EXTERNAL_EDIT: case SID_EXTERNAL_EDIT:
{ {
/* When the graphic is selected to be opened via some external tool /* When the graphic is selected to be opened via some external tool
......
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