summaryrefslogtreecommitdiff
path: root/svtools/source/filter/exportdialog.cxx
blob: db1c77e2b38ef205fc5dbf6ec41e168af617bd60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#include <tools/stream.hxx>
#include <tools/fract.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/FilterConfigItem.hxx>
#include <svtools/strings.hrc>
#include <svtools/svtresid.hxx>
#include <svtools/DocumentToGraphicRenderer.hxx>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/drawing/XDrawView.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
#include <com/sun/star/geometry/AffineMatrix2D.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <unotools/streamwrap.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/svapp.hxx>
#include <vcl/outdev.hxx>
#include <vcl/graph.hxx>
#include <rtl/ustrbuf.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <comphelper/processfactory.hxx>
#include "exportdialog.hxx"

#define FORMAT_UNKNOWN  0
#define FORMAT_JPG      1
#define FORMAT_PNG      2
#define FORMAT_BMP      3
#define FORMAT_GIF      4
#define FORMAT_TIF      10
#define FORMAT_WMF      12
#define FORMAT_EMF      13
#define FORMAT_EPS      14
#define FORMAT_SVG      16

#define UNIT_DEFAULT    -1
#define UNIT_INCH       0
#define UNIT_CM         1
#define UNIT_MM         2
#define UNIT_POINT      3
#define UNIT_PIXEL      4
#define UNIT_MAX_ID     UNIT_PIXEL

using namespace ::com::sun::star;

static sal_Int16 GetFilterFormat(const OUString& rExt)
{
    sal_Int16 nFormat = FORMAT_UNKNOWN;
    if ( rExt == "JPG" )
        nFormat = FORMAT_JPG;
    else if ( rExt == "PNG" )
        nFormat = FORMAT_PNG;
    else if ( rExt == "BMP" )
        nFormat = FORMAT_BMP;
    else if ( rExt == "GIF" )
        nFormat = FORMAT_GIF;
    else if ( rExt == "TIF" )
        nFormat = FORMAT_TIF;
    else if ( rExt == "WMF" )
        nFormat = FORMAT_WMF;
    else if ( rExt == "EMF" )
        nFormat = FORMAT_EMF;
    else if ( rExt == "EPS" )
        nFormat = FORMAT_EPS;
    else if ( rExt == "SVG" )
        nFormat = FORMAT_SVG;
    return nFormat;
}

static MapUnit GetMapUnit( sal_Int32 nUnit )
{
    MapUnit aMapUnit( MapUnit::MapPixel );
    switch( nUnit )
    {
        case UNIT_INCH  :   aMapUnit = MapUnit::MapInch; break;
        case UNIT_CM    :   aMapUnit = MapUnit::MapCM; break;
        case UNIT_MM    :   aMapUnit = MapUnit::MapMM; break;
        case UNIT_POINT :   aMapUnit = MapUnit::MapPoint; break;
        case UNIT_PIXEL :   aMapUnit = MapUnit::MapPixel; break;
    }
    return aMapUnit;
}

sal_Int32 ExportDialog::GetDefaultUnit()
{
    sal_Int32 nDefaultUnit = UNIT_CM;
    switch( mrFltCallPara.eFieldUnit )
    {
//      case FUNIT_NONE :
//      case FUNIT_PERCENT :
//      case FUNIT_CUSTOM :
        default:                nDefaultUnit = UNIT_CM; break;

        case FUNIT_MILE :       // PASSTHROUGH INTENDED
        case FUNIT_FOOT :
        case FUNIT_TWIP :
        case FUNIT_PICA :       nDefaultUnit = UNIT_INCH; break;

        case FUNIT_KM :         // PASSTHROUGH INTENDED
        case FUNIT_M :
        case FUNIT_100TH_MM :   nDefaultUnit = UNIT_CM; break;

        case FUNIT_INCH :       nDefaultUnit = UNIT_INCH; break;
        case FUNIT_CM :         nDefaultUnit = UNIT_CM; break;
        case FUNIT_MM :         nDefaultUnit = UNIT_MM; break;
        case FUNIT_POINT :      nDefaultUnit = UNIT_POINT; break;
    }
    return nDefaultUnit;
}

static basegfx::B2DRange GetShapeRangeForXShape( const uno::Reference< drawing::XShape >& rxShape,
    const uno::Reference< graphic::XPrimitiveFactory2D >& rxPrimitiveFactory2D, const uno::Sequence< beans::PropertyValue >& rViewInformation )
{
    basegfx::B2DRange aShapeRange;

    const uno::Sequence< beans::PropertyValue > aParams;
    const uno::Sequence< uno::Reference< graphic::XPrimitive2D > > aPrimitiveSequence( rxPrimitiveFactory2D->createPrimitivesFromXShape( rxShape, aParams ) );

    const sal_Int32 nCount = aPrimitiveSequence.getLength();
    for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
    {
        const geometry::RealRectangle2D aRect( aPrimitiveSequence[ nIndex ]->getRange( rViewInformation ) );
        aShapeRange.expand( basegfx::B2DTuple( aRect.X1, aRect.Y1 ) );
        aShapeRange.expand( basegfx::B2DTuple( aRect.X2, aRect.Y2 ) );
    }
    return aShapeRange;
}

uno::Sequence< beans::PropertyValue > ExportDialog::GetFilterData( bool bUpdateConfig )
{
    if ( bUpdateConfig )
    {
        sal_Int32 nUnit = mpLbSizeX->GetSelectEntryPos();
        if ( nUnit < 0 )
            nUnit = UNIT_CM;

        if ( ( mnInitialResolutionUnit == UNIT_DEFAULT ) && ( nUnit == GetDefaultUnit() ) )
            nUnit = UNIT_DEFAULT;

        // updating ui configuration
        if ( mbIsPixelFormat )
        {
            if ( nUnit > UNIT_MAX_ID )
                nUnit = UNIT_PIXEL;

            sal_Int32 nResolution = mpNfResolution->GetValue();
            if ( nResolution < 1 )
                nResolution = 96;

            mpOptionsItem->WriteInt32("PixelExportUnit", nUnit);
            mpOptionsItem->WriteInt32("PixelExportResolution", nResolution);
            mpOptionsItem->WriteInt32("PixelExportResolutionUnit", mpLbResolution->GetSelectEntryPos());
        }
        else
        {
            if ( nUnit >= UNIT_PIXEL )
                nUnit = UNIT_CM;

            mpOptionsItem->WriteInt32("VectorExportUnit", nUnit);
        }
    }

    FilterConfigItem* pFilterOptions;
    if ( bUpdateConfig )
         pFilterOptions = mpFilterOptionsItem;
    else
    {
        uno::Sequence< beans::PropertyValue > aFilterData( mpFilterOptionsItem->GetFilterData() );
        pFilterOptions = new FilterConfigItem( &aFilterData );
    }

    const OUString sLogicalWidth("LogicalWidth");
    const OUString sLogicalHeight("LogicalHeight");
    if ( mbIsPixelFormat )
    {
        pFilterOptions->WriteInt32("PixelWidth", static_cast< sal_Int32 >( maSize.Width ) );
        pFilterOptions->WriteInt32("PixelHeight", static_cast< sal_Int32 >( maSize.Height ) );
        if ( maResolution.Width && maResolution.Height )
        {
            const double f100thmmPerPixelX = 100000.0 / maResolution.Width;
            const double f100thmmPerPixelY = 100000.0 / maResolution.Height;
            sal_Int32 nLogicalWidth = static_cast< sal_Int32 >( f100thmmPerPixelX * maSize.Width );
            sal_Int32 nLogicalHeight= static_cast< sal_Int32 >( f100thmmPerPixelY * maSize.Height );
            if ( nLogicalWidth && nLogicalHeight )
            {
                pFilterOptions->WriteInt32( sLogicalWidth, nLogicalWidth );
                pFilterOptions->WriteInt32( sLogicalHeight, nLogicalHeight );
            }
        }
    }
    else
    {
        pFilterOptions->WriteInt32( sLogicalWidth, static_cast< sal_Int32 >( maSize.Width ) );
        pFilterOptions->WriteInt32( sLogicalHeight, static_cast< sal_Int32 >( maSize.Height ) );
    }
    switch ( mnFormat )
    {
        case FORMAT_JPG :
        {
            sal_Int32 nColor = mpLbColorDepth->GetSelectEntryPos();
            if ( nColor == 1 )
                nColor = 0;
            else
                nColor = 1;
            pFilterOptions->WriteInt32("ColorMode", nColor);
            pFilterOptions->WriteInt32("Quality", static_cast<sal_Int32>(mpSbCompression->GetThumbPos()));
        }
        break;

        case FORMAT_PNG :
        {
            pFilterOptions->WriteInt32("Compression", static_cast<sal_Int32>(mpSbCompression->GetThumbPos()));
            sal_Int32 nInterlace = 0;
            if ( mpCbInterlaced->IsChecked() )
                nInterlace++;
            pFilterOptions->WriteInt32("Interlaced", nInterlace);
            sal_Int32 nValue = 0;
            if ( mpCbSaveTransparency->IsChecked() )
                nValue++;
            pFilterOptions->WriteInt32("Translucent", nValue);
        }
        break;

        case FORMAT_BMP :
        {
            pFilterOptions->WriteInt32("Color", mpLbColorDepth->GetSelectEntryPos() + 1);
            pFilterOptions->WriteBool("RLE_Coding", mpCbRLEEncoding->IsChecked());
        }
        break;

        case FORMAT_GIF :
        {
            sal_Int32 nValue = 0;
            if ( mpCbInterlaced->IsChecked() )
                nValue++;
            pFilterOptions->WriteInt32("Interlaced", nValue);

            nValue = 0;
            if (mpCbSaveTransparency->IsChecked())
                nValue++;
            pFilterOptions->WriteInt32("Translucent", nValue);
        }
        break;

        case FORMAT_EPS :
        {
            sal_Int32 nCheck = 0;
            if ( mpCbEPSPreviewTIFF->IsChecked() )
                nCheck++;
            if ( mpCbEPSPreviewEPSI->IsChecked() )
                nCheck += 2;
            pFilterOptions->WriteInt32("Preview", nCheck);

            nCheck = 1;
            if ( mpRbEPSLevel2->IsChecked() )
                nCheck++;
            pFilterOptions->WriteInt32("Version", nCheck);

            nCheck = 1;
            if ( mpRbEPSColorFormat2->IsChecked() )
                nCheck++;
            pFilterOptions->WriteInt32("ColorFormat", nCheck);

            nCheck = 1;
            if ( mpRbEPSCompressionNone->IsChecked() )
                nCheck++;
            pFilterOptions->WriteInt32("CompressionMode", nCheck);
        }
        break;
    }

    uno::Sequence< beans::PropertyValue > aRet( pFilterOptions->GetFilterData() );
    if ( !bUpdateConfig )
        delete pFilterOptions;
    return aRet;
}


awt::Size ExportDialog::GetOriginalSize()
{
    basegfx::B2DRange aShapesRange;

    if ( mxPage.is () )
    {
        uno::Reference< beans::XPropertySet > xPagePropSet( mxPage, uno::UNO_QUERY );
        if ( xPagePropSet.is() )
        {
            sal_Int32 nWidth = 0;
            sal_Int32 nHeight= 0;
            css::uno::Any aAny;
            aAny = xPagePropSet->getPropertyValue("Width");
            aAny >>= nWidth;
            aAny = xPagePropSet->getPropertyValue("Height");
            aAny >>= nHeight;
            aShapesRange = basegfx::B2DRange( 0, 0, nWidth, nHeight );
        }
    }
    else if (mxShapes.is() || mxShape.is())
    {
        uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory = graphic::PrimitiveFactory2D::create( mxContext );

        basegfx::B2DHomMatrix aViewTransformation( Application::GetDefaultDevice()->GetViewTransformation() );
        css::geometry::AffineMatrix2D aTransformation;
        aTransformation.m00 = aViewTransformation.get(0,0);
        aTransformation.m01 = aViewTransformation.get(0,1);
        aTransformation.m02 = aViewTransformation.get(0,2);
        aTransformation.m10 = aViewTransformation.get(1,0);
        aTransformation.m11 = aViewTransformation.get(1,1);
        aTransformation.m12 = aViewTransformation.get(1,2);

        const OUString sViewTransformation( "ViewTransformation" );
        uno::Sequence< beans::PropertyValue > aViewInformation( 1 );
        aViewInformation[ 0 ].Value <<= aTransformation;
        aViewInformation[ 0 ].Name  = sViewTransformation;

        if ( mxShape.is() )
            aShapesRange = GetShapeRangeForXShape( mxShape, xPrimitiveFactory, aViewInformation );
        else if ( mxShapes.is() )
        {
            const sal_Int32 nCount = mxShapes->getCount();
            for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
            {
                uno::Reference< drawing::XShape > xShape;
                mxShapes->getByIndex( nIndex ) >>= xShape;
                aShapesRange.expand( GetShapeRangeForXShape( xShape, xPrimitiveFactory, aViewInformation ) );
            }
        }
    }
    else if (!mbGraphicsSource)
    {
        DocumentToGraphicRenderer aRenderer( mxSourceDocument, mbExportSelection);
        const sal_Int32 nCurrentPage = aRenderer.getCurrentPageWriter();
        const Size aSize = aRenderer.getDocumentSizeIn100mm( nCurrentPage);
        return awt::Size( aSize.Width(), aSize.Height());
    }
    return awt::Size( static_cast<sal_Int32>(aShapesRange.getWidth()), static_cast<sal_Int32>(aShapesRange.getHeight()) );
}

void ExportDialog::GetGraphicSource()
{
    if (mxGraphic.is())
        return;

    if ( mxSourceDocument.is() )
    {
        uno::Reference< frame::XModel > xModel( mxSourceDocument, uno::UNO_QUERY );
        if ( xModel.is() )
        {
            uno::Reference< frame::XController > xController( xModel->getCurrentController() );
            if ( xController.is() )
            {
                if ( mbExportSelection )                // check if there is a selection
                {
                    uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY );
                    if ( xSelectionSupplier.is() )
                    {
                        uno::Any aAny( xSelectionSupplier->getSelection() );
                        if ( aAny >>= mxShapes )
                            mbGraphicsSource = true;
                        else if ( aAny >>= mxShape )
                            mbGraphicsSource = true;
                    }
                }
                if ( !mxShape.is() && !mxShapes.is() && mbGraphicsSource )
                {
                    uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY );
                    if ( xDrawView.is() )
                    {
                        uno::Reference< drawing::XDrawPage > xCurrentPage( xDrawView->getCurrentPage() );
                        if ( xCurrentPage.is() )
                        {
                            mxPage = xCurrentPage;      // exporting whole page
                        }
                    }
                }
                // For !mbGraphicsSource the mxSourceDocument is used, from
                // which XRenderable can query XController and
                // XSelectionSupplier the same.
            }
        }
    }
}

void ExportDialog::GetGraphicStream()
{
    if ( !IsTempExportAvailable() )
    {
        delete mpTempStream;
        mpTempStream = new SvMemoryStream();
        maBitmap = Bitmap();
        return;
    }

    bool bRecreateOutputStream = mpTempStream->Tell() == 0;

    static uno::Sequence< beans::PropertyValue > aOldFilterData;
    uno::Sequence< beans::PropertyValue > aNewFilterData( GetFilterData( false ) );
    if ( aOldFilterData != aNewFilterData )
    {
        aOldFilterData = aNewFilterData;
        bRecreateOutputStream = true;
    }
    try
    {
        if ( bRecreateOutputStream )
        {
            delete mpTempStream;
            mpTempStream = new SvMemoryStream();
            maBitmap = Bitmap();

            uno::Reference< graphic::XGraphic > xGraphic;
            if (!mbGraphicsSource && !mxGraphic.is())
            {
                // Create a Graphic to be used below.
                DocumentToGraphicRenderer aRenderer( mxSourceDocument, mbExportSelection);
                const sal_Int32 nCurrentPage = aRenderer.getCurrentPageWriter();
                const Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels( nCurrentPage);

                const Size aTargetSizePixel( mbIsPixelFormat ?
                        Size( maSize.Width, maSize.Height) :
                        aDocumentSizePixel );

                Graphic aGraphic( aRenderer.renderToGraphic( nCurrentPage,
                            aDocumentSizePixel, aTargetSizePixel, COL_WHITE));
                xGraphic = aGraphic.GetXGraphic();
            }

            if ( mxGraphic.is() || xGraphic.is() )
            {
                Graphic aGraphic( mxGraphic.is() ? mxGraphic : xGraphic );

                if ( aGraphic.GetType() == GraphicType::Bitmap )
                {
                    Size aSizePixel( aGraphic.GetSizePixel() );
                    if( maSize.Width && maSize.Height &&
                        ( ( maSize.Width != aSizePixel.Width() ) ||
                          ( maSize.Height != aSizePixel.Height() ) ) )
                    {
                        BitmapEx aBmpEx( aGraphic.GetBitmapEx() );
                        // export: use highest quality
                        aBmpEx.Scale( Size( maSize.Width, maSize.Height ), BmpScaleFlag::Lanczos );
                        aGraphic = aBmpEx;
                    }
                }

                GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
                const sal_uInt16 nFilter = rFilter.GetExportFormatNumberForShortName( maExt );
                if ( rFilter.IsExportPixelFormat( nFilter ) )
                {
                    mpTempStream->SetResizeOffset(1024);
                    mpTempStream->SetStreamSize(1024);
                    rFilter.ExportGraphic( aGraphic, "", *mpTempStream, nFilter, &aNewFilterData );

                    if ( mnFormat == FORMAT_JPG )
                    {
                        mpTempStream->Seek( STREAM_SEEK_TO_BEGIN );
                        maBitmap = GetGraphicBitmap( *mpTempStream );
                        mpTempStream->Seek( STREAM_SEEK_TO_END );
                    }
                }
            }
            else
            {
                uno::Reference< lang::XComponent > xSourceDoc;
                if ( mxPage.is() )
                    xSourceDoc.set( mxPage, uno::UNO_QUERY_THROW );
                else if ( mxShapes.is() )
                    xSourceDoc.set( mxShapes, uno::UNO_QUERY_THROW );
                else if ( mxShape.is() )
                    xSourceDoc.set( mxShape, uno::UNO_QUERY_THROW );
                if ( xSourceDoc.is() )
                {
                    uno::Reference < io::XStream > xStream( new utl::OStreamWrapper( *mpTempStream ) );
                    uno::Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() );

                    OUString sFormat( maExt );
                    uno::Sequence< beans::PropertyValue > aDescriptor( 3 );
                    aDescriptor[0].Name = "OutputStream";
                    aDescriptor[0].Value <<= xOutputStream;
                    aDescriptor[1].Name = "FilterName";
                    aDescriptor[1].Value <<= sFormat;
                    aDescriptor[2].Name = "FilterData";
                    aDescriptor[2].Value <<= aNewFilterData;

                    uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter =
                        drawing::GraphicExportFilter::create( mxContext );

                    xGraphicExporter->setSourceDocument( xSourceDoc );
                    xGraphicExporter->filter( aDescriptor );

                    if ( mnFormat == FORMAT_JPG )
                    {
                        mpTempStream->Seek( STREAM_SEEK_TO_BEGIN );
                        maBitmap = GetGraphicBitmap( *mpTempStream );
                        mpTempStream->Seek( STREAM_SEEK_TO_END );
                    }
                }
            }
        }
    }
    catch( uno::Exception& )
    {

        // ups

    }
}

Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream )
{
    Bitmap aRet;
    Graphic aGraphic;
    GraphicFilter aFilter( false );
    if ( aFilter.ImportGraphic( aGraphic, "", rInputStream, GRFILTER_FORMAT_NOTFOUND, nullptr, GraphicFilterImportFlags::NONE, static_cast<css::uno::Sequence< css::beans::PropertyValue >*>(nullptr) ) == ERRCODE_NONE )
    {
        aRet = aGraphic.GetBitmap();
    }
    return aRet;
}

sal_uInt32 ExportDialog::GetRawFileSize() const
{
    sal_uInt64 nRawFileSize = 0;
    if ( mbIsPixelFormat )
    {
        sal_Int32 nBitsPerPixel = 24;
        OUString aEntry( mpLbColorDepth->GetSelectEntry() );
        if ( ms1BitTreshold == aEntry )
            nBitsPerPixel = 1;
        else if ( ms1BitDithered == aEntry )
            nBitsPerPixel = 1;
        else if ( ms4BitGrayscale == aEntry )
            nBitsPerPixel = 4;
        else if ( ms4BitColorPalette == aEntry )
            nBitsPerPixel = 8;
        else if ( ms8BitGrayscale == aEntry )
            nBitsPerPixel = 8;
        else if ( ms8BitColorPalette == aEntry )
            nBitsPerPixel = 8;
        else if ( ms24BitColor == aEntry )
            nBitsPerPixel = 24;

        if ( mbIsPixelFormat )
        {
            nRawFileSize = ( maSize.Width * nBitsPerPixel + 7 ) &~ 7;   // rounding up to 8 bits
            nRawFileSize /= 8;                                          // in bytes
            nRawFileSize *= maSize.Height;
        }
        if ( nRawFileSize > SAL_MAX_UINT32 )
            nRawFileSize = 0;
    }
    return static_cast< sal_uInt32 >( nRawFileSize );
}

// checks if the source dimension/resolution is not too big
// to determine the exact graphic output size and preview for jpg
bool ExportDialog::IsTempExportAvailable() const
{
    return GetRawFileSize() < static_cast< sal_uInt32 >( mnMaxFilesizeForRealtimePreview );
}

ExportDialog::ExportDialog(FltCallDialogParameter& rPara,
    const css::uno::Reference< css::uno::XComponentContext >& rxContext,
    const css::uno::Reference< css::lang::XComponent >& rxSourceDocument,
    bool bExportSelection, bool bIsPixelFormat, bool bGraphicsSource,
    const css::uno::Reference< css::graphic::XGraphic >& rxGraphic)
    : ModalDialog(rPara.pWindow, "GraphicExportDialog", "svt/ui/graphicexport.ui")
    , mrFltCallPara(rPara)
    , mxContext(rxContext)
    , mxSourceDocument(rxSourceDocument)
    , mxGraphic(rxGraphic)
    , mpSbCompression(nullptr)
    , mpNfCompression(nullptr)
    , msEstimatedSizePix1(SvtResId(STR_SVT_ESTIMATED_SIZE_PIX_1))
    , msEstimatedSizePix2(SvtResId(STR_SVT_ESTIMATED_SIZE_PIX_2))
    , msEstimatedSizeVec(SvtResId(STR_SVT_ESTIMATED_SIZE_VEC))
    , ms1BitTreshold(SvtResId(STR_SVT_1BIT_THRESHOLD))
    , ms1BitDithered(SvtResId(STR_SVT_1BIT_DITHERED))
    , ms4BitGrayscale(SvtResId(STR_SVT_4BIT_GRAYSCALE))
    , ms4BitColorPalette(SvtResId(STR_SVT_4BIT_COLOR_PALETTE))
    , ms8BitGrayscale(SvtResId(STR_SVT_8BIT_GRAYSCALE))
    , ms8BitColorPalette(SvtResId(STR_SVT_8BIT_COLOR_PALETTE))
    , ms24BitColor(SvtResId(STR_SVT_24BIT_TRUE_COLOR))
    , maExt(rPara.aFilterExt)
    , mnFormat(FORMAT_UNKNOWN)
    , mnMaxFilesizeForRealtimePreview(0)
    , mpTempStream(new SvMemoryStream())
    , maOriginalSize(awt::Size(0, 0))
    , mbIsPixelFormat(bIsPixelFormat)
    , mbExportSelection(bExportSelection)
    , mbGraphicsSource(bGraphicsSource)
{
    get(mpMfSizeX, "widthmf-nospin");
    get(mpMfSizeY, "heightmf-nospin");
    get(mpLbSizeX, "widthlb");
    get(mpFtResolution, "resolutionft");
    get(mpNfResolution, "resolutionmf-nospin");
    get(mpLbResolution, "resolutionlb");

    get(mpColorDepth, "colordepth");
    get(mpLbColorDepth, "colordepthlb");

    get(mpJPGQuality, "jpgquality");
    get(mpPNGCompression, "pngcompression");

    get(mpBMPCompression, "bmpcompression");
    get(mpCbRLEEncoding, "rlecb");

    get(mpMode, "mode");
    get(mpCbInterlaced, "interlacedcb");

    get(mpDrawingObjects, "drawingobjects");
    get(mpCbSaveTransparency, "savetransparencycb");

    get(mpEncoding, "encoding");
    get(mpRbBinary, "binarycb");
    get(mpRbText, "textcb");

    get(mpEPSGrid, "epsgrid");
    get(mpCbEPSPreviewTIFF, "tiffpreviewcb");
    get(mpCbEPSPreviewEPSI, "epsipreviewcb");
    get(mpRbEPSLevel1, "level1rb");
    get(mpRbEPSLevel2, "level2rb");
    get(mpRbEPSColorFormat1, "color1rb");
    get(mpRbEPSColorFormat2, "color2rb");
    get(mpRbEPSCompressionLZW, "compresslzw");
    get(mpRbEPSCompressionNone, "compressnone");

    GetGraphicSource();

    get(mpInfo, "information");
    get(mpFtEstimatedSize, "estsizeft");

    get(mpBtnOK, "ok");

    maExt = maExt.toAsciiUpperCase();

    OUString  aFilterConfigPath( "Office.Common/Filter/Graphic/Export/" );
    mpOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );
    aFilterConfigPath += maExt;
    mpFilterOptionsItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );

    mnInitialResolutionUnit = mbIsPixelFormat
        ? mpOptionsItem->ReadInt32("PixelExportUnit", UNIT_DEFAULT)
        : mpOptionsItem->ReadInt32("VectorExportUnit", UNIT_DEFAULT);

    mnMaxFilesizeForRealtimePreview = mpOptionsItem->ReadInt32("MaxFilesizeForRealtimePreview", 0);
    mpFtEstimatedSize->SetText(" \n ");

    SetText( GetText().replaceFirst("%1", maExt) ); //Set dialog title

    mnFormat = GetFilterFormat( maExt );

    Size aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MapUnit::MapCM ) );
    maResolution.Width = aResolution.Width();
    maResolution.Height= aResolution.Height();

    if ( mxGraphic.is() )
    {
        Graphic aGraphic(mxGraphic);
        Size aSize = aGraphic.GetSizePixel();
        maSize = awt::Size(aSize.getWidth(), aSize.getHeight());
        double f100thmmPerPixel = 100000.0 / static_cast< double >( maResolution.Width );
        maOriginalSize = awt::Size(
                static_cast< sal_Int32 >( f100thmmPerPixel * maSize.Width ),
                static_cast< sal_Int32 >( f100thmmPerPixel * maSize.Height ) );
    }
    else
    {
        maOriginalSize = GetOriginalSize();
        if ( bIsPixelFormat )
        {
            double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0;
            maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ),
                static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) );
        }
        else
        {
            maSize = maOriginalSize;
        }
    }
    setupControls();

    // Size
    mpLbSizeX->SetSelectHdl( LINK( this, ExportDialog, SelectListBoxHdl ) );

    if (mpSbCompression)
        mpSbCompression->SetSlideHdl(LINK(this, ExportDialog, SbCompressionUpdateHdl));
    if (mpNfCompression)
        mpNfCompression->SetModifyHdl(LINK(this, ExportDialog, SelectHdl));

    mpMfSizeX->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeX ) );
    mpMfSizeY->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlMtfSizeY ) );

    mpNfResolution->SetModifyHdl( LINK( this, ExportDialog, UpdateHdlNfResolution ) );
    mpLbResolution->SetSelectHdl( LINK( this, ExportDialog, SelectListBoxHdl ) );

    mpLbColorDepth->SetSelectHdl( LINK( this, ExportDialog, SelectListBoxHdl ) );

    mpCbInterlaced->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );

    mpCbSaveTransparency->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );

    mpCbEPSPreviewTIFF->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
    mpCbEPSPreviewEPSI->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );

    mpRbEPSCompressionLZW->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
    mpRbEPSCompressionNone->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );

    mpRbBinary->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
    mpRbText->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );

    // BMP
    mpCbRLEEncoding->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );

    // EPS
    mpRbEPSLevel1->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );
    mpRbEPSLevel2->SetClickHdl( LINK( this, ExportDialog, UpdateHdl ) );

    mpBtnOK->SetClickHdl( LINK( this, ExportDialog, OK ) );

    updateControls();
}

void ExportDialog::setupSizeControls()
{
    sal_Int32 nUnit = mnInitialResolutionUnit;
    if (nUnit == UNIT_DEFAULT)
        nUnit = GetDefaultUnit();

    if (!mbIsPixelFormat)
    {
        mpFtResolution->Hide();
        mpNfResolution->Hide();
        mpLbResolution->Hide();
        mpLbSizeX->RemoveEntry( UNIT_PIXEL );        // removing pixel
        if ( nUnit >= UNIT_PIXEL )
            nUnit = UNIT_CM;
    }
    else if ( nUnit > UNIT_MAX_ID )
        nUnit = UNIT_PIXEL;
    if ( nUnit < 0 )
        nUnit = UNIT_CM;
    mpLbSizeX->SelectEntryPos( static_cast< sal_uInt16 >( nUnit ) );

    if ( mbIsPixelFormat )      // TODO: (metafileresolutionsupport) should be supported for vector formats also... this makes
    {                           // sense eg for bitmap fillings in metafiles, to preserve high dpi output
                                // (atm without special vector support the bitmaps are rendered with 96dpi)
        sal_Int32 nResolution = mpOptionsItem->ReadInt32("PixelExportResolution", 96);
        if ( nResolution < 1 )
            nResolution = 96;
        mpNfResolution->SetValue( nResolution );

        sal_Int32 nResolutionUnit = mpOptionsItem->ReadInt32("PixelExportResolutionUnit", 1);
        if ( ( nResolutionUnit < 0 ) || ( nResolutionUnit > 2 ) )
            nResolutionUnit = 1;
        mpLbResolution->SelectEntryPos( static_cast< sal_uInt16 >( nResolutionUnit ) );
    }
}

void ExportDialog::createFilterOptions()
{
    switch( mnFormat )
    {
        case FORMAT_JPG :
        {
            sal_Int32 nColor = mpFilterOptionsItem->ReadInt32("ColorMode", 0);
            if ( nColor == 1 )
                nColor = 0;
            else
                nColor = 1;
            mpLbColorDepth->InsertEntry( ms8BitGrayscale );
            mpLbColorDepth->InsertEntry( ms24BitColor );
            mpLbColorDepth->SelectEntryPos( nColor );
            mpColorDepth->Show();

            // Quality
            mpJPGQuality->Show();
            sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32("Quality", 75);
            if ((nQuality < 1 ) || (nQuality > 100))
                nQuality = 75;
            get(mpSbCompression, "compressionjpgsb");
            get(mpNfCompression, "compressionjpgnf");
            mpSbCompression->SetRangeMin( 1 );
            mpSbCompression->SetRangeMax( 100 );
            mpNfCompression->SetMin( 1 );
            mpNfCompression->SetMax( 100 );
            mpNfCompression->SetValue( nQuality );
            mpNfCompression->SetStrictFormat( true );
        }
        break;
        case FORMAT_PNG :
        {
            // Compression 1..9
            mpPNGCompression->Show();
            sal_Int32 nCompression = mpFilterOptionsItem->ReadInt32("Compression", 6);
            if ( ( nCompression < 1 ) || ( nCompression > 9 ) )
                nCompression = 6;

            get(mpSbCompression, "compressionpngsb");
            get(mpNfCompression, "compressionpngnf");
            mpSbCompression->SetRangeMin( 1 );
            mpSbCompression->SetRangeMax( 9 );
            mpNfCompression->SetMin( 1 );
            mpNfCompression->SetMax( 9 );
            mpNfCompression->SetValue( nCompression );
            mpNfCompression->SetStrictFormat( true );

            // Interlaced
            mpMode->Show();
            mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32("Interlaced", 0) != 0);

            // Transparency
            mpDrawingObjects->Show();
            mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32("Translucent", 1) != 0);
        }
        break;
        case FORMAT_BMP :
        {
            sal_Int32 nColor = mpFilterOptionsItem->ReadInt32("Color", 0);
            if ( nColor == 0 )
                nColor = 6;
            else
                nColor--;
            mpLbColorDepth->InsertEntry( ms1BitTreshold );
            mpLbColorDepth->InsertEntry( ms1BitDithered );
            mpLbColorDepth->InsertEntry( ms4BitGrayscale );
            mpLbColorDepth->InsertEntry( ms4BitColorPalette );
            mpLbColorDepth->InsertEntry( ms8BitGrayscale );
            mpLbColorDepth->InsertEntry( ms8BitColorPalette );
            mpLbColorDepth->InsertEntry( ms24BitColor );
            mpLbColorDepth->SelectEntryPos( nColor );
            mpColorDepth->Show();

            // RLE coding
            mpBMPCompression->Show();
            mpCbRLEEncoding->Check(mpFilterOptionsItem->ReadBool("RLE_Coding", true));
        }
        break;
        case FORMAT_GIF :
        {
            // Interlaced
            mpMode->Show();
            mpCbInterlaced->Check(mpFilterOptionsItem->ReadInt32("Interlaced", 1) != 0);

            // Transparency
            mpDrawingObjects->Show();
            mpCbSaveTransparency->Check(mpFilterOptionsItem->ReadInt32("Translucent", 1) != 0);
        }
        break;
        case FORMAT_EPS :
        {
            mpEPSGrid->Show();

            sal_Int32 nPreview = mpFilterOptionsItem->ReadInt32("Preview", 0);
            sal_Int32 nVersion = mpFilterOptionsItem->ReadInt32("Version", 2);
            sal_Int32 nColor = mpFilterOptionsItem->ReadInt32("ColorFormat", 0);
            sal_Int32 nCompr = mpFilterOptionsItem->ReadInt32("CompressionMode", 2);

            mpFilterOptionsItem->ReadInt32("TextMode", 0);

            mpCbEPSPreviewTIFF->Check( ( nPreview & 1 ) != 0 );
            mpCbEPSPreviewEPSI->Check( ( nPreview & 2 ) != 0 );

            mpRbEPSLevel1->Check( nVersion == 1 );
            mpRbEPSLevel2->Check( nVersion == 2 );

            mpRbEPSColorFormat1->Check( nColor == 1 );
            mpRbEPSColorFormat2->Check( nColor != 1 );

            mpRbEPSCompressionLZW->Check( nCompr == 1 );
            mpRbEPSCompressionNone->Check( nCompr != 1 );
        }
        break;
    }
}

void ExportDialog::setupControls()
{
    setupSizeControls();
    createFilterOptions();

    if (mnMaxFilesizeForRealtimePreview || mbIsPixelFormat)
        mpInfo->Show();
}

static OUString ImpValueOfInKB( sal_Int64 rVal )
{
    double fVal( static_cast<double>( rVal ) );
    fVal /= ( 1 << 10 );
    fVal += 0.05;
    OUStringBuffer aVal( OUString::number( fVal ) );
    sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.' ) );
    if ( nX > 0 )
        aVal.setLength( nX + 2 );
    return aVal.makeStringAndClear();
}

void ExportDialog::updateControls()
{
    // Size Controls
    if ( !mbIsPixelFormat )
    {
        awt::Size aSize100thmm( maSize );
        Size aSize( LogicToLogic( Size( aSize100thmm.Width * 100, aSize100thmm.Height * 100 ), MapUnit::Map100thMM,
            MapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) ) ) );
        mpMfSizeX->SetValue( aSize.Width() );
        mpMfSizeY->SetValue( aSize.Height() );
    }
    else
    {
        MapUnit aMapUnit( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) );
        if ( aMapUnit == MapUnit::MapPixel )
        {   // calculating pixel count via resolution and original graphic size
            mpMfSizeX->SetDecimalDigits( 0 );
            mpMfSizeY->SetDecimalDigits( 0 );
            mpMfSizeX->SetValue( maSize.Width );
            mpMfSizeY->SetValue( maSize.Height );
        }
        else
        {
            mpMfSizeX->SetDecimalDigits( 2 );
            mpMfSizeY->SetDecimalDigits( 2 );
            double fRatio;
            switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
            {
                case MapUnit::MapInch : fRatio = static_cast< double >( maResolution.Width ) * 0.0254; break;
                case MapUnit::MapMM :   fRatio = static_cast< double >( maResolution.Width ) * 0.001; break;
                case MapUnit::MapPoint :fRatio = ( static_cast< double >( maResolution.Width ) * 0.0254 ) / 72.0; break;
                default:
                case MapUnit::MapCM :   fRatio = static_cast< double >( maResolution.Width ) * 0.01; break;
            }
            mpMfSizeX->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Width * 100 ) / fRatio ) + 0.5 ) );
            mpMfSizeY->SetValue( static_cast< sal_Int32 >( ( static_cast< double >( maSize.Height * 100 ) / fRatio ) + 0.5 ) );
        }
    }
    sal_Int32 nResolution = 0;
    switch( mpLbResolution->GetSelectEntryPos() )
    {
        case 0 : nResolution = maResolution.Width / 100; break;     // pixels / cm
        case 2 : nResolution = maResolution.Width; break;           // pixels / meter
        default:
        case 1 : nResolution = static_cast< sal_Int32 >(maResolution.Width * 0.0254); break;    // pixels / inch
    }
    mpNfResolution->SetValue( nResolution );

    if (mpSbCompression && mpSbCompression->IsVisible() && mpNfCompression)
        mpSbCompression->SetThumbPos(mpNfCompression->GetValue());

    GetGraphicStream();

    // updating estimated size
    sal_Int64 nRealFileSize( mpTempStream->Tell() );
    if ( mbIsPixelFormat )
    {
        OUString aEst( nRealFileSize ? msEstimatedSizePix2 : msEstimatedSizePix1 );
        sal_Int64 nRawFileSize( GetRawFileSize() );
        sal_Int32 nInd = aEst.indexOf( "%" );
        if (nInd != -1)
            aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRawFileSize ) );

        if ( nRealFileSize && nInd != -1 )
        {
            nInd = aEst.indexOf( "%", nInd );
            if (nInd != -1)
                aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
        }
        mpFtEstimatedSize->SetText( aEst );
    }
    else
    {
        if ( mnMaxFilesizeForRealtimePreview )
        {
            OUString aEst( msEstimatedSizeVec );
            sal_Int32 nInd = aEst.indexOf( "%" );
            if (nInd != -1)
                aEst = aEst.replaceAt( nInd, 2, ImpValueOfInKB( nRealFileSize ) );
            mpFtEstimatedSize->SetText( aEst );
        }
    }

    // EPS
    if ( mpRbEPSLevel1->IsVisible() )
    {
        bool bEnabled = !mpRbEPSLevel1->IsChecked();
        mpRbEPSColorFormat1->Enable( bEnabled );
        mpRbEPSColorFormat2->Enable( bEnabled );
        mpRbEPSCompressionLZW->Enable( bEnabled );
        mpRbEPSCompressionNone->Enable( bEnabled );
    }
}

ExportDialog::~ExportDialog()
{
    disposeOnce();
}

void ExportDialog::dispose()
{
    delete mpFilterOptionsItem;
    delete mpOptionsItem;
    mpMfSizeX.clear();
    mpLbSizeX.clear();
    mpMfSizeY.clear();
    mpFtResolution.clear();
    mpNfResolution.clear();
    mpLbResolution.clear();
    mpColorDepth.clear();
    mpLbColorDepth.clear();
    mpJPGQuality.clear();
    mpPNGCompression.clear();
    mpSbCompression.clear();
    mpNfCompression.clear();
    mpMode.clear();
    mpCbInterlaced.clear();
    mpBMPCompression.clear();
    mpCbRLEEncoding.clear();
    mpDrawingObjects.clear();
    mpCbSaveTransparency.clear();
    mpEncoding.clear();
    mpRbBinary.clear();
    mpRbText.clear();
    mpEPSGrid.clear();
    mpCbEPSPreviewTIFF.clear();
    mpCbEPSPreviewEPSI.clear();
    mpRbEPSLevel1.clear();
    mpRbEPSLevel2.clear();
    mpRbEPSColorFormat1.clear();
    mpRbEPSColorFormat2.clear();
    mpRbEPSCompressionLZW.clear();
    mpRbEPSCompressionNone.clear();
    mpInfo.clear();
    mpFtEstimatedSize.clear();
    mpBtnOK.clear();
    ModalDialog::dispose();
}


/*************************************************************************
|*
|* stores values set in the ini-file
|*
\************************************************************************/
IMPL_LINK_NOARG(ExportDialog, SelectHdl, Edit&, void)
{
    updateControls();
}
IMPL_LINK_NOARG(ExportDialog, SelectListBoxHdl, ListBox&, void)
{
    updateControls();
}
IMPL_LINK_NOARG(ExportDialog, UpdateHdl, Button*, void)
{
    updateControls();
}

IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeX, Edit&, void)
{
    double fRatio = static_cast< double >( maOriginalSize.Height ) / maOriginalSize.Width;

    if ( mbIsPixelFormat )
    {
        switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
        {
            case MapUnit::MapInch :     maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
            case MapUnit::MapCM :       maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.01 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
            case MapUnit::MapMM :       maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.001 * mpMfSizeX->GetValue() / 100.0 + 0.5 ); break;
            case MapUnit::MapPoint :    maSize.Width = static_cast< sal_Int32 >( static_cast< double >( maResolution.Width ) * 0.0254 * mpMfSizeX->GetValue() / 100.0 * 72 + 0.5 ); break;
            default:
            case MapUnit::MapPixel :    maSize.Width = mpMfSizeX->GetValue(); break;
        }
        maSize.Height = static_cast< sal_Int32 >( fRatio * maSize.Width + 0.5 );
    }
    else
    {
        Fraction aFract( 1, 100 );
        sal_Int32 nWidth = mpMfSizeX->GetValue();
        sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio );
        const Size aSource( nWidth, nHeight );
        MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
        Size aDest( LogicToLogic( aSource, aSourceMapMode, MapUnit::Map100thMM ) );

        maSize.Width = aDest.Width();
        maSize.Height = aDest.Height();
    }
    updateControls();
}

IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeY, Edit&, void)
{
    double fRatio = static_cast< double >( maOriginalSize.Width ) / maOriginalSize.Height;

    if ( mbIsPixelFormat )
    {
        switch( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ) )
        {
            case MapUnit::MapInch :     maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
            case MapUnit::MapCM :       maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.01 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
            case MapUnit::MapMM :       maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.001 * mpMfSizeY->GetValue() / 100.0 + 0.5 ); break;
            case MapUnit::MapPoint :    maSize.Height = static_cast< sal_Int32 >( static_cast< double >( maResolution.Height ) * 0.0254 * mpMfSizeY->GetValue() / 100.0 * 72 + 0.5 ); break;
            default:
            case MapUnit::MapPixel :    maSize.Height = mpMfSizeY->GetValue(); break;
        }
        maSize.Width = static_cast< sal_Int32 >( fRatio * maSize.Height + 0.5 );
    }
    else
    {
        Fraction aFract( 1, 100 );
        sal_Int32 nHeight= mpMfSizeY->GetValue();
        sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio );
        const Size aSource( nWidth, nHeight );
        MapMode aSourceMapMode( GetMapUnit( mpLbSizeX->GetSelectEntryPos() ),Point(), aFract, aFract );
        Size aDest( LogicToLogic( aSource, aSourceMapMode, MapUnit::Map100thMM ) );

        maSize.Height = aDest.Height();
        maSize.Width = aDest.Width();
    }
    updateControls();
}

IMPL_LINK_NOARG(ExportDialog, UpdateHdlNfResolution, Edit&, void)
{
    sal_Int32 nResolution = mpNfResolution->GetValue();
    if ( mpLbResolution->GetSelectEntryPos() == 0 )      // pixels / cm
        nResolution *= 100;
    else if ( mpLbResolution->GetSelectEntryPos() == 1 ) // pixels / inch
        nResolution = static_cast< sal_Int32 >( ( ( static_cast< double >( nResolution ) + 0.5 ) / 0.0254 ) );
    maResolution.Width = nResolution;
    maResolution.Height= nResolution;

    updateControls();
}

IMPL_LINK_NOARG(ExportDialog, SbCompressionUpdateHdl, Slider*, void)
{
    mpNfCompression->SetValue( mpSbCompression->GetThumbPos() );
    updateControls();
}

IMPL_LINK_NOARG(ExportDialog, OK, Button*, void)
{
    // writing config parameter

    mrFltCallPara.aFilterData = GetFilterData( true );
    EndDialog( RET_OK );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */