LCOV - code coverage report
Current view: top level - svtools/source/filter - exportdialog.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 633 0.2 %
Date: 2014-04-11 Functions: 2 33 6.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10