29#include <svx/strings.hrc>
39#include <com/sun/star/uno/Sequence.hxx>
48 bool ReduceResolutionCB =
false;
51 bool LosslessRB =
true;
52 bool JpegCompRB =
false;
53 int CompressionMF = 6;
55 int InterpolationCombo = 3;
64 GenericDialogController( pParent,
"svx/ui/compressgraphicdialog.ui",
"CompressGraphicDialog" ),
65 m_xGraphicObj ( pGraphicObj ),
66 m_aGraphic ( pGraphicObj->GetGraphicObject().GetGraphic() ),
67 m_aViewSize100mm ( pGraphicObj->GetLogicRect().GetSize() ),
68 m_rBindings ( rBindings ),
79 GenericDialogController( pParent,
"svx/ui/compressgraphicdialog.ui",
"CompressGraphicDialog" ),
80 m_xGraphicObj ( nullptr ),
81 m_aGraphic (
std::move( aGraphic )),
82 m_aViewSize100mm ( rViewSize100mm ),
83 m_aCropRectangle ( rCropRectangle ),
84 m_rBindings ( rBindings ),
98 if (memp.ReduceResolutionCB && (memp.MFNewWidth > 1))
100 if (memp.ReduceResolutionCB && (memp.MFNewHeight > 1))
175 pDummyVDev->EnableOutput(
false );
181 OUString aBitmapSizeString =
SvxResId(STR_IMAGE_ORIGINAL_SIZE);
182 OUString aWidthString =
GetUnitString( aOriginalSize100mm.
Width(), eFieldUnit, cSeparator );
183 OUString aHeightString =
GetUnitString( aOriginalSize100mm.
Height(), eFieldUnit, cSeparator );
184 aBitmapSizeString = aBitmapSizeString.replaceAll(
"$(WIDTH)", aWidthString);
185 aBitmapSizeString = aBitmapSizeString.replaceAll(
"$(HEIGHT)", aHeightString);
186 aBitmapSizeString = aBitmapSizeString.replaceAll(
"$(WIDTH_IN_PX)", OUString::number(aPixelSize.
Width()));
187 aBitmapSizeString = aBitmapSizeString.replaceAll(
"$(HEIGHT_IN_PX)", OUString::number(aPixelSize.
Height()));
192 OUString aViewSizeString =
SvxResId(STR_IMAGE_VIEW_SIZE);
196 aViewSizeString = aViewSizeString.replaceAll(
"$(WIDTH)", aWidthString);
197 aViewSizeString = aViewSizeString.replaceAll(
"$(HEIGHT)", aHeightString);
198 aViewSizeString = aViewSizeString.replaceAll(
"$(DPI)", OUString::number(aValX));
203 OUString aNativeSizeString =
SvxResId(STR_IMAGE_CAPACITY);
204 aNativeSizeString = aNativeSizeString.replaceAll(
"$(CAPACITY)", OUString::number(
m_aNativeSize / 1024 ));
241 if( aSelectionText ==
"Lanczos" ) {
242 return BmpScaleFlag::Lanczos;
243 }
else if( aSelectionText ==
"Bilinear" ) {
244 return BmpScaleFlag::BiLinear;
245 }
else if( aSelectionText ==
"Bicubic" ) {
246 return BmpScaleFlag::BiCubic;
247 }
else if ( aSelectionText ==
"None" ) {
248 return BmpScaleFlag::Fast;
250 return BmpScaleFlag::BestQuality;
263 Graphic aScaledGraphic( aBitmap );
272 OUString aGraphicFormatName =
m_xLosslessRB->get_active() ? OUString(
"png" ) : OUString(
"jpg" );
275 rFilter.
ExportGraphic( aScaledGraphic,
u"none", aStream, nFilterFormat, &aFilterData );
280 memp.ReduceResolutionCB = m_xReduceResolutionCB->get_active();
281 memp.MFNewWidth = m_xMFNewWidth->get_value();
282 memp.MFNewHeight = m_xMFNewHeight->get_value();
283 memp.LosslessRB = m_xLosslessRB->get_active();
284 memp.JpegCompRB = m_xJpegCompRB->get_active();
285 memp.CompressionMF = m_xCompressionMF->get_value();
286 memp.QualityMF = m_xQualityMF->get_value();
287 memp.InterpolationCombo = m_xInterpolationCombo->get_active();
293 m_dResolution = m_xMFNewWidth->get_value() / GetViewWidthInch();
296 UpdateResolutionLB();
302 if (&rScale == m_xQualitySlider.get())
303 m_xQualityMF->set_value(m_xQualitySlider->get_value());
305 m_xCompressionMF->set_value(m_xCompressionSlider->get_value());
316 m_xQualitySlider->set_value(m_xQualityMF->get_value());
322 m_xCompressionSlider->set_value(m_xCompressionMF->get_value());
328 m_dResolution = m_xMFNewHeight->get_value() / GetViewHeightInch();
331 UpdateResolutionLB();
337 m_dResolution =
static_cast<double>(m_xResolutionLB->get_active_text().toInt32());
346 bool choice = m_xLosslessRB->get_active();
347 m_xCompressionMF->set_sensitive(choice);
348 m_xCompressionSlider->set_sensitive(choice);
349 m_xQualityMF->set_sensitive(!choice);
350 m_xQualitySlider->set_sensitive(!choice);
356 bool choice = m_xReduceResolutionCB->get_active();
357 m_xMFNewWidth->set_sensitive(choice);
358 m_xMFNewHeight->set_sensitive(choice);
359 m_xResolutionLB->set_sensitive(choice);
360 m_xInterpolationCombo->set_sensitive(choice);
368 if ( m_dResolution > 0.0 )
372 Compress( aMemStream );
378 OUString aSizeAsString = OUString::number(aSize / 1024);
380 OUString aReductionSizeAsString;
381 if (m_aNativeSize > 0 )
382 aReductionSizeAsString = OUString::number(
static_cast<sal_Int32
>((m_aNativeSize - aSize) * 100.0 / m_aNativeSize) );
384 aReductionSizeAsString =
"0";
386 OUString aNewSizeString =
SvxResId(STR_IMAGE_CAPACITY_WITH_REDUCTION);
387 aNewSizeString = aNewSizeString.replaceAll(
"$(CAPACITY)", aSizeAsString);
388 aNewSizeString = aNewSizeString.replaceAll(
"$(REDUCTION)", aReductionSizeAsString);
389 m_xFixedText6->set_label(aNewSizeString);
400 double aScaleX = nPixelX /
static_cast<double>(aSize.
Width());
401 double aScaleY = nPixelY /
static_cast<double>(aSize.
Height());
427 return aResultGraphic;
441 SdrGrafCropItem aNewCrop(
442 aScaledCropedRectangle.
Left(),
443 aScaledCropedRectangle.
Top(),
444 aScaledCropedRectangle.
Right(),
445 aScaledCropedRectangle.
Bottom());
447 pNewObject->SetMergedItem(aNewCrop);
static const AllSettings & GetSettings()
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
const Size & GetSizePixel() const
std::unique_ptr< weld::Button > m_xBtnCalculate
std::unique_ptr< weld::Button > m_xBtnOkay
tools::Rectangle m_aCropRectangle
std::unique_ptr< weld::Scale > m_xCompressionSlider
std::unique_ptr< weld::ComboBox > m_xResolutionLB
std::unique_ptr< weld::Label > m_xFixedText5
void UpdateResolutionLB()
tools::Rectangle GetScaledCropRectangle() const
Graphic GetCompressedGraphic()
std::unique_ptr< weld::Label > m_xFixedText6
std::unique_ptr< weld::SpinButton > m_xQualityMF
std::unique_ptr< weld::SpinButton > m_xMFNewHeight
void Compress(SvStream &aStream)
std::unique_ptr< weld::RadioButton > m_xJpegCompRB
std::unique_ptr< weld::SpinButton > m_xCompressionMF
std::unique_ptr< weld::ComboBox > m_xInterpolationCombo
std::unique_ptr< weld::CheckButton > m_xReduceResolutionCB
SdrGrafObj * m_xGraphicObj
BmpScaleFlag GetSelectedInterpolationType() const
double GetViewWidthInch() const
std::unique_ptr< weld::Label > m_xLabelGraphicType
rtl::Reference< SdrGrafObj > GetCompressedSdrGrafObj()
double GetViewHeightInch() const
CompressGraphicsDialog(weld::Window *pParent, SdrGrafObj *pGraphicObj, SfxBindings &rBindings)
virtual ~CompressGraphicsDialog() override
std::unique_ptr< weld::Scale > m_xQualitySlider
std::unique_ptr< weld::Label > m_xFixedText3
std::unique_ptr< weld::RadioButton > m_xLosslessRB
std::unique_ptr< weld::SpinButton > m_xMFNewWidth
SfxBindings & m_rBindings
std::unique_ptr< weld::Label > m_xFixedText2
sal_uInt16 GetExportFormatNumberForShortName(std::u16string_view rShortName)
static GraphicFilter & GetGraphicFilter()
ErrCode ExportGraphic(const Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData=nullptr)
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
const std::shared_ptr< GfxLink > & GetSharedGfxLink() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
MapMode GetPrefMapMode() const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
const OUString & getNumDecimalSep() const
This class represents an embedded or linked bitmap graphic object.
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
static rtl::Reference< T > Clone(T const &rObj, SdrModel &rTargetModel)
SdrModel & getSdrModelFromSdrObject() const
SfxDispatcher * GetDispatcher() const
SfxModule * GetModule() const
FieldUnit GetFieldUnit() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
virtual sal_uInt64 TellEnd() override
void SetVersion(sal_Int32 n)
sal_uInt64 Seek(sal_uInt64 nPos)
void response(int nResponse)
std::unique_ptr< weld::Builder > m_xBuilder
IMPL_LINK_NOARG(CompressGraphicsDialog, OkayClickHdl, weld::Button &, void)
IMPL_LINK(CompressGraphicsDialog, SlideHdl, weld::Scale &, rScale, void)
OUString SvxResId(TranslateId aId)
OUString GetUnitString(tools::Long nVal_100, FieldUnit eFieldUnit, sal_Unicode cSep)
#define LINK(Instance, Class, Member)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
#define STREAM_SEEK_TO_BEGIN
constexpr TypedWhichId< SdrGrafCropItem > SDRATTR_GRAFCROP(SDRATTR_GRAF_FIRST+9)