Line data Source code
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 :
21 : #include <tools/stream.hxx>
22 : #include <tools/fract.hxx>
23 : #include <vcl/graphicfilter.hxx>
24 : #include <vcl/FilterConfigItem.hxx>
25 : #include <svtools/svtools.hrc>
26 : #include <svtools/svtresid.hxx>
27 : #include <com/sun/star/awt/Size.hpp>
28 : #include <com/sun/star/drawing/GraphicExportFilter.hpp>
29 : #include <com/sun/star/drawing/XDrawView.hpp>
30 : #include <com/sun/star/frame/XModel.hpp>
31 : #include <com/sun/star/frame/XController.hpp>
32 : #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
33 : #include <com/sun/star/geometry/AffineMatrix2D.hpp>
34 : #include <com/sun/star/io/XStream.hpp>
35 : #include <com/sun/star/view/XSelectionSupplier.hpp>
36 : #include <unotools/streamwrap.hxx>
37 : #include <vcl/msgbox.hxx>
38 : #include <vcl/svapp.hxx>
39 : #include <vcl/outdev.hxx>
40 : #include <vcl/graph.hxx>
41 : #include <rtl/ustrbuf.hxx>
42 : #include <basegfx/matrix/b2dhommatrix.hxx>
43 : #include <comphelper/processfactory.hxx>
44 : #include "exportdialog.hxx"
45 :
46 : #define FORMAT_UNKNOWN 0
47 : #define FORMAT_JPG 1
48 : #define FORMAT_PNG 2
49 : #define FORMAT_BMP 3
50 : #define FORMAT_GIF 4
51 : #define FORMAT_PBM 5
52 : #define FORMAT_PGM 6
53 : #define FORMAT_PPM 7
54 : #define FORMAT_PCT 8
55 : #define FORMAT_RAS 9
56 : #define FORMAT_TIF 10
57 : #define FORMAT_XPM 11
58 : #define FORMAT_WMF 12
59 : #define FORMAT_EMF 13
60 : #define FORMAT_EPS 14
61 : #define FORMAT_MET 15
62 : #define FORMAT_SVG 16
63 : #define FORMAT_SVM 17
64 :
65 : #define UNIT_DEFAULT -1
66 : #define UNIT_INCH 0
67 : #define UNIT_CM 1
68 : #define UNIT_MM 2
69 : #define UNIT_POINT 3
70 : #define UNIT_PIXEL 4
71 : #define UNIT_MAX_ID UNIT_PIXEL
72 :
73 : using namespace ::com::sun::star;
74 :
75 0 : static sal_Int16 GetFilterFormat(const OUString& rExt)
76 : {
77 0 : sal_Int16 nFormat = FORMAT_UNKNOWN;
78 0 : if ( rExt == "JPG" )
79 0 : nFormat = FORMAT_JPG;
80 0 : else if ( rExt == "PNG" )
81 0 : nFormat = FORMAT_PNG;
82 0 : else if ( rExt == "BMP" )
83 0 : nFormat = FORMAT_BMP;
84 0 : else if ( rExt == "GIF" )
85 0 : nFormat = FORMAT_GIF;
86 0 : else if ( rExt == "PBM" )
87 0 : nFormat = FORMAT_PBM;
88 0 : else if ( rExt == "PGM" )
89 0 : nFormat = FORMAT_PGM;
90 0 : else if ( rExt == "PPM" )
91 0 : nFormat = FORMAT_PPM;
92 0 : else if ( rExt == "PCT" )
93 0 : nFormat = FORMAT_PCT;
94 0 : else if ( rExt == "RAS" )
95 0 : nFormat = FORMAT_RAS;
96 0 : else if ( rExt == "TIF" )
97 0 : nFormat = FORMAT_TIF;
98 0 : else if ( rExt == "XPM" )
99 0 : nFormat = FORMAT_XPM;
100 0 : else if ( rExt == "WMF" )
101 0 : nFormat = FORMAT_WMF;
102 0 : else if ( rExt == "EMF" )
103 0 : nFormat = FORMAT_EMF;
104 0 : else if ( rExt == "EPS" )
105 0 : nFormat = FORMAT_EPS;
106 0 : else if ( rExt == "MET" )
107 0 : nFormat = FORMAT_MET;
108 0 : else if ( rExt == "SVG" )
109 0 : nFormat = FORMAT_SVG;
110 0 : else if ( rExt == "SVM" )
111 0 : nFormat = FORMAT_SVM;
112 0 : return nFormat;
113 : }
114 :
115 0 : static MapUnit GetMapUnit( sal_Int32 nUnit )
116 : {
117 0 : MapUnit aMapUnit( MAP_PIXEL );
118 0 : switch( nUnit )
119 : {
120 0 : case UNIT_INCH : aMapUnit = MAP_INCH; break;
121 0 : case UNIT_CM : aMapUnit = MAP_CM; break;
122 0 : case UNIT_MM : aMapUnit = MAP_MM; break;
123 0 : case UNIT_POINT : aMapUnit = MAP_POINT; break;
124 0 : case UNIT_PIXEL : aMapUnit = MAP_PIXEL; break;
125 : }
126 0 : return aMapUnit;
127 : }
128 :
129 0 : sal_Int32 ExportDialog::GetDefaultUnit()
130 : {
131 0 : sal_Int32 nDefaultUnit = UNIT_CM;
132 0 : switch( mrFltCallPara.eFieldUnit )
133 : {
134 : // case FUNIT_NONE :
135 : // case FUNIT_PERCENT :
136 : // case FUNIT_CUSTOM :
137 0 : default: nDefaultUnit = UNIT_CM; break;
138 :
139 : case FUNIT_MILE : // PASSTHROUGH INTENDED
140 : case FUNIT_FOOT :
141 : case FUNIT_TWIP :
142 0 : case FUNIT_PICA : nDefaultUnit = UNIT_INCH; break;
143 :
144 : case FUNIT_KM : // PASSTHROUGH INTENDED
145 : case FUNIT_M :
146 0 : case FUNIT_100TH_MM : nDefaultUnit = UNIT_CM; break;
147 :
148 0 : case FUNIT_INCH : nDefaultUnit = UNIT_INCH; break;
149 0 : case FUNIT_CM : nDefaultUnit = UNIT_CM; break;
150 0 : case FUNIT_MM : nDefaultUnit = UNIT_MM; break;
151 0 : case FUNIT_POINT : nDefaultUnit = UNIT_POINT; break;
152 : }
153 0 : return nDefaultUnit;
154 : }
155 :
156 0 : static basegfx::B2DRange GetShapeRangeForXShape( const uno::Reference< drawing::XShape >& rxShape,
157 : const uno::Reference< graphic::XPrimitiveFactory2D >& rxPrimitiveFactory2D, const uno::Sequence< beans::PropertyValue >& rViewInformation )
158 : {
159 0 : basegfx::B2DRange aShapeRange;
160 :
161 0 : const uno::Sequence< beans::PropertyValue > aParams;
162 0 : const uno::Sequence< uno::Reference< graphic::XPrimitive2D > > aPrimitiveSequence( rxPrimitiveFactory2D->createPrimitivesFromXShape( rxShape, aParams ) );
163 :
164 0 : const sal_Int32 nCount = aPrimitiveSequence.getLength();
165 0 : for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
166 : {
167 0 : const geometry::RealRectangle2D aRect( aPrimitiveSequence[ nIndex ]->getRange( rViewInformation ) );
168 0 : aShapeRange.expand( basegfx::B2DTuple( aRect.X1, aRect.Y1 ) );
169 0 : aShapeRange.expand( basegfx::B2DTuple( aRect.X2, aRect.Y2 ) );
170 : }
171 0 : return aShapeRange;
172 : }
173 :
174 0 : uno::Sequence< beans::PropertyValue > ExportDialog::GetFilterData( bool bUpdateConfig )
175 : {
176 0 : if ( bUpdateConfig )
177 : {
178 0 : sal_Int32 nUnit = mpLbSizeX->GetSelectEntryPos();
179 0 : if ( nUnit < 0 )
180 0 : nUnit = UNIT_CM;
181 :
182 0 : if ( ( mnInitialResolutionUnit == UNIT_DEFAULT ) && ( nUnit == GetDefaultUnit() ) )
183 0 : nUnit = UNIT_DEFAULT;
184 :
185 : // updating ui configuration
186 0 : if ( mbIsPixelFormat )
187 : {
188 0 : if ( nUnit > UNIT_MAX_ID )
189 0 : nUnit = UNIT_PIXEL;
190 :
191 0 : sal_Int32 nResolution = mpNfResolution->GetValue();
192 0 : if ( nResolution < 1 )
193 0 : nResolution = 96;
194 :
195 0 : mpOptionsItem->WriteInt32(OUString("PixelExportUnit"), nUnit);
196 0 : mpOptionsItem->WriteInt32(OUString("PixelExportResolution"), nResolution);
197 0 : mpOptionsItem->WriteInt32(OUString("PixelExportResolutionUnit"), mpLbResolution->GetSelectEntryPos());
198 : }
199 : else
200 : {
201 0 : if ( nUnit >= UNIT_PIXEL )
202 0 : nUnit = UNIT_CM;
203 :
204 0 : mpOptionsItem->WriteInt32(OUString("VectorExportUnit"), nUnit);
205 : }
206 : }
207 :
208 : FilterConfigItem* pFilterOptions;
209 0 : if ( bUpdateConfig )
210 0 : pFilterOptions = mpFilterOptionsItem;
211 : else
212 : {
213 0 : uno::Sequence< beans::PropertyValue > aFilterData( mpFilterOptionsItem->GetFilterData() );
214 0 : pFilterOptions = new FilterConfigItem( &aFilterData );
215 : }
216 :
217 0 : const OUString sLogicalWidth("LogicalWidth");
218 0 : const OUString sLogicalHeight("LogicalHeight");
219 0 : if ( mbIsPixelFormat )
220 : {
221 0 : pFilterOptions->WriteInt32(OUString("PixelWidth"), static_cast< sal_Int32 >( maSize.Width ) );
222 0 : pFilterOptions->WriteInt32(OUString("PixelHeight"), static_cast< sal_Int32 >( maSize.Height ) );
223 0 : if ( maResolution.Width && maResolution.Height )
224 : {
225 0 : const double f100thmmPerPixelX = 100000.0 / maResolution.Width;
226 0 : const double f100thmmPerPixelY = 100000.0 / maResolution.Height;
227 0 : sal_Int32 nLogicalWidth = static_cast< sal_Int32 >( f100thmmPerPixelX * maSize.Width );
228 0 : sal_Int32 nLogicalHeight= static_cast< sal_Int32 >( f100thmmPerPixelY * maSize.Height );
229 0 : if ( nLogicalWidth && nLogicalHeight )
230 : {
231 0 : pFilterOptions->WriteInt32( sLogicalWidth, nLogicalWidth );
232 0 : pFilterOptions->WriteInt32( sLogicalHeight, nLogicalHeight );
233 : }
234 : }
235 : }
236 : else
237 : {
238 0 : pFilterOptions->WriteInt32( sLogicalWidth, static_cast< sal_Int32 >( maSize.Width ) );
239 0 : pFilterOptions->WriteInt32( sLogicalHeight, static_cast< sal_Int32 >( maSize.Height ) );
240 : }
241 0 : switch ( mnFormat )
242 : {
243 : case FORMAT_JPG :
244 : {
245 0 : sal_Int32 nColor = mpLbColorDepth->GetSelectEntryPos();
246 0 : if ( nColor == 1 )
247 0 : nColor = 0;
248 : else
249 0 : nColor = 1;
250 0 : pFilterOptions->WriteInt32(OUString("ColorMode"), nColor);
251 0 : pFilterOptions->WriteInt32(OUString("Quality"), static_cast<sal_Int32>(mpSbCompression->GetThumbPos()));
252 : }
253 0 : break;
254 :
255 : case FORMAT_PNG :
256 : {
257 0 : pFilterOptions->WriteInt32(OUString("Compression"), static_cast<sal_Int32>(mpSbCompression->GetThumbPos()));
258 0 : sal_Int32 nInterlace = 0;
259 0 : if ( mpCbInterlaced->IsChecked() )
260 0 : nInterlace++;
261 0 : pFilterOptions->WriteInt32(OUString("Interlaced"), nInterlace);
262 0 : sal_Int32 nValue = 0;
263 0 : if ( mpCbSaveTransparency->IsChecked() )
264 0 : nValue++;
265 0 : pFilterOptions->WriteInt32(OUString("Translucent"), nValue);
266 : }
267 0 : break;
268 :
269 : case FORMAT_BMP :
270 : {
271 0 : pFilterOptions->WriteInt32(OUString("Color"), mpLbColorDepth->GetSelectEntryPos() + 1);
272 0 : pFilterOptions->WriteBool(OUString("RLE_Coding"), mpCbRLEEncoding->IsChecked());
273 : }
274 0 : break;
275 :
276 : case FORMAT_GIF :
277 : {
278 0 : sal_Int32 nValue = 0;
279 0 : if ( mpCbInterlaced->IsChecked() )
280 0 : nValue++;
281 0 : pFilterOptions->WriteInt32(OUString("Interlaced"), nValue);
282 :
283 0 : nValue = 0;
284 0 : if (mpCbSaveTransparency->IsChecked())
285 0 : nValue++;
286 0 : pFilterOptions->WriteInt32(OUString("Translucent"), nValue);
287 : }
288 0 : break;
289 :
290 : case FORMAT_PBM :
291 : case FORMAT_PGM :
292 : case FORMAT_PPM :
293 : {
294 0 : sal_Int32 nFormat = 0;
295 0 : if ( mpRbText->IsChecked() )
296 0 : nFormat++;
297 0 : pFilterOptions->WriteInt32(OUString("FileFormat"), nFormat);
298 : }
299 0 : break;
300 :
301 : case FORMAT_EPS :
302 : {
303 0 : sal_Int32 nCheck = 0;
304 0 : if ( mpCbEPSPreviewTIFF->IsChecked() )
305 0 : nCheck++;
306 0 : if ( mpCbEPSPreviewEPSI->IsChecked() )
307 0 : nCheck += 2;
308 0 : pFilterOptions->WriteInt32(OUString("Preview"), nCheck);
309 :
310 0 : nCheck = 1;
311 0 : if ( mpRbEPSLevel2->IsChecked() )
312 0 : nCheck++;
313 0 : pFilterOptions->WriteInt32(OUString("Version"), nCheck);
314 :
315 0 : nCheck = 1;
316 0 : if ( mpRbEPSColorFormat2->IsChecked() )
317 0 : nCheck++;
318 0 : pFilterOptions->WriteInt32(OUString("ColorFormat"), nCheck);
319 :
320 0 : nCheck = 1;
321 0 : if ( mpRbEPSCompressionNone->IsChecked() )
322 0 : nCheck++;
323 0 : pFilterOptions->WriteInt32(OUString("CompressionMode"), nCheck);
324 : }
325 0 : break;
326 : }
327 :
328 0 : uno::Sequence< beans::PropertyValue > aRet( pFilterOptions->GetFilterData() );
329 0 : if ( !bUpdateConfig )
330 0 : delete pFilterOptions;
331 0 : return aRet;
332 : }
333 :
334 :
335 0 : awt::Size ExportDialog::GetOriginalSize()
336 : {
337 0 : basegfx::B2DRange aShapesRange;
338 :
339 0 : if ( mxPage.is () )
340 : {
341 0 : uno::Reference< beans::XPropertySet > xPagePropSet( mxPage, uno::UNO_QUERY );
342 0 : if ( xPagePropSet.is() )
343 : {
344 0 : sal_Int32 nWidth = 0;
345 0 : sal_Int32 nHeight= 0;
346 0 : com::sun::star::uno::Any aAny;
347 0 : aAny = xPagePropSet->getPropertyValue("Width");
348 0 : aAny >>= nWidth;
349 0 : aAny = xPagePropSet->getPropertyValue("Height");
350 0 : aAny >>= nHeight;
351 0 : aShapesRange = basegfx::B2DRange( 0, 0, nWidth, nHeight );
352 0 : }
353 : }
354 : else
355 : {
356 0 : uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory = graphic::PrimitiveFactory2D::create( mxContext );
357 :
358 0 : basegfx::B2DHomMatrix aViewTransformation( Application::GetDefaultDevice()->GetViewTransformation() );
359 0 : com::sun::star::geometry::AffineMatrix2D aTransformation;
360 0 : aTransformation.m00 = aViewTransformation.get(0,0);
361 0 : aTransformation.m01 = aViewTransformation.get(0,1);
362 0 : aTransformation.m02 = aViewTransformation.get(0,2);
363 0 : aTransformation.m10 = aViewTransformation.get(1,0);
364 0 : aTransformation.m11 = aViewTransformation.get(1,1);
365 0 : aTransformation.m12 = aViewTransformation.get(1,2);
366 :
367 0 : const OUString sViewTransformation( "ViewTransformation" );
368 0 : uno::Sequence< beans::PropertyValue > aViewInformation( 1 );
369 0 : aViewInformation[ 0 ].Value <<= aTransformation;
370 0 : aViewInformation[ 0 ].Name = sViewTransformation;
371 :
372 0 : if ( mxShape.is() )
373 0 : aShapesRange = GetShapeRangeForXShape( mxShape, xPrimitiveFactory, aViewInformation );
374 0 : else if ( mxShapes.is() )
375 : {
376 0 : const sal_Int32 nCount = mxShapes->getCount();
377 0 : for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
378 : {
379 0 : uno::Reference< drawing::XShape > xShape;
380 0 : mxShapes->getByIndex( nIndex ) >>= xShape;
381 0 : aShapesRange.expand( GetShapeRangeForXShape( xShape, xPrimitiveFactory, aViewInformation ) );
382 0 : }
383 0 : }
384 : }
385 0 : return awt::Size( static_cast<sal_Int32>(aShapesRange.getWidth()), static_cast<sal_Int32>(aShapesRange.getHeight()) );
386 : }
387 :
388 0 : void ExportDialog::GetGraphicSource()
389 : {
390 0 : if ( mxSourceDocument.is() )
391 : {
392 0 : uno::Reference< frame::XModel > xModel( mxSourceDocument, uno::UNO_QUERY );
393 0 : if ( xModel.is() )
394 : {
395 0 : uno::Reference< frame::XController > xController( xModel->getCurrentController() );
396 0 : if ( xController.is() )
397 : {
398 0 : if ( mbExportSelection ) // check if there is a selection
399 : {
400 0 : uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY );
401 0 : if ( xSelectionSupplier.is() )
402 : {
403 0 : uno::Any aAny( xSelectionSupplier->getSelection() );
404 0 : if ( ! ( aAny >>= mxShapes ) )
405 0 : aAny >>= mxShape;
406 0 : }
407 : }
408 0 : if ( !mxShape.is() && !mxShapes.is() )
409 : {
410 0 : uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY );
411 0 : if ( xDrawView.is() )
412 : {
413 0 : uno::Reference< drawing::XDrawPage > xCurrentPage( xDrawView->getCurrentPage() );
414 0 : if ( xCurrentPage.is() )
415 : {
416 0 : mxPage = xCurrentPage; // exporting whole page
417 0 : }
418 0 : }
419 : }
420 0 : }
421 0 : }
422 : }
423 0 : }
424 :
425 0 : bool ExportDialog::GetGraphicStream()
426 : {
427 0 : bool bRet = false;
428 :
429 0 : if ( !IsTempExportAvailable() )
430 : {
431 0 : delete mpTempStream, mpTempStream = new SvMemoryStream();
432 0 : maBitmap = Bitmap();
433 0 : return bRet;
434 : }
435 :
436 0 : bool bRecreateOutputStream = mpTempStream->Tell() == 0;
437 :
438 0 : static uno::Sequence< beans::PropertyValue > aOldFilterData;
439 0 : uno::Sequence< beans::PropertyValue > aNewFilterData( GetFilterData( false ) );
440 0 : if ( aOldFilterData != aNewFilterData )
441 : {
442 0 : aOldFilterData = aNewFilterData;
443 0 : bRecreateOutputStream = true;
444 : }
445 : try
446 : {
447 0 : if ( bRecreateOutputStream )
448 : {
449 0 : delete mpTempStream, mpTempStream = new SvMemoryStream();
450 0 : maBitmap = Bitmap();
451 :
452 0 : uno::Reference < io::XStream > xStream( new utl::OStreamWrapper( *mpTempStream ) );
453 0 : uno::Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() );
454 :
455 : uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter =
456 0 : drawing::GraphicExportFilter::create( mxContext );
457 :
458 0 : OUString sFormat( maExt );
459 0 : uno::Sequence< beans::PropertyValue > aDescriptor( 3 );
460 0 : aDescriptor[0].Name = "OutputStream";
461 0 : aDescriptor[0].Value <<= xOutputStream;
462 0 : aDescriptor[1].Name = "FilterName";
463 0 : aDescriptor[1].Value <<= sFormat;
464 0 : aDescriptor[2].Name = "FilterData";
465 0 : aDescriptor[2].Value <<= aNewFilterData;
466 :
467 0 : uno::Reference< lang::XComponent > xSourceDoc;
468 0 : if ( mxPage.is() )
469 0 : xSourceDoc = uno::Reference< lang::XComponent >( mxPage, uno::UNO_QUERY_THROW );
470 0 : else if ( mxShapes.is() )
471 0 : xSourceDoc = uno::Reference< lang::XComponent >( mxShapes, uno::UNO_QUERY_THROW );
472 0 : else if ( mxShape.is() )
473 0 : xSourceDoc = uno::Reference< lang::XComponent >( mxShape, uno::UNO_QUERY_THROW );
474 0 : if ( xSourceDoc.is() )
475 : {
476 0 : xGraphicExporter->setSourceDocument( xSourceDoc );
477 0 : xGraphicExporter->filter( aDescriptor );
478 0 : bRet = true;
479 :
480 0 : if ( mnFormat == FORMAT_JPG )
481 : {
482 0 : mpTempStream->Seek( STREAM_SEEK_TO_BEGIN );
483 0 : maBitmap = GetGraphicBitmap( *mpTempStream );
484 0 : mpTempStream->Seek( STREAM_SEEK_TO_END );
485 : }
486 0 : }
487 : }
488 : else
489 0 : bRet = true;
490 : }
491 0 : catch( uno::Exception& )
492 : {
493 :
494 : // ups
495 :
496 : }
497 0 : return bRet;
498 : }
499 :
500 0 : Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream )
501 : {
502 0 : Bitmap aRet;
503 0 : Graphic aGraphic;
504 0 : GraphicFilter aFilter( false );
505 0 : if ( aFilter.ImportGraphic( aGraphic, "", rInputStream, GRFILTER_FORMAT_NOTFOUND, NULL, GraphicFilterImportFlags::NONE, static_cast<com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >*>(NULL), NULL ) == GRFILTER_OK )
506 : {
507 0 : aRet = aGraphic.GetBitmap();
508 : }
509 0 : return aRet;
510 : }
511 :
512 0 : sal_uInt32 ExportDialog::GetRawFileSize() const
513 : {
514 0 : sal_uInt64 nRawFileSize = 0;
515 0 : if ( mbIsPixelFormat )
516 : {
517 0 : sal_Int32 nBitsPerPixel = 24;
518 0 : OUString aEntry( mpLbColorDepth->GetSelectEntry() );
519 0 : if ( ms1BitTreshold == aEntry )
520 0 : nBitsPerPixel = 1;
521 0 : else if ( ms1BitDithered == aEntry )
522 0 : nBitsPerPixel = 1;
523 0 : else if ( ms4BitGrayscale == aEntry )
524 0 : nBitsPerPixel = 4;
525 0 : else if ( ms4BitColorPalette == aEntry )
526 0 : nBitsPerPixel = 8;
527 0 : else if ( ms8BitGrayscale == aEntry )
528 0 : nBitsPerPixel = 8;
529 0 : else if ( ms8BitColorPalette == aEntry )
530 0 : nBitsPerPixel = 8;
531 0 : else if ( ms24BitColor == aEntry )
532 0 : nBitsPerPixel = 24;
533 :
534 0 : if ( mbIsPixelFormat )
535 : {
536 0 : nRawFileSize = ( maSize.Width * nBitsPerPixel + 7 ) &~ 7; // rounding up to 8 bits
537 0 : nRawFileSize /= 8; // in bytes
538 0 : nRawFileSize *= maSize.Height;
539 : }
540 0 : if ( nRawFileSize > SAL_MAX_UINT32 )
541 0 : nRawFileSize = 0;
542 : }
543 0 : return static_cast< sal_uInt32 >( nRawFileSize );
544 : }
545 :
546 : // checks if the source dimension/resolution is not too big
547 : // to determine the exact graphic output size and preview for jpg
548 0 : bool ExportDialog::IsTempExportAvailable() const
549 : {
550 0 : return GetRawFileSize() < static_cast< sal_uInt32 >( mnMaxFilesizeForRealtimePreview );
551 : }
552 :
553 0 : ExportDialog::ExportDialog(FltCallDialogParameter& rPara,
554 : const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
555 : const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxSourceDocument,
556 : bool bExportSelection, bool bIsPixelFormat)
557 : : ModalDialog(rPara.pWindow, "GraphicExportDialog", "svt/ui/graphicexport.ui")
558 : , mrFltCallPara(rPara)
559 : , mxContext(rxContext)
560 : , mxSourceDocument(rxSourceDocument)
561 : , mpSbCompression(NULL)
562 : , mpNfCompression(NULL)
563 : , msEstimatedSizePix1(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_PIX_1))
564 : , msEstimatedSizePix2(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_PIX_2))
565 : , msEstimatedSizeVec(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_VEC))
566 : , ms1BitTreshold(SVT_RESSTR(STR_SVT_1BIT_THRESHOLD))
567 : , ms1BitDithered(SVT_RESSTR(STR_SVT_1BIT_DITHERED))
568 : , ms4BitGrayscale(SVT_RESSTR(STR_SVT_4BIT_GRAYSCALE))
569 : , ms4BitColorPalette(SVT_RESSTR(STR_SVT_4BIT_COLOR_PALETTE))
570 : , ms8BitGrayscale(SVT_RESSTR(STR_SVT_8BIT_GRAYSCALE))
571 : , ms8BitColorPalette(SVT_RESSTR(STR_SVT_8BIT_COLOR_PALETTE))
572 : , ms24BitColor(SVT_RESSTR(STR_SVT_24BIT_TRUE_COLOR))
573 : , maExt(rPara.aFilterExt)
574 : , mnFormat(FORMAT_UNKNOWN)
575 : , mnMaxFilesizeForRealtimePreview(0)
576 0 : , mpTempStream(new SvMemoryStream())
577 : , maOriginalSize(awt::Size(0, 0))
578 : , mbIsPixelFormat(bIsPixelFormat)
579 : , mbExportSelection(bExportSelection)
580 0 : , mbPreserveAspectRatio(true)
581 : {
582 0 : get(mpMfSizeX, "widthmf-nospin");
583 0 : get(mpMfSizeY, "heightmf-nospin");
584 0 : get(mpLbSizeX, "widthlb");
585 0 : get(mpFtResolution, "resolutionft");
586 0 : get(mpNfResolution, "resolutionmf-nospin");
587 0 : get(mpLbResolution, "resolutionlb");
588 :
589 0 : get(mpColorDepth, "colordepth");
590 0 : get(mpLbColorDepth, "colordepthlb");
591 :
592 0 : get(mpJPGQuality, "jpgquality");
593 0 : get(mpPNGCompression, "pngcompression");
594 :
595 0 : get(mpBMPCompression, "bmpcompression");
596 0 : get(mpCbRLEEncoding, "rlecb");
597 :
598 0 : get(mpMode, "mode");
599 0 : get(mpCbInterlaced, "interlacedcb");
600 :
601 0 : get(mpDrawingObjects, "drawingobjects");
602 0 : get(mpCbSaveTransparency, "savetransparencycb");
603 :
604 0 : get(mpEncoding, "encoding");
605 0 : get(mpRbBinary, "binarycb");
606 0 : get(mpRbText, "textcb");
607 :
608 0 : get(mpEPSGrid, "epsgrid");
609 0 : get(mpCbEPSPreviewTIFF, "tiffpreviewcb");
610 0 : get(mpCbEPSPreviewEPSI, "epsipreviewcb");
611 0 : get(mpRbEPSLevel1, "level1rb");
612 0 : get(mpRbEPSLevel2, "level2rb");
613 0 : get(mpRbEPSColorFormat1, "color1rb");
614 0 : get(mpRbEPSColorFormat2, "color2rb");
615 0 : get(mpRbEPSCompressionLZW, "compresslzw");
616 0 : get(mpRbEPSCompressionNone, "compressnone");
617 :
618 0 : GetGraphicSource();
619 :
620 0 : get(mpInfo, "information");
621 0 : get(mpFtEstimatedSize, "estsizeft");;
622 :
623 0 : get(mpBtnOK, "ok");
624 :
625 0 : maExt = maExt.toAsciiUpperCase();
626 :
627 0 : OUString aFilterConfigPath( "Office.Common/Filter/Graphic/Export/" );
628 0 : mpOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );
629 0 : aFilterConfigPath += maExt;
630 0 : mpFilterOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );
631 :
632 : mnInitialResolutionUnit = mbIsPixelFormat
633 0 : ? mpOptionsItem->ReadInt32(OUString("PixelExportUnit"), UNIT_DEFAULT)
634 0 : : mpOptionsItem->ReadInt32(OUString( "VectorExportUnit"), UNIT_DEFAULT);
635 :
636 0 : mnMaxFilesizeForRealtimePreview = mpOptionsItem->ReadInt32(OUString("MaxFilesizeForRealtimePreview"), 0);
637 0 : mpFtEstimatedSize->SetText(OUString(" \n "));
638 :
639 0 : SetText( GetText().replaceFirst("%1", maExt) ); //Set dialog title
640 :
641 0 : mnFormat = GetFilterFormat( maExt );
642 :
643 0 : Size aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MAP_CM ) );
644 0 : maResolution.Width = aResolution.Width();
645 0 : maResolution.Height= aResolution.Height();
646 0 : maOriginalSize = GetOriginalSize();
647 0 : if ( bIsPixelFormat )
648 : {
649 0 : double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0;
650 0 : maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ),
651 0 : static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) );
652 : }
653 : else
654 : {
655 0 : maSize = maOriginalSize;
656 : }
657 :
658 0 : setupControls();
659 :
660 : // Size
661 0 : mpLbSizeX->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
662 :
663 0 : if (mpSbCompression)
664 0 : mpSbCompression->SetScrollHdl(LINK(this, ExportDialog, SbCompressionUpdateHdl));
665 0 : if (mpNfCompression)
666 0 : mpNfCompression->SetModifyHdl(LINK(this, ExportDialog, UpdateHdl));
667 :
668 0 : mpMfSizeX->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeX ) );
669 0 : mpMfSizeY->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeY ) );
670 :
671 0 : mpNfResolution->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlNfResolution ) );
672 0 : mpLbResolution->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
673 :
674 0 : mpLbColorDepth->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
675 :
676 0 : mpCbInterlaced->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
677 :
678 0 : mpCbSaveTransparency->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
679 :
680 0 : mpCbEPSPreviewTIFF->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
681 0 : mpCbEPSPreviewEPSI->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
682 :
683 0 : mpRbEPSCompressionLZW->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
684 0 : mpRbEPSCompressionNone->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
685 :
686 0 : mpRbBinary->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
687 0 : mpRbText->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
688 :
689 : // BMP
690 0 : mpCbRLEEncoding->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
691 :
692 : // EPS
693 0 : mpRbEPSLevel1->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
694 0 : mpRbEPSLevel2->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
695 :
696 0 : mpBtnOK->SetClickHdl( LINK( this, ExportDialog, OK ) );
697 :
698 0 : updateControls();
699 0 : }
700 :
701 0 : void ExportDialog::setupSizeControls()
702 : {
703 0 : sal_Int32 nUnit = mnInitialResolutionUnit;
704 0 : if (nUnit == UNIT_DEFAULT)
705 0 : nUnit = GetDefaultUnit();
706 :
707 0 : if (!mbIsPixelFormat)
708 : {
709 0 : mpFtResolution->Hide();
710 0 : mpNfResolution->Hide();
711 0 : mpLbResolution->Hide();
712 0 : mpLbSizeX->RemoveEntry( UNIT_PIXEL ); // removing pixel
713 0 : if ( nUnit >= UNIT_PIXEL )
714 0 : nUnit = UNIT_CM;
715 : }
716 0 : else if ( nUnit > UNIT_MAX_ID )
717 0 : nUnit = UNIT_PIXEL;
718 0 : if ( nUnit < 0 )
719 0 : nUnit = UNIT_CM;
720 0 : mpLbSizeX->SelectEntryPos( static_cast< sal_uInt16 >( nUnit ) );
721 :
722 0 : if ( mbIsPixelFormat ) // TODO: (metafileresolutionsupport) should be supported for vector formats also... this makes
723 : { // sense eg for bitmap fillings in metafiles, to preserve high dpi output
724 : // (atm without special vector support the bitmaps are rendered with 96dpi)
725 0 : sal_Int32 nResolution = mpOptionsItem->ReadInt32(OUString("PixelExportResolution"), 96);
726 0 : if ( nResolution < 1 )
727 0 : nResolution = 96;
728 0 : mpNfResolution->SetValue( nResolution );
729 :
730 0 : sal_Int32 nResolutionUnit = mpOptionsItem->ReadInt32(OUString("PixelExportResolutionUnit"), 1);
731 0 : if ( ( nResolutionUnit < 0 ) || ( nResolutionUnit > 2 ) )
732 0 : nResolutionUnit = 1;
733 0 : mpLbResolution->SelectEntryPos( static_cast< sal_uInt16 >( nResolutionUnit ) );
734 : }
735 0 : }
736 :
737 0 : void ExportDialog::createFilterOptions()
738 : {
739 0 : switch( mnFormat )
740 : {
741 : case FORMAT_JPG :
742 : {
743 0 : sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("ColorMode"), 0);
744 0 : if ( nColor == 1 )
745 0 : nColor = 0;
746 : else
747 0 : nColor = 1;
748 0 : mpLbColorDepth->InsertEntry( ms8BitGrayscale );
749 0 : mpLbColorDepth->InsertEntry( ms24BitColor );
750 0 : mpLbColorDepth->SelectEntryPos( nColor );
751 0 : mpColorDepth->Show();
752 :
753 : // Quality
754 0 : mpJPGQuality->Show();
755 0 : sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32(OUString("Quality"), 75);
756 0 : if ((nQuality < 1 ) || (nQuality > 100))
757 0 : nQuality = 75;
758 0 : get(mpSbCompression, "compressionjpgsb");
759 0 : get(mpNfCompression, "compressionjpgnf-nospin");
760 0 : mpSbCompression->SetRangeMin( 1 );
761 0 : mpSbCompression->SetRangeMax( 100 );
762 0 : mpNfCompression->SetMin( 1 );
763 0 : mpNfCompression->SetMax( 100 );
764 0 : mpNfCompression->SetValue( nQuality );
765 0 : mpNfCompression->SetStrictFormat( true );
766 : }
767 0 : break;
768 : case FORMAT_PNG :
769 : {
770 : // Compression 1..9
771 0 : mpPNGCompression->Show();
772 0 : sal_Int32 nCompression = mpFilterOptionsItem->ReadInt32(OUString("Compression"), 6);
773 0 : if ( ( nCompression < 1 ) || ( nCompression > 9 ) )
774 0 : nCompression = 6;
775 :
776 0 : get(mpSbCompression, "compressionpngsb");
777 0 : get(mpNfCompression, "compressionpngnf-nospin");
778 0 : mpSbCompression->SetRangeMin( 1 );
779 0 : mpSbCompression->SetRangeMax( 9 );
780 0 : mpNfCompression->SetMin( 1 );
781 0 : mpNfCompression->SetMax( 9 );
782 0 : mpNfCompression->SetValue( 9 );
783 0 : mpNfCompression->SetStrictFormat( true );
784 :
785 : // Interlaced
786 0 : mpMode->Show();
787 0 : mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32(OUString("Interlaced"), 0) != 0);
788 :
789 : // Transparency
790 0 : mpDrawingObjects->Show();
791 0 : mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32(OUString("Translucent"), 1) != 0);
792 : }
793 0 : break;
794 : case FORMAT_BMP :
795 : {
796 0 : sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("Color"), 0);
797 0 : if ( nColor == 0 )
798 0 : nColor = 6;
799 : else
800 0 : nColor--;
801 0 : mpLbColorDepth->InsertEntry( ms1BitTreshold );
802 0 : mpLbColorDepth->InsertEntry( ms1BitDithered );
803 0 : mpLbColorDepth->InsertEntry( ms4BitGrayscale );
804 0 : mpLbColorDepth->InsertEntry( ms4BitColorPalette );
805 0 : mpLbColorDepth->InsertEntry( ms8BitGrayscale );
806 0 : mpLbColorDepth->InsertEntry( ms8BitColorPalette );
807 0 : mpLbColorDepth->InsertEntry( ms24BitColor );
808 0 : mpLbColorDepth->SelectEntryPos( nColor );
809 0 : mpColorDepth->Show();
810 :
811 : // RLE coding
812 0 : mpBMPCompression->Show();
813 0 : mpCbRLEEncoding->Check(mpFilterOptionsItem->ReadBool(OUString("RLE_Coding"), true));
814 : }
815 0 : break;
816 : case FORMAT_GIF :
817 : {
818 : // Interlaced
819 0 : mpMode->Show();
820 0 : mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32(OUString("Interlaced"), 1) != 0);
821 :
822 : // Transparency
823 0 : mpDrawingObjects->Show();
824 0 : mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32(OUString("Translucent"), 1) != 0);
825 : }
826 0 : break;
827 : case FORMAT_PBM :
828 : case FORMAT_PGM :
829 : case FORMAT_PPM :
830 : {
831 : // RB Binary / Text
832 0 : mpEncoding->Show();
833 0 : sal_Int32 nFormat = mpFilterOptionsItem->ReadInt32(OUString("FileFormat"), 1);
834 0 : mpRbBinary->Check( nFormat == 0 );
835 0 : mpRbText->Check( nFormat != 0 );
836 : }
837 0 : break;
838 : case FORMAT_EPS :
839 : {
840 0 : mpEPSGrid->Show();
841 :
842 0 : sal_Int32 nPreview = mpFilterOptionsItem->ReadInt32(OUString("Preview"), 0);
843 0 : sal_Int32 nVersion = mpFilterOptionsItem->ReadInt32(OUString("Version"), 2);
844 0 : sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("ColorFormat"), 0);
845 0 : sal_Int32 nCompr = mpFilterOptionsItem->ReadInt32(OUString("CompressionMode"), 2);
846 :
847 0 : mpFilterOptionsItem->ReadInt32(OUString("TextMode"), 0);
848 :
849 0 : mpCbEPSPreviewTIFF->Check( ( nPreview & 1 ) != 0 );
850 0 : mpCbEPSPreviewEPSI->Check( ( nPreview & 2 ) != 0 );
851 :
852 0 : mpRbEPSLevel1->Check( nVersion == 1 );
853 0 : mpRbEPSLevel2->Check( nVersion == 2 );
854 :
855 0 : mpRbEPSColorFormat1->Check( nColor == 1 );
856 0 : mpRbEPSColorFormat2->Check( nColor != 1 );
857 :
858 0 : mpRbEPSCompressionLZW->Check( nCompr == 1 );
859 0 : mpRbEPSCompressionNone->Check( nCompr != 1 );
860 : }
861 0 : break;
862 : }
863 0 : }
864 :
865 0 : void ExportDialog::setupControls()
866 : {
867 0 : setupSizeControls();
868 0 : createFilterOptions();
869 :
870 0 : if (mnMaxFilesizeForRealtimePreview || mbIsPixelFormat)
871 0 : mpInfo->Show();
872 0 : }
873 :
874 0 : static OUString ImpValueOfInKB( const sal_Int64& rVal )
875 : {
876 0 : double fVal( static_cast<double>( rVal ) );
877 0 : fVal /= ( 1 << 10 );
878 0 : fVal += 0.05;
879 0 : OUStringBuffer aVal( OUString::number( fVal ) );
880 0 : sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.', 0 ) );
881 0 : if ( nX > 0 )
882 0 : aVal.setLength( nX + 2 );
883 0 : return aVal.makeStringAndClear();
884 : }
885 :
886 0 : void ExportDialog::updateControls()
887 : {
888 0 : GetGraphicStream();
889 :
890 : // Size Controls
891 0 : if ( !mbIsPixelFormat )
892 : {
893 0 : awt::Size aSize100thmm( maSize );
894 0 : Size aSize( LogicToLogic( Size( aSize100thmm.Width * 100, aSize100thmm.Height * 100 ), MAP_100TH_MM,
895 0 : MapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) ) ) );
896 0 : mpMfSizeX->SetValue( aSize.Width() );
897 0 : mpMfSizeY->SetValue( aSize.Height() );
898 : }
899 : else
900 : {
901 0 : MapUnit aMapUnit( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) );
902 0 : if ( aMapUnit == MAP_PIXEL )
903 : { // calculating pixel count via resolution and original graphic size
904 0 : mpMfSizeX->SetDecimalDigits( 0 );
905 0 : mpMfSizeY->SetDecimalDigits( 0 );
906 0 : mpMfSizeX->SetValue( maSize.Width );
907 0 : mpMfSizeY->SetValue( maSize.Height );
908 : }
909 : else
910 : {
911 0 : mpMfSizeX->SetDecimalDigits( 2 );
912 0 : mpMfSizeY->SetDecimalDigits( 2 );
913 : double fRatio;
914 0 : switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
915 : {
916 0 : case MAP_INCH : fRatio = static_cast< double >( maResolution.Width ) * 0.0254; break;
917 0 : case MAP_MM : fRatio = static_cast< double >( maResolution.Width ) * 0.001; break;
918 0 : case MAP_POINT :fRatio = ( static_cast< double >( maResolution.Width ) * 0.0254 ) / 72.0; break;
919 : default:
920 0 : case MAP_CM : fRatio = static_cast< double >( maResolution.Width ) * 0.01; break;
921 : }
922 0 : mpMfSizeX->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Width * 100 ) / fRatio ) + 0.5 ) );
923 0 : mpMfSizeY->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Height * 100 ) / fRatio ) + 0.5 ) );
924 : }
925 : }
926 0 : sal_Int32 nResolution = 0;
927 0 : switch( mpLbResolution->GetSelectEntryPos() )
928 : {
929 0 : case 0 : nResolution = maResolution.Width / 100; break; // pixels / cm
930 0 : case 2 : nResolution = maResolution.Width; break; // pixels / meter
931 : default:
932 0 : case 1 : nResolution = static_cast< sal_Int32 >(maResolution.Width * 0.0254); break; // pixels / inch
933 : }
934 0 : mpNfResolution->SetValue( nResolution );
935 :
936 0 : if (mpSbCompression && mpSbCompression->IsVisible() && mpNfCompression)
937 0 : mpSbCompression->SetThumbPos(mpNfCompression->GetValue());
938 :
939 : // updating estimated size
940 0 : sal_Int64 nRealFileSize( mpTempStream->Tell() );
941 0 : if ( mbIsPixelFormat )
942 : {
943 0 : OUString aEst( nRealFileSize ? msEstimatedSizePix2 : msEstimatedSizePix1 );
944 0 : sal_Int64 nRawFileSize( GetRawFileSize() );
945 0 : sal_Int32 nInd = aEst.indexOf( "%" );
946 0 : if (nInd != -1)
947 0 : aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRawFileSize ) );
948 :
949 0 : if ( nRealFileSize && nInd != -1 )
950 : {
951 0 : nInd = aEst.indexOf( "%", nInd );
952 0 : if (nInd != -1)
953 0 : aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
954 : }
955 0 : mpFtEstimatedSize->SetText( aEst );
956 : }
957 : else
958 : {
959 0 : if ( mnMaxFilesizeForRealtimePreview )
960 : {
961 0 : OUString aEst( msEstimatedSizeVec );
962 0 : sal_Int32 nInd = aEst.indexOf( "%" );
963 0 : if (nInd != -1)
964 0 : aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
965 0 : mpFtEstimatedSize->SetText( aEst );
966 : }
967 : }
968 :
969 : // EPS
970 0 : if ( mpRbEPSLevel1->IsVisible() )
971 : {
972 0 : bool bEnabled = !mpRbEPSLevel1->IsChecked();
973 0 : mpRbEPSColorFormat1->Enable( bEnabled );
974 0 : mpRbEPSColorFormat2->Enable( bEnabled );
975 0 : mpRbEPSCompressionLZW->Enable( bEnabled );
976 0 : mpRbEPSCompressionNone->Enable( bEnabled );
977 : }
978 0 : }
979 :
980 0 : ExportDialog::~ExportDialog()
981 : {
982 0 : disposeOnce();
983 0 : }
984 :
985 0 : void ExportDialog::dispose()
986 : {
987 0 : delete mpFilterOptionsItem;
988 0 : delete mpOptionsItem;
989 0 : mpMfSizeX.clear();
990 0 : mpLbSizeX.clear();
991 0 : mpMfSizeY.clear();
992 0 : mpFtResolution.clear();
993 0 : mpNfResolution.clear();
994 0 : mpLbResolution.clear();
995 0 : mpColorDepth.clear();
996 0 : mpLbColorDepth.clear();
997 0 : mpJPGQuality.clear();
998 0 : mpPNGCompression.clear();
999 0 : mpSbCompression.clear();
1000 0 : mpNfCompression.clear();
1001 0 : mpMode.clear();
1002 0 : mpCbInterlaced.clear();
1003 0 : mpBMPCompression.clear();
1004 0 : mpCbRLEEncoding.clear();
1005 0 : mpDrawingObjects.clear();
1006 0 : mpCbSaveTransparency.clear();
1007 0 : mpEncoding.clear();
1008 0 : mpRbBinary.clear();
1009 0 : mpRbText.clear();
1010 0 : mpEPSGrid.clear();
1011 0 : mpCbEPSPreviewTIFF.clear();
1012 0 : mpCbEPSPreviewEPSI.clear();
1013 0 : mpRbEPSLevel1.clear();
1014 0 : mpRbEPSLevel2.clear();
1015 0 : mpRbEPSColorFormat1.clear();
1016 0 : mpRbEPSColorFormat2.clear();
1017 0 : mpRbEPSCompressionLZW.clear();
1018 0 : mpRbEPSCompressionNone.clear();
1019 0 : mpInfo.clear();
1020 0 : mpFtEstimatedSize.clear();
1021 0 : mpBtnOK.clear();
1022 0 : ModalDialog::dispose();
1023 0 : }
1024 :
1025 :
1026 : /*************************************************************************
1027 : |*
1028 : |* stores values set in the ini-file
1029 : |*
1030 : \************************************************************************/
1031 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdl)
1032 : {
1033 0 : updateControls();
1034 0 : return 0;
1035 : }
1036 :
1037 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeX)
1038 : {
1039 0 : double fRatio = static_cast< double >( maOriginalSize.Height ) / maOriginalSize.Width;
1040 :
1041 0 : if ( mbIsPixelFormat )
1042 : {
1043 0 : switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
1044 : {
1045 0 : case MAP_INCH : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1046 0 : case MAP_CM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.01 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1047 0 : case MAP_MM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.001 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1048 0 : case MAP_POINT : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * mpMfSizeX->GetValue() / 100.0 * 72 + 0.5 ); break;
1049 : default:
1050 0 : case MAP_PIXEL : maSize.Width = mpMfSizeX->GetValue(); break;
1051 : }
1052 0 : maSize.Height = static_cast< sal_Int32 >( fRatio * maSize.Width + 0.5 );
1053 : }
1054 : else
1055 : {
1056 0 : Fraction aFract( 1, 100 );
1057 0 : sal_Int32 nWidth = mpMfSizeX->GetValue();
1058 0 : sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio );
1059 0 : const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) );
1060 0 : MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
1061 0 : Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) );
1062 :
1063 0 : maSize.Width = aDest.Width();
1064 0 : if ( mbPreserveAspectRatio )
1065 0 : maSize.Height = aDest.Height();
1066 : }
1067 0 : updateControls();
1068 0 : return 0;
1069 : }
1070 :
1071 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeY)
1072 : {
1073 0 : double fRatio = static_cast< double >( maOriginalSize.Width ) / maOriginalSize.Height;
1074 :
1075 0 : if ( mbIsPixelFormat )
1076 : {
1077 0 : switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
1078 : {
1079 0 : case MAP_INCH : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1080 0 : case MAP_CM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.01 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1081 0 : case MAP_MM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.001 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1082 0 : case MAP_POINT : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * mpMfSizeY->GetValue() / 100.0 * 72 + 0.5 ); break;
1083 : default:
1084 0 : case MAP_PIXEL : maSize.Height = mpMfSizeY->GetValue(); break;
1085 : }
1086 0 : maSize.Width = static_cast< sal_Int32 >( fRatio * maSize.Height + 0.5 );
1087 : }
1088 : else
1089 : {
1090 0 : Fraction aFract( 1, 100 );
1091 0 : sal_Int32 nHeight= mpMfSizeY->GetValue();
1092 0 : sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio );
1093 0 : const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) );
1094 0 : MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
1095 0 : Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) );
1096 :
1097 0 : maSize.Height = aDest.Height();
1098 0 : if ( mbPreserveAspectRatio )
1099 0 : maSize.Width = aDest.Width();
1100 : }
1101 0 : updateControls();
1102 0 : return 0;
1103 : }
1104 :
1105 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdlNfResolution)
1106 : {
1107 0 : sal_Int32 nResolution = mpNfResolution->GetValue();
1108 0 : if ( mpLbResolution->GetSelectEntryPos() == 0 ) // pixels / cm
1109 0 : nResolution *= 100;
1110 0 : else if ( mpLbResolution->GetSelectEntryPos() == 1 ) // pixels / inch
1111 0 : nResolution = static_cast< sal_Int32 >( ( ( static_cast< double >( nResolution ) + 0.5 ) / 0.0254 ) );
1112 0 : maResolution.Width = nResolution;
1113 0 : maResolution.Height= nResolution;
1114 :
1115 0 : updateControls();
1116 0 : return 0;
1117 : }
1118 :
1119 0 : IMPL_LINK_NOARG(ExportDialog, SbCompressionUpdateHdl)
1120 : {
1121 0 : mpNfCompression->SetValue( mpSbCompression->GetThumbPos() );
1122 0 : updateControls();
1123 0 : return 0;
1124 : }
1125 :
1126 0 : IMPL_LINK_NOARG(ExportDialog, OK)
1127 : {
1128 : // writing config parameter
1129 :
1130 :
1131 0 : mrFltCallPara.aFilterData = GetFilterData( true );
1132 0 : EndDialog( RET_OK );
1133 :
1134 0 : return 0;
1135 798 : }
1136 :
1137 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|