summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2012-07-08 23:36:30 +0200
committerTomaž Vajngerl <quikee@gmail.com>2012-07-09 00:07:22 +0200
commit4d7581b9075d826feebfb095310c74627314a484 (patch)
tree7966b832c69de8c422880afc9e46a334125527d2
parentfix layout issue on Data Bar dialog (diff)
downloadcore-4d7581b9075d826feebfb095310c74627314a484.tar.gz
core-4d7581b9075d826feebfb095310c74627314a484.zip
Compress Graphic functionallity added (currently only for Draw)
This is a initial commit of "Compress Graphics" functionallity. Compress Graphics is accesible via pop-up menu option to graphics objects. Currently this funtionallity is only available in Draw. When the menu option is triggered, a Compress Graphics modal dialog opens to define DPI, compression level and type of compression. When OK is clicked, the graphics in Draw is compressed and exchanged. The current implementation is not final as it needs handling in case when the graphics is croped. Additionally cropped areas could be removed when compressing, depending on a checkbox in the dialog. Special cases of graphics need to be checked too, and some tests would not hurt. Change-Id: I9ec1a71f6ff4364a49b2521e42d88c3ba224dd87
-rw-r--r--sd/sdi/_drvwsh.sdi5
-rw-r--r--sd/source/ui/app/popup2_tmpl.src1
-rw-r--r--sd/source/ui/view/drviews2.cxx34
-rw-r--r--sd/source/ui/view/drviewsj.cxx6
-rw-r--r--svx/AllLangResTarget_svx.mk1
-rw-r--r--svx/Library_svx.mk3
-rw-r--r--svx/Package_inc.mk1
-rw-r--r--svx/inc/globlmn_tmpl.hrc5
-rw-r--r--svx/inc/svx/compressgraphicdialog.hxx69
-rw-r--r--svx/inc/svx/dialogs.hrc1
-rw-r--r--svx/inc/svx/svxids.hrc3
-rw-r--r--svx/sdi/svx.sdi24
-rw-r--r--svx/source/dialog/compressgraphicdialog.cxx241
-rw-r--r--svx/source/dialog/compressgraphicdialog.hrc45
-rw-r--r--svx/source/dialog/compressgraphicdialog.src165
15 files changed, 600 insertions, 4 deletions
diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi
index 7cb4c10ed0c9..4b09d0c9d29a 100644
--- a/sd/sdi/_drvwsh.sdi
+++ b/sd/sdi/_drvwsh.sdi
@@ -75,6 +75,11 @@ interface DrawView
ExecMethod = FuTemporary ;
StateMethod = GetMenuState ;
]
+ SID_COMPRESS_GRAPHIC
+ [
+ ExecMethod = FuTemporary ;
+ StateMethod = GetMenuState ;
+ ]
SID_CUT // ole : no, status : ?
[
ExecMethod = FuSupport ;
diff --git a/sd/source/ui/app/popup2_tmpl.src b/sd/source/ui/app/popup2_tmpl.src
index abf411542ee3..67628796964c 100644
--- a/sd/source/ui/app/popup2_tmpl.src
+++ b/sd/source/ui/app/popup2_tmpl.src
@@ -659,6 +659,7 @@
MN_STYLEDT
SEPARATOR
MenuItem { ITEM_SAVE_GRAPHIC };
+ MenuItem { ITEM_COMPRESS_GRAPHIC };
};
};
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index c4630c2831f2..75ff0f135d49 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -48,6 +48,7 @@
#include <editeng/flditem.hxx>
#include <svx/xlineit0.hxx>
#include <svx/graphichelper.hxx>
+#include <svx/compressgraphicdialog.hxx>
#include <svx/svdoutl.hxx>
#include <svx/xlnwtit.hxx>
#include <svx/svdoattr.hxx>
@@ -949,6 +950,39 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
}
break;
+ case SID_COMPRESS_GRAPHIC:
+ {
+ const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
+ if( rMarkList.GetMarkCount() == 1 )
+ {
+ SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
+ if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
+ {
+ GraphicObject aGraphicObject( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
+ {
+ CompressGraphicsDialog dialog( GetParentWindow(), aGraphicObject.GetGraphic(), pObj->GetLogicRect().GetSize(), GetViewFrame()->GetBindings() );
+ if ( dialog.Execute() == RET_OK )
+ {
+ SdrGrafObj* pNewObject = (SdrGrafObj*) pObj->Clone();
+ const Graphic aNewGraphic = dialog.GetCompressedGraphic();
+ SdrPageView* pPageView = mpDrawView->GetSdrPageView();
+ pNewObject->SetEmptyPresObj( sal_False );
+ pNewObject->SetGraphic( aNewGraphic );
+ String aUndoString( mpDrawView->GetDescriptionOfMarkedObjects() );
+ aUndoString += (sal_Unicode) ( ' ' );
+ aUndoString += String( "Compress" );
+ mpDrawView->BegUndo( aUndoString );
+ mpDrawView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
+ mpDrawView->EndUndo();
+ }
+ }
+ }
+ }
+ Cancel();
+ rReq.Ignore();
+ }
+ break;
+
default:
{
// switch Anweisung wegen CLOOKS aufgeteilt. Alle case-Anweisungen die
diff --git a/sd/source/ui/view/drviewsj.cxx b/sd/source/ui/view/drviewsj.cxx
index d6f2055e4ac5..0706bcdd4e58 100644
--- a/sd/source/ui/view/drviewsj.cxx
+++ b/sd/source/ui/view/drviewsj.cxx
@@ -71,9 +71,9 @@ namespace sd {
void DrawViewShell::GetMenuStateSel( SfxItemSet &rSet )
{
- // Status der Menueintraege, bzw. Buttons
- // Einfachselektion
+ // Status of menu entries (Buttons,...)
+ // Single selection
const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
sal_uLong nMarkCount = rMarkList.GetMarkCount();
@@ -119,6 +119,7 @@ void DrawViewShell::GetMenuStateSel( SfxItemSet &rSet )
SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_REVERSE_ORDER ) ||
SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_ORIGINAL_SIZE ) ||
SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_SAVE_GRAPHIC ) ||
+ SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_COMPRESS_GRAPHIC ) ||
SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_TEXTATTR_DLG ) )
{
const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
@@ -140,6 +141,7 @@ void DrawViewShell::GetMenuStateSel( SfxItemSet &rSet )
if ( !( pObj->ISA( SdrGrafObj ) ) )
{
rSet.DisableItem(SID_SAVE_GRAPHIC);
+ rSet.DisableItem(SID_COMPRESS_GRAPHIC);
}
// Wenn es sich um kein Gruppenobjekt oder 3D-Objekt handelt
diff --git a/svx/AllLangResTarget_svx.mk b/svx/AllLangResTarget_svx.mk
index cae5703fae06..fa4d86cdad1b 100644
--- a/svx/AllLangResTarget_svx.mk
+++ b/svx/AllLangResTarget_svx.mk
@@ -60,6 +60,7 @@ $(eval $(call gb_SrsTarget_add_files,svx/res,\
svx/source/dialog/bmpmask.src \
svx/source/dialog/contdlg.src \
svx/source/dialog/ctredlin.src \
+ svx/source/dialog/compressgraphicdialog.src \
svx/source/dialog/dlgctrl.src \
svx/source/dialog/docrecovery.src \
svx/source/dialog/fontwork.src \
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index 3ce31edd0a48..c84f4d490ddd 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -2,7 +2,7 @@
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
+#
# Copyright 2000, 2011 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
@@ -100,6 +100,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
svx/source/dialog/connctrl \
svx/source/dialog/_contdlg \
svx/source/dialog/contwnd \
+ svx/source/dialog/compressgraphicdialog \
svx/source/dialog/ctredlin \
svx/source/dialog/databaseregistrationui \
svx/source/dialog/dialcontrol \
diff --git a/svx/Package_inc.mk b/svx/Package_inc.mk
index 2490c24e8d80..392dcab57e26 100644
--- a/svx/Package_inc.mk
+++ b/svx/Package_inc.mk
@@ -554,5 +554,6 @@ $(eval $(call gb_Package_add_file,svx_inc,inc/svx/fmdpage.hxx,svx/fmdpage.hxx))
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/sxmtpitm.hxx,svx/sxmtpitm.hxx))
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/extedit.hxx,svx/extedit.hxx))
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/graphichelper.hxx,svx/graphichelper.hxx))
+$(eval $(call gb_Package_add_file,svx_inc,inc/svx/compressgraphicdialog.hxx,svx/compressgraphicdialog.hxx))
# vim: set noet sw=4 ts=4:
diff --git a/svx/inc/globlmn_tmpl.hrc b/svx/inc/globlmn_tmpl.hrc
index 8ab7e4bfeb91..0f56324958ee 100644
--- a/svx/inc/globlmn_tmpl.hrc
+++ b/svx/inc/globlmn_tmpl.hrc
@@ -262,6 +262,11 @@
Command = ".uno:ExternalEdit" ; \
Text [ en-US ] = "Edit with External Tool..." ; \
+#define ITEM_COMPRESS_GRAPHIC \
+ Identifier = SID_COMPRESS_GRAPHIC ; \
+ Command = ".uno:CompressGraphic" ; \
+ Text [ en-US ] = "Compress Graphic..." ; \
+
#define ITEM_SAVE_GRAPHIC \
Identifier = SID_SAVE_GRAPHIC ; \
Command = ".uno:SaveGraphic" ; \
diff --git a/svx/inc/svx/compressgraphicdialog.hxx b/svx/inc/svx/compressgraphicdialog.hxx
new file mode 100644
index 000000000000..a33bb768f79c
--- /dev/null
+++ b/svx/inc/svx/compressgraphicdialog.hxx
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef _COMPRESS_GRAPHICS_DIALOG_HXX
+#define _COMPRESS_GRAPHICS_DIALOG_HXX
+
+#include <vcl/dialog.hxx>
+#include <vcl/button.hxx>
+#include <vcl/fixed.hxx>
+#include <vcl/lstbox.hxx>
+#include <vcl/field.hxx>
+#include <sfx2/bindings.hxx>
+#include "svx/svxdllapi.h"
+
+class SVX_DLLPUBLIC CompressGraphicsDialog : public ModalDialog
+{
+private:
+ FixedText m_aFixedText2X;
+ FixedText m_aFixedText2;
+ FixedText m_aFixedText3X;
+ FixedText m_aFixedText3;
+ FixedText m_aFixedText4X;
+ FixedText m_aFixedText4;
+ FixedText m_aFixedText5X;
+ FixedText m_aFixedText5;
+ FixedText m_aFixedText6X;
+ FixedText m_aFixedText6;
+ ComboBox m_aResolutionLB;
+ MetricField m_aMFQuality;
+ CheckBox m_aLossless;
+ OKButton m_aBtnOK;
+ CancelButton m_aBtnCancel;
+ HelpButton m_aBtnHelp;
+ PushButton m_aBtnCalculate;
+
+ Graphic m_aGraphic;
+ Size m_aViewSize100mm;
+ SfxBindings& m_rBindings;
+
+ DECL_LINK( ResolutionModifiedHdl, void* );
+ DECL_LINK( ClickHdl, void* );
+
+ void Update();
+
+public:
+ CompressGraphicsDialog( Window* pParent, const Graphic& rGraphic, const Size& rViewSize100mm, SfxBindings& rBindings );
+ virtual ~CompressGraphicsDialog();
+
+ Graphic GetCompressedGraphic();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/inc/svx/dialogs.hrc b/svx/inc/svx/dialogs.hrc
index 12ee38a830b2..8d21cfdc46ef 100644
--- a/svx/inc/svx/dialogs.hrc
+++ b/svx/inc/svx/dialogs.hrc
@@ -243,6 +243,7 @@
#define RID_SVXTBX_STYLE (RID_SVX_START + 120)
#define RID_SVXDLG_PASSWORD (RID_SVX_START + 141)
+#define RID_SVXDLG_COMPRESSGRAPHICS (RID_SVX_START + 142)
// Dialog for functions
#define RID_SVXDLG_CALCFUNC (RID_SVX_START + 206)
diff --git a/svx/inc/svx/svxids.hrc b/svx/inc/svx/svxids.hrc
index 6acefcb38208..a932a117bb99 100644
--- a/svx/inc/svx/svxids.hrc
+++ b/svx/inc/svx/svxids.hrc
@@ -936,9 +936,10 @@
#define SID_EXTERNAL_EDIT (SID_SVX_START+1113)
#define SID_ATTR_PAGE_SHARED_FIRST (SID_SVX_START+1114)
#define SID_SAVE_GRAPHIC (SID_SVX_START+1115)
+#define SID_COMPRESS_GRAPHIC (SID_SVX_START+1116)
// IMPORTANT NOTE: adjust SID_SVX_FIRSTFREE, when adding new slot id
-#define SID_SVX_FIRSTFREE (SID_SAVE_GRAPHIC + 1)
+#define SID_SVX_FIRSTFREE (SID_COMPRESS_GRAPHIC + 1)
// --------------------------------------------------------------------------
// Overflow check for slot IDs
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 5344e1764b91..eea97a40a5bd 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -5996,6 +5996,30 @@ SfxVoidItem SaveGraphic SID_SAVE_GRAPHIC
GroupId = GID_MODIFY;
]
+SfxVoidItem CompressGraphic SID_COMPRESS_GRAPHIC
+()
+[
+ /* flags: */
+ AutoUpdate = FALSE,
+ Cachable = Cachable,
+ FastCall = FALSE,
+ HasCoreId = FALSE,
+ HasDialog = FALSE,
+ ReadOnlyDoc = TRUE,
+ Toggle = FALSE,
+ Container = FALSE,
+ RecordAbsolute = FALSE,
+ RecordPerSet;
+ Synchron;
+
+ /* config: */
+ AccelConfig = FALSE,
+ MenuConfig = FALSE,
+ StatusBarConfig = FALSE,
+ ToolBoxConfig = FALSE,
+ GroupId = GID_MODIFY;
+]
+
//--------------------------------------------------------------------------
SfxBoolItem Init3D SID_3D_INIT
diff --git a/svx/source/dialog/compressgraphicdialog.cxx b/svx/source/dialog/compressgraphicdialog.cxx
new file mode 100644
index 000000000000..b1bdb6ad9621
--- /dev/null
+++ b/svx/source/dialog/compressgraphicdialog.cxx
@@ -0,0 +1,241 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <svx/dialogs.hrc>
+#include <svx/dialmgr.hxx>
+#include <vcl/graph.hxx>
+#include <compressgraphicdialog.hrc>
+#include <svx/compressgraphicdialog.hxx>
+#include <dlgunit.hxx>
+#include <vcl/virdev.hxx>
+#include <sfx2/dispatch.hxx>
+#include <vcl/svapp.hxx>
+#include <comphelper/processfactory.hxx>
+#include <svtools/filter.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::beans;
+
+CompressGraphicsDialog::CompressGraphicsDialog( Window* pParent, const Graphic& rGraphic, const Size& rViewSize100mm, SfxBindings& rBindings ) :
+ ModalDialog ( pParent, SVX_RES( RID_SVXDLG_COMPRESSGRAPHICS ) ),
+ m_aFixedText2X ( this, SVX_RES( FT_CG_2_X ) ),
+ m_aFixedText2 ( this, SVX_RES( FT_CG_2 ) ),
+ m_aFixedText3X ( this, SVX_RES( FT_CG_3_X ) ),
+ m_aFixedText3 ( this, SVX_RES( FT_CG_3 ) ),
+ m_aFixedText4X ( this, SVX_RES( FT_CG_4_X ) ),
+ m_aFixedText4 ( this, SVX_RES( FT_CG_4 ) ),
+ m_aFixedText5X ( this, SVX_RES( FT_CG_5_X ) ),
+ m_aFixedText5 ( this, SVX_RES( FT_CG_5 ) ),
+ m_aFixedText6X ( this, SVX_RES( FT_CG_6_X ) ),
+ m_aFixedText6 ( this, SVX_RES( FT_CG_6 ) ),
+ m_aResolutionLB ( this, SVX_RES( LB_CG_RESOLUTION ) ),
+ m_aMFQuality ( this, SVX_RES( MF_CG_QUALITY ) ),
+ m_aLossless ( this, SVX_RES( CB_CG_LOSSLESS ) ),
+ m_aBtnOK ( this, SVX_RES( BUTTON_CG_OK ) ),
+ m_aBtnCancel ( this, SVX_RES( BUTTON_CG_CANCEL ) ),
+ m_aBtnHelp ( this, SVX_RES( BUTTON_CG_HELP ) ),
+ m_aBtnCalculate ( this, SVX_RES( BUTTON_CG_CALCULATE ) ),
+ m_aGraphic ( rGraphic ),
+ m_aViewSize100mm ( rViewSize100mm ),
+ m_rBindings ( rBindings )
+{
+ FreeResource();
+
+ SetStyle(GetStyle() | WB_CENTER | WB_VCENTER);
+ m_aMFQuality.SetValue( 90L );
+ m_aResolutionLB.SetText(String("96 DPI"));
+ m_aResolutionLB.SetModifyHdl( LINK( this, CompressGraphicsDialog, ResolutionModifiedHdl ));
+ m_aBtnCalculate.SetClickHdl( LINK( this, CompressGraphicsDialog, ClickHdl ) );
+ Update();
+}
+
+CompressGraphicsDialog::~CompressGraphicsDialog()
+{
+}
+
+void CompressGraphicsDialog::Update()
+{
+ const FieldUnit eFieldUnit = m_rBindings.GetDispatcher()->GetModule()->GetFieldUnit();
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep()[0];
+
+ VirtualDevice* pDummyVDev = new VirtualDevice();
+ pDummyVDev->EnableOutput( false );
+ pDummyVDev->SetMapMode( m_aGraphic.GetPrefMapMode() );
+
+ Size aPixelSize = m_aGraphic.GetSizePixel();
+ Size aOriginalSize100mm( pDummyVDev->PixelToLogic( m_aGraphic.GetSizePixel(), MAP_100TH_MM ) );
+
+ String aBitmapSizeString;
+ aBitmapSizeString += GetUnitString( aOriginalSize100mm.Width(), eFieldUnit, cSep );
+ aBitmapSizeString += String( " x " ) ;
+ aBitmapSizeString += GetUnitString( aOriginalSize100mm.Height(), eFieldUnit, cSep );
+ aBitmapSizeString += String( " ( " ) ;
+ aBitmapSizeString += UniString::CreateFromInt32(aPixelSize.Width());
+ aBitmapSizeString += String( " x " ) ;
+ aBitmapSizeString += UniString::CreateFromInt32(aPixelSize.Height());
+ aBitmapSizeString += String( " px )" ) ;
+ m_aFixedText2.SetText(aBitmapSizeString);
+
+ String aViewSizeString;
+
+ int aValX = aPixelSize.Width() * 100 / MetricField::ConvertValue(m_aViewSize100mm.Width(), 2, MAP_100TH_MM, FUNIT_INCH);
+ //int aValY = aPixelSize.Height() * 100 / MetricField::ConvertValue(m_aViewSize100mm.Height(), 2, MAP_100TH_MM, FUNIT_INCH);
+
+ aViewSizeString += GetUnitString( m_aViewSize100mm.Width(), eFieldUnit, cSep );
+ aViewSizeString += String( " x " ) ;
+ aViewSizeString += GetUnitString( m_aViewSize100mm.Height(), eFieldUnit, cSep );
+ aViewSizeString += ( " at " ) ;
+ aViewSizeString += UniString::CreateFromInt32(aValX);
+ aViewSizeString += ( " DPI" ) ;
+ m_aFixedText3.SetText(aViewSizeString);
+
+ int aResolution = m_aResolutionLB.GetText().ToInt32();
+ int nPixelX = (sal_Int32)((double)MetricField::ConvertValue(m_aViewSize100mm.Width(), 2, MAP_100TH_MM, FUNIT_INCH) / 100 * aResolution );
+ int nPixelY = (sal_Int32)((double)MetricField::ConvertValue(m_aViewSize100mm.Height(), 2, MAP_100TH_MM, FUNIT_INCH) / 100 * aResolution );
+
+ SvMemoryStream aMemStream;
+ aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+ m_aGraphic.ExportNative(aMemStream);
+ aMemStream.Seek( STREAM_SEEK_TO_END );
+ sal_Int32 aNativeSize = aMemStream.Tell();
+
+ String aCompressedSizeString;
+ aCompressedSizeString += UniString::CreateFromInt32(nPixelX);
+ aCompressedSizeString += String( " x " ) ;
+ aCompressedSizeString += UniString::CreateFromInt32(nPixelY);
+ aCompressedSizeString += ( " at " ) ;
+ aCompressedSizeString += UniString::CreateFromInt32(aResolution);
+ aCompressedSizeString += ( " DPI" ) ;
+ m_aFixedText4.SetText(aCompressedSizeString);
+
+ String aNativeSizeString;
+ aNativeSizeString += UniString::CreateFromInt32(aNativeSize / 1024);
+ aNativeSizeString += String( " kiB" ) ;
+
+ m_aFixedText5.SetText(aNativeSizeString);
+ m_aFixedText6.SetText(String("??"));
+}
+
+IMPL_LINK_NOARG( CompressGraphicsDialog, ResolutionModifiedHdl )
+{
+ Update();
+ return 0L;
+}
+
+IMPL_LINK_NOARG( CompressGraphicsDialog, ClickHdl )
+{
+ int aResolution = m_aResolutionLB.GetText().ToInt32();
+ sal_Int32 aSize = 0;
+
+ if ( aResolution > 0 )
+ {
+ long nPixelX = (long)((double) MetricField::ConvertValue(m_aViewSize100mm.Width(), 2, MAP_100TH_MM, FUNIT_INCH) / 100.0 * (double) aResolution );
+ long nPixelY = (long)((double) MetricField::ConvertValue(m_aViewSize100mm.Height(), 2, MAP_100TH_MM, FUNIT_INCH) / 100.0 * (double) aResolution );
+
+ BitmapEx bitmap = m_aGraphic.GetBitmapEx();
+ bitmap.Scale(Size(nPixelX, nPixelY), BMP_SCALE_BEST);
+ Graphic aScaledGraphic = Graphic (bitmap);
+ GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+
+ Sequence< PropertyValue > aFilterData( 3 );
+ aFilterData[ 0 ].Name = "Interlaced";
+ aFilterData[ 0 ].Value <<= (sal_Int32) 0;
+ aFilterData[ 1 ].Name = "Compression";
+ aFilterData[ 1 ].Value <<= (sal_Int32) 9;
+ aFilterData[ 2 ].Name = "Quality";
+ aFilterData[ 2 ].Value <<= (sal_Int32) m_aMFQuality.GetValue();
+
+ SvMemoryStream aMemStream;
+ aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+
+ if ( m_aLossless.IsChecked() )
+ {
+ sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( String( "png" ) );
+ rFilter.ExportGraphic( aScaledGraphic, String("test.png"), aMemStream, nFilterFormat, &aFilterData );
+ aMemStream.Seek( STREAM_SEEK_TO_END );
+ aSize = aMemStream.Tell();
+ }
+ else
+ {
+ sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( String( "jpg" ) );
+ rFilter.ExportGraphic( aScaledGraphic, String("test.jpg"), aMemStream, nFilterFormat, &aFilterData );
+ aMemStream.Seek( STREAM_SEEK_TO_END );
+ aSize = aMemStream.Tell();
+ }
+ }
+
+ if ( aSize > 0 )
+ {
+ String aNewSizeString;
+ aNewSizeString += UniString::CreateFromInt32(aSize / 1024);
+ aNewSizeString += String( " kiB" ) ;
+ m_aFixedText6.SetText(aNewSizeString);
+ }
+ return 0L;
+}
+
+Graphic CompressGraphicsDialog::GetCompressedGraphic()
+{
+ int aResolution = m_aResolutionLB.GetText().ToInt32();
+
+ if ( aResolution > 0 )
+ {
+ long nPixelX = (long)((double) MetricField::ConvertValue( m_aViewSize100mm.Width(), 2, MAP_100TH_MM, FUNIT_INCH) / 100.0 * (double) aResolution );
+ long nPixelY = (long)((double) MetricField::ConvertValue( m_aViewSize100mm.Height(), 2, MAP_100TH_MM, FUNIT_INCH) / 100.0 * (double) aResolution );
+
+ BitmapEx bitmap = m_aGraphic.GetBitmapEx();
+ bitmap.Scale(Size(nPixelX, nPixelY), BMP_SCALE_BEST);
+ Graphic aScaledGraphic = Graphic (bitmap);
+ GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+
+ Sequence< PropertyValue > aFilterData( 3 );
+ aFilterData[ 0 ].Name = "Interlaced";
+ aFilterData[ 0 ].Value <<= (sal_Int32) 0;
+ aFilterData[ 1 ].Name = "Compression";
+ aFilterData[ 1 ].Value <<= (sal_Int32) 9;
+ aFilterData[ 2 ].Name = "Quality";
+ aFilterData[ 2 ].Value <<= (sal_Int32) m_aMFQuality.GetValue();
+
+ SvMemoryStream aMemStream;
+ aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+ Graphic aResultGraphic = Graphic ();
+
+ if ( m_aLossless.IsChecked() )
+ {
+ sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( String( "png" ) );
+ rFilter.ExportGraphic( aScaledGraphic, String("test.png"), aMemStream, nFilterFormat, &aFilterData );
+ aMemStream.Seek( STREAM_SEEK_TO_BEGIN );
+ rFilter.ImportGraphic( aResultGraphic, String("test.png"), aMemStream );
+ }
+ else
+ {
+ sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( String( "jpg" ) );
+ rFilter.ExportGraphic( aScaledGraphic, String("test.jpg"), aMemStream, nFilterFormat, &aFilterData );
+ aMemStream.Seek( STREAM_SEEK_TO_BEGIN );
+ rFilter.ImportGraphic( aResultGraphic, String("test.jpg"), aMemStream );
+ }
+ return aResultGraphic;
+ }
+ return m_aGraphic;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/dialog/compressgraphicdialog.hrc b/svx/source/dialog/compressgraphicdialog.hrc
new file mode 100644
index 000000000000..1b94aa432376
--- /dev/null
+++ b/svx/source/dialog/compressgraphicdialog.hrc
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef _COMPRESS_GRAPHICS_DIALOG_HRC
+#define _COMPRESS_GRAPHICS_DIALOG_HRC
+
+#define FT_CG_2 2
+#define FT_CG_2_X 3
+
+#define FT_CG_3 4
+#define FT_CG_3_X 5
+
+#define FT_CG_4 6
+#define FT_CG_4_X 7
+
+#define FT_CG_5 8
+#define FT_CG_5_X 9
+
+#define FT_CG_6 10
+#define FT_CG_6_X 11
+
+#define LB_CG_RESOLUTION 20
+#define MF_CG_QUALITY 21
+#define CB_CG_LOSSLESS 22
+
+#define BUTTON_CG_OK 30
+#define BUTTON_CG_CANCEL 31
+#define BUTTON_CG_HELP 32
+#define BUTTON_CG_CALCULATE 33
+
+#endif
diff --git a/svx/source/dialog/compressgraphicdialog.src b/svx/source/dialog/compressgraphicdialog.src
new file mode 100644
index 000000000000..a336fd1906fe
--- /dev/null
+++ b/svx/source/dialog/compressgraphicdialog.src
@@ -0,0 +1,165 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <svx/dialogs.hrc>
+#include "helpid.hrc"
+#include "compressgraphicdialog.hrc"
+
+ModalDialog RID_SVXDLG_COMPRESSGRAPHICS
+{
+ HelpID = "svx:ModalDialog:RID_SVXDLG_COMPRESSGRAPHICS";
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 226 , 200 ) ;
+ Moveable = TRUE ;
+ Sizeable = TRUE ;
+ Closeable = TRUE ;
+ Hide = TRUE ;
+ Text [ en-US ] = "Compress Graphics" ;
+
+ FixedText FT_CG_2_X
+ {
+ Pos = MAP_APPFONT ( 6 , 8 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Text [ en-US ] = "Original Size:" ;
+ };
+
+ FixedText FT_CG_2
+ {
+ Pos = MAP_APPFONT ( 56 , 8 ) ;
+ Size = MAP_APPFONT ( 124 , 10 ) ;
+ };
+
+ FixedText FT_CG_3_X
+ {
+ Pos = MAP_APPFONT ( 6 , 20 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Text [ en-US ] = "View Size:" ;
+ };
+
+ FixedText FT_CG_3
+ {
+ Pos = MAP_APPFONT ( 56 , 20 ) ;
+ Size = MAP_APPFONT ( 124 , 10 ) ;
+ };
+
+ FixedText FT_CG_4_X
+ {
+ Pos = MAP_APPFONT ( 6 , 32 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Text [ en-US ] = "Compressed Size:" ;
+ };
+
+ FixedText FT_CG_4
+ {
+ Pos = MAP_APPFONT ( 56 , 32 ) ;
+ Size = MAP_APPFONT ( 124 , 10 ) ;
+ };
+
+ FixedText FT_CG_5_X
+ {
+ Pos = MAP_APPFONT ( 6 , 44 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Text [ en-US ] = "Image Capacity:" ;
+ };
+
+ FixedText FT_CG_5
+ {
+ Pos = MAP_APPFONT ( 56 , 44 ) ;
+ Size = MAP_APPFONT ( 124 , 10 ) ;
+ };
+
+ FixedText FT_CG_6_X
+ {
+ Pos = MAP_APPFONT ( 6 , 56 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Text [ en-US ] = "New Capacity:" ;
+ };
+
+ FixedText FT_CG_6
+ {
+ Pos = MAP_APPFONT ( 56 , 56 ) ;
+ Size = MAP_APPFONT ( 124 , 10 ) ;
+ };
+
+ ComboBox LB_CG_RESOLUTION
+ {
+ HelpID = "sfx2:ListBox:TP_COMMONPRINTOPTIONS:LB_REDUCEBITMAPS_RESOLUTION";
+ TabStop = TRUE;
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6, 68 ) ;
+ Size = MAP_APPFONT ( 60, 100 ) ;
+ DropDown = TRUE;
+ StringList [ en-US ] =
+ {
+ "75 DPI";
+ "96 DPI";
+ "150 DPI";
+ "200 DPI";
+ "300 DPI";
+ "600 DPI";
+ };
+ };
+
+ MetricField MF_CG_QUALITY
+ {
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70, 68 ) ;
+ Size = MAP_APPFONT ( 29 , 12 ) ;
+ TabStop = TRUE ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Maximum = 99 ;
+ Last = 99 ;
+ SpinSize = 1 ;
+ Unit = FUNIT_PERCENT ;
+ };
+
+ CheckBox CB_CG_LOSSLESS
+ {
+ Pos = MAP_APPFONT ( 6 , 80 ) ;
+ Size = MAP_APPFONT ( 118 , 10 ) ;
+ Text [ en-US ] = "Lossless";
+ };
+
+ OKButton BUTTON_CG_OK
+ {
+ Pos = MAP_APPFONT ( 170 , 6 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ DefButton = TRUE ;
+ };
+
+ CancelButton BUTTON_CG_CANCEL
+ {
+ Pos = MAP_APPFONT ( 170 , 23 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+
+ HelpButton BUTTON_CG_HELP
+ {
+ Pos = MAP_APPFONT ( 170 , 43 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+
+ PushButton BUTTON_CG_CALCULATE
+ {
+ Pos = MAP_APPFONT ( 170 , 63 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "Calculate";
+ };
+};