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