xref: /trunk/main/svx/source/unodraw/UnoGraphicExporter.cxx (revision 90cac51f49ef55cdf2009baecff9c2c1fd8f34b6) !
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir #include <vos/mutex.hxx>
29cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
30cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
32cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp>
33cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp>
34cdf0e10cSrcweir #include <com/sun/star/document/XMimeTypeInfo.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
37cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
38cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
39cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
40cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicRenderer.hpp>
41cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp>
42cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
43cdf0e10cSrcweir #include <com/sun/star/task/XInteractionContinuation.hpp>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <comphelper/interaction.hxx>
46cdf0e10cSrcweir #include <framework/interaction.hxx>
47cdf0e10cSrcweir #include <com/sun/star/drawing/GraphicFilterRequest.hpp>
48cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
49cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
50cdf0e10cSrcweir #include <osl/diagnose.h>
51cdf0e10cSrcweir #include <osl/mutex.hxx>
52cdf0e10cSrcweir #include <vcl/metaact.hxx>
53cdf0e10cSrcweir #include <vcl/svapp.hxx>
54cdf0e10cSrcweir #include <vcl/virdev.hxx>
55cdf0e10cSrcweir #include <svtools/FilterConfigItem.hxx>
56cdf0e10cSrcweir #include <svl/outstrm.hxx>
57cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
58cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontact.hxx>
59cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
60cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
61cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrobj.hxx>
62cdf0e10cSrcweir #include <editeng/numitem.hxx>
63cdf0e10cSrcweir #include <svx/svdpagv.hxx>
64cdf0e10cSrcweir #include <svx/svdograf.hxx>
65cdf0e10cSrcweir #include "svx/xoutbmp.hxx"
66cdf0e10cSrcweir #include "svtools/filter.hxx"
67cdf0e10cSrcweir #include "svx/unoapi.hxx"
68cdf0e10cSrcweir #include <svx/svdpage.hxx>
69cdf0e10cSrcweir #include <svx/svdmodel.hxx>
70cdf0e10cSrcweir #include <svx/fmview.hxx>
71cdf0e10cSrcweir #include <svx/fmmodel.hxx>
72cdf0e10cSrcweir #include <svx/unopage.hxx>
73cdf0e10cSrcweir #include <svx/pageitem.hxx>
74cdf0e10cSrcweir #include <editeng/eeitem.hxx>
75cdf0e10cSrcweir #include <svx/svdoutl.hxx>
76cdf0e10cSrcweir #include <editeng/flditem.hxx>
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #include "boost/scoped_ptr.hpp"
79cdf0e10cSrcweir 
80cdf0e10cSrcweir #define MAX_EXT_PIX         2048
81cdf0e10cSrcweir 
82cdf0e10cSrcweir using namespace ::comphelper;
83cdf0e10cSrcweir using namespace ::osl;
84cdf0e10cSrcweir using namespace ::vos;
85cdf0e10cSrcweir using ::rtl::OUString;
86cdf0e10cSrcweir using namespace ::cppu;
87cdf0e10cSrcweir using namespace ::com::sun::star;
88cdf0e10cSrcweir using namespace ::com::sun::star::uno;
89cdf0e10cSrcweir using namespace ::com::sun::star::util;
90cdf0e10cSrcweir using namespace ::com::sun::star::container;
91cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
92cdf0e10cSrcweir using namespace ::com::sun::star::lang;
93cdf0e10cSrcweir using namespace ::com::sun::star::document;
94cdf0e10cSrcweir using namespace ::com::sun::star::frame;
95cdf0e10cSrcweir using namespace ::com::sun::star::beans;
96cdf0e10cSrcweir using namespace ::com::sun::star::task;
97cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactredirector.hxx>
98cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontact.hxx>
99cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
100cdf0e10cSrcweir 
101cdf0e10cSrcweir // #i102251#
102cdf0e10cSrcweir #include <editeng/editstat.hxx>
103cdf0e10cSrcweir 
104cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
105cdf0e10cSrcweir 
106cdf0e10cSrcweir namespace svx
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     struct ExportSettings
109cdf0e10cSrcweir     {
110cdf0e10cSrcweir         OUString maFilterName;
111cdf0e10cSrcweir         OUString maMediaType;
112cdf0e10cSrcweir         URL maURL;
113cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > mxOutputStream;
114cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::graphic::XGraphicRenderer > mxGraphicRenderer;
115cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >    mxStatusIndicator;
116cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > mxInteractionHandler;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         sal_Int32 mnWidth;
119cdf0e10cSrcweir         sal_Int32 mnHeight;
120cdf0e10cSrcweir         sal_Bool mbExportOnlyBackground;
121cdf0e10cSrcweir         sal_Bool mbVerboseComments;
122cdf0e10cSrcweir         sal_Bool mbScrollText;
123cdf0e10cSrcweir         sal_Bool mbUseHighContrast;
124cdf0e10cSrcweir         sal_Bool mbTranslucent;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         Sequence< PropertyValue >   maFilterData;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         Fraction    maScaleX;
129cdf0e10cSrcweir         Fraction    maScaleY;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         ExportSettings( SdrModel* pDoc );
132cdf0e10cSrcweir     };
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     ExportSettings::ExportSettings( SdrModel* pDoc )
135cdf0e10cSrcweir     : mnWidth( 0 )
136cdf0e10cSrcweir     , mnHeight( 0 )
137cdf0e10cSrcweir     , mbExportOnlyBackground( false )
138cdf0e10cSrcweir     , mbVerboseComments( false )
139cdf0e10cSrcweir     , mbScrollText( false )
140cdf0e10cSrcweir     , mbUseHighContrast( false )
141cdf0e10cSrcweir     , mbTranslucent( sal_False )
142cdf0e10cSrcweir     , maScaleX( 1, 1 )
143cdf0e10cSrcweir     , maScaleY( 1, 1 )
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         if( pDoc )
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             maScaleX = pDoc->GetScaleFraction();
148cdf0e10cSrcweir             maScaleY = pDoc->GetScaleFraction();
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     /** implements a component to export shapes or pages to external graphic formats.
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         @implements com.sun.star.drawing.GraphicExportFilter
155cdf0e10cSrcweir     */
156cdf0e10cSrcweir     class GraphicExporter : public WeakImplHelper4< XFilter, XExporter, XServiceInfo, XMimeTypeInfo >
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir     public:
159cdf0e10cSrcweir         GraphicExporter();
160cdf0e10cSrcweir         virtual ~GraphicExporter();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         // XFilter
163cdf0e10cSrcweir         virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) throw(RuntimeException);
164cdf0e10cSrcweir         virtual void SAL_CALL cancel(  ) throw(RuntimeException);
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         // XExporter
167cdf0e10cSrcweir         virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         // XServiceInfo
170cdf0e10cSrcweir         virtual OUString SAL_CALL getImplementationName(  ) throw(RuntimeException);
171cdf0e10cSrcweir         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
172cdf0e10cSrcweir         virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(RuntimeException);
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         // XMimeTypeInfo
175cdf0e10cSrcweir         virtual sal_Bool SAL_CALL supportsMimeType( const ::rtl::OUString& MimeTypeName ) throw (RuntimeException);
176cdf0e10cSrcweir         virtual Sequence< OUString > SAL_CALL getSupportedMimeTypeNames(  ) throw (RuntimeException);
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         VirtualDevice* CreatePageVDev( SdrPage* pPage, sal_uIntPtr nWidthPixel, sal_uIntPtr nHeightPixel ) const;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         DECL_LINK( CalcFieldValueHdl, EditFieldInfo* );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         void ParseSettings( const Sequence< PropertyValue >& aDescriptor, ExportSettings& rSettings );
183cdf0e10cSrcweir         bool GetGraphic( ExportSettings& rSettings, Graphic& aGraphic, sal_Bool bVectorType );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     private:
186cdf0e10cSrcweir         Reference< XShape >     mxShape;
187cdf0e10cSrcweir         Reference< XDrawPage >  mxPage;
188cdf0e10cSrcweir         Reference< XShapes >    mxShapes;
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         SvxDrawPage*        mpUnoPage;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         Link                maOldCalcFieldValueHdl;
193cdf0e10cSrcweir         sal_Int32           mnPageNumber;
194cdf0e10cSrcweir         SdrPage*            mpCurrentPage;
195cdf0e10cSrcweir         SdrModel*           mpDoc;
196cdf0e10cSrcweir     };
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     SVX_DLLPUBLIC Reference< XInterface > SAL_CALL GraphicExporter_createInstance(const Reference< XMultiServiceFactory > & )
199cdf0e10cSrcweir         throw( Exception )
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         return (XWeak*)new GraphicExporter();
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     SVX_DLLPUBLIC Sequence< OUString > SAL_CALL GraphicExporter_getSupportedServiceNames()
205cdf0e10cSrcweir         throw()
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         Sequence< OUString > aSupportedServiceNames( 1 );
208cdf0e10cSrcweir         aSupportedServiceNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GraphicExportFilter" ) );
209cdf0e10cSrcweir         return aSupportedServiceNames;
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     SVX_DLLPUBLIC OUString SAL_CALL GraphicExporter_getImplementationName()
213cdf0e10cSrcweir         throw()
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Draw.GraphicExporter" ) );
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     /** creates a bitmap that is optionaly transparent from a metafile
219cdf0e10cSrcweir     */
220cdf0e10cSrcweir     BitmapEx GetBitmapFromMetaFile( const GDIMetaFile& rMtf, sal_Bool bTransparent, const Size* pSize )
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         Graphic     aGraphic( rMtf );
223cdf0e10cSrcweir         BitmapEx    aBmpEx;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         // #i102089# support user's settings of AA and LineSnap when the MetaFile gets
226cdf0e10cSrcweir         // rasterconverted to a bitmap
227cdf0e10cSrcweir         const SvtOptionsDrawinglayer aDrawinglayerOpt;
228cdf0e10cSrcweir         const GraphicConversionParameters aParameters(
229cdf0e10cSrcweir             pSize ? *pSize : Size(0, 0),
230cdf0e10cSrcweir             true, // allow unlimited size
231cdf0e10cSrcweir             aDrawinglayerOpt.IsAntiAliasing(),
232cdf0e10cSrcweir             aDrawinglayerOpt.IsSnapHorVerLinesToDiscrete());
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         if( bTransparent )
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir             Graphic aMaskGraphic(rMtf.GetMonochromeMtf(COL_BLACK));
237cdf0e10cSrcweir             Bitmap  aMaskBmp(aMaskGraphic.GetBitmap(aParameters));
238cdf0e10cSrcweir 
239cdf0e10cSrcweir             aMaskBmp.Convert(BMP_CONVERSION_1BIT_THRESHOLD);
240cdf0e10cSrcweir             aBmpEx = BitmapEx(aGraphic.GetBitmap(aParameters), aMaskBmp);
241cdf0e10cSrcweir         }
242cdf0e10cSrcweir         else
243cdf0e10cSrcweir         {
244cdf0e10cSrcweir             aBmpEx = BitmapEx(aGraphic.GetBitmap(aParameters));
245cdf0e10cSrcweir         }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         aBmpEx.SetPrefMapMode( rMtf.GetPrefMapMode() );
248cdf0e10cSrcweir         aBmpEx.SetPrefSize( rMtf.GetPrefSize() );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         return aBmpEx;
251cdf0e10cSrcweir     }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     Size* CalcSize( sal_Int32 nWidth, sal_Int32 nHeight, const Size& aBoundSize, Size& aOutSize )
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         if( (nWidth == 0) && (nHeight == 0) )
256cdf0e10cSrcweir             return NULL;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         if( (nWidth == 0) && (nHeight != 0) && (aBoundSize.Height() != 0) )
259cdf0e10cSrcweir         {
260cdf0e10cSrcweir             nWidth = ( nHeight * aBoundSize.Width() ) / aBoundSize.Height();
261cdf0e10cSrcweir         }
262cdf0e10cSrcweir         else if( (nWidth != 0) && (nHeight == 0) && (aBoundSize.Width() != 0) )
263cdf0e10cSrcweir         {
264cdf0e10cSrcweir             nHeight = ( nWidth * aBoundSize.Height() ) / aBoundSize.Width();
265cdf0e10cSrcweir         }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         aOutSize.Width() = nWidth;
268cdf0e10cSrcweir         aOutSize.Height() = nHeight;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir         return &aOutSize;
271cdf0e10cSrcweir     }
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir class ImplExportCheckVisisbilityRedirector : public ::sdr::contact::ViewObjectContactRedirector
275cdf0e10cSrcweir {
276cdf0e10cSrcweir public:
277cdf0e10cSrcweir     ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage );
278cdf0e10cSrcweir     virtual ~ImplExportCheckVisisbilityRedirector();
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     virtual drawinglayer::primitive2d::Primitive2DSequence createRedirectedPrimitive2DSequence(
281cdf0e10cSrcweir         const sdr::contact::ViewObjectContact& rOriginal,
282cdf0e10cSrcweir         const sdr::contact::DisplayInfo& rDisplayInfo);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir private:
285cdf0e10cSrcweir     SdrPage*    mpCurrentPage;
286cdf0e10cSrcweir };
287cdf0e10cSrcweir 
288cdf0e10cSrcweir ImplExportCheckVisisbilityRedirector::ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage )
289cdf0e10cSrcweir :   ViewObjectContactRedirector(), mpCurrentPage( pCurrentPage )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir ImplExportCheckVisisbilityRedirector::~ImplExportCheckVisisbilityRedirector()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence ImplExportCheckVisisbilityRedirector::createRedirectedPrimitive2DSequence(
298cdf0e10cSrcweir     const sdr::contact::ViewObjectContact& rOriginal,
299cdf0e10cSrcweir     const sdr::contact::DisplayInfo& rDisplayInfo)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     if(pObject)
304cdf0e10cSrcweir     {
305cdf0e10cSrcweir         SdrPage* pPage = mpCurrentPage;
306cdf0e10cSrcweir         if( pPage == 0 )
307cdf0e10cSrcweir             pPage = pObject->GetPage();
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         if( (pPage == 0) || pPage->checkVisibility(rOriginal, rDisplayInfo, false) )
310cdf0e10cSrcweir         {
311cdf0e10cSrcweir             return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         return drawinglayer::primitive2d::Primitive2DSequence();
315cdf0e10cSrcweir     }
316cdf0e10cSrcweir     else
317cdf0e10cSrcweir     {
318cdf0e10cSrcweir         // not an object, maybe a page
319cdf0e10cSrcweir         return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
320cdf0e10cSrcweir     }
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir using namespace ::svx;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir GraphicExporter::GraphicExporter()
326cdf0e10cSrcweir : mpUnoPage( NULL ), mnPageNumber(-1), mpCurrentPage(0), mpDoc( NULL )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir GraphicExporter::~GraphicExporter()
331cdf0e10cSrcweir {
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir IMPL_LINK(GraphicExporter, CalcFieldValueHdl, EditFieldInfo*, pInfo)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir     if( pInfo )
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         if( mpCurrentPage )
339cdf0e10cSrcweir         {
340cdf0e10cSrcweir             pInfo->SetSdrPage( mpCurrentPage );
341cdf0e10cSrcweir         }
342cdf0e10cSrcweir         else if( mnPageNumber != -1 )
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir             const SvxFieldData* pField = pInfo->GetField().GetField();
345cdf0e10cSrcweir             if( pField && pField->ISA( SvxPageField ) )
346cdf0e10cSrcweir             {
347cdf0e10cSrcweir                 String aPageNumValue;
348cdf0e10cSrcweir                 sal_Bool bUpper = sal_False;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir                 switch(mpDoc->GetPageNumType())
351cdf0e10cSrcweir                 {
352cdf0e10cSrcweir                     case SVX_CHARS_UPPER_LETTER:
353cdf0e10cSrcweir                         aPageNumValue += (sal_Unicode)(char)((mnPageNumber - 1) % 26 + 'A');
354cdf0e10cSrcweir                         break;
355cdf0e10cSrcweir                     case SVX_CHARS_LOWER_LETTER:
356cdf0e10cSrcweir                         aPageNumValue += (sal_Unicode)(char)((mnPageNumber - 1) % 26 + 'a');
357cdf0e10cSrcweir                         break;
358cdf0e10cSrcweir                     case SVX_ROMAN_UPPER:
359cdf0e10cSrcweir                         bUpper = sal_True;
360cdf0e10cSrcweir                     case SVX_ROMAN_LOWER:
361cdf0e10cSrcweir                         aPageNumValue += SvxNumberFormat::CreateRomanString(mnPageNumber, bUpper);
362cdf0e10cSrcweir                         break;
363cdf0e10cSrcweir                     case SVX_NUMBER_NONE:
364cdf0e10cSrcweir                         aPageNumValue.Erase();
365cdf0e10cSrcweir                         aPageNumValue += sal_Unicode(' ');
366cdf0e10cSrcweir                         break;
367cdf0e10cSrcweir                     default:
368cdf0e10cSrcweir                         aPageNumValue += String::CreateFromInt32( (sal_Int32)mnPageNumber );
369cdf0e10cSrcweir                 }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir                 pInfo->SetRepresentation( aPageNumValue );
372cdf0e10cSrcweir 
373cdf0e10cSrcweir                 return(0);
374cdf0e10cSrcweir             }
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir     }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir     long nRet = maOldCalcFieldValueHdl.Call( pInfo );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     if( pInfo && mpCurrentPage )
381cdf0e10cSrcweir         pInfo->SetSdrPage( 0 );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     return nRet;
384cdf0e10cSrcweir }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir /** creates an virtual device for the given page
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     @return the returned VirtualDevice is owned by the caller
389cdf0e10cSrcweir */
390cdf0e10cSrcweir VirtualDevice* GraphicExporter::CreatePageVDev( SdrPage* pPage, sal_uIntPtr nWidthPixel, sal_uIntPtr nHeightPixel ) const
391cdf0e10cSrcweir {
392cdf0e10cSrcweir     VirtualDevice*  pVDev = new VirtualDevice();
393cdf0e10cSrcweir     MapMode         aMM( MAP_100TH_MM );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir     Point aPoint( 0, 0 );
396cdf0e10cSrcweir     Size aPageSize(pPage->GetSize());
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     // use scaling?
399cdf0e10cSrcweir     if( nWidthPixel )
400cdf0e10cSrcweir     {
401cdf0e10cSrcweir         const Fraction aFrac( (long) nWidthPixel, pVDev->LogicToPixel( aPageSize, aMM ).Width() );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir         aMM.SetScaleX( aFrac );
404cdf0e10cSrcweir 
405cdf0e10cSrcweir         if( nHeightPixel == 0 )
406cdf0e10cSrcweir             aMM.SetScaleY( aFrac );
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     if( nHeightPixel )
410cdf0e10cSrcweir     {
411cdf0e10cSrcweir         const Fraction aFrac( (long) nHeightPixel, pVDev->LogicToPixel( aPageSize, aMM ).Height() );
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         if( nWidthPixel == 0 )
414cdf0e10cSrcweir             aMM.SetScaleX( aFrac );
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         aMM.SetScaleY( aFrac );
417cdf0e10cSrcweir     }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir     pVDev->SetMapMode( aMM );
420cdf0e10cSrcweir #ifdef DBG_UTIL
421cdf0e10cSrcweir     sal_Bool bAbort = !
422cdf0e10cSrcweir #endif
423cdf0e10cSrcweir         pVDev->SetOutputSize(aPageSize);
424cdf0e10cSrcweir     DBG_ASSERT(!bAbort, "virt. Device nicht korrekt erzeugt");
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     SdrView* pView = new SdrView(mpDoc, pVDev);
427cdf0e10cSrcweir     pView->SetPageVisible( sal_False );
428cdf0e10cSrcweir     pView->SetBordVisible( sal_False );
429cdf0e10cSrcweir     pView->SetGridVisible( sal_False );
430cdf0e10cSrcweir     pView->SetHlplVisible( sal_False );
431cdf0e10cSrcweir     pView->SetGlueVisible( sal_False );
432cdf0e10cSrcweir     pView->ShowSdrPage(pPage);
433cdf0e10cSrcweir     Region aRegion (Rectangle( aPoint, aPageSize ) );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     pView->CompleteRedraw(pVDev, aRegion, &aRedirector);
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     delete pView;
440cdf0e10cSrcweir     return pVDev;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir void GraphicExporter::ParseSettings( const Sequence< PropertyValue >& aDescriptor, ExportSettings& rSettings )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir     sal_Int32 nArgs = aDescriptor.getLength();
446cdf0e10cSrcweir     const PropertyValue* pValues = aDescriptor.getConstArray();
447cdf0e10cSrcweir     while( nArgs-- )
448cdf0e10cSrcweir     {
449cdf0e10cSrcweir         if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FilterName" ) ) )
450cdf0e10cSrcweir         {
451cdf0e10cSrcweir             pValues->Value >>= rSettings.maFilterName;
452cdf0e10cSrcweir         }
453cdf0e10cSrcweir         else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
454cdf0e10cSrcweir         {
455cdf0e10cSrcweir             pValues->Value >>= rSettings.maMediaType;
456cdf0e10cSrcweir         }
457cdf0e10cSrcweir         else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) )
458cdf0e10cSrcweir         {
459cdf0e10cSrcweir             if( !( pValues->Value >>= rSettings.maURL ) )
460cdf0e10cSrcweir             {
461cdf0e10cSrcweir                 pValues->Value >>= rSettings.maURL.Complete;
462cdf0e10cSrcweir             }
463cdf0e10cSrcweir         }
464cdf0e10cSrcweir         else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OutputStream" ) ) )
465cdf0e10cSrcweir         {
466cdf0e10cSrcweir             pValues->Value >>= rSettings.mxOutputStream;
467cdf0e10cSrcweir         }
468cdf0e10cSrcweir         else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "GraphicRenderer" ) ) )
469cdf0e10cSrcweir         {
470cdf0e10cSrcweir             pValues->Value >>= rSettings.mxGraphicRenderer;
471cdf0e10cSrcweir         }
472cdf0e10cSrcweir         else if ( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" ) ) )
473cdf0e10cSrcweir         {
474cdf0e10cSrcweir             pValues->Value >>= rSettings.mxStatusIndicator;
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir         else if ( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" ) ) )
477cdf0e10cSrcweir         {
478cdf0e10cSrcweir             pValues->Value >>= rSettings.mxInteractionHandler;
479cdf0e10cSrcweir         }
480cdf0e10cSrcweir         else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Width" ) ) )  // for compatibility reasons, deprecated
481cdf0e10cSrcweir         {
482cdf0e10cSrcweir             pValues->Value >>= rSettings.mnWidth;
483cdf0e10cSrcweir         }
484cdf0e10cSrcweir         else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Height" ) ) ) // for compatibility reasons, deprecated
485cdf0e10cSrcweir         {
486cdf0e10cSrcweir             pValues->Value >>= rSettings.mnHeight;
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir         else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ExportOnlyBackground" ) ) )   // for compatibility reasons, deprecated
489cdf0e10cSrcweir         {
490cdf0e10cSrcweir             pValues->Value >>= rSettings.mbExportOnlyBackground;
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir         else if ( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FilterData" ) ) )
493cdf0e10cSrcweir         {
494cdf0e10cSrcweir             pValues->Value >>= rSettings.maFilterData;
495cdf0e10cSrcweir 
496cdf0e10cSrcweir             sal_Int32 nFilterArgs = rSettings.maFilterData.getLength();
497cdf0e10cSrcweir             PropertyValue* pDataValues = rSettings.maFilterData.getArray();
498cdf0e10cSrcweir             while( nFilterArgs-- )
499cdf0e10cSrcweir             {
500cdf0e10cSrcweir                 if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Translucent" ) ) )
501cdf0e10cSrcweir                 {
502cdf0e10cSrcweir                     if ( !( pDataValues->Value >>= rSettings.mbTranslucent ) )  // SJ: TODO: The GIF Transparency is stored as int32 in
503cdf0e10cSrcweir                     {                                               // configuration files, this has to be changed to boolean
504cdf0e10cSrcweir                         sal_Int32 nTranslucent = 0;
505cdf0e10cSrcweir                         if ( pDataValues->Value >>= nTranslucent )
506cdf0e10cSrcweir                             rSettings.mbTranslucent = nTranslucent != 0;
507cdf0e10cSrcweir                     }
508cdf0e10cSrcweir                 }
509cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PixelWidth" ) ) )
510cdf0e10cSrcweir                 {
511cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mnWidth;
512cdf0e10cSrcweir                 }
513cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PixelHeight" ) ) )
514cdf0e10cSrcweir                 {
515cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mnHeight;
516cdf0e10cSrcweir                 }
517cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Width" ) ) )  // for compatibility reasons, deprecated
518cdf0e10cSrcweir                 {
519cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mnWidth;
520cdf0e10cSrcweir                     pDataValues->Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PixelWidth" ) );
521cdf0e10cSrcweir                 }
522cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Height" ) ) ) // for compatibility reasons, deprecated
523cdf0e10cSrcweir                 {
524cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mnHeight;
525cdf0e10cSrcweir                     pDataValues->Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PixelHeight" ) );
526cdf0e10cSrcweir                 }
527cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ExportOnlyBackground" ) ) )
528cdf0e10cSrcweir                 {
529cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mbExportOnlyBackground;
530cdf0e10cSrcweir                 }
531cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HighContrast" ) ) )
532cdf0e10cSrcweir                 {
533cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mbUseHighContrast;
534cdf0e10cSrcweir                 }
535cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PageNumber" ) ) )
536cdf0e10cSrcweir                 {
537cdf0e10cSrcweir                     pDataValues->Value >>= mnPageNumber;
538cdf0e10cSrcweir                 }
539cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "VerboseComments" ) ) )
540cdf0e10cSrcweir                 {
541cdf0e10cSrcweir                     // #110496# Read flag for verbose metafile comments
542cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mbVerboseComments;
543cdf0e10cSrcweir                 }
544cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScrollText" ) ) )
545cdf0e10cSrcweir                 {
546cdf0e10cSrcweir                     // #110496# Read flag solitary scroll text metafile
547cdf0e10cSrcweir                     pDataValues->Value >>= rSettings.mbScrollText;
548cdf0e10cSrcweir                 }
549cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CurrentPage" ) ) )
550cdf0e10cSrcweir                 {
551cdf0e10cSrcweir                     Reference< XDrawPage >  xPage;
552cdf0e10cSrcweir                     pDataValues->Value >>= xPage;
553cdf0e10cSrcweir                     if( xPage.is() )
554cdf0e10cSrcweir                     {
555cdf0e10cSrcweir                         SvxDrawPage* pUnoPage = SvxDrawPage::getImplementation( xPage );
556cdf0e10cSrcweir                         if( pUnoPage && pUnoPage->GetSdrPage() )
557cdf0e10cSrcweir                             mpCurrentPage = pUnoPage->GetSdrPage();
558cdf0e10cSrcweir                     }
559cdf0e10cSrcweir                 }
560cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleXNumerator" ) ) )
561cdf0e10cSrcweir                 {
562cdf0e10cSrcweir                     sal_Int32 nVal = 1;
563cdf0e10cSrcweir                     if( pDataValues->Value >>= nVal )
564cdf0e10cSrcweir                         rSettings.maScaleX = Fraction( nVal, rSettings.maScaleX.GetDenominator() );
565cdf0e10cSrcweir                 }
566cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleXDenominator" ) ) )
567cdf0e10cSrcweir                 {
568cdf0e10cSrcweir                     sal_Int32 nVal = 1;
569cdf0e10cSrcweir                     if( pDataValues->Value >>= nVal )
570cdf0e10cSrcweir                         rSettings.maScaleX = Fraction( rSettings.maScaleX.GetNumerator(), nVal );
571cdf0e10cSrcweir                 }
572cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleYNumerator" ) ) )
573cdf0e10cSrcweir                 {
574cdf0e10cSrcweir                     sal_Int32 nVal = 1;
575cdf0e10cSrcweir                     if( pDataValues->Value >>= nVal )
576cdf0e10cSrcweir                         rSettings.maScaleY = Fraction( nVal, rSettings.maScaleY.GetDenominator() );
577cdf0e10cSrcweir                 }
578cdf0e10cSrcweir                 else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleYDenominator" ) ) )
579cdf0e10cSrcweir                 {
580cdf0e10cSrcweir                     sal_Int32 nVal = 1;
581cdf0e10cSrcweir                     if( pDataValues->Value >>= nVal )
582cdf0e10cSrcweir                         rSettings.maScaleY = Fraction( rSettings.maScaleY.GetNumerator(), nVal );
583cdf0e10cSrcweir                 }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir                 pDataValues++;
586cdf0e10cSrcweir             }
587cdf0e10cSrcweir         }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir         pValues++;
590cdf0e10cSrcweir     }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir     // putting the StatusIndicator that we got from the MediaDescriptor into our local FilterData copy
593cdf0e10cSrcweir     if ( rSettings.mxStatusIndicator.is() )
594cdf0e10cSrcweir     {
595cdf0e10cSrcweir         rtl::OUString sStatusIndicator( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) );
596cdf0e10cSrcweir         int i = rSettings.maFilterData.getLength();
597cdf0e10cSrcweir         rSettings.maFilterData.realloc( i + 1 );
598cdf0e10cSrcweir         rSettings.maFilterData[ i ].Name = sStatusIndicator;
599cdf0e10cSrcweir         rSettings.maFilterData[ i ].Value <<= rSettings.mxStatusIndicator;
600cdf0e10cSrcweir     }
601cdf0e10cSrcweir }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir bool GraphicExporter::GetGraphic( ExportSettings& rSettings, Graphic& aGraphic, sal_Bool bVectorType )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir     if( !mpDoc || !mpUnoPage )
606cdf0e10cSrcweir         return false;
607cdf0e10cSrcweir 
608cdf0e10cSrcweir     SdrPage* pPage = mpUnoPage->GetSdrPage();
609cdf0e10cSrcweir     if( !pPage )
610cdf0e10cSrcweir         return false;
611cdf0e10cSrcweir 
612cdf0e10cSrcweir     VirtualDevice       aVDev;
613cdf0e10cSrcweir     const MapMode       aMap( mpDoc->GetScaleUnit(), Point(), rSettings.maScaleX, rSettings.maScaleY );
614cdf0e10cSrcweir 
615cdf0e10cSrcweir     SdrOutliner& rOutl=mpDoc->GetDrawOutliner(NULL);
616cdf0e10cSrcweir     maOldCalcFieldValueHdl = rOutl.GetCalcFieldValueHdl();
617cdf0e10cSrcweir     rOutl.SetCalcFieldValueHdl( LINK(this, GraphicExporter, CalcFieldValueHdl) );
618cdf0e10cSrcweir     rOutl.SetBackgroundColor( pPage->GetPageBackgroundColor() );
619cdf0e10cSrcweir 
620cdf0e10cSrcweir     // #i102251#
621cdf0e10cSrcweir     const sal_uInt32 nOldCntrl(rOutl.GetControlWord());
622cdf0e10cSrcweir     sal_uInt32 nCntrl = nOldCntrl & ~EE_CNTRL_ONLINESPELLING;
623cdf0e10cSrcweir     rOutl.SetControlWord(nCntrl);
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     SdrObject* pTempBackgroundShape = 0;
626cdf0e10cSrcweir     std::vector< SdrObject* > aShapes;
627cdf0e10cSrcweir     bool bRet = true;
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     // export complete page?
630cdf0e10cSrcweir     if ( !mxShape.is() )
631cdf0e10cSrcweir     {
632cdf0e10cSrcweir         if( rSettings.mbExportOnlyBackground )
633cdf0e10cSrcweir         {
634cdf0e10cSrcweir             const SdrPageProperties* pCorrectProperties = pPage->getCorrectSdrPageProperties();
635cdf0e10cSrcweir 
636cdf0e10cSrcweir             if(pCorrectProperties)
637cdf0e10cSrcweir             {
638cdf0e10cSrcweir                 pTempBackgroundShape = new SdrRectObj(Rectangle(Point(0,0), pPage->GetSize()));
639cdf0e10cSrcweir                 pTempBackgroundShape->SetMergedItemSet(pCorrectProperties->GetItemSet());
640cdf0e10cSrcweir                 pTempBackgroundShape->SetMergedItem(XLineStyleItem(XLINE_NONE));
641cdf0e10cSrcweir                 pTempBackgroundShape->NbcSetStyleSheet(pCorrectProperties->GetStyleSheet(), true);
642cdf0e10cSrcweir                 aShapes.push_back(pTempBackgroundShape);
643cdf0e10cSrcweir             }
644cdf0e10cSrcweir         }
645cdf0e10cSrcweir         else
646cdf0e10cSrcweir         {
647cdf0e10cSrcweir             const Size aSize( pPage->GetSize() );
648cdf0e10cSrcweir 
649cdf0e10cSrcweir             // generate a bitmap to convert it to a pixel format.
650cdf0e10cSrcweir             // For gif pictures there can also be a vector format used (bTranslucent)
651cdf0e10cSrcweir             if ( !bVectorType && !rSettings.mbTranslucent )
652cdf0e10cSrcweir             {
653cdf0e10cSrcweir                 long nWidthPix = 0;
654cdf0e10cSrcweir                 long nHeightPix = 0;
655cdf0e10cSrcweir                 if ( rSettings.mnWidth > 0 && rSettings.mnHeight > 0 )
656cdf0e10cSrcweir                 {
657cdf0e10cSrcweir                     nWidthPix = rSettings.mnWidth;
658cdf0e10cSrcweir                     nHeightPix = rSettings.mnHeight;
659cdf0e10cSrcweir                 }
660cdf0e10cSrcweir                 else
661cdf0e10cSrcweir                 {
662cdf0e10cSrcweir                     const Size aSizePix( Application::GetDefaultDevice()->LogicToPixel( aSize, aMap ) );
663cdf0e10cSrcweir                     if (aSizePix.Width() > MAX_EXT_PIX || aSizePix.Height() > MAX_EXT_PIX)
664cdf0e10cSrcweir                     {
665cdf0e10cSrcweir                         if (aSizePix.Width() > MAX_EXT_PIX)
666cdf0e10cSrcweir                             nWidthPix = MAX_EXT_PIX;
667cdf0e10cSrcweir                         else
668cdf0e10cSrcweir                             nWidthPix = aSizePix.Width();
669cdf0e10cSrcweir                         if (aSizePix.Height() > MAX_EXT_PIX)
670cdf0e10cSrcweir                             nHeightPix = MAX_EXT_PIX;
671cdf0e10cSrcweir                         else
672cdf0e10cSrcweir                             nHeightPix = aSizePix.Height();
673cdf0e10cSrcweir 
674cdf0e10cSrcweir                         double fWidthDif = aSizePix.Width() / nWidthPix;
675cdf0e10cSrcweir                         double fHeightDif = aSizePix.Height() / nHeightPix;
676cdf0e10cSrcweir 
677cdf0e10cSrcweir                         if (fWidthDif > fHeightDif)
678cdf0e10cSrcweir                             nHeightPix = static_cast<long>(aSizePix.Height() / fWidthDif);
679cdf0e10cSrcweir                         else
680cdf0e10cSrcweir                             nWidthPix = static_cast<long>(aSizePix.Width() / fHeightDif);
681cdf0e10cSrcweir                     }
682cdf0e10cSrcweir                     else
683cdf0e10cSrcweir                     {
684cdf0e10cSrcweir                         nWidthPix = aSizePix.Width();
685cdf0e10cSrcweir                         nHeightPix = aSizePix.Height();
686cdf0e10cSrcweir                     }
687cdf0e10cSrcweir                 }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir                 boost::scoped_ptr< SdrView > pLocalView;
690cdf0e10cSrcweir                 if( PTR_CAST( FmFormModel, mpDoc ) )
691cdf0e10cSrcweir                 {
692cdf0e10cSrcweir                     pLocalView.reset( new FmFormView( PTR_CAST( FmFormModel, mpDoc ), &aVDev ) );
693cdf0e10cSrcweir                 }
694cdf0e10cSrcweir                 else
695cdf0e10cSrcweir                 {
696cdf0e10cSrcweir                     pLocalView.reset( new SdrView( mpDoc, &aVDev ) );
697cdf0e10cSrcweir                 }
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 
700cdf0e10cSrcweir                 VirtualDevice*  pVDev = CreatePageVDev( pPage, nWidthPix, nHeightPix );
701cdf0e10cSrcweir 
702cdf0e10cSrcweir                 if( pVDev )
703cdf0e10cSrcweir                 {
704cdf0e10cSrcweir                     aGraphic = pVDev->GetBitmap( Point(), pVDev->GetOutputSize() );
705cdf0e10cSrcweir                     aGraphic.SetPrefMapMode( aMap );
706cdf0e10cSrcweir                     aGraphic.SetPrefSize( aSize );
707cdf0e10cSrcweir                     delete pVDev;
708cdf0e10cSrcweir                 }
709cdf0e10cSrcweir             }
710cdf0e10cSrcweir             // create a metafile to export a vector format
711cdf0e10cSrcweir             else
712cdf0e10cSrcweir             {
713cdf0e10cSrcweir                 GDIMetaFile aMtf;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir                 aVDev.SetMapMode( aMap );
716cdf0e10cSrcweir                 if( rSettings.mbUseHighContrast )
717cdf0e10cSrcweir                     aVDev.SetDrawMode( aVDev.GetDrawMode() | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
718cdf0e10cSrcweir                 aVDev.EnableOutput( sal_False );
719cdf0e10cSrcweir                 aMtf.Record( &aVDev );
720cdf0e10cSrcweir                 Size aNewSize;
721cdf0e10cSrcweir 
722cdf0e10cSrcweir                 // create a view
723cdf0e10cSrcweir                 SdrView*        pView;
724cdf0e10cSrcweir 
725cdf0e10cSrcweir                 if( PTR_CAST( FmFormModel, mpDoc ) )
726cdf0e10cSrcweir                 {
727cdf0e10cSrcweir                     pView = new FmFormView( PTR_CAST( FmFormModel, mpDoc ), &aVDev );
728cdf0e10cSrcweir                 }
729cdf0e10cSrcweir                 else
730cdf0e10cSrcweir                 {
731cdf0e10cSrcweir                     pView = new SdrView( mpDoc, &aVDev );
732cdf0e10cSrcweir                 }
733cdf0e10cSrcweir 
734cdf0e10cSrcweir                 pView->SetBordVisible( sal_False );
735cdf0e10cSrcweir                 pView->SetPageVisible( sal_False );
736cdf0e10cSrcweir                 pView->ShowSdrPage( pPage );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir                 if ( pView && pPage )
739cdf0e10cSrcweir                 {
740cdf0e10cSrcweir                     pView->SetBordVisible( sal_False );
741cdf0e10cSrcweir                     pView->SetPageVisible( sal_False );
742cdf0e10cSrcweir                     pView->ShowSdrPage( pPage );
743cdf0e10cSrcweir 
744cdf0e10cSrcweir                     const Point aNewOrg( pPage->GetLftBorder(), pPage->GetUppBorder() );
745cdf0e10cSrcweir                     aNewSize = Size( aSize.Width() - pPage->GetLftBorder() - pPage->GetRgtBorder(),
746cdf0e10cSrcweir                                           aSize.Height() - pPage->GetUppBorder() - pPage->GetLwrBorder() );
747cdf0e10cSrcweir                     const Rectangle aClipRect( aNewOrg, aNewSize );
748cdf0e10cSrcweir                     MapMode         aVMap( aMap );
749cdf0e10cSrcweir 
750cdf0e10cSrcweir                     aVDev.Push();
751cdf0e10cSrcweir                     aVMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) );
752cdf0e10cSrcweir                     aVDev.SetRelativeMapMode( aVMap );
753cdf0e10cSrcweir                     aVDev.IntersectClipRegion( aClipRect );
754cdf0e10cSrcweir 
755cdf0e10cSrcweir                     // Use new StandardCheckVisisbilityRedirector
756cdf0e10cSrcweir                     ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage );
757cdf0e10cSrcweir 
758cdf0e10cSrcweir                     pView->CompleteRedraw(&aVDev, Region(Rectangle(Point(), aNewSize)), &aRedirector);
759cdf0e10cSrcweir 
760cdf0e10cSrcweir                     aVDev.Pop();
761cdf0e10cSrcweir 
762cdf0e10cSrcweir                     aMtf.Stop();
763cdf0e10cSrcweir                     aMtf.WindStart();
764cdf0e10cSrcweir                     aMtf.SetPrefMapMode( aMap );
765cdf0e10cSrcweir                     aMtf.SetPrefSize( aNewSize );
766cdf0e10cSrcweir 
767cdf0e10cSrcweir                     // AW: Here the current version was filtering out the META_CLIPREGION_ACTIONs
768cdf0e10cSrcweir                     // from the metafile. I asked some other developers why this was done, but no
769cdf0e10cSrcweir                     // one knew a direct reason. Since it's in for long time, it may be an old
770cdf0e10cSrcweir                     // piece of code. MetaFiles save and load ClipRegions with polygons with preserving
771cdf0e10cSrcweir                     // the polygons, so a resolution-indepent roundtrip is supported. Removed this
772cdf0e10cSrcweir                     // code since it destroys some MetaFiles where ClipRegions are used. Anyways,
773cdf0e10cSrcweir                     // just filtering them out is a hack, at least the encapsulated content would need
774cdf0e10cSrcweir                     // to be clipped geometrically.
775cdf0e10cSrcweir                     aGraphic = Graphic(aMtf);
776cdf0e10cSrcweir                 }
777cdf0e10cSrcweir 
778cdf0e10cSrcweir                 if ( pView )
779cdf0e10cSrcweir                 {
780cdf0e10cSrcweir                     pView->HideSdrPage();
781cdf0e10cSrcweir                     delete pView;
782cdf0e10cSrcweir                 }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir                 if( rSettings.mbTranslucent )
785cdf0e10cSrcweir                 {
786cdf0e10cSrcweir                     Size aOutSize;
787cdf0e10cSrcweir                     aGraphic = GetBitmapFromMetaFile( aGraphic.GetGDIMetaFile(), sal_True, CalcSize( rSettings.mnWidth, rSettings.mnHeight, aNewSize, aOutSize ) );
788cdf0e10cSrcweir                 }
789cdf0e10cSrcweir             }
790cdf0e10cSrcweir         }
791cdf0e10cSrcweir     }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir     // export only single shape or shape collection
794cdf0e10cSrcweir     else
795cdf0e10cSrcweir     {
796cdf0e10cSrcweir         // build list of SdrObject
797cdf0e10cSrcweir         if( mxShapes.is() )
798cdf0e10cSrcweir         {
799cdf0e10cSrcweir             Reference< XShape > xShape;
800cdf0e10cSrcweir             const sal_Int32 nCount = mxShapes->getCount();
801cdf0e10cSrcweir 
802cdf0e10cSrcweir             for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
803cdf0e10cSrcweir             {
804cdf0e10cSrcweir                 mxShapes->getByIndex( nIndex ) >>= xShape;
805cdf0e10cSrcweir                 SdrObject* pObj = GetSdrObjectFromXShape( xShape );
806cdf0e10cSrcweir                 if( pObj )
807cdf0e10cSrcweir                     aShapes.push_back( pObj );
808cdf0e10cSrcweir             }
809cdf0e10cSrcweir         }
810cdf0e10cSrcweir         else
811cdf0e10cSrcweir         {
812cdf0e10cSrcweir             // only one shape
813cdf0e10cSrcweir             SdrObject* pObj = GetSdrObjectFromXShape( mxShape );
814cdf0e10cSrcweir             if( pObj )
815cdf0e10cSrcweir                 aShapes.push_back( pObj );
816cdf0e10cSrcweir         }
817cdf0e10cSrcweir 
818cdf0e10cSrcweir         if( aShapes.empty() )
819cdf0e10cSrcweir             bRet = false;
820cdf0e10cSrcweir     }
821cdf0e10cSrcweir 
822cdf0e10cSrcweir     if( bRet && !aShapes.empty() )
823cdf0e10cSrcweir     {
824cdf0e10cSrcweir         // special treatment for only one SdrGrafObj that has text
825cdf0e10cSrcweir         sal_Bool bSingleGraphic = sal_False;
826cdf0e10cSrcweir 
827cdf0e10cSrcweir         if( 1 == aShapes.size() )
828cdf0e10cSrcweir         {
829cdf0e10cSrcweir             if( !bVectorType )
830cdf0e10cSrcweir             {
831cdf0e10cSrcweir                 SdrObject* pObj = aShapes.front();
832cdf0e10cSrcweir                 if( pObj && pObj->ISA( SdrGrafObj ) && !( (SdrGrafObj*) pObj )->HasText() )
833cdf0e10cSrcweir                 {
834cdf0e10cSrcweir                     aGraphic = ( (SdrGrafObj*) pObj )->GetTransformedGraphic();
835cdf0e10cSrcweir                     if ( aGraphic.GetType() == GRAPHIC_BITMAP )
836cdf0e10cSrcweir                     {
837cdf0e10cSrcweir                         Size aSizePixel( aGraphic.GetSizePixel() );
838cdf0e10cSrcweir                         if( rSettings.mnWidth && rSettings.mnHeight &&
839cdf0e10cSrcweir                             ( ( rSettings.mnWidth != aSizePixel.Width() ) ||
840cdf0e10cSrcweir                               ( rSettings.mnHeight != aSizePixel.Height() ) ) )
841cdf0e10cSrcweir                         {
842cdf0e10cSrcweir                             BitmapEx aBmpEx( aGraphic.GetBitmapEx() );
843cdf0e10cSrcweir                             aBmpEx.Scale( Size( rSettings.mnWidth, rSettings.mnHeight ) );
844cdf0e10cSrcweir                             aGraphic = aBmpEx;
845cdf0e10cSrcweir                         }
846*90cac51fSArmin Le Grand 
847*90cac51fSArmin Le Grand                         // #118804# only accept for bitmap graphics, else the
848*90cac51fSArmin Le Grand                         // conversion to bitmap will happen anywhere without size control
849*90cac51fSArmin Le Grand                         // as evtl. defined in rSettings.mnWidth/mnHeight
850cdf0e10cSrcweir                         bSingleGraphic = sal_True;
851cdf0e10cSrcweir                     }
852cdf0e10cSrcweir                 }
853*90cac51fSArmin Le Grand             }
854cdf0e10cSrcweir             else if( rSettings.mbScrollText )
855cdf0e10cSrcweir             {
856cdf0e10cSrcweir                 SdrObject* pObj = aShapes.front();
857cdf0e10cSrcweir                 if( pObj && pObj->ISA( SdrTextObj )
858cdf0e10cSrcweir                     && ( (SdrTextObj*) pObj )->HasText() )
859cdf0e10cSrcweir                 {
860cdf0e10cSrcweir                     Rectangle aScrollRectangle;
861cdf0e10cSrcweir                     Rectangle aPaintRectangle;
862cdf0e10cSrcweir 
863cdf0e10cSrcweir                     const boost::scoped_ptr< GDIMetaFile > pMtf(
864cdf0e10cSrcweir                         ( (SdrTextObj*) pObj )->GetTextScrollMetaFileAndRectangle(
865cdf0e10cSrcweir                         aScrollRectangle, aPaintRectangle ) );
866cdf0e10cSrcweir 
867cdf0e10cSrcweir                     // take the larger one of the two rectangles (that
868cdf0e10cSrcweir                     // should be the bound rect of the retrieved
869cdf0e10cSrcweir                     // metafile)
870cdf0e10cSrcweir                     Rectangle aTextRect;
871cdf0e10cSrcweir 
872cdf0e10cSrcweir                     if( aScrollRectangle.IsInside( aPaintRectangle ) )
873cdf0e10cSrcweir                         aTextRect = aScrollRectangle;
874cdf0e10cSrcweir                     else
875cdf0e10cSrcweir                         aTextRect = aPaintRectangle;
876cdf0e10cSrcweir 
877cdf0e10cSrcweir                     // setup pref size and mapmode
878cdf0e10cSrcweir                     pMtf->SetPrefSize( aTextRect.GetSize() );
879cdf0e10cSrcweir 
880cdf0e10cSrcweir                     // set actual origin (mtf is at actual shape
881cdf0e10cSrcweir                     // output position)
882cdf0e10cSrcweir                     MapMode aLocalMapMode( aMap );
883cdf0e10cSrcweir                     aLocalMapMode.SetOrigin(
884cdf0e10cSrcweir                         Point( -aPaintRectangle.Left(),
885cdf0e10cSrcweir                                -aPaintRectangle.Top() ) );
886cdf0e10cSrcweir                     pMtf->SetPrefMapMode( aLocalMapMode );
887cdf0e10cSrcweir 
888cdf0e10cSrcweir                     pMtf->AddAction( new MetaCommentAction(
889cdf0e10cSrcweir                                          "XTEXT_SCROLLRECT", 0,
890cdf0e10cSrcweir                                          reinterpret_cast<sal_uInt8 const*>(&aScrollRectangle),
891cdf0e10cSrcweir                                          sizeof( Rectangle ) ) );
892cdf0e10cSrcweir                     pMtf->AddAction( new MetaCommentAction(
893cdf0e10cSrcweir                                          "XTEXT_PAINTRECT", 0,
894cdf0e10cSrcweir                                          reinterpret_cast<sal_uInt8 const*>(&aPaintRectangle),
895cdf0e10cSrcweir                                          sizeof( Rectangle ) ) );
896cdf0e10cSrcweir 
897cdf0e10cSrcweir                     aGraphic = Graphic( *pMtf );
898cdf0e10cSrcweir 
899cdf0e10cSrcweir                     bSingleGraphic = sal_True;
900cdf0e10cSrcweir                 }
901cdf0e10cSrcweir             }
902cdf0e10cSrcweir         }
903cdf0e10cSrcweir 
904cdf0e10cSrcweir         if( !bSingleGraphic )
905cdf0e10cSrcweir         {
906cdf0e10cSrcweir             // create a metafile for all shapes
907cdf0e10cSrcweir             VirtualDevice   aOut;
908cdf0e10cSrcweir 
909cdf0e10cSrcweir             // calculate bound rect for all shapes
910cdf0e10cSrcweir             Rectangle aBound;
911cdf0e10cSrcweir 
912cdf0e10cSrcweir             {
913cdf0e10cSrcweir                 std::vector< SdrObject* >::iterator aIter = aShapes.begin();
914cdf0e10cSrcweir                 const std::vector< SdrObject* >::iterator aEnd = aShapes.end();
915cdf0e10cSrcweir 
916cdf0e10cSrcweir                 while( aIter != aEnd )
917cdf0e10cSrcweir                 {
918cdf0e10cSrcweir                     SdrObject* pObj = (*aIter++);
919cdf0e10cSrcweir                     Rectangle aR1(pObj->GetCurrentBoundRect());
920cdf0e10cSrcweir                     if (aBound.IsEmpty())
921cdf0e10cSrcweir                         aBound=aR1;
922cdf0e10cSrcweir                     else
923cdf0e10cSrcweir                         aBound.Union(aR1);
924cdf0e10cSrcweir                 }
925cdf0e10cSrcweir             }
926cdf0e10cSrcweir 
927cdf0e10cSrcweir             aOut.EnableOutput( sal_False );
928cdf0e10cSrcweir             aOut.SetMapMode( aMap );
929cdf0e10cSrcweir             if( rSettings.mbUseHighContrast )
930cdf0e10cSrcweir                 aOut.SetDrawMode( aVDev.GetDrawMode() | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
931cdf0e10cSrcweir 
932cdf0e10cSrcweir             GDIMetaFile aMtf;
933cdf0e10cSrcweir             aMtf.Clear();
934cdf0e10cSrcweir             aMtf.Record( &aOut );
935cdf0e10cSrcweir 
936cdf0e10cSrcweir             MapMode aOutMap( aMap );
937cdf0e10cSrcweir             aOutMap.SetOrigin( Point( -aBound.TopLeft().X(), -aBound.TopLeft().Y() ) );
938cdf0e10cSrcweir             aOut.SetRelativeMapMode( aOutMap );
939cdf0e10cSrcweir 
940cdf0e10cSrcweir             sdr::contact::DisplayInfo aDisplayInfo;
941cdf0e10cSrcweir 
942cdf0e10cSrcweir             if(mpCurrentPage)
943cdf0e10cSrcweir             {
944cdf0e10cSrcweir                 if(mpCurrentPage->TRG_HasMasterPage() && pPage->IsMasterPage())
945cdf0e10cSrcweir                 {
946cdf0e10cSrcweir                     // MasterPage is processed as another page's SubContent
947cdf0e10cSrcweir                     aDisplayInfo.SetProcessLayers(mpCurrentPage->TRG_GetMasterPageVisibleLayers());
948cdf0e10cSrcweir                     aDisplayInfo.SetSubContentActive(true);
949cdf0e10cSrcweir                 }
950cdf0e10cSrcweir             }
951cdf0e10cSrcweir 
952cdf0e10cSrcweir             if(!aShapes.empty())
953cdf0e10cSrcweir             {
954cdf0e10cSrcweir                 // more effective way to paint a vector of SdrObjects. Hand over the processed page
955cdf0e10cSrcweir                 // to have it in the
956cdf0e10cSrcweir                 sdr::contact::ObjectContactOfObjListPainter aMultiObjectPainter(aOut, aShapes, mpCurrentPage);
957cdf0e10cSrcweir                 ImplExportCheckVisisbilityRedirector aCheckVisibilityRedirector(mpCurrentPage);
958cdf0e10cSrcweir                 aMultiObjectPainter.SetViewObjectContactRedirector(&aCheckVisibilityRedirector);
959cdf0e10cSrcweir 
960cdf0e10cSrcweir                 aMultiObjectPainter.ProcessDisplay(aDisplayInfo);
961cdf0e10cSrcweir             }
962cdf0e10cSrcweir 
963cdf0e10cSrcweir             aMtf.Stop();
964cdf0e10cSrcweir             aMtf.WindStart();
965cdf0e10cSrcweir 
966cdf0e10cSrcweir             const Size  aExtSize( aOut.PixelToLogic( Size( 0, 0  ) ) );
967cdf0e10cSrcweir             Size        aBoundSize( aBound.GetWidth() + ( aExtSize.Width() ),
968cdf0e10cSrcweir                                     aBound.GetHeight() + ( aExtSize.Height() ) );
969cdf0e10cSrcweir 
970cdf0e10cSrcweir             aMtf.SetPrefMapMode( aMap );
971cdf0e10cSrcweir             aMtf.SetPrefSize( aBoundSize );
972cdf0e10cSrcweir 
973cdf0e10cSrcweir             if( !bVectorType )
974cdf0e10cSrcweir             {
975cdf0e10cSrcweir                 Size aOutSize;
976cdf0e10cSrcweir                 aGraphic = GetBitmapFromMetaFile( aMtf, rSettings.mbTranslucent, CalcSize( rSettings.mnWidth, rSettings.mnHeight, aBoundSize, aOutSize ) );
977cdf0e10cSrcweir             }
978cdf0e10cSrcweir             else
979cdf0e10cSrcweir             {
980cdf0e10cSrcweir                 aGraphic = aMtf;
981cdf0e10cSrcweir             }
982cdf0e10cSrcweir         }
983cdf0e10cSrcweir     }
984cdf0e10cSrcweir 
985cdf0e10cSrcweir     if(pTempBackgroundShape)
986cdf0e10cSrcweir     {
987cdf0e10cSrcweir         SdrObject::Free(pTempBackgroundShape);
988cdf0e10cSrcweir     }
989cdf0e10cSrcweir 
990cdf0e10cSrcweir     rOutl.SetCalcFieldValueHdl( maOldCalcFieldValueHdl );
991cdf0e10cSrcweir 
992cdf0e10cSrcweir     // #i102251#
993cdf0e10cSrcweir     rOutl.SetControlWord(nOldCntrl);
994cdf0e10cSrcweir 
995cdf0e10cSrcweir     return bRet;
996cdf0e10cSrcweir 
997cdf0e10cSrcweir }
998cdf0e10cSrcweir 
999cdf0e10cSrcweir // XFilter
1000cdf0e10cSrcweir sal_Bool SAL_CALL GraphicExporter::filter( const Sequence< PropertyValue >& aDescriptor )
1001cdf0e10cSrcweir     throw(RuntimeException)
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir     if( NULL == mpUnoPage )
1006cdf0e10cSrcweir         return sal_False;
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir     GraphicFilter*              pFilter = GraphicFilter::GetGraphicFilter();
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir     if( NULL == pFilter || NULL == mpUnoPage->GetSdrPage() || NULL == mpDoc )
1011cdf0e10cSrcweir         return sal_False;
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir     // get the arguments from the descriptor
1014cdf0e10cSrcweir     ExportSettings aSettings( mpDoc );
1015cdf0e10cSrcweir     ParseSettings( aDescriptor, aSettings );
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir     const sal_uInt16    nFilter = aSettings.maMediaType.getLength()
1018cdf0e10cSrcweir                             ? pFilter->GetExportFormatNumberForMediaType( aSettings.maMediaType )
1019cdf0e10cSrcweir                             : pFilter->GetExportFormatNumberForShortName( aSettings.maFilterName );
1020cdf0e10cSrcweir     sal_Bool            bVectorType = !pFilter->IsExportPixelFormat( nFilter );
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir     // create the output stuff
1023cdf0e10cSrcweir     Graphic aGraphic;
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir     sal_uInt16 nStatus = GetGraphic( aSettings, aGraphic, bVectorType ) ? GRFILTER_OK : GRFILTER_FILTERERROR;
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir     if( nStatus == GRFILTER_OK )
1028cdf0e10cSrcweir     {
1029cdf0e10cSrcweir         // export graphic only if it has a size
1030cdf0e10cSrcweir         const Size aGraphSize( aGraphic.GetPrefSize() );
1031cdf0e10cSrcweir         if ( ( aGraphSize.Width() == 0 ) || ( aGraphSize.Height() == 0 ) )
1032cdf0e10cSrcweir         {
1033cdf0e10cSrcweir             nStatus = GRFILTER_FILTERERROR;
1034cdf0e10cSrcweir         }
1035cdf0e10cSrcweir         else
1036cdf0e10cSrcweir         {
1037cdf0e10cSrcweir             // now we have a graphic, so export it
1038cdf0e10cSrcweir             if( aSettings.mxGraphicRenderer.is() )
1039cdf0e10cSrcweir             {
1040cdf0e10cSrcweir                 // render graphic directly into given renderer
1041cdf0e10cSrcweir                 aSettings.mxGraphicRenderer->render( aGraphic.GetXGraphic() );
1042cdf0e10cSrcweir             }
1043cdf0e10cSrcweir             else if( aSettings.mxOutputStream.is() )
1044cdf0e10cSrcweir             {
1045cdf0e10cSrcweir                 // TODO: Either utilize optional XSeekable functionality for the
1046cdf0e10cSrcweir                 // SvOutputStream, or adapt the graphic filter to not seek anymore.
1047cdf0e10cSrcweir                 SvMemoryStream aStream( 1024, 1024 );
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir                 nStatus = pFilter->ExportGraphic( aGraphic, String(), aStream, nFilter, &aSettings.maFilterData );
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir                 // copy temp stream to XOutputStream
1052cdf0e10cSrcweir                 SvOutputStream aOutputStream( aSettings.mxOutputStream );
1053cdf0e10cSrcweir                 aStream.Seek(0);
1054cdf0e10cSrcweir                 aOutputStream << aStream;
1055cdf0e10cSrcweir             }
1056cdf0e10cSrcweir             else
1057cdf0e10cSrcweir             {
1058cdf0e10cSrcweir                 INetURLObject aURLObject( aSettings.maURL.Complete );
1059cdf0e10cSrcweir                 DBG_ASSERT( aURLObject.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir                 nStatus = XOutBitmap::ExportGraphic( aGraphic, aURLObject, *pFilter, nFilter, &aSettings.maFilterData );
1062cdf0e10cSrcweir             }
1063cdf0e10cSrcweir         }
1064cdf0e10cSrcweir     }
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir     if ( aSettings.mxInteractionHandler.is() && ( nStatus != GRFILTER_OK ) )
1067cdf0e10cSrcweir     {
1068cdf0e10cSrcweir         Any aInteraction;
1069cdf0e10cSrcweir         Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > lContinuations(1);
1070cdf0e10cSrcweir         ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
1071cdf0e10cSrcweir         lContinuations[0] = Reference< XInteractionContinuation >(static_cast< XInteractionContinuation* >(pApprove), UNO_QUERY);
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir         GraphicFilterRequest aErrorCode;
1074cdf0e10cSrcweir         aErrorCode.ErrCode = nStatus;
1075cdf0e10cSrcweir         aInteraction <<= aErrorCode;
1076cdf0e10cSrcweir         aSettings.mxInteractionHandler->handle( framework::InteractionRequest::CreateRequest( aInteraction, lContinuations ) );
1077cdf0e10cSrcweir     }
1078cdf0e10cSrcweir     return nStatus == GRFILTER_OK;
1079cdf0e10cSrcweir }
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir void SAL_CALL GraphicExporter::cancel()
1082cdf0e10cSrcweir     throw(RuntimeException)
1083cdf0e10cSrcweir {
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir // XExporter
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir /** the source 'document' could be a XDrawPage, a XShape or a generic XShapes */
1089cdf0e10cSrcweir void SAL_CALL GraphicExporter::setSourceDocument( const Reference< lang::XComponent >& xComponent )
1090cdf0e10cSrcweir     throw(IllegalArgumentException, RuntimeException)
1091cdf0e10cSrcweir {
1092cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir     mxShapes = NULL;
1095cdf0e10cSrcweir     mpUnoPage = NULL;
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir     try
1098cdf0e10cSrcweir     {
1099cdf0e10cSrcweir     // any break inside this one loop while will throw a IllegalArgumentException
1100cdf0e10cSrcweir     do
1101cdf0e10cSrcweir     {
1102cdf0e10cSrcweir         mxPage = Reference< XDrawPage >::query( xComponent );
1103cdf0e10cSrcweir         mxShapes = Reference< XShapes >::query( xComponent );
1104cdf0e10cSrcweir         mxShape = Reference< XShape >::query( xComponent );
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir         // Step 1: try a generic XShapes
1107cdf0e10cSrcweir         if( !mxPage.is() && !mxShape.is() && mxShapes.is() )
1108cdf0e10cSrcweir         {
1109cdf0e10cSrcweir             // we do not support empty shape collections
1110cdf0e10cSrcweir             if( 0 == mxShapes->getCount() )
1111cdf0e10cSrcweir                 break;
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir             // get first shape to detect corresponding page and model
1114cdf0e10cSrcweir             mxShapes->getByIndex(0) >>= mxShape;
1115cdf0e10cSrcweir         }
1116cdf0e10cSrcweir         else
1117cdf0e10cSrcweir         {
1118cdf0e10cSrcweir             mxShapes = NULL;
1119cdf0e10cSrcweir         }
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir         // Step 2: try a shape
1122cdf0e10cSrcweir         if( mxShape.is() )
1123cdf0e10cSrcweir         {
1124cdf0e10cSrcweir             if( NULL == GetSdrObjectFromXShape( mxShape ) )
1125cdf0e10cSrcweir                 break;
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir             // get page for this shape
1128cdf0e10cSrcweir             Reference< XChild > xChild( mxShape, UNO_QUERY );
1129cdf0e10cSrcweir             if( !xChild.is() )
1130cdf0e10cSrcweir                 break;
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir             Reference< XInterface > xInt;
1133cdf0e10cSrcweir             do
1134cdf0e10cSrcweir             {
1135cdf0e10cSrcweir                 xInt = xChild->getParent();
1136cdf0e10cSrcweir                 mxPage = Reference< XDrawPage >::query( xInt );
1137cdf0e10cSrcweir                 if( !mxPage.is() )
1138cdf0e10cSrcweir                     xChild = Reference< XChild >::query( xInt );
1139cdf0e10cSrcweir             }
1140cdf0e10cSrcweir             while( !mxPage.is() && xChild.is() );
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir             if( !mxPage.is() )
1143cdf0e10cSrcweir                 break;
1144cdf0e10cSrcweir         }
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir         // Step 3: check the page
1147cdf0e10cSrcweir         if( !mxPage.is() )
1148cdf0e10cSrcweir             break;
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir         mpUnoPage = SvxDrawPage::getImplementation( mxPage );
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir         if( NULL == mpUnoPage || NULL == mpUnoPage->GetSdrPage() )
1153cdf0e10cSrcweir             break;
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir         mpDoc = mpUnoPage->GetSdrPage()->GetModel();
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir         // Step 4:  If we got a generic XShapes test all contained shapes
1158cdf0e10cSrcweir         //          if they belong to the same XDrawPage
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir         if( mxShapes.is() )
1161cdf0e10cSrcweir         {
1162cdf0e10cSrcweir             SdrPage* pPage = mpUnoPage->GetSdrPage();
1163cdf0e10cSrcweir             SdrObject* pObj;
1164cdf0e10cSrcweir             Reference< XShape > xShape;
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir             sal_Bool bOk = sal_True;
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir             const sal_Int32 nCount = mxShapes->getCount();
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir             // test all but the first shape if they have the same page than
1171cdf0e10cSrcweir             // the first shape
1172cdf0e10cSrcweir             for( sal_Int32 nIndex = 1; bOk && ( nIndex < nCount ); nIndex++ )
1173cdf0e10cSrcweir             {
1174cdf0e10cSrcweir                 mxShapes->getByIndex( nIndex ) >>= xShape;
1175cdf0e10cSrcweir                 pObj = GetSdrObjectFromXShape( xShape );
1176cdf0e10cSrcweir                 bOk = pObj && pObj->GetPage() == pPage;
1177cdf0e10cSrcweir             }
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir             if( !bOk )
1180cdf0e10cSrcweir                 break;
1181cdf0e10cSrcweir         }
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir         // no errors so far
1184cdf0e10cSrcweir         return;
1185cdf0e10cSrcweir     }
1186cdf0e10cSrcweir     while( 0 );
1187cdf0e10cSrcweir     }
1188cdf0e10cSrcweir     catch( Exception& )
1189cdf0e10cSrcweir     {
1190cdf0e10cSrcweir     }
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir     throw IllegalArgumentException();
1193cdf0e10cSrcweir }
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir // XServiceInfo
1196cdf0e10cSrcweir OUString SAL_CALL GraphicExporter::getImplementationName(  )
1197cdf0e10cSrcweir     throw(RuntimeException)
1198cdf0e10cSrcweir {
1199cdf0e10cSrcweir     return GraphicExporter_getImplementationName();
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir sal_Bool SAL_CALL GraphicExporter::supportsService( const OUString& ServiceName )
1203cdf0e10cSrcweir     throw(RuntimeException)
1204cdf0e10cSrcweir {
1205cdf0e10cSrcweir     Sequence< OUString > aSeq( GraphicExporter_getSupportedServiceNames() );
1206cdf0e10cSrcweir     sal_Int32 nArgs = aSeq.getLength();
1207cdf0e10cSrcweir     const OUString* pService = aSeq.getConstArray();
1208cdf0e10cSrcweir     while( nArgs-- )
1209cdf0e10cSrcweir         if( *pService++ == ServiceName )
1210cdf0e10cSrcweir             return sal_True;
1211cdf0e10cSrcweir 
1212cdf0e10cSrcweir     return sal_False;
1213cdf0e10cSrcweir }
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir Sequence< OUString > SAL_CALL GraphicExporter::getSupportedServiceNames(  )
1216cdf0e10cSrcweir     throw(RuntimeException)
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir     return GraphicExporter_getSupportedServiceNames();
1219cdf0e10cSrcweir }
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir // XMimeTypeInfo
1222cdf0e10cSrcweir sal_Bool SAL_CALL GraphicExporter::supportsMimeType( const OUString& MimeTypeName ) throw (RuntimeException)
1223cdf0e10cSrcweir {
1224cdf0e10cSrcweir     const String aMimeTypeName( MimeTypeName );
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir     GraphicFilter*  pFilter = GraphicFilter::GetGraphicFilter();
1227cdf0e10cSrcweir     sal_uInt16 nCount = pFilter->GetExportFormatCount();
1228cdf0e10cSrcweir     sal_uInt16 nFilter;
1229cdf0e10cSrcweir     for( nFilter = 0; nFilter < nCount; nFilter++ )
1230cdf0e10cSrcweir     {
1231cdf0e10cSrcweir         if( aMimeTypeName.Equals( pFilter->GetExportFormatMediaType( nFilter ) ) )
1232cdf0e10cSrcweir         {
1233cdf0e10cSrcweir             return sal_True;
1234cdf0e10cSrcweir         }
1235cdf0e10cSrcweir     }
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir     return sal_False;
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir Sequence< OUString > SAL_CALL GraphicExporter::getSupportedMimeTypeNames(  ) throw (RuntimeException)
1241cdf0e10cSrcweir {
1242cdf0e10cSrcweir     GraphicFilter*  pFilter = GraphicFilter::GetGraphicFilter();
1243cdf0e10cSrcweir     sal_uInt16 nCount = pFilter->GetExportFormatCount();
1244cdf0e10cSrcweir     sal_uInt16 nFilter;
1245cdf0e10cSrcweir     sal_uInt16 nFound = 0;
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir     Sequence< OUString > aSeq( nCount );
1248cdf0e10cSrcweir     OUString* pStr = aSeq.getArray();
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     for( nFilter = 0; nFilter < nCount; nFilter++ )
1251cdf0e10cSrcweir     {
1252cdf0e10cSrcweir         OUString aMimeType( pFilter->GetExportFormatMediaType( nFilter ) );
1253cdf0e10cSrcweir         if( aMimeType.getLength() )
1254cdf0e10cSrcweir         {
1255cdf0e10cSrcweir             *pStr++ = aMimeType;
1256cdf0e10cSrcweir             nFound++;
1257cdf0e10cSrcweir         }
1258cdf0e10cSrcweir     }
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir     if( nFound < nCount )
1261cdf0e10cSrcweir         aSeq.realloc( nFound );
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir     return aSeq;
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir Graphic SvxGetGraphicForShape( SdrObject& rShape, bool bVector )
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir     Graphic aGraphic;
1269cdf0e10cSrcweir     try
1270cdf0e10cSrcweir     {
1271cdf0e10cSrcweir         rtl::Reference< GraphicExporter > xExporter( new GraphicExporter() );
1272cdf0e10cSrcweir         Reference< XComponent > xComp( rShape.getUnoShape(), UNO_QUERY_THROW );
1273cdf0e10cSrcweir         xExporter->setSourceDocument( xComp );
1274cdf0e10cSrcweir         ExportSettings aSettings( rShape.GetModel() );
1275cdf0e10cSrcweir         xExporter->GetGraphic( aSettings, aGraphic, bVector );
1276cdf0e10cSrcweir     }
1277cdf0e10cSrcweir     catch( Exception& )
1278cdf0e10cSrcweir     {
1279cdf0e10cSrcweir         DBG_ERROR("SvxGetGraphicForShape(), exception caught!");
1280cdf0e10cSrcweir     }
1281cdf0e10cSrcweir     return aGraphic;
1282cdf0e10cSrcweir }
1283cdf0e10cSrcweir 
1284