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:
public:
CompressGraphicsDialog( Window* pParent, SdrGrafObj* pGraphicObj, SfxBindings& rBindings );
CompressGraphicsDialog( Window* pParent, Graphic& rGraphic, Size rViewSize100mm, Rectangle& rCropRectangle, SfxBindings& rBindings );
virtual ~CompressGraphicsDialog();
SdrGrafObj* GetCompressedSdrGrafObj();
Graphic GetCompressedGraphic();
Rectangle GetScaledCropRectangle();
};
#endif
......
......@@ -43,7 +43,21 @@ CompressGraphicsDialog::CompressGraphicsDialog( Window* pParent, SdrGrafObj* pGr
m_pGraphicObj ( pGraphicObj ),
m_aGraphic ( pGraphicObj->GetGraphicObject().GetGraphic() ),
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_dResolution ( 96.0 )
{
......@@ -184,15 +198,15 @@ sal_uLong CompressGraphicsDialog::GetSelectedInterpolationType()
void CompressGraphicsDialog::Compress(SvStream& aStream)
{
BitmapEx bitmap = m_aGraphic.GetBitmapEx();
BitmapEx aBitmap = m_aGraphic.GetBitmapEx();
if ( m_pReduceResolutionCB->IsChecked() )
{
long nPixelX = (long)( GetViewWidthInch() * 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();
Sequence< PropertyValue > aFilterData( 3 );
......@@ -206,7 +220,7 @@ void CompressGraphicsDialog::Compress(SvStream& aStream)
String aGraphicFormatName = m_pLosslessRB->IsChecked() ? String( "png" ) : String( "jpg" );
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 )
......@@ -266,7 +280,7 @@ IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl )
{
sal_Int32 aSize = 0;
if ( m_dResolution > 0 )
if ( m_dResolution > 0.0 )
{
SvMemoryStream aMemStream;
aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
......@@ -286,38 +300,63 @@ IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl )
return 0L;
}
SdrGrafObj* CompressGraphicsDialog::GetCompressedSdrGrafObj()
Rectangle CompressGraphicsDialog::GetScaledCropRectangle()
{
if ( m_dResolution > 0 )
if ( m_pReduceResolutionCB->IsChecked() )
{
SdrGrafObj* pNewObject = (SdrGrafObj*) m_pGraphicObj->Clone();
if ( m_pReduceResolutionCB->IsChecked() )
{
const SdrGrafCropItem& rCrop = (const SdrGrafCropItem&) m_pGraphicObj->GetMergedItem(SDRATTR_GRAFCROP);
long nPixelX = (long)( GetViewWidthInch() * m_dResolution );
long nPixelY = (long)( GetViewHeightInch() * m_dResolution );
Size size = m_aGraphic.GetBitmapEx().GetSizePixel();
double aScaleX = nPixelX / (double) size.Width();
double aScaleY = nPixelY / (double) size.Height();
SdrGrafCropItem aNewCrop(
rCrop.GetLeft() * aScaleX,
rCrop.GetTop() * aScaleY,
rCrop.GetRight() * aScaleX,
rCrop.GetBottom()* aScaleY);
pNewObject->SetMergedItem(aNewCrop);
}
long nPixelX = (long)( GetViewWidthInch() * m_dResolution );
long nPixelY = (long)( GetViewHeightInch() * m_dResolution );
Size aSize = m_aGraphic.GetBitmapEx().GetSizePixel();
double aScaleX = nPixelX / (double) aSize.Width();
double aScaleY = nPixelY / (double) aSize.Height();
return Rectangle(
m_aCropRectangle.Left() * aScaleX,
m_aCropRectangle.Top() * aScaleY,
m_aCropRectangle.Right() * aScaleX,
m_aCropRectangle.Bottom()* aScaleY);
}
else
{
return m_aCropRectangle;
}
}
Graphic CompressGraphicsDialog::GetCompressedGraphic()
{
if ( m_dResolution > 0.0 )
{
SvMemoryStream aMemStream;
aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
Compress( aMemStream );
aMemStream.Seek( STREAM_SEEK_TO_BEGIN );
Graphic aResultGraphic;
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;
}
......
......@@ -42,13 +42,18 @@ interface BaseTextGraphic
DisableFlags="SW_DISABLE_ON_PROTECTED_CURSOR";
]
SID_SAVE_GRAPHIC
[
ExecMethod = Execute ;
StateMethod = GetAttrState ;
]
SID_COMPRESS_GRAPHIC
[
ExecMethod = Execute ;
StateMethod = GetAttrState ;
]
SID_EXTERNAL_EDIT
[
ExecMethod = Execute ;
......
......@@ -1286,6 +1286,7 @@ Menu MN_GRF_POPUPMENU
MN_FRM_CAPTION_ITEM
SEPARATOR;
MenuItem { ITEM_SAVE_GRAPHIC };
MenuItem { ITEM_COMPRESS_GRAPHIC };
MenuItem { ITEM_EXTERNAL_EDIT };
SEPARATOR;
MenuItem
......
......@@ -41,6 +41,7 @@
#include <svx/sdgmoitm.hxx>
#include <editeng/brushitem.hxx>
#include <svx/grfflt.hxx>
#include <svx/compressgraphicdialog.hxx>
#include <svx/tbxcolor.hxx>
#include <fmturl.hxx>
#include <view.hxx>
......@@ -115,6 +116,50 @@ void SwGrfShell::Execute(SfxRequest &rReq)
}
}
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:
{
/* 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