1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <tools/stream.hxx>
22 #include <tools/fract.hxx>
23 #include <vcl/graphicfilter.hxx>
24 #include <vcl/FilterConfigItem.hxx>
25 #include <svtools/svtools.hrc>
26 #include <svtools/svtresid.hxx>
27 #include <com/sun/star/awt/Size.hpp>
28 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
29 #include <com/sun/star/drawing/XDrawView.hpp>
30 #include <com/sun/star/frame/XModel.hpp>
31 #include <com/sun/star/frame/XController.hpp>
32 #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
33 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
34 #include <com/sun/star/io/XStream.hpp>
35 #include <com/sun/star/view/XSelectionSupplier.hpp>
36 #include <unotools/streamwrap.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/outdev.hxx>
40 #include <vcl/graph.hxx>
41 #include <rtl/ustrbuf.hxx>
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 #include <comphelper/processfactory.hxx>
44 #include "exportdialog.hxx"
46 #define FORMAT_UNKNOWN 0
65 #define UNIT_DEFAULT -1
71 #define UNIT_MAX_ID UNIT_PIXEL
73 using namespace ::com::sun::star
;
75 static sal_Int16
GetFilterFormat(const OUString
& rExt
)
77 sal_Int16 nFormat
= FORMAT_UNKNOWN
;
80 else if ( rExt
== "PNG" )
82 else if ( rExt
== "BMP" )
84 else if ( rExt
== "GIF" )
86 else if ( rExt
== "PBM" )
88 else if ( rExt
== "PGM" )
90 else if ( rExt
== "PPM" )
92 else if ( rExt
== "PCT" )
94 else if ( rExt
== "RAS" )
96 else if ( rExt
== "TIF" )
98 else if ( rExt
== "XPM" )
100 else if ( rExt
== "WMF" )
101 nFormat
= FORMAT_WMF
;
102 else if ( rExt
== "EMF" )
103 nFormat
= FORMAT_EMF
;
104 else if ( rExt
== "EPS" )
105 nFormat
= FORMAT_EPS
;
106 else if ( rExt
== "MET" )
107 nFormat
= FORMAT_MET
;
108 else if ( rExt
== "SVG" )
109 nFormat
= FORMAT_SVG
;
110 else if ( rExt
== "SVM" )
111 nFormat
= FORMAT_SVM
;
115 static MapUnit
GetMapUnit( sal_Int32 nUnit
)
117 MapUnit
aMapUnit( MAP_PIXEL
);
120 case UNIT_INCH
: aMapUnit
= MAP_INCH
; break;
121 case UNIT_CM
: aMapUnit
= MAP_CM
; break;
122 case UNIT_MM
: aMapUnit
= MAP_MM
; break;
123 case UNIT_POINT
: aMapUnit
= MAP_POINT
; break;
124 case UNIT_PIXEL
: aMapUnit
= MAP_PIXEL
; break;
129 sal_Int32
ExportDialog::GetDefaultUnit()
131 sal_Int32 nDefaultUnit
= UNIT_CM
;
132 switch( mrFltCallPara
.eFieldUnit
)
135 // case FUNIT_PERCENT :
136 // case FUNIT_CUSTOM :
137 default: nDefaultUnit
= UNIT_CM
; break;
139 case FUNIT_MILE
: // PASSTHROUGH INTENDED
142 case FUNIT_PICA
: nDefaultUnit
= UNIT_INCH
; break;
144 case FUNIT_KM
: // PASSTHROUGH INTENDED
146 case FUNIT_100TH_MM
: nDefaultUnit
= UNIT_CM
; break;
148 case FUNIT_INCH
: nDefaultUnit
= UNIT_INCH
; break;
149 case FUNIT_CM
: nDefaultUnit
= UNIT_CM
; break;
150 case FUNIT_MM
: nDefaultUnit
= UNIT_MM
; break;
151 case FUNIT_POINT
: nDefaultUnit
= UNIT_POINT
; break;
156 static basegfx::B2DRange
GetShapeRangeForXShape( const uno::Reference
< drawing::XShape
>& rxShape
,
157 const uno::Reference
< graphic::XPrimitiveFactory2D
>& rxPrimitiveFactory2D
, const uno::Sequence
< beans::PropertyValue
>& rViewInformation
)
159 basegfx::B2DRange aShapeRange
;
161 const uno::Sequence
< beans::PropertyValue
> aParams
;
162 const uno::Sequence
< uno::Reference
< graphic::XPrimitive2D
> > aPrimitiveSequence( rxPrimitiveFactory2D
->createPrimitivesFromXShape( rxShape
, aParams
) );
164 const sal_Int32 nCount
= aPrimitiveSequence
.getLength();
165 for( sal_Int32 nIndex
= 0; nIndex
< nCount
; nIndex
++ )
167 const geometry::RealRectangle2D
aRect( aPrimitiveSequence
[ nIndex
]->getRange( rViewInformation
) );
168 aShapeRange
.expand( basegfx::B2DTuple( aRect
.X1
, aRect
.Y1
) );
169 aShapeRange
.expand( basegfx::B2DTuple( aRect
.X2
, aRect
.Y2
) );
174 uno::Sequence
< beans::PropertyValue
> ExportDialog::GetFilterData( bool bUpdateConfig
)
178 sal_Int32 nUnit
= mpLbSizeX
->GetSelectEntryPos();
182 if ( ( mnInitialResolutionUnit
== UNIT_DEFAULT
) && ( nUnit
== GetDefaultUnit() ) )
183 nUnit
= UNIT_DEFAULT
;
185 // updating ui configuration
186 if ( mbIsPixelFormat
)
188 if ( nUnit
> UNIT_MAX_ID
)
191 sal_Int32 nResolution
= mpNfResolution
->GetValue();
192 if ( nResolution
< 1 )
195 mpOptionsItem
->WriteInt32(OUString("PixelExportUnit"), nUnit
);
196 mpOptionsItem
->WriteInt32(OUString("PixelExportResolution"), nResolution
);
197 mpOptionsItem
->WriteInt32(OUString("PixelExportResolutionUnit"), mpLbResolution
->GetSelectEntryPos());
201 if ( nUnit
>= UNIT_PIXEL
)
204 mpOptionsItem
->WriteInt32(OUString("VectorExportUnit"), nUnit
);
208 FilterConfigItem
* pFilterOptions
;
210 pFilterOptions
= mpFilterOptionsItem
;
213 uno::Sequence
< beans::PropertyValue
> aFilterData( mpFilterOptionsItem
->GetFilterData() );
214 pFilterOptions
= new FilterConfigItem( &aFilterData
);
217 const OUString
sLogicalWidth("LogicalWidth");
218 const OUString
sLogicalHeight("LogicalHeight");
219 if ( mbIsPixelFormat
)
221 pFilterOptions
->WriteInt32(OUString("PixelWidth"), static_cast< sal_Int32
>( maSize
.Width
) );
222 pFilterOptions
->WriteInt32(OUString("PixelHeight"), static_cast< sal_Int32
>( maSize
.Height
) );
223 if ( maResolution
.Width
&& maResolution
.Height
)
225 const double f100thmmPerPixelX
= 100000.0 / maResolution
.Width
;
226 const double f100thmmPerPixelY
= 100000.0 / maResolution
.Height
;
227 sal_Int32 nLogicalWidth
= static_cast< sal_Int32
>( f100thmmPerPixelX
* maSize
.Width
);
228 sal_Int32 nLogicalHeight
= static_cast< sal_Int32
>( f100thmmPerPixelY
* maSize
.Height
);
229 if ( nLogicalWidth
&& nLogicalHeight
)
231 pFilterOptions
->WriteInt32( sLogicalWidth
, nLogicalWidth
);
232 pFilterOptions
->WriteInt32( sLogicalHeight
, nLogicalHeight
);
238 pFilterOptions
->WriteInt32( sLogicalWidth
, static_cast< sal_Int32
>( maSize
.Width
) );
239 pFilterOptions
->WriteInt32( sLogicalHeight
, static_cast< sal_Int32
>( maSize
.Height
) );
245 sal_Int32 nColor
= mpLbColorDepth
->GetSelectEntryPos();
250 pFilterOptions
->WriteInt32(OUString("ColorMode"), nColor
);
251 pFilterOptions
->WriteInt32(OUString("Quality"), static_cast<sal_Int32
>(mpSbCompression
->GetThumbPos()));
257 pFilterOptions
->WriteInt32(OUString("Compression"), static_cast<sal_Int32
>(mpSbCompression
->GetThumbPos()));
258 sal_Int32 nInterlace
= 0;
259 if ( mpCbInterlaced
->IsChecked() )
261 pFilterOptions
->WriteInt32(OUString("Interlaced"), nInterlace
);
262 sal_Int32 nValue
= 0;
263 if ( mpCbSaveTransparency
->IsChecked() )
265 pFilterOptions
->WriteInt32(OUString("Translucent"), nValue
);
271 pFilterOptions
->WriteInt32(OUString("Color"), mpLbColorDepth
->GetSelectEntryPos() + 1);
272 pFilterOptions
->WriteBool(OUString("RLE_Coding"), mpCbRLEEncoding
->IsChecked());
278 sal_Int32 nValue
= 0;
279 if ( mpCbInterlaced
->IsChecked() )
281 pFilterOptions
->WriteInt32(OUString("Interlaced"), nValue
);
284 if (mpCbSaveTransparency
->IsChecked())
286 pFilterOptions
->WriteInt32(OUString("Translucent"), nValue
);
294 sal_Int32 nFormat
= 0;
295 if ( mpRbText
->IsChecked() )
297 pFilterOptions
->WriteInt32(OUString("FileFormat"), nFormat
);
303 sal_Int32 nCheck
= 0;
304 if ( mpCbEPSPreviewTIFF
->IsChecked() )
306 if ( mpCbEPSPreviewEPSI
->IsChecked() )
308 pFilterOptions
->WriteInt32(OUString("Preview"), nCheck
);
311 if ( mpRbEPSLevel2
->IsChecked() )
313 pFilterOptions
->WriteInt32(OUString("Version"), nCheck
);
316 if ( mpRbEPSColorFormat2
->IsChecked() )
318 pFilterOptions
->WriteInt32(OUString("ColorFormat"), nCheck
);
321 if ( mpRbEPSCompressionNone
->IsChecked() )
323 pFilterOptions
->WriteInt32(OUString("CompressionMode"), nCheck
);
328 uno::Sequence
< beans::PropertyValue
> aRet( pFilterOptions
->GetFilterData() );
329 if ( !bUpdateConfig
)
330 delete pFilterOptions
;
335 awt::Size
ExportDialog::GetOriginalSize()
337 basegfx::B2DRange aShapesRange
;
341 uno::Reference
< beans::XPropertySet
> xPagePropSet( mxPage
, uno::UNO_QUERY
);
342 if ( xPagePropSet
.is() )
344 sal_Int32 nWidth
= 0;
345 sal_Int32 nHeight
= 0;
346 com::sun::star::uno::Any aAny
;
347 aAny
= xPagePropSet
->getPropertyValue("Width");
349 aAny
= xPagePropSet
->getPropertyValue("Height");
351 aShapesRange
= basegfx::B2DRange( 0, 0, nWidth
, nHeight
);
356 uno::Reference
< graphic::XPrimitiveFactory2D
> xPrimitiveFactory
= graphic::PrimitiveFactory2D::create( mxContext
);
358 basegfx::B2DHomMatrix
aViewTransformation( Application::GetDefaultDevice()->GetViewTransformation() );
359 com::sun::star::geometry::AffineMatrix2D aTransformation
;
360 aTransformation
.m00
= aViewTransformation
.get(0,0);
361 aTransformation
.m01
= aViewTransformation
.get(0,1);
362 aTransformation
.m02
= aViewTransformation
.get(0,2);
363 aTransformation
.m10
= aViewTransformation
.get(1,0);
364 aTransformation
.m11
= aViewTransformation
.get(1,1);
365 aTransformation
.m12
= aViewTransformation
.get(1,2);
367 const OUString
sViewTransformation( "ViewTransformation" );
368 uno::Sequence
< beans::PropertyValue
> aViewInformation( 1 );
369 aViewInformation
[ 0 ].Value
<<= aTransformation
;
370 aViewInformation
[ 0 ].Name
= sViewTransformation
;
373 aShapesRange
= GetShapeRangeForXShape( mxShape
, xPrimitiveFactory
, aViewInformation
);
374 else if ( mxShapes
.is() )
376 const sal_Int32 nCount
= mxShapes
->getCount();
377 for( sal_Int32 nIndex
= 0; nIndex
< nCount
; nIndex
++ )
379 uno::Reference
< drawing::XShape
> xShape
;
380 mxShapes
->getByIndex( nIndex
) >>= xShape
;
381 aShapesRange
.expand( GetShapeRangeForXShape( xShape
, xPrimitiveFactory
, aViewInformation
) );
385 return awt::Size( static_cast<sal_Int32
>(aShapesRange
.getWidth()), static_cast<sal_Int32
>(aShapesRange
.getHeight()) );
388 void ExportDialog::GetGraphicSource()
390 if ( mxSourceDocument
.is() )
392 uno::Reference
< frame::XModel
> xModel( mxSourceDocument
, uno::UNO_QUERY
);
395 uno::Reference
< frame::XController
> xController( xModel
->getCurrentController() );
396 if ( xController
.is() )
398 if ( mbExportSelection
) // check if there is a selection
400 uno::Reference
< view::XSelectionSupplier
> xSelectionSupplier( xController
, uno::UNO_QUERY
);
401 if ( xSelectionSupplier
.is() )
403 uno::Any
aAny( xSelectionSupplier
->getSelection() );
404 if ( ! ( aAny
>>= mxShapes
) )
408 if ( !mxShape
.is() && !mxShapes
.is() )
410 uno::Reference
< drawing::XDrawView
> xDrawView( xController
, uno::UNO_QUERY
);
411 if ( xDrawView
.is() )
413 uno::Reference
< drawing::XDrawPage
> xCurrentPage( xDrawView
->getCurrentPage() );
414 if ( xCurrentPage
.is() )
416 mxPage
= xCurrentPage
; // exporting whole page
425 bool ExportDialog::GetGraphicStream()
429 if ( !IsTempExportAvailable() )
431 delete mpTempStream
, mpTempStream
= new SvMemoryStream();
436 bool bRecreateOutputStream
= mpTempStream
->Tell() == 0;
438 static uno::Sequence
< beans::PropertyValue
> aOldFilterData
;
439 uno::Sequence
< beans::PropertyValue
> aNewFilterData( GetFilterData( false ) );
440 if ( aOldFilterData
!= aNewFilterData
)
442 aOldFilterData
= aNewFilterData
;
443 bRecreateOutputStream
= true;
447 if ( bRecreateOutputStream
)
449 delete mpTempStream
, mpTempStream
= new SvMemoryStream();
452 uno::Reference
< io::XStream
> xStream( new utl::OStreamWrapper( *mpTempStream
) );
453 uno::Reference
< io::XOutputStream
> xOutputStream( xStream
->getOutputStream() );
455 uno::Reference
< drawing::XGraphicExportFilter
> xGraphicExporter
=
456 drawing::GraphicExportFilter::create( mxContext
);
458 OUString
sFormat( maExt
);
459 uno::Sequence
< beans::PropertyValue
> aDescriptor( 3 );
460 aDescriptor
[0].Name
= "OutputStream";
461 aDescriptor
[0].Value
<<= xOutputStream
;
462 aDescriptor
[1].Name
= "FilterName";
463 aDescriptor
[1].Value
<<= sFormat
;
464 aDescriptor
[2].Name
= "FilterData";
465 aDescriptor
[2].Value
<<= aNewFilterData
;
467 uno::Reference
< lang::XComponent
> xSourceDoc
;
469 xSourceDoc
= uno::Reference
< lang::XComponent
>( mxPage
, uno::UNO_QUERY_THROW
);
470 else if ( mxShapes
.is() )
471 xSourceDoc
= uno::Reference
< lang::XComponent
>( mxShapes
, uno::UNO_QUERY_THROW
);
472 else if ( mxShape
.is() )
473 xSourceDoc
= uno::Reference
< lang::XComponent
>( mxShape
, uno::UNO_QUERY_THROW
);
474 if ( xSourceDoc
.is() )
476 xGraphicExporter
->setSourceDocument( xSourceDoc
);
477 xGraphicExporter
->filter( aDescriptor
);
480 if ( mnFormat
== FORMAT_JPG
)
482 mpTempStream
->Seek( STREAM_SEEK_TO_BEGIN
);
483 maBitmap
= GetGraphicBitmap( *mpTempStream
);
484 mpTempStream
->Seek( STREAM_SEEK_TO_END
);
491 catch( uno::Exception
& )
500 Bitmap
ExportDialog::GetGraphicBitmap( SvStream
& rInputStream
)
504 GraphicFilter
aFilter( false );
505 if ( aFilter
.ImportGraphic( aGraphic
, "", rInputStream
, GRFILTER_FORMAT_NOTFOUND
, NULL
, GraphicFilterImportFlags::NONE
, static_cast<com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>*>(NULL
), NULL
) == GRFILTER_OK
)
507 aRet
= aGraphic
.GetBitmap();
512 sal_uInt32
ExportDialog::GetRawFileSize() const
514 sal_uInt64 nRawFileSize
= 0;
515 if ( mbIsPixelFormat
)
517 sal_Int32 nBitsPerPixel
= 24;
518 OUString
aEntry( mpLbColorDepth
->GetSelectEntry() );
519 if ( ms1BitTreshold
== aEntry
)
521 else if ( ms1BitDithered
== aEntry
)
523 else if ( ms4BitGrayscale
== aEntry
)
525 else if ( ms4BitColorPalette
== aEntry
)
527 else if ( ms8BitGrayscale
== aEntry
)
529 else if ( ms8BitColorPalette
== aEntry
)
531 else if ( ms24BitColor
== aEntry
)
534 if ( mbIsPixelFormat
)
536 nRawFileSize
= ( maSize
.Width
* nBitsPerPixel
+ 7 ) &~ 7; // rounding up to 8 bits
537 nRawFileSize
/= 8; // in bytes
538 nRawFileSize
*= maSize
.Height
;
540 if ( nRawFileSize
> SAL_MAX_UINT32
)
543 return static_cast< sal_uInt32
>( nRawFileSize
);
546 // checks if the source dimension/resolution is not too big
547 // to determine the exact graphic output size and preview for jpg
548 bool ExportDialog::IsTempExportAvailable() const
550 return GetRawFileSize() < static_cast< sal_uInt32
>( mnMaxFilesizeForRealtimePreview
);
553 ExportDialog::ExportDialog(FltCallDialogParameter
& rPara
,
554 const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>& rxContext
,
555 const com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& rxSourceDocument
,
556 bool bExportSelection
, bool bIsPixelFormat
)
557 : ModalDialog(rPara
.pWindow
, "GraphicExportDialog", "svt/ui/graphicexport.ui")
558 , mrFltCallPara(rPara
)
559 , mxContext(rxContext
)
560 , mxSourceDocument(rxSourceDocument
)
561 , mpSbCompression(NULL
)
562 , mpNfCompression(NULL
)
563 , msEstimatedSizePix1(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_PIX_1
))
564 , msEstimatedSizePix2(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_PIX_2
))
565 , msEstimatedSizeVec(SVT_RESSTR(STR_SVT_ESTIMATED_SIZE_VEC
))
566 , ms1BitTreshold(SVT_RESSTR(STR_SVT_1BIT_THRESHOLD
))
567 , ms1BitDithered(SVT_RESSTR(STR_SVT_1BIT_DITHERED
))
568 , ms4BitGrayscale(SVT_RESSTR(STR_SVT_4BIT_GRAYSCALE
))
569 , ms4BitColorPalette(SVT_RESSTR(STR_SVT_4BIT_COLOR_PALETTE
))
570 , ms8BitGrayscale(SVT_RESSTR(STR_SVT_8BIT_GRAYSCALE
))
571 , ms8BitColorPalette(SVT_RESSTR(STR_SVT_8BIT_COLOR_PALETTE
))
572 , ms24BitColor(SVT_RESSTR(STR_SVT_24BIT_TRUE_COLOR
))
573 , maExt(rPara
.aFilterExt
)
574 , mnFormat(FORMAT_UNKNOWN
)
575 , mnMaxFilesizeForRealtimePreview(0)
576 , mpTempStream(new SvMemoryStream())
577 , maOriginalSize(awt::Size(0, 0))
578 , mbIsPixelFormat(bIsPixelFormat
)
579 , mbExportSelection(bExportSelection
)
580 , mbPreserveAspectRatio(true)
582 get(mpMfSizeX
, "widthmf-nospin");
583 get(mpMfSizeY
, "heightmf-nospin");
584 get(mpLbSizeX
, "widthlb");
585 get(mpFtResolution
, "resolutionft");
586 get(mpNfResolution
, "resolutionmf-nospin");
587 get(mpLbResolution
, "resolutionlb");
589 get(mpColorDepth
, "colordepth");
590 get(mpLbColorDepth
, "colordepthlb");
592 get(mpJPGQuality
, "jpgquality");
593 get(mpPNGCompression
, "pngcompression");
595 get(mpBMPCompression
, "bmpcompression");
596 get(mpCbRLEEncoding
, "rlecb");
599 get(mpCbInterlaced
, "interlacedcb");
601 get(mpDrawingObjects
, "drawingobjects");
602 get(mpCbSaveTransparency
, "savetransparencycb");
604 get(mpEncoding
, "encoding");
605 get(mpRbBinary
, "binarycb");
606 get(mpRbText
, "textcb");
608 get(mpEPSGrid
, "epsgrid");
609 get(mpCbEPSPreviewTIFF
, "tiffpreviewcb");
610 get(mpCbEPSPreviewEPSI
, "epsipreviewcb");
611 get(mpRbEPSLevel1
, "level1rb");
612 get(mpRbEPSLevel2
, "level2rb");
613 get(mpRbEPSColorFormat1
, "color1rb");
614 get(mpRbEPSColorFormat2
, "color2rb");
615 get(mpRbEPSCompressionLZW
, "compresslzw");
616 get(mpRbEPSCompressionNone
, "compressnone");
620 get(mpInfo
, "information");
621 get(mpFtEstimatedSize
, "estsizeft");;
625 maExt
= maExt
.toAsciiUpperCase();
627 OUString
aFilterConfigPath( "Office.Common/Filter/Graphic/Export/" );
628 mpOptionsItem
= new FilterConfigItem( aFilterConfigPath
, &rPara
.aFilterData
);
629 aFilterConfigPath
+= maExt
;
630 mpFilterOptionsItem
= new FilterConfigItem( aFilterConfigPath
, &rPara
.aFilterData
);
632 mnInitialResolutionUnit
= mbIsPixelFormat
633 ? mpOptionsItem
->ReadInt32(OUString("PixelExportUnit"), UNIT_DEFAULT
)
634 : mpOptionsItem
->ReadInt32(OUString( "VectorExportUnit"), UNIT_DEFAULT
);
636 mnMaxFilesizeForRealtimePreview
= mpOptionsItem
->ReadInt32(OUString("MaxFilesizeForRealtimePreview"), 0);
637 mpFtEstimatedSize
->SetText(OUString(" \n "));
639 SetText( GetText().replaceFirst("%1", maExt
) ); //Set dialog title
641 mnFormat
= GetFilterFormat( maExt
);
643 Size
aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MAP_CM
) );
644 maResolution
.Width
= aResolution
.Width();
645 maResolution
.Height
= aResolution
.Height();
646 maOriginalSize
= GetOriginalSize();
647 if ( bIsPixelFormat
)
649 double fPixelsPer100thmm
= static_cast< double >( maResolution
.Width
) / 100000.0;
650 maSize
= awt::Size( static_cast< sal_Int32
>( ( fPixelsPer100thmm
* maOriginalSize
.Width
) + 0.5 ),
651 static_cast< sal_Int32
>( ( fPixelsPer100thmm
* maOriginalSize
.Height
) + 0.5 ) );
655 maSize
= maOriginalSize
;
661 mpLbSizeX
->SetSelectHdl( LINK( this, ExportDialog
, UpdateHdl
) );
664 mpSbCompression
->SetScrollHdl(LINK(this, ExportDialog
, SbCompressionUpdateHdl
));
666 mpNfCompression
->SetModifyHdl(LINK(this, ExportDialog
, UpdateHdl
));
668 mpMfSizeX
->SetModifyHdl( LINK( this, ExportDialog
, UpdateHdlMtfSizeX
) );
669 mpMfSizeY
->SetModifyHdl( LINK( this, ExportDialog
, UpdateHdlMtfSizeY
) );
671 mpNfResolution
->SetModifyHdl( LINK( this, ExportDialog
, UpdateHdlNfResolution
) );
672 mpLbResolution
->SetSelectHdl( LINK( this, ExportDialog
, UpdateHdl
) );
674 mpLbColorDepth
->SetSelectHdl( LINK( this, ExportDialog
, UpdateHdl
) );
676 mpCbInterlaced
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
678 mpCbSaveTransparency
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
680 mpCbEPSPreviewTIFF
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
681 mpCbEPSPreviewEPSI
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
683 mpRbEPSCompressionLZW
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
684 mpRbEPSCompressionNone
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
686 mpRbBinary
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
687 mpRbText
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
690 mpCbRLEEncoding
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
693 mpRbEPSLevel1
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
694 mpRbEPSLevel2
->SetClickHdl( LINK( this, ExportDialog
, UpdateHdl
) );
696 mpBtnOK
->SetClickHdl( LINK( this, ExportDialog
, OK
) );
701 void ExportDialog::setupSizeControls()
703 sal_Int32 nUnit
= mnInitialResolutionUnit
;
704 if (nUnit
== UNIT_DEFAULT
)
705 nUnit
= GetDefaultUnit();
707 if (!mbIsPixelFormat
)
709 mpFtResolution
->Hide();
710 mpNfResolution
->Hide();
711 mpLbResolution
->Hide();
712 mpLbSizeX
->RemoveEntry( UNIT_PIXEL
); // removing pixel
713 if ( nUnit
>= UNIT_PIXEL
)
716 else if ( nUnit
> UNIT_MAX_ID
)
720 mpLbSizeX
->SelectEntryPos( static_cast< sal_uInt16
>( nUnit
) );
722 if ( mbIsPixelFormat
) // TODO: (metafileresolutionsupport) should be supported for vector formats also... this makes
723 { // sense eg for bitmap fillings in metafiles, to preserve high dpi output
724 // (atm without special vector support the bitmaps are rendered with 96dpi)
725 sal_Int32 nResolution
= mpOptionsItem
->ReadInt32(OUString("PixelExportResolution"), 96);
726 if ( nResolution
< 1 )
728 mpNfResolution
->SetValue( nResolution
);
730 sal_Int32 nResolutionUnit
= mpOptionsItem
->ReadInt32(OUString("PixelExportResolutionUnit"), 1);
731 if ( ( nResolutionUnit
< 0 ) || ( nResolutionUnit
> 2 ) )
733 mpLbResolution
->SelectEntryPos( static_cast< sal_uInt16
>( nResolutionUnit
) );
737 void ExportDialog::createFilterOptions()
743 sal_Int32 nColor
= mpFilterOptionsItem
->ReadInt32(OUString("ColorMode"), 0);
748 mpLbColorDepth
->InsertEntry( ms8BitGrayscale
);
749 mpLbColorDepth
->InsertEntry( ms24BitColor
);
750 mpLbColorDepth
->SelectEntryPos( nColor
);
751 mpColorDepth
->Show();
754 mpJPGQuality
->Show();
755 sal_Int32 nQuality
= mpFilterOptionsItem
->ReadInt32(OUString("Quality"), 75);
756 if ((nQuality
< 1 ) || (nQuality
> 100))
758 get(mpSbCompression
, "compressionjpgsb");
759 get(mpNfCompression
, "compressionjpgnf-nospin");
760 mpSbCompression
->SetRangeMin( 1 );
761 mpSbCompression
->SetRangeMax( 100 );
762 mpNfCompression
->SetMin( 1 );
763 mpNfCompression
->SetMax( 100 );
764 mpNfCompression
->SetValue( nQuality
);
765 mpNfCompression
->SetStrictFormat( true );
771 mpPNGCompression
->Show();
772 sal_Int32 nCompression
= mpFilterOptionsItem
->ReadInt32(OUString("Compression"), 6);
773 if ( ( nCompression
< 1 ) || ( nCompression
> 9 ) )
776 get(mpSbCompression
, "compressionpngsb");
777 get(mpNfCompression
, "compressionpngnf-nospin");
778 mpSbCompression
->SetRangeMin( 1 );
779 mpSbCompression
->SetRangeMax( 9 );
780 mpNfCompression
->SetMin( 1 );
781 mpNfCompression
->SetMax( 9 );
782 mpNfCompression
->SetValue( 9 );
783 mpNfCompression
->SetStrictFormat( true );
787 mpCbInterlaced
->Check(mpFilterOptionsItem
->ReadInt32(OUString("Interlaced"), 0) != 0);
790 mpDrawingObjects
->Show();
791 mpCbSaveTransparency
->Check(mpFilterOptionsItem
->ReadInt32(OUString("Translucent"), 1) != 0);
796 sal_Int32 nColor
= mpFilterOptionsItem
->ReadInt32(OUString("Color"), 0);
801 mpLbColorDepth
->InsertEntry( ms1BitTreshold
);
802 mpLbColorDepth
->InsertEntry( ms1BitDithered
);
803 mpLbColorDepth
->InsertEntry( ms4BitGrayscale
);
804 mpLbColorDepth
->InsertEntry( ms4BitColorPalette
);
805 mpLbColorDepth
->InsertEntry( ms8BitGrayscale
);
806 mpLbColorDepth
->InsertEntry( ms8BitColorPalette
);
807 mpLbColorDepth
->InsertEntry( ms24BitColor
);
808 mpLbColorDepth
->SelectEntryPos( nColor
);
809 mpColorDepth
->Show();
812 mpBMPCompression
->Show();
813 mpCbRLEEncoding
->Check(mpFilterOptionsItem
->ReadBool(OUString("RLE_Coding"), true));
820 mpCbInterlaced
->Check(mpFilterOptionsItem
->ReadInt32(OUString("Interlaced"), 1) != 0);
823 mpDrawingObjects
->Show();
824 mpCbSaveTransparency
->Check(mpFilterOptionsItem
->ReadInt32(OUString("Translucent"), 1) != 0);
833 sal_Int32 nFormat
= mpFilterOptionsItem
->ReadInt32(OUString("FileFormat"), 1);
834 mpRbBinary
->Check( nFormat
== 0 );
835 mpRbText
->Check( nFormat
!= 0 );
842 sal_Int32 nPreview
= mpFilterOptionsItem
->ReadInt32(OUString("Preview"), 0);
843 sal_Int32 nVersion
= mpFilterOptionsItem
->ReadInt32(OUString("Version"), 2);
844 sal_Int32 nColor
= mpFilterOptionsItem
->ReadInt32(OUString("ColorFormat"), 0);
845 sal_Int32 nCompr
= mpFilterOptionsItem
->ReadInt32(OUString("CompressionMode"), 2);
847 mpFilterOptionsItem
->ReadInt32(OUString("TextMode"), 0);
849 mpCbEPSPreviewTIFF
->Check( ( nPreview
& 1 ) != 0 );
850 mpCbEPSPreviewEPSI
->Check( ( nPreview
& 2 ) != 0 );
852 mpRbEPSLevel1
->Check( nVersion
== 1 );
853 mpRbEPSLevel2
->Check( nVersion
== 2 );
855 mpRbEPSColorFormat1
->Check( nColor
== 1 );
856 mpRbEPSColorFormat2
->Check( nColor
!= 1 );
858 mpRbEPSCompressionLZW
->Check( nCompr
== 1 );
859 mpRbEPSCompressionNone
->Check( nCompr
!= 1 );
865 void ExportDialog::setupControls()
868 createFilterOptions();
870 if (mnMaxFilesizeForRealtimePreview
|| mbIsPixelFormat
)
874 static OUString
ImpValueOfInKB( const sal_Int64
& rVal
)
876 double fVal( static_cast<double>( rVal
) );
879 OUStringBuffer
aVal( OUString::number( fVal
) );
880 sal_Int32
nX( OUString( aVal
.getStr() ).indexOf( '.', 0 ) );
882 aVal
.setLength( nX
+ 2 );
883 return aVal
.makeStringAndClear();
886 void ExportDialog::updateControls()
891 if ( !mbIsPixelFormat
)
893 awt::Size
aSize100thmm( maSize
);
894 Size
aSize( LogicToLogic( Size( aSize100thmm
.Width
* 100, aSize100thmm
.Height
* 100 ), MAP_100TH_MM
,
895 MapMode( GetMapUnit( mpLbSizeX
->GetSelectEntryPos() ) ) ) );
896 mpMfSizeX
->SetValue( aSize
.Width() );
897 mpMfSizeY
->SetValue( aSize
.Height() );
901 MapUnit
aMapUnit( GetMapUnit( mpLbSizeX
->GetSelectEntryPos() ) );
902 if ( aMapUnit
== MAP_PIXEL
)
903 { // calculating pixel count via resolution and original graphic size
904 mpMfSizeX
->SetDecimalDigits( 0 );
905 mpMfSizeY
->SetDecimalDigits( 0 );
906 mpMfSizeX
->SetValue( maSize
.Width
);
907 mpMfSizeY
->SetValue( maSize
.Height
);
911 mpMfSizeX
->SetDecimalDigits( 2 );
912 mpMfSizeY
->SetDecimalDigits( 2 );
914 switch( GetMapUnit( mpLbSizeX
->GetSelectEntryPos() ) )
916 case MAP_INCH
: fRatio
= static_cast< double >( maResolution
.Width
) * 0.0254; break;
917 case MAP_MM
: fRatio
= static_cast< double >( maResolution
.Width
) * 0.001; break;
918 case MAP_POINT
:fRatio
= ( static_cast< double >( maResolution
.Width
) * 0.0254 ) / 72.0; break;
920 case MAP_CM
: fRatio
= static_cast< double >( maResolution
.Width
) * 0.01; break;
922 mpMfSizeX
->SetValue( static_cast< sal_Int32
>( ( static_cast< double >( maSize
.Width
* 100 ) / fRatio
) + 0.5 ) );
923 mpMfSizeY
->SetValue( static_cast< sal_Int32
>( ( static_cast< double >( maSize
.Height
* 100 ) / fRatio
) + 0.5 ) );
926 sal_Int32 nResolution
= 0;
927 switch( mpLbResolution
->GetSelectEntryPos() )
929 case 0 : nResolution
= maResolution
.Width
/ 100; break; // pixels / cm
930 case 2 : nResolution
= maResolution
.Width
; break; // pixels / meter
932 case 1 : nResolution
= static_cast< sal_Int32
>(maResolution
.Width
* 0.0254); break; // pixels / inch
934 mpNfResolution
->SetValue( nResolution
);
936 if (mpSbCompression
&& mpSbCompression
->IsVisible() && mpNfCompression
)
937 mpSbCompression
->SetThumbPos(mpNfCompression
->GetValue());
939 // updating estimated size
940 sal_Int64
nRealFileSize( mpTempStream
->Tell() );
941 if ( mbIsPixelFormat
)
943 OUString
aEst( nRealFileSize
? msEstimatedSizePix2
: msEstimatedSizePix1
);
944 sal_Int64
nRawFileSize( GetRawFileSize() );
945 sal_Int32 nInd
= aEst
.indexOf( "%" );
947 aEst
= aEst
.replaceAt( nInd
, 2, ImpValueOfInKB( nRawFileSize
) );
949 if ( nRealFileSize
&& nInd
!= -1 )
951 nInd
= aEst
.indexOf( "%", nInd
);
953 aEst
= aEst
.replaceAt( nInd
, 2, ImpValueOfInKB( nRealFileSize
) );
955 mpFtEstimatedSize
->SetText( aEst
);
959 if ( mnMaxFilesizeForRealtimePreview
)
961 OUString
aEst( msEstimatedSizeVec
);
962 sal_Int32 nInd
= aEst
.indexOf( "%" );
964 aEst
= aEst
.replaceAt( nInd
, 2, ImpValueOfInKB( nRealFileSize
) );
965 mpFtEstimatedSize
->SetText( aEst
);
970 if ( mpRbEPSLevel1
->IsVisible() )
972 bool bEnabled
= !mpRbEPSLevel1
->IsChecked();
973 mpRbEPSColorFormat1
->Enable( bEnabled
);
974 mpRbEPSColorFormat2
->Enable( bEnabled
);
975 mpRbEPSCompressionLZW
->Enable( bEnabled
);
976 mpRbEPSCompressionNone
->Enable( bEnabled
);
980 ExportDialog::~ExportDialog()
985 void ExportDialog::dispose()
987 delete mpFilterOptionsItem
;
988 delete mpOptionsItem
;
992 mpFtResolution
.clear();
993 mpNfResolution
.clear();
994 mpLbResolution
.clear();
995 mpColorDepth
.clear();
996 mpLbColorDepth
.clear();
997 mpJPGQuality
.clear();
998 mpPNGCompression
.clear();
999 mpSbCompression
.clear();
1000 mpNfCompression
.clear();
1002 mpCbInterlaced
.clear();
1003 mpBMPCompression
.clear();
1004 mpCbRLEEncoding
.clear();
1005 mpDrawingObjects
.clear();
1006 mpCbSaveTransparency
.clear();
1011 mpCbEPSPreviewTIFF
.clear();
1012 mpCbEPSPreviewEPSI
.clear();
1013 mpRbEPSLevel1
.clear();
1014 mpRbEPSLevel2
.clear();
1015 mpRbEPSColorFormat1
.clear();
1016 mpRbEPSColorFormat2
.clear();
1017 mpRbEPSCompressionLZW
.clear();
1018 mpRbEPSCompressionNone
.clear();
1020 mpFtEstimatedSize
.clear();
1022 ModalDialog::dispose();
1026 /*************************************************************************
1028 |* stores values set in the ini-file
1030 \************************************************************************/
1031 IMPL_LINK_NOARG(ExportDialog
, UpdateHdl
)
1037 IMPL_LINK_NOARG(ExportDialog
, UpdateHdlMtfSizeX
)
1039 double fRatio
= static_cast< double >( maOriginalSize
.Height
) / maOriginalSize
.Width
;
1041 if ( mbIsPixelFormat
)
1043 switch( GetMapUnit( mpLbSizeX
->GetSelectEntryPos() ) )
1045 case MAP_INCH
: maSize
.Width
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Width
) * 0.0254 * mpMfSizeX
->GetValue() / 100.0 + 0.5 ); break;
1046 case MAP_CM
: maSize
.Width
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Width
) * 0.01 * mpMfSizeX
->GetValue() / 100.0 + 0.5 ); break;
1047 case MAP_MM
: maSize
.Width
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Width
) * 0.001 * mpMfSizeX
->GetValue() / 100.0 + 0.5 ); break;
1048 case MAP_POINT
: maSize
.Width
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Width
) * 0.0254 * mpMfSizeX
->GetValue() / 100.0 * 72 + 0.5 ); break;
1050 case MAP_PIXEL
: maSize
.Width
= mpMfSizeX
->GetValue(); break;
1052 maSize
.Height
= static_cast< sal_Int32
>( fRatio
* maSize
.Width
+ 0.5 );
1056 Fraction
aFract( 1, 100 );
1057 sal_Int32 nWidth
= mpMfSizeX
->GetValue();
1058 sal_Int32 nHeight
= static_cast< sal_Int32
>( nWidth
* 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
.Width
= aDest
.Width();
1064 if ( mbPreserveAspectRatio
)
1065 maSize
.Height
= aDest
.Height();
1071 IMPL_LINK_NOARG(ExportDialog
, UpdateHdlMtfSizeY
)
1073 double fRatio
= static_cast< double >( maOriginalSize
.Width
) / maOriginalSize
.Height
;
1075 if ( mbIsPixelFormat
)
1077 switch( GetMapUnit( mpLbSizeX
->GetSelectEntryPos() ) )
1079 case MAP_INCH
: maSize
.Height
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Height
) * 0.0254 * mpMfSizeY
->GetValue() / 100.0 + 0.5 ); break;
1080 case MAP_CM
: maSize
.Height
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Height
) * 0.01 * mpMfSizeY
->GetValue() / 100.0 + 0.5 ); break;
1081 case MAP_MM
: maSize
.Height
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Height
) * 0.001 * mpMfSizeY
->GetValue() / 100.0 + 0.5 ); break;
1082 case MAP_POINT
: maSize
.Height
= static_cast< sal_Int32
>( static_cast< double >( maResolution
.Height
) * 0.0254 * mpMfSizeY
->GetValue() / 100.0 * 72 + 0.5 ); break;
1084 case MAP_PIXEL
: maSize
.Height
= mpMfSizeY
->GetValue(); break;
1086 maSize
.Width
= static_cast< sal_Int32
>( fRatio
* maSize
.Height
+ 0.5 );
1090 Fraction
aFract( 1, 100 );
1091 sal_Int32 nHeight
= mpMfSizeY
->GetValue();
1092 sal_Int32 nWidth
= static_cast< sal_Int32
>( nHeight
* fRatio
);
1093 const Size
aSource( static_cast< sal_Int32
>( nWidth
), static_cast< sal_Int32
>( nHeight
) );
1094 MapMode
aSourceMapMode( GetMapUnit( mpLbSizeX
->GetSelectEntryPos() ),Point(), aFract
, aFract
);
1095 Size
aDest( LogicToLogic( aSource
, aSourceMapMode
, MAP_100TH_MM
) );
1097 maSize
.Height
= aDest
.Height();
1098 if ( mbPreserveAspectRatio
)
1099 maSize
.Width
= aDest
.Width();
1105 IMPL_LINK_NOARG(ExportDialog
, UpdateHdlNfResolution
)
1107 sal_Int32 nResolution
= mpNfResolution
->GetValue();
1108 if ( mpLbResolution
->GetSelectEntryPos() == 0 ) // pixels / cm
1110 else if ( mpLbResolution
->GetSelectEntryPos() == 1 ) // pixels / inch
1111 nResolution
= static_cast< sal_Int32
>( ( ( static_cast< double >( nResolution
) + 0.5 ) / 0.0254 ) );
1112 maResolution
.Width
= nResolution
;
1113 maResolution
.Height
= nResolution
;
1119 IMPL_LINK_NOARG(ExportDialog
, SbCompressionUpdateHdl
)
1121 mpNfCompression
->SetValue( mpSbCompression
->GetThumbPos() );
1126 IMPL_LINK_NOARG(ExportDialog
, OK
)
1128 // writing config parameter
1131 mrFltCallPara
.aFilterData
= GetFilterData( true );
1132 EndDialog( RET_OK
);
1137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */