2012-07-08 23:36:30 +02:00
|
|
|
/* -*- 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 .
|
|
|
|
*/
|
|
|
|
|
2017-10-23 22:30:42 +02:00
|
|
|
#include "dlgunit.hxx"
|
2016-06-22 17:26:05 -07:00
|
|
|
#include <vcl/fixed.hxx>
|
2012-12-09 22:34:32 +01:00
|
|
|
#include <vcl/graph.hxx>
|
2013-01-02 22:07:41 +01:00
|
|
|
#include <vcl/graphicfilter.hxx>
|
2016-06-22 17:26:05 -07:00
|
|
|
#include <vcl/lstbox.hxx>
|
2012-07-08 23:36:30 +02:00
|
|
|
#include <vcl/virdev.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
2014-01-02 23:52:37 +01:00
|
|
|
#include <vcl/settings.hxx>
|
2016-06-22 17:26:05 -07:00
|
|
|
#include <vcl/slider.hxx>
|
2017-06-11 20:56:30 +01:00
|
|
|
#include <svx/strings.hrc>
|
2012-12-09 22:34:32 +01:00
|
|
|
#include <svx/svdograf.hxx>
|
|
|
|
#include <svx/sdgcpitm.hxx>
|
|
|
|
#include <svx/dialmgr.hxx>
|
|
|
|
#include <svx/compressgraphicdialog.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
2012-07-08 23:36:30 +02:00
|
|
|
#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;
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
CompressGraphicsDialog::CompressGraphicsDialog( vcl::Window* pParent, SdrGrafObj* pGraphicObj, SfxBindings& rBindings ) :
|
2012-12-09 22:34:32 +01:00
|
|
|
ModalDialog ( pParent, "CompressGraphicDialog", "svx/ui/compressgraphicdialog.ui" ),
|
|
|
|
m_pGraphicObj ( pGraphicObj ),
|
|
|
|
m_aGraphic ( pGraphicObj->GetGraphicObject().GetGraphic() ),
|
|
|
|
m_aViewSize100mm ( pGraphicObj->GetLogicRect().GetSize() ),
|
2013-02-24 13:45:47 +01:00
|
|
|
m_rBindings ( rBindings ),
|
|
|
|
m_dResolution ( 96.0 )
|
|
|
|
{
|
2014-10-17 15:43:45 +02:00
|
|
|
const SdrGrafCropItem& rCrop = static_cast<const SdrGrafCropItem&>( m_pGraphicObj->GetMergedItem(SDRATTR_GRAFCROP) );
|
2017-03-30 20:27:55 +02:00
|
|
|
m_aCropRectangle = tools::Rectangle(rCrop.GetLeft(), rCrop.GetTop(), rCrop.GetRight(), rCrop.GetBottom());
|
2013-02-24 13:45:47 +01:00
|
|
|
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2017-07-28 14:53:10 +02:00
|
|
|
CompressGraphicsDialog::CompressGraphicsDialog( vcl::Window* pParent, Graphic const & rGraphic, Size rViewSize100mm, tools::Rectangle const & rCropRectangle, SfxBindings& rBindings ) :
|
2013-02-24 13:45:47 +01:00
|
|
|
ModalDialog ( pParent, "CompressGraphicDialog", "svx/ui/compressgraphicdialog.ui" ),
|
2015-11-10 10:25:28 +01:00
|
|
|
m_pGraphicObj ( nullptr ),
|
2013-02-24 13:45:47 +01:00
|
|
|
m_aGraphic ( rGraphic ),
|
|
|
|
m_aViewSize100mm ( rViewSize100mm ),
|
|
|
|
m_aCropRectangle ( rCropRectangle ),
|
2012-12-09 22:34:32 +01:00
|
|
|
m_rBindings ( rBindings ),
|
|
|
|
m_dResolution ( 96.0 )
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
2012-07-15 22:22:45 +02:00
|
|
|
|
2015-03-09 14:29:30 +02:00
|
|
|
CompressGraphicsDialog::~CompressGraphicsDialog()
|
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-03-09 14:29:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompressGraphicsDialog::dispose()
|
|
|
|
{
|
|
|
|
m_pLabelGraphicType.clear();
|
|
|
|
m_pFixedText2.clear();
|
|
|
|
m_pFixedText3.clear();
|
|
|
|
m_pFixedText5.clear();
|
|
|
|
m_pFixedText6.clear();
|
|
|
|
m_pReduceResolutionCB.clear();
|
|
|
|
m_pMFNewWidth.clear();
|
|
|
|
m_pMFNewHeight.clear();
|
|
|
|
m_pResolutionLB.clear();
|
|
|
|
m_pLosslessRB.clear();
|
|
|
|
m_pJpegCompRB.clear();
|
|
|
|
m_pCompressionMF.clear();
|
|
|
|
m_pQualityMF.clear();
|
|
|
|
m_pBtnCalculate.clear();
|
|
|
|
m_pInterpolationCombo.clear();
|
2016-06-30 14:09:31 +02:00
|
|
|
m_pCompressionSlider.clear();
|
|
|
|
m_pQualitySlider.clear();
|
2015-03-09 14:29:30 +02:00
|
|
|
ModalDialog::dispose();
|
|
|
|
}
|
|
|
|
|
2012-12-09 22:34:32 +01:00
|
|
|
void CompressGraphicsDialog::Initialize()
|
|
|
|
{
|
2013-04-25 22:53:58 +02:00
|
|
|
get(m_pLabelGraphicType, "label-graphic-type");
|
2012-12-11 14:05:09 +00:00
|
|
|
get(m_pFixedText2, "label-original-size");
|
|
|
|
get(m_pFixedText3, "label-view-size");
|
|
|
|
get(m_pFixedText5, "label-image-capacity");
|
|
|
|
get(m_pFixedText6, "label-new-capacity");
|
|
|
|
get(m_pJpegCompRB, "radio-jpeg");
|
|
|
|
get(m_pCompressionMF, "spin-compression");
|
2015-05-23 18:53:12 +09:00
|
|
|
get(m_pCompressionSlider, "scale-compression");
|
2012-12-11 14:05:09 +00:00
|
|
|
get(m_pLosslessRB, "radio-lossless");
|
|
|
|
get(m_pQualityMF, "spin-quality");
|
2015-05-23 18:53:12 +09:00
|
|
|
get(m_pQualitySlider, "scale-quality");
|
2012-12-11 14:05:09 +00:00
|
|
|
get(m_pReduceResolutionCB, "checkbox-reduce-resolution");
|
|
|
|
get(m_pMFNewWidth, "spin-new-width");
|
|
|
|
get(m_pMFNewHeight, "spin-new-height");
|
|
|
|
get(m_pResolutionLB, "combo-resolution");
|
|
|
|
get(m_pBtnCalculate, "calculate");
|
|
|
|
get(m_pInterpolationCombo, "interpolation-method-combo");
|
|
|
|
|
2015-11-06 09:37:52 +01:00
|
|
|
m_pInterpolationCombo->SelectEntry( "Lanczos" );
|
2012-12-11 14:05:09 +00:00
|
|
|
|
2016-07-13 12:16:34 +01:00
|
|
|
m_pInterpolationCombo->SetSelectHdl( LINK( this, CompressGraphicsDialog, NewInterpolationModifiedHdl ));
|
|
|
|
|
2012-12-11 14:05:09 +00:00
|
|
|
m_pMFNewWidth->SetModifyHdl( LINK( this, CompressGraphicsDialog, NewWidthModifiedHdl ));
|
|
|
|
m_pMFNewHeight->SetModifyHdl( LINK( this, CompressGraphicsDialog, NewHeightModifiedHdl ));
|
|
|
|
|
|
|
|
m_pResolutionLB->SetModifyHdl( LINK( this, CompressGraphicsDialog, ResolutionModifiedHdl ));
|
|
|
|
m_pBtnCalculate->SetClickHdl( LINK( this, CompressGraphicsDialog, CalculateClickHdl ) );
|
|
|
|
|
|
|
|
m_pLosslessRB->SetToggleHdl( LINK( this, CompressGraphicsDialog, ToggleCompressionRB ) );
|
|
|
|
m_pJpegCompRB->SetToggleHdl( LINK( this, CompressGraphicsDialog, ToggleCompressionRB ) );
|
|
|
|
|
|
|
|
m_pReduceResolutionCB->SetToggleHdl( LINK( this, CompressGraphicsDialog, ToggleReduceResolutionRB ) );
|
|
|
|
|
2015-05-23 18:53:12 +09:00
|
|
|
m_pQualitySlider->SetLinkedField(m_pQualityMF);
|
2016-07-13 12:16:34 +01:00
|
|
|
m_pQualitySlider->SetEndSlideHdl( LINK( this, CompressGraphicsDialog, EndSlideHdl ));
|
2015-05-23 18:53:12 +09:00
|
|
|
m_pCompressionSlider->SetLinkedField(m_pCompressionMF);
|
2016-07-13 12:16:34 +01:00
|
|
|
m_pCompressionSlider->SetEndSlideHdl( LINK( this, CompressGraphicsDialog, EndSlideHdl ));
|
|
|
|
m_pQualityMF->SetModifyHdl( LINK( this, CompressGraphicsDialog, NewQualityModifiedHdl ));
|
|
|
|
m_pCompressionMF->SetModifyHdl( LINK( this, CompressGraphicsDialog, NewCompressionModifiedHdl ));
|
2015-05-23 18:53:12 +09:00
|
|
|
|
2012-12-11 14:05:09 +00:00
|
|
|
m_pJpegCompRB->Check();
|
|
|
|
m_pReduceResolutionCB->Check();
|
2012-07-15 22:22:45 +02:00
|
|
|
|
|
|
|
UpdateNewWidthMF();
|
|
|
|
UpdateNewHeightMF();
|
|
|
|
UpdateResolutionLB();
|
2012-07-08 23:36:30 +02:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompressGraphicsDialog::Update()
|
|
|
|
{
|
2013-04-25 22:53:58 +02:00
|
|
|
GfxLinkType aLinkType = m_aGraphic.GetLink().GetType();
|
|
|
|
OUString aGraphicTypeString;
|
|
|
|
switch(aLinkType)
|
|
|
|
{
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativeGif:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_GIF);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativeJpg:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_JPEG);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativePng:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_PNG);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativeTif:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_TIFF);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativeWmf:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_WMF);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativeMet:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_MET);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativePct:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_PCT);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativeSvg:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_SVG);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
2016-05-30 10:24:32 +02:00
|
|
|
case GfxLinkType::NativeBmp:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_BMP);
|
2014-02-27 13:46:24 +00:00
|
|
|
break;
|
2013-04-25 22:53:58 +02:00
|
|
|
default:
|
2017-05-18 21:14:00 +01:00
|
|
|
aGraphicTypeString = SvxResId(STR_IMAGE_UNKNOWN);
|
2013-04-25 22:53:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_pLabelGraphicType->SetText(aGraphicTypeString);
|
|
|
|
|
2012-07-08 23:36:30 +02:00
|
|
|
const FieldUnit eFieldUnit = m_rBindings.GetDispatcher()->GetModule()->GetFieldUnit();
|
2012-11-22 19:48:13 +01:00
|
|
|
const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
|
2012-12-09 22:34:32 +01:00
|
|
|
sal_Unicode cSeparator = rLocaleWrapper.getNumDecimalSep()[0];
|
2012-07-08 23:36:30 +02:00
|
|
|
|
2017-05-14 00:40:21 +02:00
|
|
|
ScopedVclPtrInstance<VirtualDevice> pDummyVDev;
|
2012-07-08 23:36:30 +02:00
|
|
|
pDummyVDev->EnableOutput( false );
|
|
|
|
pDummyVDev->SetMapMode( m_aGraphic.GetPrefMapMode() );
|
|
|
|
|
|
|
|
Size aPixelSize = m_aGraphic.GetSizePixel();
|
2016-09-20 16:41:39 +02:00
|
|
|
Size aOriginalSize100mm( pDummyVDev->PixelToLogic( m_aGraphic.GetSizePixel(), MapUnit::Map100thMM ) );
|
2012-07-08 23:36:30 +02:00
|
|
|
|
2017-05-18 21:14:00 +01:00
|
|
|
OUString aBitmapSizeString = SvxResId(STR_IMAGE_ORIGINAL_SIZE);
|
2013-02-21 18:39:22 +01:00
|
|
|
OUString aWidthString = GetUnitString( aOriginalSize100mm.Width(), eFieldUnit, cSeparator );
|
|
|
|
OUString aHeightString = GetUnitString( aOriginalSize100mm.Height(), eFieldUnit, cSeparator );
|
2013-07-13 20:12:42 +01:00
|
|
|
aBitmapSizeString = aBitmapSizeString.replaceAll("$(WIDTH)", aWidthString);
|
|
|
|
aBitmapSizeString = aBitmapSizeString.replaceAll("$(HEIGHT)", aHeightString);
|
2013-08-21 15:07:31 +02:00
|
|
|
aBitmapSizeString = aBitmapSizeString.replaceAll("$(WIDTH_IN_PX)", OUString::number(aPixelSize.Width()));
|
|
|
|
aBitmapSizeString = aBitmapSizeString.replaceAll("$(HEIGHT_IN_PX)", OUString::number(aPixelSize.Height()));
|
2012-12-11 14:05:09 +00:00
|
|
|
m_pFixedText2->SetText(aBitmapSizeString);
|
2012-07-08 23:36:30 +02:00
|
|
|
|
2012-07-24 20:21:22 +02:00
|
|
|
int aValX = (int) (aPixelSize.Width() / GetViewWidthInch());
|
2012-07-08 23:36:30 +02:00
|
|
|
|
2017-05-18 21:14:00 +01:00
|
|
|
OUString aViewSizeString = SvxResId(STR_IMAGE_VIEW_SIZE);
|
2013-02-21 18:39:22 +01:00
|
|
|
|
|
|
|
aWidthString = GetUnitString( m_aViewSize100mm.Width(), eFieldUnit, cSeparator );
|
|
|
|
aHeightString = GetUnitString( m_aViewSize100mm.Height(), eFieldUnit, cSeparator );
|
2013-07-13 20:12:42 +01:00
|
|
|
aViewSizeString = aViewSizeString.replaceAll("$(WIDTH)", aWidthString);
|
|
|
|
aViewSizeString = aViewSizeString.replaceAll("$(HEIGHT)", aHeightString);
|
|
|
|
aViewSizeString = aViewSizeString.replaceAll("$(DPI)", OUString::number(aValX));
|
2012-12-11 14:05:09 +00:00
|
|
|
m_pFixedText3->SetText(aViewSizeString);
|
2012-07-08 23:36:30 +02:00
|
|
|
|
|
|
|
SvMemoryStream aMemStream;
|
|
|
|
aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
|
|
|
|
m_aGraphic.ExportNative(aMemStream);
|
|
|
|
aMemStream.Seek( STREAM_SEEK_TO_END );
|
|
|
|
sal_Int32 aNativeSize = aMemStream.Tell();
|
|
|
|
|
2017-05-18 21:14:00 +01:00
|
|
|
OUString aNativeSizeString = SvxResId(STR_IMAGE_CAPACITY);
|
2013-08-21 15:07:31 +02:00
|
|
|
aNativeSizeString = aNativeSizeString.replaceAll("$(CAPACITY)", OUString::number(aNativeSize / 1024));
|
2012-12-11 14:05:09 +00:00
|
|
|
m_pFixedText5->SetText(aNativeSizeString);
|
2013-02-21 18:39:22 +01:00
|
|
|
|
2013-09-20 09:49:51 +02:00
|
|
|
m_pFixedText6->SetText("??");
|
2012-07-08 23:36:30 +02:00
|
|
|
}
|
|
|
|
|
2012-07-15 22:22:45 +02:00
|
|
|
void CompressGraphicsDialog::UpdateNewWidthMF()
|
|
|
|
{
|
2012-07-24 20:21:22 +02:00
|
|
|
int nPixelX = (sal_Int32)( GetViewWidthInch() * m_dResolution );
|
2013-01-20 13:55:09 +01:00
|
|
|
m_pMFNewWidth->SetText( OUString::number( nPixelX ));
|
2012-07-15 22:22:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompressGraphicsDialog::UpdateNewHeightMF()
|
|
|
|
{
|
2012-07-24 20:21:22 +02:00
|
|
|
int nPixelY = (sal_Int32)( GetViewHeightInch() * m_dResolution );
|
2013-01-20 13:55:09 +01:00
|
|
|
m_pMFNewHeight->SetText( OUString::number( nPixelY ));
|
2012-07-15 22:22:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompressGraphicsDialog::UpdateResolutionLB()
|
|
|
|
{
|
2013-08-21 15:07:31 +02:00
|
|
|
m_pResolutionLB->SetText( OUString::number( (sal_Int32) m_dResolution ) );
|
2012-07-15 22:22:45 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 20:21:22 +02:00
|
|
|
double CompressGraphicsDialog::GetViewWidthInch()
|
|
|
|
{
|
2016-09-20 16:41:39 +02:00
|
|
|
return (double) MetricField::ConvertValue(m_aViewSize100mm.Width(), 2, MapUnit::Map100thMM, FUNIT_INCH) / 100.0;
|
2012-07-24 20:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double CompressGraphicsDialog::GetViewHeightInch()
|
|
|
|
{
|
2016-09-20 16:41:39 +02:00
|
|
|
return (double) MetricField::ConvertValue(m_aViewSize100mm.Height(), 2, MapUnit::Map100thMM, FUNIT_INCH) / 100.0;
|
2012-07-24 20:21:22 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:09:24 +02:00
|
|
|
BmpScaleFlag CompressGraphicsDialog::GetSelectedInterpolationType()
|
2012-07-24 20:21:22 +02:00
|
|
|
{
|
2017-09-14 16:50:25 +02:00
|
|
|
OUString aSelectionText = m_pInterpolationCombo->GetSelectedEntry();
|
2012-12-09 22:34:32 +01:00
|
|
|
|
|
|
|
if( aSelectionText == "Lanczos" ) {
|
2015-05-05 14:09:24 +02:00
|
|
|
return BmpScaleFlag::Lanczos;
|
2012-12-09 22:34:32 +01:00
|
|
|
} else if( aSelectionText == "Bilinear" ) {
|
2015-05-05 14:09:24 +02:00
|
|
|
return BmpScaleFlag::BiLinear;
|
2012-12-09 22:34:32 +01:00
|
|
|
} else if( aSelectionText == "Bicubic" ) {
|
2015-05-05 14:09:24 +02:00
|
|
|
return BmpScaleFlag::BiCubic;
|
2012-12-09 22:34:32 +01:00
|
|
|
} else if ( aSelectionText == "None" ) {
|
2015-05-05 14:09:24 +02:00
|
|
|
return BmpScaleFlag::Fast;
|
2012-12-09 22:34:32 +01:00
|
|
|
}
|
2015-05-05 14:09:24 +02:00
|
|
|
return BmpScaleFlag::BestQuality;
|
2012-12-09 22:34:32 +01:00
|
|
|
}
|
2012-07-24 20:21:22 +02:00
|
|
|
|
2012-12-09 22:34:32 +01:00
|
|
|
void CompressGraphicsDialog::Compress(SvStream& aStream)
|
|
|
|
{
|
2013-02-24 13:45:47 +01:00
|
|
|
BitmapEx aBitmap = m_aGraphic.GetBitmapEx();
|
2012-12-11 14:05:09 +00:00
|
|
|
if ( m_pReduceResolutionCB->IsChecked() )
|
2012-07-24 20:21:22 +02:00
|
|
|
{
|
2012-12-09 22:34:32 +01:00
|
|
|
long nPixelX = (long)( GetViewWidthInch() * m_dResolution );
|
|
|
|
long nPixelY = (long)( GetViewHeightInch() * m_dResolution );
|
|
|
|
|
2013-02-24 13:45:47 +01:00
|
|
|
aBitmap.Scale( Size( nPixelX, nPixelY ), GetSelectedInterpolationType() );
|
2012-07-24 20:21:22 +02:00
|
|
|
}
|
2013-02-24 13:45:47 +01:00
|
|
|
Graphic aScaledGraphic( aBitmap );
|
2012-07-24 20:21:22 +02:00
|
|
|
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
|
|
|
|
Sequence< PropertyValue > aFilterData( 3 );
|
|
|
|
aFilterData[ 0 ].Name = "Interlaced";
|
|
|
|
aFilterData[ 0 ].Value <<= (sal_Int32) 0;
|
|
|
|
aFilterData[ 1 ].Name = "Compression";
|
2012-12-11 14:05:09 +00:00
|
|
|
aFilterData[ 1 ].Value <<= (sal_Int32) m_pCompressionMF->GetValue();
|
2012-07-24 20:21:22 +02:00
|
|
|
aFilterData[ 2 ].Name = "Quality";
|
2012-12-11 14:05:09 +00:00
|
|
|
aFilterData[ 2 ].Value <<= (sal_Int32) m_pQualityMF->GetValue();
|
2012-07-24 20:21:22 +02:00
|
|
|
|
2013-09-04 15:29:16 +02:00
|
|
|
OUString aGraphicFormatName = m_pLosslessRB->IsChecked() ? OUString( "png" ) : OUString( "jpg" );
|
2012-07-24 20:21:22 +02:00
|
|
|
|
|
|
|
sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( aGraphicFormatName );
|
2015-11-06 09:37:52 +01:00
|
|
|
rFilter.ExportGraphic( aScaledGraphic, "none", aStream, nFilterFormat, &aFilterData );
|
2012-07-24 20:21:22 +02:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, NewWidthModifiedHdl, Edit&, void )
|
2012-07-15 22:22:45 +02:00
|
|
|
{
|
2016-07-13 12:16:34 +01:00
|
|
|
fprintf(stderr, "NewWidthModifiedHdl\n");
|
|
|
|
|
2012-12-11 14:05:09 +00:00
|
|
|
m_dResolution = m_pMFNewWidth->GetValue() / GetViewWidthInch();
|
2012-07-15 22:22:45 +02:00
|
|
|
|
|
|
|
UpdateNewHeightMF();
|
|
|
|
UpdateResolutionLB();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, EndSlideHdl, Slider*, void )
|
2016-07-13 12:16:34 +01:00
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, NewInterpolationModifiedHdl, ListBox&, void )
|
2016-07-13 12:16:34 +01:00
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, NewQualityModifiedHdl, Edit&, void )
|
2016-07-13 12:16:34 +01:00
|
|
|
{
|
|
|
|
m_pQualitySlider->SetThumbPos(m_pQualityMF->GetValue());
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, NewCompressionModifiedHdl, Edit&, void )
|
2016-07-13 12:16:34 +01:00
|
|
|
{
|
|
|
|
m_pCompressionSlider->SetThumbPos(m_pCompressionMF->GetValue());
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, NewHeightModifiedHdl, Edit&, void )
|
2012-07-15 22:22:45 +02:00
|
|
|
{
|
2012-12-11 14:05:09 +00:00
|
|
|
m_dResolution = m_pMFNewHeight->GetValue() / GetViewHeightInch();
|
2012-07-15 22:22:45 +02:00
|
|
|
|
|
|
|
UpdateNewWidthMF();
|
|
|
|
UpdateResolutionLB();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, ResolutionModifiedHdl, Edit&, void )
|
2012-07-08 23:36:30 +02:00
|
|
|
{
|
2013-01-21 14:32:09 +01:00
|
|
|
m_dResolution = (double) m_pResolutionLB->GetText().toInt32();
|
2012-07-15 22:22:45 +02:00
|
|
|
|
|
|
|
UpdateNewWidthMF();
|
|
|
|
UpdateNewHeightMF();
|
2012-07-08 23:36:30 +02:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, ToggleCompressionRB, RadioButton&, void )
|
2012-07-15 22:22:45 +02:00
|
|
|
{
|
2012-12-11 14:05:09 +00:00
|
|
|
bool choice = m_pLosslessRB->IsChecked();
|
|
|
|
m_pCompressionMF->Enable(choice);
|
2015-05-23 18:53:12 +09:00
|
|
|
m_pCompressionSlider->Enable(choice);
|
2012-12-11 14:05:09 +00:00
|
|
|
m_pQualityMF->Enable(!choice);
|
2015-05-23 18:53:12 +09:00
|
|
|
m_pQualitySlider->Enable(!choice);
|
2016-07-13 12:16:34 +01:00
|
|
|
Update();
|
2012-07-15 22:22:45 +02:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, ToggleReduceResolutionRB, CheckBox&, void )
|
2012-07-15 22:22:45 +02:00
|
|
|
{
|
2012-12-11 14:05:09 +00:00
|
|
|
bool choice = m_pReduceResolutionCB->IsChecked();
|
|
|
|
m_pMFNewWidth->Enable(choice);
|
|
|
|
m_pMFNewHeight->Enable(choice);
|
|
|
|
m_pResolutionLB->Enable(choice);
|
|
|
|
m_pInterpolationCombo->Enable(choice);
|
2016-07-13 12:16:34 +01:00
|
|
|
Update();
|
2012-07-15 22:22:45 +02:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl, Button*, void )
|
2012-07-08 23:36:30 +02:00
|
|
|
{
|
|
|
|
sal_Int32 aSize = 0;
|
|
|
|
|
2013-02-24 13:45:47 +01:00
|
|
|
if ( m_dResolution > 0.0 )
|
2012-07-08 23:36:30 +02:00
|
|
|
{
|
|
|
|
SvMemoryStream aMemStream;
|
|
|
|
aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
|
2012-07-24 20:21:22 +02:00
|
|
|
Compress( aMemStream );
|
2012-07-15 22:22:45 +02:00
|
|
|
aMemStream.Seek( STREAM_SEEK_TO_END );
|
|
|
|
aSize = aMemStream.Tell();
|
2012-07-08 23:36:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( aSize > 0 )
|
|
|
|
{
|
2013-08-21 15:07:31 +02:00
|
|
|
OUString aSizeAsString = OUString::number(aSize / 1024);
|
2013-02-21 18:39:22 +01:00
|
|
|
|
2017-05-18 21:14:00 +01:00
|
|
|
OUString aNewSizeString = SvxResId(STR_IMAGE_CAPACITY);
|
2013-07-13 20:12:42 +01:00
|
|
|
aNewSizeString = aNewSizeString.replaceAll("$(CAPACITY)", aSizeAsString);
|
2012-12-11 14:05:09 +00:00
|
|
|
m_pFixedText6->SetText(aNewSizeString);
|
2012-07-08 23:36:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle CompressGraphicsDialog::GetScaledCropRectangle()
|
2012-07-08 23:36:30 +02:00
|
|
|
{
|
2013-02-24 13:45:47 +01:00
|
|
|
if ( m_pReduceResolutionCB->IsChecked() )
|
2012-07-08 23:36:30 +02:00
|
|
|
{
|
2013-02-24 13:45:47 +01:00
|
|
|
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();
|
|
|
|
|
2017-03-30 20:27:55 +02:00
|
|
|
return tools::Rectangle(
|
2013-02-24 13:45:47 +01:00
|
|
|
m_aCropRectangle.Left() * aScaleX,
|
|
|
|
m_aCropRectangle.Top() * aScaleY,
|
|
|
|
m_aCropRectangle.Right() * aScaleX,
|
|
|
|
m_aCropRectangle.Bottom()* aScaleY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_aCropRectangle;
|
|
|
|
}
|
|
|
|
}
|
2012-12-09 22:34:32 +01:00
|
|
|
|
2013-02-24 13:45:47 +01:00
|
|
|
Graphic CompressGraphicsDialog::GetCompressedGraphic()
|
|
|
|
{
|
|
|
|
if ( m_dResolution > 0.0 )
|
|
|
|
{
|
2012-12-09 22:34:32 +01:00
|
|
|
SvMemoryStream aMemStream;
|
|
|
|
aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
|
|
|
|
Compress( aMemStream );
|
|
|
|
aMemStream.Seek( STREAM_SEEK_TO_BEGIN );
|
|
|
|
Graphic aResultGraphic;
|
2012-07-08 23:36:30 +02:00
|
|
|
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
|
2013-02-24 13:45:47 +01:00
|
|
|
rFilter.ImportGraphic( aResultGraphic, OUString("import"), aMemStream );
|
2012-12-09 22:34:32 +01:00
|
|
|
|
2013-02-24 13:45:47 +01:00
|
|
|
return aResultGraphic;
|
|
|
|
}
|
|
|
|
return Graphic();
|
|
|
|
}
|
|
|
|
|
|
|
|
SdrGrafObj* CompressGraphicsDialog::GetCompressedSdrGrafObj()
|
|
|
|
{
|
|
|
|
if ( m_dResolution > 0.0 )
|
|
|
|
{
|
2015-05-11 12:51:10 +02:00
|
|
|
SdrGrafObj* pNewObject = m_pGraphicObj->Clone();
|
2013-02-24 13:45:47 +01:00
|
|
|
|
|
|
|
if ( m_pReduceResolutionCB->IsChecked() )
|
|
|
|
{
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle aScaledCropedRectangle = GetScaledCropRectangle();
|
2013-02-24 13:45:47 +01:00
|
|
|
SdrGrafCropItem aNewCrop(
|
|
|
|
aScaledCropedRectangle.Left(),
|
|
|
|
aScaledCropedRectangle.Top(),
|
|
|
|
aScaledCropedRectangle.Right(),
|
|
|
|
aScaledCropedRectangle.Bottom());
|
|
|
|
|
|
|
|
pNewObject->SetMergedItem(aNewCrop);
|
|
|
|
}
|
|
|
|
pNewObject->SetGraphic( GetCompressedGraphic() );
|
2012-12-09 22:34:32 +01:00
|
|
|
|
|
|
|
return pNewObject;
|
|
|
|
}
|
2015-11-10 10:25:28 +01:00
|
|
|
return nullptr;
|
2012-12-09 22:34:32 +01:00
|
|
|
}
|
|
|
|
|
2012-07-08 23:36:30 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|