GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / filter / exportdialog.cxx
blobfe152ff683c45bb91d7f9a413ab0aa1c5efc732f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #ifndef __GNUC__
22 # pragma hdrstop
23 #endif
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"
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
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
76 using namespace ::com::sun::star;
78 static sal_Int16 GetFilterFormat(const OUString& rExt)
80 sal_Int16 nFormat = FORMAT_UNKNOWN;
81 if ( rExt == "JPG" )
82 nFormat = FORMAT_JPG;
83 else if ( rExt == "PNG" )
84 nFormat = FORMAT_PNG;
85 else if ( rExt == "BMP" )
86 nFormat = FORMAT_BMP;
87 else if ( rExt == "GIF" )
88 nFormat = FORMAT_GIF;
89 else if ( rExt == "PBM" )
90 nFormat = FORMAT_PBM;
91 else if ( rExt == "PGM" )
92 nFormat = FORMAT_PGM;
93 else if ( rExt == "PPM" )
94 nFormat = FORMAT_PPM;
95 else if ( rExt == "PCT" )
96 nFormat = FORMAT_PCT;
97 else if ( rExt == "RAS" )
98 nFormat = FORMAT_RAS;
99 else if ( rExt == "TIF" )
100 nFormat = FORMAT_TIF;
101 else if ( rExt == "XPM" )
102 nFormat = FORMAT_XPM;
103 else if ( rExt == "WMF" )
104 nFormat = FORMAT_WMF;
105 else if ( rExt == "EMF" )
106 nFormat = FORMAT_EMF;
107 else if ( rExt == "EPS" )
108 nFormat = FORMAT_EPS;
109 else if ( rExt == "MET" )
110 nFormat = FORMAT_MET;
111 else if ( rExt == "SVG" )
112 nFormat = FORMAT_SVG;
113 else if ( rExt == "SVM" )
114 nFormat = FORMAT_SVM;
115 return nFormat;
118 static MapUnit GetMapUnit( sal_Int32 nUnit )
120 MapUnit aMapUnit( MAP_PIXEL );
121 switch( nUnit )
123 case UNIT_INCH : aMapUnit = MAP_INCH; break;
124 case UNIT_CM : aMapUnit = MAP_CM; break;
125 case UNIT_MM : aMapUnit = MAP_MM; break;
126 case UNIT_POINT : aMapUnit = MAP_POINT; break;
127 case UNIT_PIXEL : aMapUnit = MAP_PIXEL; break;
129 return aMapUnit;
132 sal_Int32 ExportDialog::GetDefaultUnit()
134 sal_Int32 nDefaultUnit = UNIT_CM;
135 switch( mrFltCallPara.eFieldUnit )
137 // case FUNIT_NONE :
138 // case FUNIT_PERCENT :
139 // case FUNIT_CUSTOM :
140 default: nDefaultUnit = UNIT_CM; break;
142 case FUNIT_MILE : // PASSTHROUGH INTENDED
143 case FUNIT_FOOT :
144 case FUNIT_TWIP :
145 case FUNIT_PICA : nDefaultUnit = UNIT_INCH; break;
147 case FUNIT_KM : // PASSTHROUGH INTENDED
148 case FUNIT_M :
149 case FUNIT_100TH_MM : nDefaultUnit = UNIT_CM; break;
151 case FUNIT_INCH : nDefaultUnit = UNIT_INCH; break;
152 case FUNIT_CM : nDefaultUnit = UNIT_CM; break;
153 case FUNIT_MM : nDefaultUnit = UNIT_MM; break;
154 case FUNIT_POINT : nDefaultUnit = UNIT_POINT; break;
156 return nDefaultUnit;
159 static basegfx::B2DRange GetShapeRangeForXShape( const uno::Reference< drawing::XShape >& rxShape,
160 const uno::Reference< graphic::XPrimitiveFactory2D >& rxPrimitiveFactory2D, const uno::Sequence< beans::PropertyValue >& rViewInformation )
162 basegfx::B2DRange aShapeRange;
164 const uno::Sequence< beans::PropertyValue > aParams;
165 const uno::Sequence< uno::Reference< graphic::XPrimitive2D > > aPrimitiveSequence( rxPrimitiveFactory2D->createPrimitivesFromXShape( rxShape, aParams ) );
167 const sal_Int32 nCount = aPrimitiveSequence.getLength();
168 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
170 const geometry::RealRectangle2D aRect( aPrimitiveSequence[ nIndex ]->getRange( rViewInformation ) );
171 aShapeRange.expand( basegfx::B2DTuple( aRect.X1, aRect.Y1 ) );
172 aShapeRange.expand( basegfx::B2DTuple( aRect.X2, aRect.Y2 ) );
174 return aShapeRange;
177 uno::Sequence< beans::PropertyValue > ExportDialog::GetFilterData( sal_Bool bUpdateConfig )
179 if ( bUpdateConfig )
181 sal_Int32 nUnit = mpLbSizeX->GetSelectEntryPos();
182 if ( nUnit < 0 )
183 nUnit = UNIT_CM;
185 if ( ( mnInitialResolutionUnit == UNIT_DEFAULT ) && ( nUnit == GetDefaultUnit() ) )
186 nUnit = UNIT_DEFAULT;
188 // updating ui configuration
189 if ( mbIsPixelFormat )
191 if ( nUnit > UNIT_MAX_ID )
192 nUnit = UNIT_PIXEL;
194 sal_Int32 nResolution = mpNfResolution->GetValue();
195 if ( nResolution < 1 )
196 nResolution = 96;
198 mpOptionsItem->WriteInt32(OUString("PixelExportUnit"), nUnit);
199 mpOptionsItem->WriteInt32(OUString("PixelExportResolution"), nResolution);
200 mpOptionsItem->WriteInt32(OUString("PixelExportResolutionUnit"), mpLbResolution->GetSelectEntryPos());
202 else
204 if ( nUnit >= UNIT_PIXEL )
205 nUnit = UNIT_CM;
207 mpOptionsItem->WriteInt32(OUString("VectorExportUnit"), nUnit);
211 FilterConfigItem* pFilterOptions;
212 if ( bUpdateConfig )
213 pFilterOptions = mpFilterOptionsItem;
214 else
216 uno::Sequence< beans::PropertyValue > aFilterData( mpFilterOptionsItem->GetFilterData() );
217 pFilterOptions = new FilterConfigItem( &aFilterData );
220 const OUString sLogicalWidth(OUString("LogicalWidth"));
221 const OUString sLogicalHeight(OUString("LogicalHeight"));
222 if ( mbIsPixelFormat )
224 pFilterOptions->WriteInt32(OUString("PixelWidth"), static_cast< sal_Int32 >( maSize.Width ) );
225 pFilterOptions->WriteInt32(OUString("PixelHeight"), static_cast< sal_Int32 >( maSize.Height ) );
226 if ( maResolution.Width && maResolution.Height )
228 const double f100thmmPerPixelX = 100000.0 / maResolution.Width;
229 const double f100thmmPerPixelY = 100000.0 / maResolution.Height;
230 sal_Int32 nLogicalWidth = static_cast< sal_Int32 >( f100thmmPerPixelX * maSize.Width );
231 sal_Int32 nLogicalHeight= static_cast< sal_Int32 >( f100thmmPerPixelY * maSize.Height );
232 if ( nLogicalWidth && nLogicalHeight )
234 pFilterOptions->WriteInt32( sLogicalWidth, nLogicalWidth );
235 pFilterOptions->WriteInt32( sLogicalHeight, nLogicalHeight );
239 else
241 pFilterOptions->WriteInt32( sLogicalWidth, static_cast< sal_Int32 >( maSize.Width ) );
242 pFilterOptions->WriteInt32( sLogicalHeight, static_cast< sal_Int32 >( maSize.Height ) );
244 switch ( mnFormat )
246 case FORMAT_JPG :
248 sal_Int32 nColor = mpLbColorDepth->GetSelectEntryPos();
249 if ( nColor == 1 )
250 nColor = 0;
251 else
252 nColor = 1;
253 pFilterOptions->WriteInt32(OUString("ColorMode"), nColor);
254 pFilterOptions->WriteInt32(OUString("Quality"), static_cast<sal_Int32>(mpSbCompression->GetThumbPos()));
256 break;
258 case FORMAT_PNG :
260 pFilterOptions->WriteInt32(OUString("Compression"), static_cast<sal_Int32>(mpSbCompression->GetThumbPos()));
261 sal_Int32 nInterlace = 0;
262 if ( mpCbInterlaced->IsChecked() )
263 nInterlace++;
264 pFilterOptions->WriteInt32(OUString("Interlaced"), nInterlace);
265 sal_Int32 nValue = 0;
266 if ( mpCbSaveTransparency->IsChecked() )
267 nValue++;
268 pFilterOptions->WriteInt32(OUString("Translucent"), nValue);
270 break;
272 case FORMAT_BMP :
274 pFilterOptions->WriteInt32(OUString("Color"), mpLbColorDepth->GetSelectEntryPos() + 1);
275 pFilterOptions->WriteBool(OUString("RLE_Coding"), mpCbRLEEncoding->IsChecked());
277 break;
279 case FORMAT_GIF :
281 sal_Int32 nValue = 0;
282 if ( mpCbInterlaced->IsChecked() )
283 nValue++;
284 pFilterOptions->WriteInt32(OUString("Interlaced"), nValue);
286 nValue = 0;
287 if (mpCbSaveTransparency->IsChecked())
288 nValue++;
289 pFilterOptions->WriteInt32(OUString("Translucent"), nValue);
291 break;
293 case FORMAT_PBM :
294 case FORMAT_PGM :
295 case FORMAT_PPM :
297 sal_Int32 nFormat = 0;
298 if ( mpRbText->IsChecked() )
299 nFormat++;
300 pFilterOptions->WriteInt32(OUString("FileFormat"), nFormat);
302 break;
304 case FORMAT_EPS :
306 sal_Int32 nCheck = 0;
307 if ( mpCbEPSPreviewTIFF->IsChecked() )
308 nCheck++;
309 if ( mpCbEPSPreviewEPSI->IsChecked() )
310 nCheck += 2;
311 pFilterOptions->WriteInt32(OUString("Preview"), nCheck);
313 nCheck = 1;
314 if ( mpRbEPSLevel2->IsChecked() )
315 nCheck++;
316 pFilterOptions->WriteInt32(OUString("Version"), nCheck);
318 nCheck = 1;
319 if ( mpRbEPSColorFormat2->IsChecked() )
320 nCheck++;
321 pFilterOptions->WriteInt32(OUString("ColorFormat"), nCheck);
323 nCheck = 1;
324 if ( mpRbEPSCompressionNone->IsChecked() )
325 nCheck++;
326 pFilterOptions->WriteInt32(OUString("CompressionMode"), nCheck);
328 break;
331 uno::Sequence< beans::PropertyValue > aRet( pFilterOptions->GetFilterData() );
332 if ( bUpdateConfig == sal_False )
333 delete pFilterOptions;
334 return aRet;
338 awt::Size ExportDialog::GetOriginalSize()
340 basegfx::B2DRange aShapesRange;
342 if ( mxPage.is () )
344 uno::Reference< beans::XPropertySet > xPagePropSet( mxPage, uno::UNO_QUERY );
345 if ( xPagePropSet.is() )
347 sal_Int32 nWidth = 0;
348 sal_Int32 nHeight= 0;
349 com::sun::star::uno::Any aAny;
350 aAny = xPagePropSet->getPropertyValue("Width");
351 aAny >>= nWidth;
352 aAny = xPagePropSet->getPropertyValue("Height");
353 aAny >>= nHeight;
354 aShapesRange = basegfx::B2DRange( 0, 0, nWidth, nHeight );
357 else
359 uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory = graphic::PrimitiveFactory2D::create( mxContext );
361 basegfx::B2DHomMatrix aViewTransformation( Application::GetDefaultDevice()->GetViewTransformation() );
362 com::sun::star::geometry::AffineMatrix2D aTransformation;
363 aTransformation.m00 = aViewTransformation.get(0,0);
364 aTransformation.m01 = aViewTransformation.get(0,1);
365 aTransformation.m02 = aViewTransformation.get(0,2);
366 aTransformation.m10 = aViewTransformation.get(1,0);
367 aTransformation.m11 = aViewTransformation.get(1,1);
368 aTransformation.m12 = aViewTransformation.get(1,2);
370 const OUString sViewTransformation( "ViewTransformation" );
371 uno::Sequence< beans::PropertyValue > aViewInformation( 1 );
372 aViewInformation[ 0 ].Value <<= aTransformation;
373 aViewInformation[ 0 ].Name = sViewTransformation;
375 if ( mxShape.is() )
376 aShapesRange = GetShapeRangeForXShape( mxShape, xPrimitiveFactory, aViewInformation );
377 else if ( mxShapes.is() )
379 const sal_Int32 nCount = mxShapes->getCount();
380 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
382 uno::Reference< drawing::XShape > xShape;
383 mxShapes->getByIndex( nIndex ) >>= xShape;
384 aShapesRange.expand( GetShapeRangeForXShape( xShape, xPrimitiveFactory, aViewInformation ) );
388 return awt::Size( static_cast<sal_Int32>(aShapesRange.getWidth()), static_cast<sal_Int32>(aShapesRange.getHeight()) );
391 void ExportDialog::GetGraphicSource()
393 if ( mxSourceDocument.is() )
395 uno::Reference< frame::XModel > xModel( mxSourceDocument, uno::UNO_QUERY );
396 if ( xModel.is() )
398 uno::Reference< frame::XController > xController( xModel->getCurrentController() );
399 if ( xController.is() )
401 if ( mbExportSelection ) // check if there is a selection
403 uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY );
404 if ( xSelectionSupplier.is() )
406 uno::Any aAny( xSelectionSupplier->getSelection() );
407 if ( ! ( aAny >>= mxShapes ) )
408 aAny >>= mxShape;
411 if ( !mxShape.is() && !mxShapes.is() )
413 uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY );
414 if ( xDrawView.is() )
416 uno::Reference< drawing::XDrawPage > xCurrentPage( xDrawView->getCurrentPage() );
417 if ( xCurrentPage.is() )
419 mxPage = xCurrentPage; // exporting whole page
428 sal_Bool ExportDialog::GetGraphicStream()
430 sal_Bool bRet = sal_False;
432 if ( !IsTempExportAvailable() )
434 delete mpTempStream, mpTempStream = new SvMemoryStream();
435 maBitmap = Bitmap();
436 return bRet;
439 sal_Bool bRecreateOutputStream = mpTempStream->Tell() == 0;
441 static uno::Sequence< beans::PropertyValue > aOldFilterData;
442 uno::Sequence< beans::PropertyValue > aNewFilterData( GetFilterData( sal_False ) );
443 if ( aOldFilterData != aNewFilterData )
445 aOldFilterData = aNewFilterData;
446 bRecreateOutputStream = sal_True;
450 if ( bRecreateOutputStream )
452 delete mpTempStream, mpTempStream = new SvMemoryStream();
453 maBitmap = Bitmap();
455 uno::Reference < io::XStream > xStream( new utl::OStreamWrapper( *mpTempStream ) );
456 uno::Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() );
458 uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter =
459 drawing::GraphicExportFilter::create( mxContext );
461 OUString sFormat( maExt );
462 uno::Sequence< beans::PropertyValue > aDescriptor( 3 );
463 aDescriptor[0].Name = "OutputStream";
464 aDescriptor[0].Value <<= xOutputStream;
465 aDescriptor[1].Name = "FilterName";
466 aDescriptor[1].Value <<= sFormat;
467 aDescriptor[2].Name = "FilterData";
468 aDescriptor[2].Value <<= aNewFilterData;
470 uno::Reference< lang::XComponent > xSourceDoc;
471 if ( mxPage.is() )
472 xSourceDoc = uno::Reference< lang::XComponent >( mxPage, uno::UNO_QUERY_THROW );
473 else if ( mxShapes.is() )
474 xSourceDoc = uno::Reference< lang::XComponent >( mxShapes, uno::UNO_QUERY_THROW );
475 else if ( mxShape.is() )
476 xSourceDoc = uno::Reference< lang::XComponent >( mxShape, uno::UNO_QUERY_THROW );
477 if ( xSourceDoc.is() )
479 xGraphicExporter->setSourceDocument( xSourceDoc );
480 xGraphicExporter->filter( aDescriptor );
481 bRet = sal_True;
483 if ( mnFormat == FORMAT_JPG )
485 mpTempStream->Seek( STREAM_SEEK_TO_BEGIN );
486 maBitmap = GetGraphicBitmap( *mpTempStream );
487 mpTempStream->Seek( STREAM_SEEK_TO_END );
491 else
492 bRet = sal_True;
494 catch( uno::Exception& )
497 // ups
500 return bRet;
503 Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream )
505 Bitmap aRet;
506 Graphic aGraphic;
507 GraphicFilter aFilter( sal_False );
508 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 )
510 aRet = aGraphic.GetBitmap();
512 return aRet;
515 sal_uInt32 ExportDialog::GetRawFileSize() const
517 sal_uInt64 nRawFileSize = 0;
518 if ( mbIsPixelFormat )
520 sal_Int32 nBitsPerPixel = 24;
521 OUString aEntry( mpLbColorDepth->GetSelectEntry() );
522 if ( ms1BitTreshold == aEntry )
523 nBitsPerPixel = 1;
524 else if ( ms1BitDithered == aEntry )
525 nBitsPerPixel = 1;
526 else if ( ms4BitGrayscale == aEntry )
527 nBitsPerPixel = 4;
528 else if ( ms4BitColorPalette == aEntry )
529 nBitsPerPixel = 8;
530 else if ( ms8BitGrayscale == aEntry )
531 nBitsPerPixel = 8;
532 else if ( ms8BitColorPalette == aEntry )
533 nBitsPerPixel = 8;
534 else if ( ms24BitColor == aEntry )
535 nBitsPerPixel = 24;
537 if ( mbIsPixelFormat )
539 nRawFileSize = ( maSize.Width * nBitsPerPixel + 7 ) &~ 7; // rounding up to 8 bits
540 nRawFileSize /= 8; // in bytes
541 nRawFileSize *= maSize.Height;
543 if ( nRawFileSize > SAL_MAX_UINT32 )
544 nRawFileSize = 0;
546 return static_cast< sal_uInt32 >( nRawFileSize );
549 // checks if the source dimension/resolution is not too big
550 // to determine the exact graphic output size and preview for jpg
551 sal_Bool ExportDialog::IsTempExportAvailable() const
553 return GetRawFileSize() < static_cast< sal_uInt32 >( mnMaxFilesizeForRealtimePreview );
556 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 sal_Bool bExportSelection, sal_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 , mpTempStream(new SvMemoryStream())
580 , maOriginalSize(awt::Size(0, 0))
581 , mbIsPixelFormat(bIsPixelFormat)
582 , mbExportSelection(bExportSelection)
583 , mbPreserveAspectRatio(sal_True)
585 get(mpMfSizeX, "widthmf-nospin");
586 get(mpMfSizeY, "heightmf-nospin");
587 get(mpLbSizeX, "widthlb");
588 get(mpFtResolution, "resolutionft");
589 get(mpNfResolution, "resolutionmf-nospin");
590 get(mpLbResolution, "resolutionlb");
592 get(mpColorDepth, "colordepth");
593 get(mpLbColorDepth, "colordepthlb");
595 get(mpJPGQuality, "jpgquality");
596 get(mpPNGCompression, "pngcompression");
598 get(mpBMPCompression, "bmpcompression");
599 get(mpCbRLEEncoding, "rlecb");
601 get(mpMode, "mode");
602 get(mpCbInterlaced, "interlacedcb");
604 get(mpDrawingObjects, "drawingobjects");
605 get(mpCbSaveTransparency, "savetransparencycb");
607 get(mpEncoding, "encoding");
608 get(mpRbBinary, "binarycb");
609 get(mpRbText, "textcb");
611 get(mpEPSGrid, "epsgrid");
612 get(mpCbEPSPreviewTIFF, "tiffpreviewcb");
613 get(mpCbEPSPreviewEPSI, "epsipreviewcb");
614 get(mpRbEPSLevel1, "level1rb");
615 get(mpRbEPSLevel2, "level2rb");
616 get(mpRbEPSColorFormat1, "color1rb");
617 get(mpRbEPSColorFormat2, "color2rb");
618 get(mpRbEPSCompressionLZW, "compresslzw");
619 get(mpRbEPSCompressionNone, "compressnone");
621 GetGraphicSource();
623 get(mpInfo, "information");
624 get(mpFtEstimatedSize, "estsizeft");;
626 get(mpBtnOK, "ok");
628 maExt = maExt.toAsciiUpperCase();
630 OUString aFilterConfigPath( "Office.Common/Filter/Graphic/Export/" );
631 mpOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );
632 aFilterConfigPath += maExt;
633 mpFilterOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );
635 mnInitialResolutionUnit = mbIsPixelFormat
636 ? mpOptionsItem->ReadInt32(OUString("PixelExportUnit"), UNIT_DEFAULT)
637 : mpOptionsItem->ReadInt32(OUString( "VectorExportUnit"), UNIT_DEFAULT);
639 mnMaxFilesizeForRealtimePreview = mpOptionsItem->ReadInt32(OUString("MaxFilesizeForRealtimePreview"), 0);
640 mpFtEstimatedSize->SetText(OUString(" \n "));
642 OUString aTitle(maExt);
643 aTitle += GetText();
644 SetText(aTitle);
646 mnFormat = GetFilterFormat( maExt );
648 Size aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MAP_CM ) );
649 maResolution.Width = aResolution.Width();
650 maResolution.Height= aResolution.Height();
651 maOriginalSize = GetOriginalSize();
652 if ( bIsPixelFormat )
654 double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0;
655 maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ),
656 static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) );
658 else
660 maSize = maOriginalSize;
663 setupControls();
665 // Size
666 mpLbSizeX->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
668 if (mpSbCompression)
669 mpSbCompression->SetScrollHdl(LINK(this, ExportDialog, SbCompressionUpdateHdl));
670 if (mpNfCompression)
671 mpNfCompression->SetModifyHdl(LINK(this, ExportDialog, UpdateHdl));
673 mpMfSizeX->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeX ) );
674 mpMfSizeY->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeY ) );
676 mpNfResolution->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlNfResolution ) );
677 mpLbResolution->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
679 mpLbColorDepth->SetSelectHdl( LINK( this, ExportDialog, UpdateHdl ) );
681 mpCbInterlaced->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
683 mpCbSaveTransparency->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
685 mpCbEPSPreviewTIFF->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
686 mpCbEPSPreviewEPSI->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
688 mpRbEPSCompressionLZW->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
689 mpRbEPSCompressionNone->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
691 mpRbBinary->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
692 mpRbText->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
694 // BMP
695 mpCbRLEEncoding->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
697 // EPS
698 mpRbEPSLevel1->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
699 mpRbEPSLevel2->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
701 mpBtnOK->SetClickHdl( LINK( this, ExportDialog, OK ) );
703 updateControls();
706 void ExportDialog::setupSizeControls()
708 sal_Int32 nUnit = mnInitialResolutionUnit;
709 if (nUnit == UNIT_DEFAULT)
710 nUnit = GetDefaultUnit();
712 if (!mbIsPixelFormat)
714 mpFtResolution->Hide();
715 mpNfResolution->Hide();
716 mpLbResolution->Hide();
717 mpLbSizeX->RemoveEntry( UNIT_PIXEL ); // removing pixel
718 if ( nUnit >= UNIT_PIXEL )
719 nUnit = UNIT_CM;
721 else if ( nUnit > UNIT_MAX_ID )
722 nUnit = UNIT_PIXEL;
723 if ( nUnit < 0 )
724 nUnit = UNIT_CM;
725 mpLbSizeX->SelectEntryPos( static_cast< sal_uInt16 >( nUnit ) );
727 if ( mbIsPixelFormat ) // TODO: (metafileresolutionsupport) should be supported for vector formats also... this makes
728 { // sense eg for bitmap fillings in metafiles, to preserve high dpi output
729 // (atm without special vector support the bitmaps are rendered with 96dpi)
730 sal_Int32 nResolution = mpOptionsItem->ReadInt32(OUString("PixelExportResolution"), 96);
731 if ( nResolution < 1 )
732 nResolution = 96;
733 mpNfResolution->SetValue( nResolution );
735 sal_Int32 nResolutionUnit = mpOptionsItem->ReadInt32(OUString("PixelExportResolutionUnit"), 1);
736 if ( ( nResolutionUnit < 0 ) || ( nResolutionUnit > 2 ) )
737 nResolutionUnit = 1;
738 mpLbResolution->SelectEntryPos( static_cast< sal_uInt16 >( nResolutionUnit ) );
742 void ExportDialog::createFilterOptions()
744 switch( mnFormat )
746 case FORMAT_JPG :
748 sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("ColorMode"), 0);
749 if ( nColor == 1 )
750 nColor = 0;
751 else
752 nColor = 1;
753 mpLbColorDepth->InsertEntry( ms8BitGrayscale );
754 mpLbColorDepth->InsertEntry( ms24BitColor );
755 mpLbColorDepth->SelectEntryPos( nColor );
756 mpColorDepth->Show();
758 // Quality
759 mpJPGQuality->Show();
760 sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32(OUString("Quality"), 75);
761 if ((nQuality < 1 ) || (nQuality > 100))
762 nQuality = 75;
763 get(mpSbCompression, "compressionjpgsb");
764 get(mpNfCompression, "compressionjpgnf-nospin");
765 mpSbCompression->SetRangeMin( 1 );
766 mpSbCompression->SetRangeMax( 100 );
767 mpNfCompression->SetMin( 1 );
768 mpNfCompression->SetMax( 100 );
769 mpNfCompression->SetValue( nQuality );
770 mpNfCompression->SetStrictFormat( sal_True );
772 break;
773 case FORMAT_PNG :
775 // Compression 1..9
776 mpPNGCompression->Show();
777 sal_Int32 nCompression = mpFilterOptionsItem->ReadInt32(OUString("Compression"), 6);
778 if ( ( nCompression < 1 ) || ( nCompression > 9 ) )
779 nCompression = 6;
781 get(mpSbCompression, "compressionpngsb");
782 get(mpNfCompression, "compressionpngnf-nospin");
783 mpSbCompression->SetRangeMin( 1 );
784 mpSbCompression->SetRangeMax( 9 );
785 mpNfCompression->SetMin( 1 );
786 mpNfCompression->SetMax( 9 );
787 mpNfCompression->SetValue( 9 );
788 mpNfCompression->SetStrictFormat( sal_True );
790 // Interlaced
791 mpMode->Show();
792 mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32(OUString("Interlaced"), 0) != 0);
794 // Transparency
795 mpDrawingObjects->Show();
796 mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32(OUString("Translucent"), 1) != 0);
798 break;
799 case FORMAT_BMP :
801 sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("Color"), 0);
802 if ( nColor == 0 )
803 nColor = 6;
804 else
805 nColor--;
806 mpLbColorDepth->InsertEntry( ms1BitTreshold );
807 mpLbColorDepth->InsertEntry( ms1BitDithered );
808 mpLbColorDepth->InsertEntry( ms4BitGrayscale );
809 mpLbColorDepth->InsertEntry( ms4BitColorPalette );
810 mpLbColorDepth->InsertEntry( ms8BitGrayscale );
811 mpLbColorDepth->InsertEntry( ms8BitColorPalette );
812 mpLbColorDepth->InsertEntry( ms24BitColor );
813 mpLbColorDepth->SelectEntryPos( nColor );
814 mpColorDepth->Show();
816 // RLE coding
817 mpBMPCompression->Show();
818 mpCbRLEEncoding->Check(mpFilterOptionsItem->ReadBool(OUString("RLE_Coding"), sal_True));
820 break;
821 case FORMAT_GIF :
823 // Interlaced
824 mpMode->Show();
825 mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32(OUString("Interlaced"), 1) != 0);
827 // Transparency
828 mpDrawingObjects->Show();
829 mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32(OUString("Translucent"), 1) != 0);
831 break;
832 case FORMAT_PBM :
833 case FORMAT_PGM :
834 case FORMAT_PPM :
836 // RB Binary / Text
837 mpEncoding->Show();
838 sal_Int32 nFormat = mpFilterOptionsItem->ReadInt32(OUString("FileFormat"), 1);
839 mpRbBinary->Check( nFormat == 0 );
840 mpRbText->Check( nFormat != 0 );
842 break;
843 case FORMAT_EPS :
845 mpEPSGrid->Show();
847 sal_Int32 nPreview = mpFilterOptionsItem->ReadInt32(OUString("Preview"), 0);
848 sal_Int32 nVersion = mpFilterOptionsItem->ReadInt32(OUString("Version"), 2);
849 sal_Int32 nColor = mpFilterOptionsItem->ReadInt32(OUString("ColorFormat"), 0);
850 sal_Int32 nCompr = mpFilterOptionsItem->ReadInt32(OUString("CompressionMode"), 2);
852 mpFilterOptionsItem->ReadInt32(OUString("TextMode"), 0);
854 mpCbEPSPreviewTIFF->Check( ( nPreview & 1 ) != 0 );
855 mpCbEPSPreviewEPSI->Check( ( nPreview & 2 ) != 0 );
857 mpRbEPSLevel1->Check( nVersion == 1 );
858 mpRbEPSLevel2->Check( nVersion == 2 );
860 mpRbEPSColorFormat1->Check( nColor == 1 );
861 mpRbEPSColorFormat2->Check( nColor != 1 );
863 mpRbEPSCompressionLZW->Check( nCompr == 1 );
864 mpRbEPSCompressionNone->Check( nCompr != 1 );
866 break;
870 void ExportDialog::setupControls()
872 setupSizeControls();
873 createFilterOptions();
875 if (mnMaxFilesizeForRealtimePreview || mbIsPixelFormat)
876 mpInfo->Show();
879 static OUString ImpValueOfInKB( const sal_Int64& rVal )
881 double fVal( static_cast<double>( rVal ) );
882 fVal /= ( 1 << 10 );
883 fVal += 0.05;
884 OUStringBuffer aVal( OUString::number( fVal ) );
885 sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.', 0 ) );
886 if ( nX > 0 )
887 aVal.setLength( nX + 2 );
888 return aVal.makeStringAndClear();
891 void ExportDialog::updateControls()
893 GetGraphicStream();
895 // Size Controls
896 if ( !mbIsPixelFormat )
898 awt::Size aSize100thmm( maSize );
899 Size aSize( LogicToLogic( Size( aSize100thmm.Width * 100, aSize100thmm.Height * 100 ), MAP_100TH_MM,
900 MapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) ) ) );
901 mpMfSizeX->SetValue( aSize.Width() );
902 mpMfSizeY->SetValue( aSize.Height() );
904 else
906 MapUnit aMapUnit( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) );
907 if ( aMapUnit == MAP_PIXEL )
908 { // calculating pixel count via resolution and original graphic size
909 mpMfSizeX->SetDecimalDigits( 0 );
910 mpMfSizeY->SetDecimalDigits( 0 );
911 mpMfSizeX->SetValue( maSize.Width );
912 mpMfSizeY->SetValue( maSize.Height );
914 else
916 mpMfSizeX->SetDecimalDigits( 2 );
917 mpMfSizeY->SetDecimalDigits( 2 );
918 double fRatio;
919 switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
921 case MAP_INCH : fRatio = static_cast< double >( maResolution.Width ) * 0.0254; break;
922 case MAP_MM : fRatio = static_cast< double >( maResolution.Width ) * 0.001; break;
923 case MAP_POINT :fRatio = ( static_cast< double >( maResolution.Width ) * 0.0254 ) / 72.0; break;
924 default:
925 case MAP_CM : fRatio = static_cast< double >( maResolution.Width ) * 0.01; break;
927 mpMfSizeX->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Width * 100 ) / fRatio ) + 0.5 ) );
928 mpMfSizeY->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Height * 100 ) / fRatio ) + 0.5 ) );
931 sal_Int32 nResolution = 0;
932 switch( mpLbResolution->GetSelectEntryPos() )
934 case 0 : nResolution = maResolution.Width / 100; break; // pixels / cm
935 case 2 : nResolution = maResolution.Width; break; // pixels / meter
936 default:
937 case 1 : nResolution = static_cast< sal_Int32 >(maResolution.Width * 0.0254); break; // pixels / inch
939 mpNfResolution->SetValue( nResolution );
941 if (mpSbCompression && mpSbCompression->IsVisible() && mpNfCompression)
942 mpSbCompression->SetThumbPos(mpNfCompression->GetValue());
944 // updating estimated size
945 sal_Int64 nRealFileSize( mpTempStream->Tell() );
946 if ( mbIsPixelFormat )
948 OUString aEst( nRealFileSize ? msEstimatedSizePix2 : msEstimatedSizePix1 );
949 sal_Int64 nRawFileSize( GetRawFileSize() );
950 sal_Int32 nInd = aEst.indexOf( "%" );
951 if (nInd != -1)
952 aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRawFileSize ) );
954 if ( nRealFileSize && nInd != -1 )
956 nInd = aEst.indexOf( "%", nInd );
957 if (nInd != -1)
958 aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
960 mpFtEstimatedSize->SetText( aEst );
962 else
964 if ( mnMaxFilesizeForRealtimePreview )
966 OUString aEst( msEstimatedSizeVec );
967 sal_Int32 nInd = aEst.indexOf( "%" );
968 if (nInd != -1)
969 aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
970 mpFtEstimatedSize->SetText( aEst );
974 // EPS
975 if ( mpRbEPSLevel1->IsVisible() )
977 sal_Bool bEnabled = mpRbEPSLevel1->IsChecked() == sal_False;
978 mpRbEPSColorFormat1->Enable( bEnabled );
979 mpRbEPSColorFormat2->Enable( bEnabled );
980 mpRbEPSCompressionLZW->Enable( bEnabled );
981 mpRbEPSCompressionNone->Enable( bEnabled );
985 ExportDialog::~ExportDialog()
987 delete mpFilterOptionsItem;
988 delete mpOptionsItem;
992 /*************************************************************************
994 |* Speichert eingestellte Werte in ini-Datei
996 \************************************************************************/
997 IMPL_LINK_NOARG(ExportDialog, UpdateHdl)
999 updateControls();
1000 return 0;
1003 IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeX)
1005 double fRatio = static_cast< double >( maOriginalSize.Height ) / maOriginalSize.Width;
1007 if ( mbIsPixelFormat )
1009 switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
1011 case MAP_INCH : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1012 case MAP_CM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.01 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1013 case MAP_MM : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.001 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
1014 case MAP_POINT : maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * mpMfSizeX->GetValue() / 100.0 * 72 + 0.5 ); break;
1015 default:
1016 case MAP_PIXEL : maSize.Width = mpMfSizeX->GetValue(); break;
1018 maSize.Height = static_cast< sal_Int32 >( fRatio * maSize.Width + 0.5 );
1020 else
1022 Fraction aFract( 1, 100 );
1023 sal_Int32 nWidth = mpMfSizeX->GetValue();
1024 sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio );
1025 const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) );
1026 MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
1027 Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) );
1029 maSize.Width = aDest.Width();
1030 if ( mbPreserveAspectRatio )
1031 maSize.Height = aDest.Height();
1033 updateControls();
1034 return 0;
1037 IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeY)
1039 double fRatio = static_cast< double >( maOriginalSize.Width ) / maOriginalSize.Height;
1041 if ( mbIsPixelFormat )
1043 switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
1045 case MAP_INCH : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1046 case MAP_CM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.01 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1047 case MAP_MM : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.001 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
1048 case MAP_POINT : maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * mpMfSizeY->GetValue() / 100.0 * 72 + 0.5 ); break;
1049 default:
1050 case MAP_PIXEL : maSize.Height = mpMfSizeY->GetValue(); break;
1052 maSize.Width = static_cast< sal_Int32 >( fRatio * maSize.Height + 0.5 );
1054 else
1056 Fraction aFract( 1, 100 );
1057 sal_Int32 nHeight= mpMfSizeY->GetValue();
1058 sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio );
1059 const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) );
1060 MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
1061 Size aDest( LogicToLogic( aSource, aSourceMapMode, MAP_100TH_MM ) );
1063 maSize.Height = aDest.Height();
1064 if ( mbPreserveAspectRatio )
1065 maSize.Width = aDest.Width();
1067 updateControls();
1068 return 0;
1071 IMPL_LINK_NOARG(ExportDialog, UpdateHdlNfResolution)
1073 sal_Int32 nResolution = mpNfResolution->GetValue();
1074 if ( mpLbResolution->GetSelectEntryPos() == 0 ) // pixels / cm
1075 nResolution *= 100;
1076 else if ( mpLbResolution->GetSelectEntryPos() == 1 ) // pixels / inch
1077 nResolution = static_cast< sal_Int32 >( ( ( static_cast< double >( nResolution ) + 0.5 ) / 0.0254 ) );
1078 maResolution.Width = nResolution;
1079 maResolution.Height= nResolution;
1081 updateControls();
1082 return 0;
1085 IMPL_LINK_NOARG(ExportDialog, SbCompressionUpdateHdl)
1087 mpNfCompression->SetValue( mpSbCompression->GetThumbPos() );
1088 updateControls();
1089 return 0;
1092 IMPL_LINK_NOARG(ExportDialog, OK)
1094 // writing config parameter
1097 mrFltCallPara.aFilterData = GetFilterData( sal_True );
1098 EndDialog( RET_OK );
1100 return 0;
1103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */