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( sal_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(OUString("LogicalWidth"));
221 0 : const OUString sLogicalHeight(OUString("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 == sal_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 : sal_Bool ExportDialog::GetGraphicStream()
429 : {
430 0 : sal_Bool bRet = sal_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 : sal_Bool bRecreateOutputStream = mpTempStream->Tell() == 0;
440 :
441 0 : static uno::Sequence< beans::PropertyValue > aOldFilterData;
442 0 : uno::Sequence< beans::PropertyValue > aNewFilterData( GetFilterData( sal_False ) );
443 0 : if ( aOldFilterData != aNewFilterData )
444 : {
445 0 : aOldFilterData = aNewFilterData;
446 0 : bRecreateOutputStream = sal_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 : sal_Int32 nProperties = 2;
462 0 : uno::Sequence< beans::PropertyValue > aFilterData( nProperties );
463 :
464 :
465 0 : OUString sFormat( maExt );
466 0 : uno::Sequence< beans::PropertyValue > aDescriptor( 3 );
467 0 : aDescriptor[0].Name = OUString("OutputStream");
468 0 : aDescriptor[0].Value <<= xOutputStream;
469 0 : aDescriptor[1].Name = OUString("FilterName");
470 0 : aDescriptor[1].Value <<= sFormat;
471 0 : aDescriptor[2].Name = OUString("FilterData");
472 0 : aDescriptor[2].Value <<= aNewFilterData;
473 :
474 0 : uno::Reference< lang::XComponent > xSourceDoc;
475 0 : if ( mxPage.is() )
476 0 : xSourceDoc = uno::Reference< lang::XComponent >( mxPage, uno::UNO_QUERY_THROW );
477 0 : else if ( mxShapes.is() )
478 0 : xSourceDoc = uno::Reference< lang::XComponent >( mxShapes, uno::UNO_QUERY_THROW );
479 0 : else if ( mxShape.is() )
480 0 : xSourceDoc = uno::Reference< lang::XComponent >( mxShape, uno::UNO_QUERY_THROW );
481 0 : if ( xSourceDoc.is() )
482 : {
483 0 : xGraphicExporter->setSourceDocument( xSourceDoc );
484 0 : xGraphicExporter->filter( aDescriptor );
485 0 : bRet = sal_True;
486 :
487 0 : if ( mnFormat == FORMAT_JPG )
488 : {
489 0 : mpTempStream->Seek( STREAM_SEEK_TO_BEGIN );
490 0 : maBitmap = GetGraphicBitmap( *mpTempStream );
491 0 : mpTempStream->Seek( STREAM_SEEK_TO_END );
492 : }
493 0 : }
494 : }
495 : else
496 0 : bRet = sal_True;
497 : }
498 0 : catch( uno::Exception& )
499 : {
500 :
501 : // ups
502 :
503 : }
504 0 : return bRet;
505 : }
506 :
507 0 : Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream )
508 : {
509 0 : Bitmap aRet;
510 0 : Graphic aGraphic;
511 0 : GraphicFilter aFilter( sal_False );
512 0 : if ( aFilter.ImportGraphic( aGraphic, String(), rInputStream, GRFILTER_FORMAT_NOTFOUND, NULL, 0, static_cast<com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >*>(NULL), NULL ) == GRFILTER_OK )
513 : {
514 0 : aRet = aGraphic.GetBitmap();
515 : }
516 0 : return aRet;
517 : }
518 :
519 0 : sal_uInt32 ExportDialog::GetRawFileSize() const
520 : {
521 0 : sal_uInt64 nRawFileSize = 0;
522 0 : if ( mbIsPixelFormat )
523 : {
524 0 : sal_Int32 nBitsPerPixel = 24;
525 0 : String aEntry( mpLbColorDepth->GetSelectEntry() );
526 0 : if ( ms1BitTreshold == aEntry )
527 0 : nBitsPerPixel = 1;
528 0 : else if ( ms1BitDithered == aEntry )
529 0 : nBitsPerPixel = 1;
530 0 : else if ( ms4BitGrayscale == aEntry )
531 0 : nBitsPerPixel = 4;
532 0 : else if ( ms4BitColorPalette == aEntry )
533 0 : nBitsPerPixel = 8;
534 0 : else if ( ms8BitGrayscale == aEntry )
535 0 : nBitsPerPixel = 8;
536 0 : else if ( ms8BitColorPalette == aEntry )
537 0 : nBitsPerPixel = 8;
538 0 : else if ( ms24BitColor == aEntry )
539 0 : nBitsPerPixel = 24;
540 :
541 0 : if ( mbIsPixelFormat )
542 : {
543 0 : nRawFileSize = ( maSize.Width * nBitsPerPixel + 7 ) &~ 7; // rounding up to 8 bits
544 0 : nRawFileSize /= 8; // in bytes
545 0 : nRawFileSize *= maSize.Height;
546 : }
547 0 : if ( nRawFileSize > SAL_MAX_UINT32 )
548 0 : nRawFileSize = 0;
549 : }
550 0 : return static_cast< sal_uInt32 >( nRawFileSize );
551 : }
552 :
553 : // checks if the source dimension/resolution is not too big
554 : // to determine the exact graphic output size and preview for jpg
555 0 : sal_Bool ExportDialog::IsTempExportAvailable() const
556 : {
557 0 : return GetRawFileSize() < static_cast< sal_uInt32 >( mnMaxFilesizeForRealtimePreview );
558 : }
559 :
560 0 : ExportDialog::ExportDialog(FltCallDialogParameter& rPara,
561 : const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
562 : const com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxSourceDocument,
563 : sal_Bool bExportSelection, sal_Bool bIsPixelFormat)
564 : : ModalDialog(rPara.pWindow, "GraphicExportDialog", "svt/ui/graphicexport.ui")
565 : , mrFltCallPara(rPara)
566 : , mxContext(rxContext)
567 : , mxSourceDocument(rxSourceDocument)
568 : , mpSbCompression(NULL)
569 : , mpNfCompression(NULL)
570 : , msEstimatedSizePix1(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_PIX_1))
571 : , msEstimatedSizePix2(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_PIX_2))
572 : , msEstimatedSizeVec(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_VEC))
573 : , ms1BitTreshold(SVT_RESSTR(STR_SVT_1BIT_THRESHOLD))
574 : , ms1BitDithered(SVT_RESSTR(STR_SVT_1BIT_DITHERED))
575 : , ms4BitGrayscale(SVT_RESSTR(STR_SVT_4BIT_GRAYSCALE))
576 : , ms4BitColorPalette(SVT_RESSTR(STR_SVT_4BIT_COLOR_PALETTE))
577 : , ms8BitGrayscale(SVT_RESSTR(STR_SVT_8BIT_GRAYSCALE))
578 : , ms8BitColorPalette(SVT_RESSTR(STR_SVT_8BIT_COLOR_PALETTE))
579 : , ms24BitColor(SVT_RESSTR(STR_SVT_24BIT_TRUE_COLOR))
580 : , maExt(rPara.aFilterExt)
581 : , mnFormat(FORMAT_UNKNOWN)
582 : , mnMaxFilesizeForRealtimePreview(0)
583 0 : , mpTempStream(new SvMemoryStream())
584 : , maOriginalSize(awt::Size(0, 0))
585 : , mbIsPixelFormat(bIsPixelFormat)
586 : , mbExportSelection(bExportSelection)
587 0 : , mbPreserveAspectRatio(sal_True)
588 : {
589 0 : get(mpMfSizeX, "widthmf-nospin");
590 0 : get(mpMfSizeY, "heightmf-nospin");
591 0 : get(mpLbSizeX, "widthlb");
592 0 : get(mpFtResolution, "resolutionft");
593 0 : get(mpNfResolution, "resolutionmf-nospin");
594 0 : get(mpLbResolution, "resolutionlb");
595 :
596 0 : get(mpColorDepth, "colordepth");
597 0 : get(mpLbColorDepth, "colordepthlb");
598 :
599 0 : get(mpJPGQuality, "jpgquality");
600 0 : get(mpPNGCompression, "pngcompression");
601 :
602 0 : get(mpBMPCompression, "bmpcompression");
603 0 : get(mpCbRLEEncoding, "rlecb");
604 :
605 0 : get(mpMode, "mode");
606 0 : get(mpCbInterlaced, "interlacedcb");
607 :
608 0 : get(mpDrawingObjects, "drawingobjects");
609 0 : get(mpCbSaveTransparency, "savetransparencycb");
610 :
611 0 : get(mpEncoding, "encoding");
612 0 : get(mpRbBinary, "binarycb");
613 0 : get(mpRbText, "textcb");
614 :
615 0 : get(mpEPSGrid, "epsgrid");
616 0 : get(mpCbEPSPreviewTIFF, "tiffpreviewcb");
617 0 : get(mpCbEPSPreviewEPSI, "epsipreviewcb");
618 0 : get(mpRbEPSLevel1, "level1rb");
619 0 : get(mpRbEPSLevel2, "level2rb");
620 0 : get(mpRbEPSColorFormat1, "color1rb");
621 0 : get(mpRbEPSColorFormat2, "color2rb");
622 0 : get(mpRbEPSCompressionLZW, "compresslzw");
623 0 : get(mpRbEPSCompressionNone, "compressnone");
624 :
625 0 : GetGraphicSource();
626 :
627 0 : get(mpInfo, "information");
628 0 : get(mpFtEstimatedSize, "estsizeft");;
629 :
630 0 : get(mpBtnOK, "ok");
631 :
632 0 : maExt.ToUpperAscii();
633 :
634 0 : String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Export/" ) );
635 0 : mpOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );
636 0 : aFilterConfigPath.Append( maExt );
637 0 : mpFilterOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );
638 :
639 : mnInitialResolutionUnit = mbIsPixelFormat
640 0 : ? mpOptionsItem->ReadInt32(OUString("PixelExportUnit"), UNIT_DEFAULT)
641 0 : : mpOptionsItem->ReadInt32(OUString( "VectorExportUnit"), UNIT_DEFAULT);
642 :
643 0 : mnMaxFilesizeForRealtimePreview = mpOptionsItem->ReadInt32(OUString("MaxFilesizeForRealtimePreview"), 0);
644 0 : mpFtEstimatedSize->SetText(OUString(" \n "));
645 :
646 0 : String aTitle(maExt);
647 0 : aTitle += GetText();
648 0 : SetText(aTitle);
649 :
650 0 : mnFormat = GetFilterFormat( maExt );
651 :
652 0 : Size aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MAP_CM ) );
653 0 : maResolution.Width = aResolution.Width();
654 0 : maResolution.Height= aResolution.Height();
655 0 : maOriginalSize = GetOriginalSize();
656 0 : if ( bIsPixelFormat )
657 : {
658 0 : double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0;
659 0 : maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ),
660 0 : static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) );
661 : }
662 : else
663 : {
664 0 : maSize = maOriginalSize;
665 : }
666 :
667 0 : setupControls();
668 :
669 : // Size
670 0 : mpLbSizeX->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
671 :
672 0 : if (mpSbCompression)
673 0 : mpSbCompression->SetScrollHdl(LINK(this, ExportDialog, SbCompressionUpdateHdl));
674 0 : if (mpNfCompression)
675 0 : mpNfCompression->SetModifyHdl(LINK(this, ExportDialog, UpdateHdl));
676 :
677 0 : mpMfSizeX->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeX ) );
678 0 : mpMfSizeY->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeY ) );
679 :
680 0 : mpNfResolution->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlNfResolution ) );
681 0 : mpLbResolution->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
682 :
683 0 : mpLbColorDepth->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
684 :
685 0 : mpCbInterlaced->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
686 :
687 0 : mpCbSaveTransparency->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
688 :
689 0 : mpCbEPSPreviewTIFF->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
690 0 : mpCbEPSPreviewEPSI->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
691 :
692 0 : mpRbEPSCompressionLZW->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
693 0 : mpRbEPSCompressionNone->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
694 :
695 0 : mpRbBinary->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
696 0 : mpRbText->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
697 :
698 : // BMP
699 0 : mpCbRLEEncoding->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
700 :
701 : // EPS
702 0 : mpRbEPSLevel1->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
703 0 : mpRbEPSLevel2->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
704 :
705 0 : mpBtnOK->SetClickHdl( LINK( this, ExportDialog, OK ) );
706 :
707 0 : updateControls();
708 0 : }
709 :
710 0 : void ExportDialog::setupSizeControls()
711 : {
712 0 : sal_Int32 nUnit = mnInitialResolutionUnit;
713 0 : if (nUnit == UNIT_DEFAULT)
714 0 : nUnit = GetDefaultUnit();
715 :
716 0 : if (!mbIsPixelFormat)
717 : {
718 0 : mpFtResolution->Hide();
719 0 : mpNfResolution->Hide();
720 0 : mpLbResolution->Hide();
721 0 : mpLbSizeX->RemoveEntry( UNIT_PIXEL ); // removing pixel
722 0 : if ( nUnit >= UNIT_PIXEL )
723 0 : nUnit = UNIT_CM;
724 : }
725 0 : else if ( nUnit > UNIT_MAX_ID )
726 0 : nUnit = UNIT_PIXEL;
727 0 : if ( nUnit < 0 )
728 0 : nUnit = UNIT_CM;
729 0 : mpLbSizeX->SelectEntryPos( static_cast< sal_uInt16 >( nUnit ) );
730 :
731 0 : if ( mbIsPixelFormat ) // TODO: (metafileresolutionsupport) should be supported for vector formats also... this makes
732 : { // sense eg for bitmap fillings in metafiles, to preserve high dpi output
733 : // (atm without special vector support the bitmaps are rendered with 96dpi)
734 0 : sal_Int32 nResolution = mpOptionsItem->ReadInt32(OUString("PixelExportResolution"), 96);
735 0 : if ( nResolution < 1 )
736 0 : nResolution = 96;
737 0 : mpNfResolution->SetValue( nResolution );
738 :
739 0 : sal_Int32 nResolutionUnit = mpOptionsItem->ReadInt32(OUString("PixelExportResolutionUnit"), 1);
740 0 : if ( ( nResolutionUnit < 0 ) || ( nResolutionUnit > 2 ) )
741 0 : nResolutionUnit = 1;
742 0 : mpLbResolution->SelectEntryPos( static_cast< sal_uInt16 >( nResolutionUnit ) );
743 : }
744 0 : }
745 :
746 0 : void ExportDialog::createFilterOptions()
747 : {
748 0 : switch( mnFormat )
749 : {
750 : case FORMAT_JPG :
751 : {
752 0 : sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("ColorMode"), 0);
753 0 : if ( nColor == 1 )
754 0 : nColor = 0;
755 : else
756 0 : nColor = 1;
757 0 : mpLbColorDepth->InsertEntry( ms8BitGrayscale );
758 0 : mpLbColorDepth->InsertEntry( ms24BitColor );
759 0 : mpLbColorDepth->SelectEntryPos( nColor );
760 0 : mpColorDepth->Show();
761 :
762 : // Quality
763 0 : mpJPGQuality->Show();
764 0 : sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32(OUString("Quality"), 75);
765 0 : if ((nQuality < 1 ) || (nQuality > 100))
766 0 : nQuality = 75;
767 0 : get(mpSbCompression, "compressionjpgsb");
768 0 : get(mpNfCompression, "compressionjpgnf-nospin");
769 0 : mpSbCompression->SetRangeMin( 1 );
770 0 : mpSbCompression->SetRangeMax( 100 );
771 0 : mpNfCompression->SetMin( 1 );
772 0 : mpNfCompression->SetMax( 100 );
773 0 : mpNfCompression->SetValue( nQuality );
774 0 : mpNfCompression->SetStrictFormat( sal_True );
775 : }
776 0 : break;
777 : case FORMAT_PNG :
778 : {
779 : // Compression 1..9
780 0 : mpPNGCompression->Show();
781 0 : sal_Int32 nCompression = mpFilterOptionsItem->ReadInt32(OUString("Compression"), 6);
782 0 : if ( ( nCompression < 1 ) || ( nCompression > 9 ) )
783 0 : nCompression = 6;
784 :
785 0 : get(mpSbCompression, "compressionpngsb");
786 0 : get(mpNfCompression, "compressionpngnf-nospin");
787 0 : mpSbCompression->SetRangeMin( 1 );
788 0 : mpSbCompression->SetRangeMax( 9 );
789 0 : mpNfCompression->SetMin( 1 );
790 0 : mpNfCompression->SetMax( 9 );
791 0 : mpNfCompression->SetValue( 9 );
792 0 : mpNfCompression->SetStrictFormat( sal_True );
793 :
794 : // Interlaced
795 0 : mpMode->Show();
796 0 : mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32(OUString("Interlaced"), 0) != 0);
797 :
798 : // Transparency
799 0 : mpDrawingObjects->Show();
800 0 : mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32(OUString("Translucent"), 1) != 0);
801 : }
802 0 : break;
803 : case FORMAT_BMP :
804 : {
805 0 : sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("Color"), 0);
806 0 : if ( nColor == 0 )
807 0 : nColor = 6;
808 : else
809 0 : nColor--;
810 0 : mpLbColorDepth->InsertEntry( ms1BitTreshold );
811 0 : mpLbColorDepth->InsertEntry( ms1BitDithered );
812 0 : mpLbColorDepth->InsertEntry( ms4BitGrayscale );
813 0 : mpLbColorDepth->InsertEntry( ms4BitColorPalette );
814 0 : mpLbColorDepth->InsertEntry( ms8BitGrayscale );
815 0 : mpLbColorDepth->InsertEntry( ms8BitColorPalette );
816 0 : mpLbColorDepth->InsertEntry( ms24BitColor );
817 0 : mpLbColorDepth->SelectEntryPos( nColor );
818 0 : mpColorDepth->Show();
819 :
820 : // RLE coding
821 0 : mpBMPCompression->Show();
822 0 : mpCbRLEEncoding->Check(mpFilterOptionsItem->ReadBool(OUString("RLE_Coding"), sal_True));
823 : }
824 0 : break;
825 : case FORMAT_GIF :
826 : {
827 : // Interlaced
828 0 : mpMode->Show();
829 0 : mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32(OUString("Interlaced"), 1) != 0);
830 :
831 : // Transparency
832 0 : mpDrawingObjects->Show();
833 0 : mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32(OUString("Translucent"), 1) != 0);
834 : }
835 0 : break;
836 : case FORMAT_PBM :
837 : case FORMAT_PGM :
838 : case FORMAT_PPM :
839 : {
840 : // RB Binary / Text
841 0 : mpEncoding->Show();
842 0 : sal_Int32 nFormat = mpFilterOptionsItem->ReadInt32(OUString("FileFormat"), 1);
843 0 : mpRbBinary->Check( nFormat == 0 );
844 0 : mpRbText->Check( nFormat != 0 );
845 : }
846 0 : break;
847 : case FORMAT_EPS :
848 : {
849 0 : mpEPSGrid->Show();
850 :
851 0 : sal_Int32 nPreview = mpFilterOptionsItem->ReadInt32(OUString("Preview"), 0);
852 0 : sal_Int32 nVersion = mpFilterOptionsItem->ReadInt32(OUString("Version"), 2);
853 0 : sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("ColorFormat"), 0);
854 0 : sal_Int32 nCompr = mpFilterOptionsItem->ReadInt32(OUString("CompressionMode"), 2);
855 :
856 0 : mpFilterOptionsItem->ReadInt32(OUString("TextMode"), 0);
857 :
858 0 : mpCbEPSPreviewTIFF->Check( ( nPreview & 1 ) != 0 );
859 0 : mpCbEPSPreviewEPSI->Check( ( nPreview & 2 ) != 0 );
860 :
861 0 : mpRbEPSLevel1->Check( nVersion == 1 );
862 0 : mpRbEPSLevel2->Check( nVersion == 2 );
863 :
864 0 : mpRbEPSColorFormat1->Check( nColor == 1 );
865 0 : mpRbEPSColorFormat2->Check( nColor != 1 );
866 :
867 0 : mpRbEPSCompressionLZW->Check( nCompr == 1 );
868 0 : mpRbEPSCompressionNone->Check( nCompr != 1 );
869 : }
870 0 : break;
871 : }
872 0 : }
873 :
874 0 : void ExportDialog::setupControls()
875 : {
876 0 : setupSizeControls();
877 0 : createFilterOptions();
878 :
879 0 : if (mnMaxFilesizeForRealtimePreview || mbIsPixelFormat)
880 0 : mpInfo->Show();
881 0 : }
882 :
883 0 : static OUString ImpValueOfInKB( const sal_Int64& rVal )
884 : {
885 0 : double fVal( static_cast<double>( rVal ) );
886 0 : fVal /= ( 1 << 10 );
887 0 : fVal += 0.05;
888 0 : OUStringBuffer aVal( OUString::valueOf( fVal ) );
889 0 : sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.', 0 ) );
890 0 : if ( nX > 0 )
891 0 : aVal.setLength( nX + 2 );
892 0 : return aVal.makeStringAndClear();
893 : }
894 :
895 0 : void ExportDialog::updateControls()
896 : {
897 0 : GetGraphicStream();
898 :
899 : // Size Controls
900 0 : if ( !mbIsPixelFormat )
901 : {
902 0 : awt::Size aSize100thmm( maSize );
903 : Size aSize( LogicToLogic( Size( aSize100thmm.Width * 100, aSize100thmm.Height * 100 ), MAP_100TH_MM,
904 0 : MapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) ) ) );
905 0 : mpMfSizeX->SetValue( aSize.Width() );
906 0 : mpMfSizeY->SetValue( aSize.Height() );
907 : }
908 : else
909 : {
910 0 : MapUnit aMapUnit( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) );
911 0 : if ( aMapUnit == MAP_PIXEL )
912 : { // calculating pixel count via resolution and original graphic size
913 0 : mpMfSizeX->SetDecimalDigits( 0 );
914 0 : mpMfSizeY->SetDecimalDigits( 0 );
915 0 : mpMfSizeX->SetValue( maSize.Width );
916 0 : mpMfSizeY->SetValue( maSize.Height );
917 : }
918 : else
919 : {
920 0 : mpMfSizeX->SetDecimalDigits( 2 );
921 0 : mpMfSizeY->SetDecimalDigits( 2 );
922 : double fRatio;
923 0 : switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
924 : {
925 0 : case MAP_INCH : fRatio = static_cast< double >( maResolution.Width ) * 0.0254; break;
926 0 : case MAP_MM : fRatio = static_cast< double >( maResolution.Width ) * 0.001; break;
927 0 : case MAP_POINT :fRatio = ( static_cast< double >( maResolution.Width ) * 0.0254 ) / 72.0; break;
928 : default:
929 0 : case MAP_CM : fRatio = static_cast< double >( maResolution.Width ) * 0.01; break;
930 : }
931 0 : mpMfSizeX->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Width * 100 ) / fRatio ) + 0.5 ) );
932 0 : mpMfSizeY->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Height * 100 ) / fRatio ) + 0.5 ) );
933 : }
934 : }
935 0 : sal_Int32 nResolution = 0;
936 0 : switch( mpLbResolution->GetSelectEntryPos() )
937 : {
938 0 : case 0 : nResolution = maResolution.Width / 100; break; // pixels / cm
939 0 : case 2 : nResolution = maResolution.Width; break; // pixels / meter
940 : default:
941 0 : case 1 : nResolution = static_cast< sal_Int32 >(maResolution.Width * 0.0254); break; // pixels / inch
942 : }
943 0 : mpNfResolution->SetValue( nResolution );
944 :
945 0 : if (mpSbCompression && mpSbCompression->IsVisible() && mpNfCompression)
946 0 : mpSbCompression->SetThumbPos(mpNfCompression->GetValue());
947 :
948 : // updating estimated size
949 0 : sal_Int64 nRealFileSize( mpTempStream->Tell() );
950 0 : if ( mbIsPixelFormat )
951 : {
952 0 : String aEst( nRealFileSize ? msEstimatedSizePix2 : msEstimatedSizePix1 );
953 0 : sal_Int64 nRawFileSize( GetRawFileSize() );
954 0 : xub_StrLen nInd = aEst.Search( '%' );
955 0 : aEst.Replace( nInd, 2, ImpValueOfInKB( nRawFileSize ) );
956 :
957 0 : if ( nRealFileSize )
958 : {
959 0 : nInd = aEst.Search( '%', nInd );
960 0 : aEst.Replace( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
961 : }
962 0 : mpFtEstimatedSize->SetText( aEst );
963 : }
964 : else
965 : {
966 0 : if ( mnMaxFilesizeForRealtimePreview )
967 : {
968 0 : String aEst( msEstimatedSizeVec );
969 0 : xub_StrLen nInd = aEst.Search( '%', 0 );
970 0 : aEst.Replace( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
971 0 : mpFtEstimatedSize->SetText( aEst );
972 : }
973 : }
974 :
975 : // EPS
976 0 : if ( mpRbEPSLevel1->IsVisible() )
977 : {
978 0 : sal_Bool bEnabled = mpRbEPSLevel1->IsChecked() == sal_False;
979 0 : mpRbEPSColorFormat1->Enable( bEnabled );
980 0 : mpRbEPSColorFormat2->Enable( bEnabled );
981 0 : mpRbEPSCompressionLZW->Enable( bEnabled );
982 0 : mpRbEPSCompressionNone->Enable( bEnabled );
983 : }
984 0 : }
985 :
986 0 : ExportDialog::~ExportDialog()
987 : {
988 0 : delete mpFilterOptionsItem;
989 0 : delete mpOptionsItem;
990 0 : }
991 :
992 :
993 : /*************************************************************************
994 : |*
995 : |* Speichert eingestellte Werte in ini-Datei
996 : |*
997 : \************************************************************************/
998 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdl)
999 : {
1000 0 : updateControls();
1001 0 : return 0;
1002 : }
1003 :
1004 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeX)
1005 : {
1006 0 : double fRatio = static_cast< double >( maOriginalSize.Height ) / maOriginalSize.Width;
1007 :
1008 0 : if ( mbIsPixelFormat )
1009 : {
1010 0 : switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
1011 : {
1012 0 : case MAP_INCH : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1013 0 : case MAP_CM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.01 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1014 0 : case MAP_MM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.001 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1015 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;
1016 : default:
1017 0 : case MAP_PIXEL : maSize.Width = mpMfSizeX->GetValue(); break;
1018 : }
1019 0 : maSize.Height = static_cast< sal_Int32 >( fRatio * maSize.Width + 0.5 );
1020 : }
1021 : else
1022 : {
1023 0 : Fraction aFract( 1, 100 );
1024 0 : sal_Int32 nWidth = mpMfSizeX->GetValue();
1025 0 : sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio );
1026 0 : const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) );
1027 0 : MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
1028 0 : Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) );
1029 :
1030 0 : maSize.Width = aDest.Width();
1031 0 : if ( mbPreserveAspectRatio )
1032 0 : maSize.Height = aDest.Height();
1033 : }
1034 0 : updateControls();
1035 0 : return 0;
1036 : }
1037 :
1038 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeY)
1039 : {
1040 0 : double fRatio = static_cast< double >( maOriginalSize.Width ) / maOriginalSize.Height;
1041 :
1042 0 : if ( mbIsPixelFormat )
1043 : {
1044 0 : switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
1045 : {
1046 0 : case MAP_INCH : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1047 0 : case MAP_CM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.01 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1048 0 : case MAP_MM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.001 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1049 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;
1050 : default:
1051 0 : case MAP_PIXEL : maSize.Height = mpMfSizeY->GetValue(); break;
1052 : }
1053 0 : maSize.Width = static_cast< sal_Int32 >( fRatio * maSize.Height + 0.5 );
1054 : }
1055 : else
1056 : {
1057 0 : Fraction aFract( 1, 100 );
1058 0 : sal_Int32 nHeight= mpMfSizeY->GetValue();
1059 0 : sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio );
1060 0 : const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) );
1061 0 : MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
1062 0 : Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) );
1063 :
1064 0 : maSize.Height = aDest.Height();
1065 0 : if ( mbPreserveAspectRatio )
1066 0 : maSize.Width = aDest.Width();
1067 : }
1068 0 : updateControls();
1069 0 : return 0;
1070 : }
1071 :
1072 0 : IMPL_LINK_NOARG(ExportDialog, UpdateHdlNfResolution)
1073 : {
1074 0 : sal_Int32 nResolution = mpNfResolution->GetValue();
1075 0 : if ( mpLbResolution->GetSelectEntryPos() == 0 ) // pixels / cm
1076 0 : nResolution *= 100;
1077 0 : else if ( mpLbResolution->GetSelectEntryPos() == 1 ) // pixels / inch
1078 0 : nResolution = static_cast< sal_Int32 >( ( ( static_cast< double >( nResolution ) + 0.5 ) / 0.0254 ) );
1079 0 : maResolution.Width = nResolution;
1080 0 : maResolution.Height= nResolution;
1081 :
1082 0 : updateControls();
1083 0 : return 0;
1084 : }
1085 :
1086 0 : IMPL_LINK_NOARG(ExportDialog, SbCompressionUpdateHdl)
1087 : {
1088 0 : mpNfCompression->SetValue( mpSbCompression->GetThumbPos() );
1089 0 : updateControls();
1090 0 : return 0;
1091 : }
1092 :
1093 0 : IMPL_LINK_NOARG(ExportDialog, OK)
1094 : {
1095 : // writing config parameter
1096 :
1097 :
1098 0 : mrFltCallPara.aFilterData = GetFilterData( sal_True );
1099 0 : EndDialog( RET_OK );
1100 :
1101 0 : return 0;
1102 465 : }
1103 :
1104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|