/src/libreoffice/svx/source/dialog/compressgraphicdialog.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include "dlgunit.hxx" |
21 | | #include <utility> |
22 | | #include <vcl/fieldvalues.hxx> |
23 | | #include <vcl/gfxlink.hxx> |
24 | | #include <vcl/graph.hxx> |
25 | | #include <vcl/graphicfilter.hxx> |
26 | | #include <vcl/virdev.hxx> |
27 | | #include <vcl/svapp.hxx> |
28 | | #include <vcl/settings.hxx> |
29 | | #include <vcl/vclenum.hxx> |
30 | | #include <vcl/weld/Builder.hxx> |
31 | | #include <vcl/weld/weld.hxx> |
32 | | #include <svx/strings.hrc> |
33 | | #include <svx/svdograf.hxx> |
34 | | #include <svx/sdgcpitm.hxx> |
35 | | #include <svx/dialmgr.hxx> |
36 | | #include <svx/graphichelper.hxx> |
37 | | #include <svx/compressgraphicdialog.hxx> |
38 | | #include <sfx2/dispatch.hxx> |
39 | | #include <sfx2/module.hxx> |
40 | | #include <comphelper/fileformat.h> |
41 | | #include <comphelper/propertyvalue.hxx> |
42 | | #include <com/sun/star/uno/Sequence.hxx> |
43 | | #include <tools/stream.hxx> |
44 | | #include <unotools/localedatawrapper.hxx> |
45 | | |
46 | | // tdf#146929 - remember user settings within the current session |
47 | | // memp is filled in dtor and restored after initialization |
48 | | namespace |
49 | | { |
50 | | struct memParam { |
51 | | bool ReduceResolutionCB = true; |
52 | | int MFNewWidth = 1; |
53 | | int MFNewHeight = 1; |
54 | | int InterpolationCombo = 3; |
55 | | }; |
56 | | memParam memp; |
57 | | } |
58 | | |
59 | | using namespace com::sun::star::uno; |
60 | | using namespace com::sun::star::beans; |
61 | | |
62 | | CompressGraphicsDialog::CompressGraphicsDialog( weld::Window* pParent, SdrGrafObj* pGraphicObj, SfxBindings& rBindings ) : |
63 | 0 | GenericDialogController( pParent, u"svx/ui/compressgraphicdialog.ui"_ustr, u"CompressGraphicDialog"_ustr ), |
64 | 0 | m_xGraphicObj ( pGraphicObj ), |
65 | 0 | m_aGraphic ( pGraphicObj->GetGraphicObject().GetGraphic() ), |
66 | 0 | m_aViewSize100mm ( pGraphicObj->GetLogicRect().GetSize() ), |
67 | 0 | m_rBindings ( rBindings ), |
68 | 0 | m_dResolution ( 300 ) |
69 | 0 | { |
70 | 0 | const SdrGrafCropItem& rCrop = m_xGraphicObj->GetMergedItem(SDRATTR_GRAFCROP); |
71 | 0 | m_aCropRectangle = tools::Rectangle(rCrop.GetLeft(), rCrop.GetTop(), rCrop.GetRight(), rCrop.GetBottom()); |
72 | |
|
73 | 0 | Initialize(); |
74 | 0 | recallParameter(); |
75 | 0 | } |
76 | | |
77 | | CompressGraphicsDialog::CompressGraphicsDialog( weld::Window* pParent, Graphic aGraphic, Size rViewSize100mm, tools::Rectangle const & rCropRectangle, SfxBindings& rBindings ) : |
78 | 0 | GenericDialogController( pParent, u"svx/ui/compressgraphicdialog.ui"_ustr, u"CompressGraphicDialog"_ustr ), |
79 | 0 | m_xGraphicObj ( nullptr ), |
80 | 0 | m_aGraphic (std::move( aGraphic )), |
81 | 0 | m_aViewSize100mm ( rViewSize100mm ), |
82 | 0 | m_aCropRectangle ( rCropRectangle ), |
83 | 0 | m_rBindings ( rBindings ), |
84 | 0 | m_dResolution ( 300 ) |
85 | 0 | { |
86 | 0 | Initialize(); |
87 | 0 | recallParameter(); |
88 | 0 | } |
89 | | |
90 | | CompressGraphicsDialog::~CompressGraphicsDialog() |
91 | 0 | { |
92 | 0 | } |
93 | | |
94 | | void CompressGraphicsDialog::recallParameter() |
95 | 0 | { |
96 | 0 | m_xReduceResolutionCB->set_active( memp.ReduceResolutionCB ); |
97 | 0 | if (memp.ReduceResolutionCB && (memp.MFNewWidth > 1)) |
98 | 0 | m_xMFNewWidth->set_value( memp.MFNewWidth ); |
99 | 0 | if (memp.ReduceResolutionCB && (memp.MFNewHeight > 1)) |
100 | 0 | m_xMFNewHeight->set_value( memp.MFNewHeight ); |
101 | |
|
102 | 0 | m_xInterpolationCombo->set_active( memp.InterpolationCombo ); |
103 | |
|
104 | 0 | UpdateSensitivity(m_xReduceResolutionCB->get_active()); |
105 | 0 | } |
106 | | |
107 | | void CompressGraphicsDialog::Initialize() |
108 | 0 | { |
109 | 0 | m_xLabelGraphicType = m_xBuilder->weld_label(u"label-graphic-type"_ustr); |
110 | 0 | m_xFixedText2 = m_xBuilder->weld_label(u"label-original-size"_ustr); |
111 | 0 | m_xFixedText3 = m_xBuilder->weld_label(u"label-view-size"_ustr); |
112 | 0 | m_xFixedText5 = m_xBuilder->weld_label(u"label-image-capacity"_ustr); |
113 | 0 | m_xFixedText6 = m_xBuilder->weld_label(u"label-new-capacity"_ustr); |
114 | 0 | m_xJpegCompRB = m_xBuilder->weld_radio_button(u"radio-jpeg"_ustr); |
115 | 0 | m_xCompressionMF = m_xBuilder->weld_spin_button(u"spin-compression"_ustr); |
116 | 0 | m_xCompressionSlider = m_xBuilder->weld_scale(u"scale-compression"_ustr); |
117 | 0 | m_xLosslessRB = m_xBuilder->weld_radio_button(u"radio-lossless"_ustr); |
118 | 0 | m_xQualityMF = m_xBuilder->weld_spin_button(u"spin-quality"_ustr); |
119 | 0 | m_xQualitySlider = m_xBuilder->weld_scale(u"scale-quality"_ustr); |
120 | 0 | m_xReduceResolutionCB = m_xBuilder->weld_check_button(u"checkbox-change-resolution"_ustr); |
121 | 0 | m_xMFNewWidth = m_xBuilder->weld_spin_button(u"spin-new-width"_ustr); |
122 | 0 | m_xMFNewHeight = m_xBuilder->weld_spin_button(u"spin-new-height"_ustr); |
123 | 0 | m_xResolutionLB = m_xBuilder->weld_combo_box(u"combo-resolution"_ustr); |
124 | 0 | m_xBtnCalculate = m_xBuilder->weld_button(u"calculate"_ustr); |
125 | 0 | m_xInterpolationCombo = m_xBuilder->weld_combo_box(u"interpolation-method-combo"_ustr); |
126 | 0 | m_xBtnOkay = m_xBuilder->weld_button(u"ok"_ustr); |
127 | |
|
128 | 0 | m_xInterpolationCombo->set_active_text(u"Lanczos"_ustr); |
129 | |
|
130 | 0 | m_xInterpolationCombo->connect_changed(LINK(this, CompressGraphicsDialog, NewInterpolationModifiedHdl)); |
131 | |
|
132 | 0 | m_xMFNewWidth->connect_value_changed( LINK( this, CompressGraphicsDialog, NewWidthModifiedHdl )); |
133 | 0 | m_xMFNewHeight->connect_value_changed( LINK( this, CompressGraphicsDialog, NewHeightModifiedHdl )); |
134 | |
|
135 | 0 | m_xResolutionLB->connect_changed( LINK( this, CompressGraphicsDialog, ResolutionModifiedHdl )); |
136 | 0 | m_xBtnCalculate->connect_clicked( LINK( this, CompressGraphicsDialog, CalculateClickHdl ) ); |
137 | |
|
138 | 0 | m_xLosslessRB->connect_toggled( LINK( this, CompressGraphicsDialog, ToggleCompressionRB ) ); |
139 | 0 | m_xJpegCompRB->connect_toggled( LINK( this, CompressGraphicsDialog, ToggleCompressionRB ) ); |
140 | |
|
141 | 0 | m_xReduceResolutionCB->connect_toggled( LINK( this, CompressGraphicsDialog, ToggleReduceResolutionRB ) ); |
142 | |
|
143 | 0 | m_xQualitySlider->connect_value_changed( LINK( this, CompressGraphicsDialog, SlideHdl )); |
144 | 0 | m_xCompressionSlider->connect_value_changed( LINK( this, CompressGraphicsDialog, SlideHdl )); |
145 | 0 | m_xQualityMF->connect_value_changed( LINK( this, CompressGraphicsDialog, NewQualityModifiedHdl )); |
146 | 0 | m_xCompressionMF->connect_value_changed( LINK( this, CompressGraphicsDialog, NewCompressionModifiedHdl )); |
147 | |
|
148 | 0 | const auto& pGfxLink = m_aGraphic.GetSharedGfxLink(); |
149 | 0 | bool bDefaultChoice = (pGfxLink) ? (pGfxLink->GetType() == GfxLinkType::NativeJpg) : false; |
150 | |
|
151 | 0 | m_xJpegCompRB->set_active(bDefaultChoice); |
152 | 0 | m_xQualitySlider->set_sensitive(bDefaultChoice); |
153 | 0 | m_xQualityMF->set_sensitive(bDefaultChoice); |
154 | | |
155 | |
|
156 | 0 | m_xReduceResolutionCB->set_active(true); |
157 | |
|
158 | 0 | m_xBtnOkay->connect_clicked( LINK( this, CompressGraphicsDialog, OkayClickHdl ) ); |
159 | 0 | UpdateNewWidthMF(); |
160 | 0 | UpdateNewHeightMF(); |
161 | 0 | UpdateResolutionLB(); |
162 | 0 | Update(); |
163 | 0 | } |
164 | | |
165 | | void CompressGraphicsDialog::Update() |
166 | 0 | { |
167 | 0 | auto pGfxLink = m_aGraphic.GetSharedGfxLink(); |
168 | |
|
169 | 0 | m_xLabelGraphicType->set_label(GraphicHelper::GetImageType(m_aGraphic)); |
170 | |
|
171 | 0 | const FieldUnit eFieldUnit = m_rBindings.GetDispatcher()->GetModule()->GetFieldUnit(); |
172 | 0 | const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() ); |
173 | 0 | sal_Unicode cSeparator = rLocaleWrapper.getNumDecimalSep()[0]; |
174 | |
|
175 | 0 | ScopedVclPtrInstance<VirtualDevice> pDummyVDev; |
176 | 0 | pDummyVDev->EnableOutput( false ); |
177 | 0 | pDummyVDev->SetMapMode( m_aGraphic.GetPrefMapMode() ); |
178 | |
|
179 | 0 | Size aPixelSize = m_aGraphic.GetSizePixel(); |
180 | 0 | Size aOriginalSize100mm(pDummyVDev->PixelToLogic(m_aGraphic.GetSizePixel(), MapMode(MapUnit::Map100thMM))); |
181 | |
|
182 | 0 | OUString aBitmapSizeString = SvxResId(STR_IMAGE_ORIGINAL_SIZE); |
183 | 0 | OUString aWidthString = GetUnitString( aOriginalSize100mm.Width(), eFieldUnit, cSeparator ); |
184 | 0 | OUString aHeightString = GetUnitString( aOriginalSize100mm.Height(), eFieldUnit, cSeparator ); |
185 | 0 | aBitmapSizeString = aBitmapSizeString.replaceAll("$(WIDTH)", aWidthString); |
186 | 0 | aBitmapSizeString = aBitmapSizeString.replaceAll("$(HEIGHT)", aHeightString); |
187 | 0 | aBitmapSizeString = aBitmapSizeString.replaceAll("$(WIDTH_IN_PX)", OUString::number(aPixelSize.Width())); |
188 | 0 | aBitmapSizeString = aBitmapSizeString.replaceAll("$(HEIGHT_IN_PX)", OUString::number(aPixelSize.Height())); |
189 | 0 | m_xFixedText2->set_label(aBitmapSizeString); |
190 | |
|
191 | 0 | int aValX = static_cast<int>(aPixelSize.Width() / GetViewWidthInch()); |
192 | |
|
193 | 0 | OUString aViewSizeString = SvxResId(STR_IMAGE_VIEW_SIZE); |
194 | |
|
195 | 0 | aWidthString = GetUnitString( m_aViewSize100mm.Width(), eFieldUnit, cSeparator ); |
196 | 0 | aHeightString = GetUnitString( m_aViewSize100mm.Height(), eFieldUnit, cSeparator ); |
197 | 0 | aViewSizeString = aViewSizeString.replaceAll("$(WIDTH)", aWidthString); |
198 | 0 | aViewSizeString = aViewSizeString.replaceAll("$(HEIGHT)", aHeightString); |
199 | 0 | aViewSizeString = aViewSizeString.replaceAll("$(DPI)", OUString::number(aValX)); |
200 | 0 | m_xFixedText3->set_label(aViewSizeString); |
201 | |
|
202 | 0 | m_aNativeSize = pGfxLink ? pGfxLink->GetDataSize() : 0; |
203 | |
|
204 | 0 | OUString aNativeSizeString = SvxResId(STR_IMAGE_CAPACITY); |
205 | 0 | aNativeSizeString = aNativeSizeString.replaceAll("$(CAPACITY)", OUString::number( m_aNativeSize / 1024 )); |
206 | 0 | m_xFixedText5->set_label(aNativeSizeString); |
207 | |
|
208 | 0 | m_xFixedText6->set_label(u"??"_ustr); |
209 | 0 | } |
210 | | |
211 | | void CompressGraphicsDialog::UpdateSensitivity(const bool bSensitive) |
212 | 0 | { |
213 | 0 | m_xMFNewWidth->set_sensitive(bSensitive); |
214 | 0 | m_xMFNewHeight->set_sensitive(bSensitive); |
215 | 0 | m_xResolutionLB->set_sensitive(bSensitive); |
216 | 0 | m_xInterpolationCombo->set_sensitive(bSensitive); |
217 | 0 | } |
218 | | |
219 | | void CompressGraphicsDialog::UpdateNewWidthMF() |
220 | 0 | { |
221 | 0 | int nPixelX = static_cast<sal_Int32>( GetViewWidthInch() * m_dResolution ); |
222 | 0 | m_xMFNewWidth->set_value(nPixelX); |
223 | 0 | } |
224 | | |
225 | | void CompressGraphicsDialog::UpdateNewHeightMF() |
226 | 0 | { |
227 | 0 | int nPixelY = static_cast<sal_Int32>( GetViewHeightInch() * m_dResolution ); |
228 | 0 | m_xMFNewHeight->set_value(nPixelY); |
229 | 0 | } |
230 | | |
231 | | void CompressGraphicsDialog::UpdateResolutionLB() |
232 | 0 | { |
233 | 0 | m_xResolutionLB->set_entry_text( OUString::number( static_cast<sal_Int32>(m_dResolution) ) ); |
234 | 0 | } |
235 | | |
236 | | double CompressGraphicsDialog::GetViewWidthInch() const |
237 | 0 | { |
238 | 0 | return static_cast<double>(vcl::ConvertAndScaleValue(m_aViewSize100mm.Width(), 2, MapUnit::Map100thMM, FieldUnit::INCH)) / 100.0; |
239 | 0 | } |
240 | | |
241 | | double CompressGraphicsDialog::GetViewHeightInch() const |
242 | 0 | { |
243 | 0 | return static_cast<double>(vcl::ConvertAndScaleValue(m_aViewSize100mm.Height(), 2, MapUnit::Map100thMM, FieldUnit::INCH)) / 100.0; |
244 | 0 | } |
245 | | |
246 | | BmpScaleFlag CompressGraphicsDialog::GetSelectedInterpolationType() const |
247 | 0 | { |
248 | 0 | OUString aSelectionText = m_xInterpolationCombo->get_active_text(); |
249 | |
|
250 | 0 | if( aSelectionText == "Lanczos" ) { |
251 | 0 | return BmpScaleFlag::Lanczos; |
252 | 0 | } else if( aSelectionText == "Bilinear" ) { |
253 | 0 | return BmpScaleFlag::BiLinear; |
254 | 0 | } else if( aSelectionText == "Bicubic" ) { |
255 | 0 | return BmpScaleFlag::BiCubic; |
256 | 0 | } else if ( aSelectionText == "None" ) { |
257 | 0 | return BmpScaleFlag::Fast; |
258 | 0 | } |
259 | 0 | return BmpScaleFlag::BestQuality; |
260 | 0 | } |
261 | | |
262 | | void CompressGraphicsDialog::Compress(SvStream& aStream) |
263 | 0 | { |
264 | 0 | Bitmap aBitmap = m_aGraphic.GetBitmap(); |
265 | 0 | if ( m_xReduceResolutionCB->get_active() ) |
266 | 0 | { |
267 | 0 | tools::Long nPixelX = static_cast<tools::Long>( GetViewWidthInch() * m_dResolution ); |
268 | 0 | tools::Long nPixelY = static_cast<tools::Long>( GetViewHeightInch() * m_dResolution ); |
269 | |
|
270 | 0 | aBitmap.Scale( Size( nPixelX, nPixelY ), GetSelectedInterpolationType() ); |
271 | 0 | } |
272 | 0 | Graphic aScaledGraphic( aBitmap ); |
273 | 0 | GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); |
274 | |
|
275 | 0 | Sequence< PropertyValue > aFilterData{ |
276 | 0 | comphelper::makePropertyValue(u"Interlaced"_ustr, sal_Int32(0)), |
277 | 0 | comphelper::makePropertyValue(u"Compression"_ustr, static_cast<sal_Int32>(m_xCompressionMF->get_value())), |
278 | 0 | comphelper::makePropertyValue(u"Quality"_ustr, static_cast<sal_Int32>(m_xQualityMF->get_value())) |
279 | 0 | }; |
280 | |
|
281 | 0 | OUString aGraphicFormatName = m_xLosslessRB->get_active() ? u"png"_ustr : u"jpg"_ustr; |
282 | |
|
283 | 0 | sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( aGraphicFormatName ); |
284 | 0 | rFilter.ExportGraphic( aScaledGraphic, u"none", aStream, nFilterFormat, &aFilterData ); |
285 | 0 | } |
286 | | |
287 | | IMPL_LINK_NOARG( CompressGraphicsDialog, OkayClickHdl, weld::Button&, void ) |
288 | 0 | { |
289 | 0 | memp.ReduceResolutionCB = m_xReduceResolutionCB->get_active(); |
290 | 0 | memp.MFNewWidth = m_xMFNewWidth->get_value(); |
291 | 0 | memp.MFNewHeight = m_xMFNewHeight->get_value(); |
292 | 0 | memp.InterpolationCombo = m_xInterpolationCombo->get_active(); |
293 | 0 | CompressGraphicsDialog::response(RET_OK); |
294 | 0 | } |
295 | | |
296 | | IMPL_LINK_NOARG( CompressGraphicsDialog, NewWidthModifiedHdl, weld::SpinButton&, void ) |
297 | 0 | { |
298 | 0 | m_dResolution = m_xMFNewWidth->get_value() / GetViewWidthInch(); |
299 | |
|
300 | 0 | UpdateNewHeightMF(); |
301 | 0 | UpdateResolutionLB(); |
302 | 0 | Update(); |
303 | 0 | } |
304 | | |
305 | | IMPL_LINK( CompressGraphicsDialog, SlideHdl, weld::Scale&, rScale, void ) |
306 | 0 | { |
307 | 0 | if (&rScale == m_xQualitySlider.get()) |
308 | 0 | m_xQualityMF->set_value(m_xQualitySlider->get_value()); |
309 | 0 | else |
310 | 0 | m_xCompressionMF->set_value(m_xCompressionSlider->get_value()); |
311 | 0 | Update(); |
312 | 0 | } |
313 | | |
314 | | IMPL_LINK_NOARG( CompressGraphicsDialog, NewInterpolationModifiedHdl, weld::ComboBox&, void ) |
315 | 0 | { |
316 | 0 | Update(); |
317 | 0 | } |
318 | | |
319 | | IMPL_LINK_NOARG( CompressGraphicsDialog, NewQualityModifiedHdl, weld::SpinButton&, void ) |
320 | 0 | { |
321 | 0 | m_xQualitySlider->set_value(m_xQualityMF->get_value()); |
322 | 0 | Update(); |
323 | 0 | } |
324 | | |
325 | | IMPL_LINK_NOARG( CompressGraphicsDialog, NewCompressionModifiedHdl, weld::SpinButton&, void ) |
326 | 0 | { |
327 | 0 | m_xCompressionSlider->set_value(m_xCompressionMF->get_value()); |
328 | 0 | Update(); |
329 | 0 | } |
330 | | |
331 | | IMPL_LINK_NOARG( CompressGraphicsDialog, NewHeightModifiedHdl, weld::SpinButton&, void ) |
332 | 0 | { |
333 | 0 | m_dResolution = m_xMFNewHeight->get_value() / GetViewHeightInch(); |
334 | |
|
335 | 0 | UpdateNewWidthMF(); |
336 | 0 | UpdateResolutionLB(); |
337 | 0 | Update(); |
338 | 0 | } |
339 | | |
340 | | IMPL_LINK_NOARG( CompressGraphicsDialog, ResolutionModifiedHdl, weld::ComboBox&, void ) |
341 | 0 | { |
342 | 0 | m_dResolution = static_cast<double>(m_xResolutionLB->get_active_text().toInt32()); |
343 | |
|
344 | 0 | UpdateNewWidthMF(); |
345 | 0 | UpdateNewHeightMF(); |
346 | 0 | Update(); |
347 | 0 | } |
348 | | |
349 | | IMPL_LINK_NOARG( CompressGraphicsDialog, ToggleCompressionRB, weld::Toggleable&, void ) |
350 | 0 | { |
351 | 0 | bool choice = m_xLosslessRB->get_active(); |
352 | 0 | m_xCompressionMF->set_sensitive(choice); |
353 | 0 | m_xCompressionSlider->set_sensitive(choice); |
354 | 0 | m_xQualityMF->set_sensitive(!choice); |
355 | 0 | m_xQualitySlider->set_sensitive(!choice); |
356 | 0 | Update(); |
357 | 0 | } |
358 | | |
359 | | IMPL_LINK_NOARG( CompressGraphicsDialog, ToggleReduceResolutionRB, weld::Toggleable&, void ) |
360 | 0 | { |
361 | 0 | UpdateSensitivity(m_xReduceResolutionCB->get_active()); |
362 | 0 | Update(); |
363 | 0 | } |
364 | | |
365 | | IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl, weld::Button&, void ) |
366 | 0 | { |
367 | 0 | sal_Int32 aSize = 0; |
368 | |
|
369 | 0 | if ( m_dResolution > 0.0 ) |
370 | 0 | { |
371 | 0 | SvMemoryStream aMemStream; |
372 | 0 | aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); |
373 | 0 | Compress( aMemStream ); |
374 | 0 | aSize = aMemStream.TellEnd(); |
375 | 0 | } |
376 | |
|
377 | 0 | if ( aSize > 0 ) |
378 | 0 | { |
379 | 0 | OUString aSizeAsString = OUString::number(aSize / 1024); |
380 | |
|
381 | 0 | OUString aReductionSizeAsString; |
382 | 0 | if (m_aNativeSize > 0 ) |
383 | 0 | aReductionSizeAsString = OUString::number( static_cast<sal_Int32>((m_aNativeSize - aSize) * 100.0 / m_aNativeSize) ); |
384 | 0 | else |
385 | 0 | aReductionSizeAsString = "0"; |
386 | |
|
387 | 0 | OUString aNewSizeString = SvxResId(STR_IMAGE_CAPACITY_WITH_REDUCTION); |
388 | 0 | aNewSizeString = aNewSizeString.replaceAll("$(CAPACITY)", aSizeAsString); |
389 | 0 | aNewSizeString = aNewSizeString.replaceAll("$(REDUCTION)", aReductionSizeAsString); |
390 | 0 | m_xFixedText6->set_label(aNewSizeString); |
391 | 0 | } |
392 | 0 | } |
393 | | |
394 | | tools::Rectangle CompressGraphicsDialog::GetScaledCropRectangle() const |
395 | 0 | { |
396 | 0 | if ( m_xReduceResolutionCB->get_active() ) |
397 | 0 | { |
398 | 0 | tools::Long nPixelX = static_cast<tools::Long>( GetViewWidthInch() * m_dResolution ); |
399 | 0 | tools::Long nPixelY = static_cast<tools::Long>( GetViewHeightInch() * m_dResolution ); |
400 | 0 | Size aSize = m_aGraphic.GetBitmap().GetSizePixel(); |
401 | 0 | double aScaleX = nPixelX / static_cast<double>(aSize.Width()); |
402 | 0 | double aScaleY = nPixelY / static_cast<double>(aSize.Height()); |
403 | |
|
404 | 0 | return tools::Rectangle( |
405 | 0 | m_aCropRectangle.Left() * aScaleX, |
406 | 0 | m_aCropRectangle.Top() * aScaleY, |
407 | 0 | m_aCropRectangle.Right() * aScaleX, |
408 | 0 | m_aCropRectangle.Bottom()* aScaleY); |
409 | 0 | } |
410 | 0 | else |
411 | 0 | { |
412 | 0 | return m_aCropRectangle; |
413 | 0 | } |
414 | 0 | } |
415 | | |
416 | | Graphic CompressGraphicsDialog::GetCompressedGraphic() |
417 | 0 | { |
418 | 0 | if ( m_dResolution > 0.0 ) |
419 | 0 | { |
420 | 0 | SvMemoryStream aMemStream; |
421 | 0 | aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); |
422 | 0 | Compress( aMemStream ); |
423 | 0 | aMemStream.Seek( STREAM_SEEK_TO_BEGIN ); |
424 | 0 | Graphic aResultGraphic; |
425 | 0 | GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); |
426 | 0 | rFilter.ImportGraphic( aResultGraphic, u"import", aMemStream ); |
427 | |
|
428 | 0 | return aResultGraphic; |
429 | 0 | } |
430 | 0 | return Graphic(); |
431 | 0 | } |
432 | | |
433 | | rtl::Reference<SdrGrafObj> CompressGraphicsDialog::GetCompressedSdrGrafObj() |
434 | 0 | { |
435 | 0 | if ( m_dResolution > 0.0 ) |
436 | 0 | { |
437 | 0 | rtl::Reference<SdrGrafObj> pNewObject = SdrObject::Clone(*m_xGraphicObj, m_xGraphicObj->getSdrModelFromSdrObject()); |
438 | |
|
439 | 0 | if ( m_xReduceResolutionCB->get_active() ) |
440 | 0 | { |
441 | 0 | tools::Rectangle aScaledCropedRectangle = GetScaledCropRectangle(); |
442 | 0 | SdrGrafCropItem aNewCrop( |
443 | 0 | aScaledCropedRectangle.Left(), |
444 | 0 | aScaledCropedRectangle.Top(), |
445 | 0 | aScaledCropedRectangle.Right(), |
446 | 0 | aScaledCropedRectangle.Bottom()); |
447 | |
|
448 | 0 | pNewObject->SetMergedItem(aNewCrop); |
449 | 0 | } |
450 | 0 | pNewObject->SetGraphic( GetCompressedGraphic() ); |
451 | |
|
452 | 0 | return pNewObject; |
453 | 0 | } |
454 | 0 | return nullptr; |
455 | 0 | } |
456 | | |
457 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |