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
10f6e50924SAndrew Rist *
11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist *
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.
19f6e50924SAndrew Rist *
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
ExportSettings(SdrModel * pDoc)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
GraphicExporter_createInstance(const Reference<XMultiServiceFactory> &)198cdf0e10cSrcweir SVX_DLLPUBLIC Reference< XInterface > SAL_CALL GraphicExporter_createInstance(const Reference< XMultiServiceFactory > & )
199cdf0e10cSrcweir throw( Exception )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir return (XWeak*)new GraphicExporter();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
GraphicExporter_getSupportedServiceNames()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
GraphicExporter_getImplementationName()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 */
GetBitmapFromMetaFile(const GDIMetaFile & rMtf,sal_Bool bTransparent,const Size * pSize)220cdf0e10cSrcweir BitmapEx GetBitmapFromMetaFile( const GDIMetaFile& rMtf, sal_Bool bTransparent, const Size* pSize )
221cdf0e10cSrcweir {
2221c86731aSArmin Le Grand BitmapEx aBmpEx;
223cdf0e10cSrcweir
2241c86731aSArmin Le Grand if(bTransparent)
2251c86731aSArmin Le Grand {
2261c86731aSArmin Le Grand // use new primitive conversion tooling
2271c86731aSArmin Le Grand basegfx::B2DRange aRange(basegfx::B2DPoint(0.0, 0.0));
228*99f4991cSArmin Le Grand sal_uInt32 nMaximumQuadraticPixels(500000);
2291c86731aSArmin Le Grand
2301c86731aSArmin Le Grand if(pSize)
2311c86731aSArmin Le Grand {
2321c86731aSArmin Le Grand // use 100th mm for primitive bitmap converter tool, input is pixel
2331c86731aSArmin Le Grand // use a real OutDev to get the correct DPI, the static LogicToLogic assumes 72dpi which is wrong (!)
2341c86731aSArmin Le Grand const Size aSize100th(Application::GetDefaultDevice()->PixelToLogic(*pSize, MapMode(MAP_100TH_MM)));
2351c86731aSArmin Le Grand
2361c86731aSArmin Le Grand aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height()));
237*99f4991cSArmin Le Grand
238*99f4991cSArmin Le Grand // when explicitely pixels are requested from the GraphicExporter, use a *very* high limit
239*99f4991cSArmin Le Grand // of 16gb (4096x4096 pixels), else use the default for the converters
240*99f4991cSArmin Le Grand nMaximumQuadraticPixels = std::min(sal_uInt32(4096 * 4096), sal_uInt32(pSize->Width() * pSize->Height()));
2411c86731aSArmin Le Grand }
2421c86731aSArmin Le Grand else
2431c86731aSArmin Le Grand {
2441c86731aSArmin Le Grand // use 100th mm for primitive bitmap converter tool
2451c86731aSArmin Le Grand const Size aSize100th(Application::GetDefaultDevice()->LogicToLogic(rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MapMode(MAP_100TH_MM)));
2461c86731aSArmin Le Grand
2471c86731aSArmin Le Grand aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height()));
2481c86731aSArmin Le Grand }
2491c86731aSArmin Le Grand
250*99f4991cSArmin Le Grand aBmpEx = convertMetafileToBitmapEx(rMtf, aRange, nMaximumQuadraticPixels);
251*99f4991cSArmin Le Grand }
252*99f4991cSArmin Le Grand else
253cdf0e10cSrcweir {
2541c86731aSArmin Le Grand const SvtOptionsDrawinglayer aDrawinglayerOpt;
255*99f4991cSArmin Le Grand Size aTargetSize(0, 0);
256*99f4991cSArmin Le Grand
257*99f4991cSArmin Le Grand if(pSize)
258*99f4991cSArmin Le Grand {
259*99f4991cSArmin Le Grand // #122820# If a concrete target size in pixels is given, use it
260*99f4991cSArmin Le Grand aTargetSize = *pSize;
261*99f4991cSArmin Le Grand
262*99f4991cSArmin Le Grand // get hairline and full bound rect to evtl. reduce given target pixel size when
263*99f4991cSArmin Le Grand // it is known that it will be expanded to get the right and bottom hairlines right
264*99f4991cSArmin Le Grand Rectangle aHairlineRect;
265*99f4991cSArmin Le Grand const Rectangle aRect(rMtf.GetBoundRect(*Application::GetDefaultDevice(), &aHairlineRect));
266*99f4991cSArmin Le Grand
267*99f4991cSArmin Le Grand if(!aRect.IsEmpty() && !aHairlineRect.IsEmpty())
268*99f4991cSArmin Le Grand {
269*99f4991cSArmin Le Grand if(aRect.Right() == aHairlineRect.Right() || aRect.Bottom() == aHairlineRect.Bottom())
270*99f4991cSArmin Le Grand {
271*99f4991cSArmin Le Grand if(aTargetSize.Width())
272*99f4991cSArmin Le Grand {
273*99f4991cSArmin Le Grand aTargetSize.Width() -= 1;
274*99f4991cSArmin Le Grand }
275*99f4991cSArmin Le Grand
276*99f4991cSArmin Le Grand if(aTargetSize.Height())
277*99f4991cSArmin Le Grand {
278*99f4991cSArmin Le Grand aTargetSize.Height() -= 1;
279*99f4991cSArmin Le Grand }
280*99f4991cSArmin Le Grand }
281*99f4991cSArmin Le Grand }
282*99f4991cSArmin Le Grand }
283*99f4991cSArmin Le Grand
2841c86731aSArmin Le Grand const GraphicConversionParameters aParameters(
285*99f4991cSArmin Le Grand aTargetSize,
2861c86731aSArmin Le Grand true, // allow unlimited size
2871c86731aSArmin Le Grand aDrawinglayerOpt.IsAntiAliasing(),
2881c86731aSArmin Le Grand aDrawinglayerOpt.IsSnapHorVerLinesToDiscrete());
2891c86731aSArmin Le Grand const Graphic aGraphic(rMtf);
2901c86731aSArmin Le Grand
291cdf0e10cSrcweir aBmpEx = BitmapEx(aGraphic.GetBitmap(aParameters));
2921c86731aSArmin Le Grand aBmpEx.SetPrefMapMode( rMtf.GetPrefMapMode() );
2931c86731aSArmin Le Grand aBmpEx.SetPrefSize( rMtf.GetPrefSize() );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir return aBmpEx;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir
CalcSize(sal_Int32 nWidth,sal_Int32 nHeight,const Size & aBoundSize,Size & aOutSize)299cdf0e10cSrcweir Size* CalcSize( sal_Int32 nWidth, sal_Int32 nHeight, const Size& aBoundSize, Size& aOutSize )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir if( (nWidth == 0) && (nHeight == 0) )
302cdf0e10cSrcweir return NULL;
303cdf0e10cSrcweir
304cdf0e10cSrcweir if( (nWidth == 0) && (nHeight != 0) && (aBoundSize.Height() != 0) )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir nWidth = ( nHeight * aBoundSize.Width() ) / aBoundSize.Height();
307cdf0e10cSrcweir }
308cdf0e10cSrcweir else if( (nWidth != 0) && (nHeight == 0) && (aBoundSize.Width() != 0) )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir nHeight = ( nWidth * aBoundSize.Height() ) / aBoundSize.Width();
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313cdf0e10cSrcweir aOutSize.Width() = nWidth;
314cdf0e10cSrcweir aOutSize.Height() = nHeight;
315cdf0e10cSrcweir
316cdf0e10cSrcweir return &aOutSize;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir }
319cdf0e10cSrcweir
320cdf0e10cSrcweir class ImplExportCheckVisisbilityRedirector : public ::sdr::contact::ViewObjectContactRedirector
321cdf0e10cSrcweir {
322cdf0e10cSrcweir public:
323cdf0e10cSrcweir ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage );
324cdf0e10cSrcweir virtual ~ImplExportCheckVisisbilityRedirector();
325cdf0e10cSrcweir
326cdf0e10cSrcweir virtual drawinglayer::primitive2d::Primitive2DSequence createRedirectedPrimitive2DSequence(
327cdf0e10cSrcweir const sdr::contact::ViewObjectContact& rOriginal,
328cdf0e10cSrcweir const sdr::contact::DisplayInfo& rDisplayInfo);
329cdf0e10cSrcweir
330cdf0e10cSrcweir private:
331cdf0e10cSrcweir SdrPage* mpCurrentPage;
332cdf0e10cSrcweir };
333cdf0e10cSrcweir
ImplExportCheckVisisbilityRedirector(SdrPage * pCurrentPage)334cdf0e10cSrcweir ImplExportCheckVisisbilityRedirector::ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage )
335cdf0e10cSrcweir : ViewObjectContactRedirector(), mpCurrentPage( pCurrentPage )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
~ImplExportCheckVisisbilityRedirector()339cdf0e10cSrcweir ImplExportCheckVisisbilityRedirector::~ImplExportCheckVisisbilityRedirector()
340cdf0e10cSrcweir {
341cdf0e10cSrcweir }
342cdf0e10cSrcweir
createRedirectedPrimitive2DSequence(const sdr::contact::ViewObjectContact & rOriginal,const sdr::contact::DisplayInfo & rDisplayInfo)343cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence ImplExportCheckVisisbilityRedirector::createRedirectedPrimitive2DSequence(
344cdf0e10cSrcweir const sdr::contact::ViewObjectContact& rOriginal,
345cdf0e10cSrcweir const sdr::contact::DisplayInfo& rDisplayInfo)
346cdf0e10cSrcweir {
347cdf0e10cSrcweir SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
348cdf0e10cSrcweir
349cdf0e10cSrcweir if(pObject)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir SdrPage* pPage = mpCurrentPage;
352cdf0e10cSrcweir if( pPage == 0 )
353cdf0e10cSrcweir pPage = pObject->GetPage();
354cdf0e10cSrcweir
355cdf0e10cSrcweir if( (pPage == 0) || pPage->checkVisibility(rOriginal, rDisplayInfo, false) )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir return drawinglayer::primitive2d::Primitive2DSequence();
361cdf0e10cSrcweir }
362cdf0e10cSrcweir else
363cdf0e10cSrcweir {
364cdf0e10cSrcweir // not an object, maybe a page
365cdf0e10cSrcweir return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
366cdf0e10cSrcweir }
367cdf0e10cSrcweir }
368cdf0e10cSrcweir
369cdf0e10cSrcweir using namespace ::svx;
370cdf0e10cSrcweir
GraphicExporter()371cdf0e10cSrcweir GraphicExporter::GraphicExporter()
372cdf0e10cSrcweir : mpUnoPage( NULL ), mnPageNumber(-1), mpCurrentPage(0), mpDoc( NULL )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir }
375cdf0e10cSrcweir
~GraphicExporter()376cdf0e10cSrcweir GraphicExporter::~GraphicExporter()
377cdf0e10cSrcweir {
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
IMPL_LINK(GraphicExporter,CalcFieldValueHdl,EditFieldInfo *,pInfo)380cdf0e10cSrcweir IMPL_LINK(GraphicExporter, CalcFieldValueHdl, EditFieldInfo*, pInfo)
381cdf0e10cSrcweir {
382cdf0e10cSrcweir if( pInfo )
383cdf0e10cSrcweir {
384cdf0e10cSrcweir if( mpCurrentPage )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir pInfo->SetSdrPage( mpCurrentPage );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir else if( mnPageNumber != -1 )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir const SvxFieldData* pField = pInfo->GetField().GetField();
391cdf0e10cSrcweir if( pField && pField->ISA( SvxPageField ) )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir String aPageNumValue;
394cdf0e10cSrcweir sal_Bool bUpper = sal_False;
395cdf0e10cSrcweir
396cdf0e10cSrcweir switch(mpDoc->GetPageNumType())
397cdf0e10cSrcweir {
398cdf0e10cSrcweir case SVX_CHARS_UPPER_LETTER:
399cdf0e10cSrcweir aPageNumValue += (sal_Unicode)(char)((mnPageNumber - 1) % 26 + 'A');
400cdf0e10cSrcweir break;
401cdf0e10cSrcweir case SVX_CHARS_LOWER_LETTER:
402cdf0e10cSrcweir aPageNumValue += (sal_Unicode)(char)((mnPageNumber - 1) % 26 + 'a');
403cdf0e10cSrcweir break;
404cdf0e10cSrcweir case SVX_ROMAN_UPPER:
405cdf0e10cSrcweir bUpper = sal_True;
406cdf0e10cSrcweir case SVX_ROMAN_LOWER:
407cdf0e10cSrcweir aPageNumValue += SvxNumberFormat::CreateRomanString(mnPageNumber, bUpper);
408cdf0e10cSrcweir break;
409cdf0e10cSrcweir case SVX_NUMBER_NONE:
410cdf0e10cSrcweir aPageNumValue.Erase();
411cdf0e10cSrcweir aPageNumValue += sal_Unicode(' ');
412cdf0e10cSrcweir break;
413cdf0e10cSrcweir default:
414cdf0e10cSrcweir aPageNumValue += String::CreateFromInt32( (sal_Int32)mnPageNumber );
415cdf0e10cSrcweir }
416cdf0e10cSrcweir
417cdf0e10cSrcweir pInfo->SetRepresentation( aPageNumValue );
418cdf0e10cSrcweir
419cdf0e10cSrcweir return(0);
420cdf0e10cSrcweir }
421cdf0e10cSrcweir }
422cdf0e10cSrcweir }
423cdf0e10cSrcweir
424cdf0e10cSrcweir long nRet = maOldCalcFieldValueHdl.Call( pInfo );
425cdf0e10cSrcweir
426cdf0e10cSrcweir if( pInfo && mpCurrentPage )
427cdf0e10cSrcweir pInfo->SetSdrPage( 0 );
428cdf0e10cSrcweir
429cdf0e10cSrcweir return nRet;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir
432cdf0e10cSrcweir /** creates an virtual device for the given page
433cdf0e10cSrcweir
434cdf0e10cSrcweir @return the returned VirtualDevice is owned by the caller
435cdf0e10cSrcweir */
CreatePageVDev(SdrPage * pPage,sal_uIntPtr nWidthPixel,sal_uIntPtr nHeightPixel) const436cdf0e10cSrcweir VirtualDevice* GraphicExporter::CreatePageVDev( SdrPage* pPage, sal_uIntPtr nWidthPixel, sal_uIntPtr nHeightPixel ) const
437cdf0e10cSrcweir {
438cdf0e10cSrcweir VirtualDevice* pVDev = new VirtualDevice();
439cdf0e10cSrcweir MapMode aMM( MAP_100TH_MM );
440cdf0e10cSrcweir
441cdf0e10cSrcweir Point aPoint( 0, 0 );
442cdf0e10cSrcweir Size aPageSize(pPage->GetSize());
443cdf0e10cSrcweir
444cdf0e10cSrcweir // use scaling?
445cdf0e10cSrcweir if( nWidthPixel )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir const Fraction aFrac( (long) nWidthPixel, pVDev->LogicToPixel( aPageSize, aMM ).Width() );
448cdf0e10cSrcweir
449cdf0e10cSrcweir aMM.SetScaleX( aFrac );
450cdf0e10cSrcweir
451cdf0e10cSrcweir if( nHeightPixel == 0 )
452cdf0e10cSrcweir aMM.SetScaleY( aFrac );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir
455cdf0e10cSrcweir if( nHeightPixel )
456cdf0e10cSrcweir {
457cdf0e10cSrcweir const Fraction aFrac( (long) nHeightPixel, pVDev->LogicToPixel( aPageSize, aMM ).Height() );
458cdf0e10cSrcweir
459cdf0e10cSrcweir if( nWidthPixel == 0 )
460cdf0e10cSrcweir aMM.SetScaleX( aFrac );
461cdf0e10cSrcweir
462cdf0e10cSrcweir aMM.SetScaleY( aFrac );
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir pVDev->SetMapMode( aMM );
466*99f4991cSArmin Le Grand bool bSuccess(false);
467*99f4991cSArmin Le Grand
468*99f4991cSArmin Le Grand // #122820# If available, use pixel size directly
469*99f4991cSArmin Le Grand if(nWidthPixel && nHeightPixel)
470*99f4991cSArmin Le Grand {
471*99f4991cSArmin Le Grand bSuccess = pVDev->SetOutputSizePixel(Size(nWidthPixel, nHeightPixel));
472*99f4991cSArmin Le Grand }
473*99f4991cSArmin Le Grand else
474*99f4991cSArmin Le Grand {
475*99f4991cSArmin Le Grand bSuccess = pVDev->SetOutputSize(aPageSize);
476*99f4991cSArmin Le Grand }
477*99f4991cSArmin Le Grand
478*99f4991cSArmin Le Grand if(bSuccess)
479*99f4991cSArmin Le Grand {
480*99f4991cSArmin Le Grand SdrView* pView = new SdrView(mpDoc, pVDev);
481*99f4991cSArmin Le Grand pView->SetPageVisible( sal_False );
482*99f4991cSArmin Le Grand pView->SetBordVisible( sal_False );
483*99f4991cSArmin Le Grand pView->SetGridVisible( sal_False );
484*99f4991cSArmin Le Grand pView->SetHlplVisible( sal_False );
485*99f4991cSArmin Le Grand pView->SetGlueVisible( sal_False );
486*99f4991cSArmin Le Grand pView->ShowSdrPage(pPage);
487*99f4991cSArmin Le Grand Region aRegion (Rectangle( aPoint, aPageSize ) );
488*99f4991cSArmin Le Grand
489*99f4991cSArmin Le Grand ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage );
490*99f4991cSArmin Le Grand
491*99f4991cSArmin Le Grand pView->CompleteRedraw(pVDev, aRegion, &aRedirector);
492*99f4991cSArmin Le Grand delete pView;
493*99f4991cSArmin Le Grand }
494*99f4991cSArmin Le Grand else
495*99f4991cSArmin Le Grand {
496*99f4991cSArmin Le Grand OSL_ENSURE(false, "Could not get a VirtualDevice of requested size (!)");
497*99f4991cSArmin Le Grand }
498*99f4991cSArmin Le Grand
499cdf0e10cSrcweir return pVDev;
500cdf0e10cSrcweir }
501cdf0e10cSrcweir
ParseSettings(const Sequence<PropertyValue> & aDescriptor,ExportSettings & rSettings)502cdf0e10cSrcweir void GraphicExporter::ParseSettings( const Sequence< PropertyValue >& aDescriptor, ExportSettings& rSettings )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir sal_Int32 nArgs = aDescriptor.getLength();
505cdf0e10cSrcweir const PropertyValue* pValues = aDescriptor.getConstArray();
506cdf0e10cSrcweir while( nArgs-- )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FilterName" ) ) )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir pValues->Value >>= rSettings.maFilterName;
511cdf0e10cSrcweir }
512cdf0e10cSrcweir else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir pValues->Value >>= rSettings.maMediaType;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) )
517cdf0e10cSrcweir {
518cdf0e10cSrcweir if( !( pValues->Value >>= rSettings.maURL ) )
519cdf0e10cSrcweir {
520cdf0e10cSrcweir pValues->Value >>= rSettings.maURL.Complete;
521cdf0e10cSrcweir }
522cdf0e10cSrcweir }
523cdf0e10cSrcweir else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OutputStream" ) ) )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir pValues->Value >>= rSettings.mxOutputStream;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "GraphicRenderer" ) ) )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir pValues->Value >>= rSettings.mxGraphicRenderer;
530cdf0e10cSrcweir }
531cdf0e10cSrcweir else if ( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" ) ) )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir pValues->Value >>= rSettings.mxStatusIndicator;
534cdf0e10cSrcweir }
535cdf0e10cSrcweir else if ( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" ) ) )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir pValues->Value >>= rSettings.mxInteractionHandler;
538cdf0e10cSrcweir }
539cdf0e10cSrcweir else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Width" ) ) ) // for compatibility reasons, deprecated
540cdf0e10cSrcweir {
541cdf0e10cSrcweir pValues->Value >>= rSettings.mnWidth;
542cdf0e10cSrcweir }
543cdf0e10cSrcweir else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Height" ) ) ) // for compatibility reasons, deprecated
544cdf0e10cSrcweir {
545cdf0e10cSrcweir pValues->Value >>= rSettings.mnHeight;
546cdf0e10cSrcweir }
547cdf0e10cSrcweir else if( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ExportOnlyBackground" ) ) ) // for compatibility reasons, deprecated
548cdf0e10cSrcweir {
549cdf0e10cSrcweir pValues->Value >>= rSettings.mbExportOnlyBackground;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir else if ( pValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FilterData" ) ) )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir pValues->Value >>= rSettings.maFilterData;
554cdf0e10cSrcweir
555cdf0e10cSrcweir sal_Int32 nFilterArgs = rSettings.maFilterData.getLength();
556cdf0e10cSrcweir PropertyValue* pDataValues = rSettings.maFilterData.getArray();
557cdf0e10cSrcweir while( nFilterArgs-- )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Translucent" ) ) )
560cdf0e10cSrcweir {
561cdf0e10cSrcweir if ( !( pDataValues->Value >>= rSettings.mbTranslucent ) ) // SJ: TODO: The GIF Transparency is stored as int32 in
562cdf0e10cSrcweir { // configuration files, this has to be changed to boolean
563cdf0e10cSrcweir sal_Int32 nTranslucent = 0;
564cdf0e10cSrcweir if ( pDataValues->Value >>= nTranslucent )
565cdf0e10cSrcweir rSettings.mbTranslucent = nTranslucent != 0;
566cdf0e10cSrcweir }
567cdf0e10cSrcweir }
568cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PixelWidth" ) ) )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir pDataValues->Value >>= rSettings.mnWidth;
571cdf0e10cSrcweir }
572cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PixelHeight" ) ) )
573cdf0e10cSrcweir {
574cdf0e10cSrcweir pDataValues->Value >>= rSettings.mnHeight;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Width" ) ) ) // for compatibility reasons, deprecated
577cdf0e10cSrcweir {
578cdf0e10cSrcweir pDataValues->Value >>= rSettings.mnWidth;
579cdf0e10cSrcweir pDataValues->Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PixelWidth" ) );
580cdf0e10cSrcweir }
581cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Height" ) ) ) // for compatibility reasons, deprecated
582cdf0e10cSrcweir {
583cdf0e10cSrcweir pDataValues->Value >>= rSettings.mnHeight;
584cdf0e10cSrcweir pDataValues->Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PixelHeight" ) );
585cdf0e10cSrcweir }
586cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ExportOnlyBackground" ) ) )
587cdf0e10cSrcweir {
588cdf0e10cSrcweir pDataValues->Value >>= rSettings.mbExportOnlyBackground;
589cdf0e10cSrcweir }
590cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HighContrast" ) ) )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir pDataValues->Value >>= rSettings.mbUseHighContrast;
593cdf0e10cSrcweir }
594cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PageNumber" ) ) )
595cdf0e10cSrcweir {
596cdf0e10cSrcweir pDataValues->Value >>= mnPageNumber;
597cdf0e10cSrcweir }
598cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "VerboseComments" ) ) )
599cdf0e10cSrcweir {
600cdf0e10cSrcweir // #110496# Read flag for verbose metafile comments
601cdf0e10cSrcweir pDataValues->Value >>= rSettings.mbVerboseComments;
602cdf0e10cSrcweir }
603cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScrollText" ) ) )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir // #110496# Read flag solitary scroll text metafile
606cdf0e10cSrcweir pDataValues->Value >>= rSettings.mbScrollText;
607cdf0e10cSrcweir }
608cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CurrentPage" ) ) )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir Reference< XDrawPage > xPage;
611cdf0e10cSrcweir pDataValues->Value >>= xPage;
612cdf0e10cSrcweir if( xPage.is() )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir SvxDrawPage* pUnoPage = SvxDrawPage::getImplementation( xPage );
615cdf0e10cSrcweir if( pUnoPage && pUnoPage->GetSdrPage() )
616cdf0e10cSrcweir mpCurrentPage = pUnoPage->GetSdrPage();
617cdf0e10cSrcweir }
618cdf0e10cSrcweir }
619cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleXNumerator" ) ) )
620cdf0e10cSrcweir {
621cdf0e10cSrcweir sal_Int32 nVal = 1;
622cdf0e10cSrcweir if( pDataValues->Value >>= nVal )
623cdf0e10cSrcweir rSettings.maScaleX = Fraction( nVal, rSettings.maScaleX.GetDenominator() );
624cdf0e10cSrcweir }
625cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleXDenominator" ) ) )
626cdf0e10cSrcweir {
627cdf0e10cSrcweir sal_Int32 nVal = 1;
628cdf0e10cSrcweir if( pDataValues->Value >>= nVal )
629cdf0e10cSrcweir rSettings.maScaleX = Fraction( rSettings.maScaleX.GetNumerator(), nVal );
630cdf0e10cSrcweir }
631cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleYNumerator" ) ) )
632cdf0e10cSrcweir {
633cdf0e10cSrcweir sal_Int32 nVal = 1;
634cdf0e10cSrcweir if( pDataValues->Value >>= nVal )
635cdf0e10cSrcweir rSettings.maScaleY = Fraction( nVal, rSettings.maScaleY.GetDenominator() );
636cdf0e10cSrcweir }
637cdf0e10cSrcweir else if( pDataValues->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ScaleYDenominator" ) ) )
638cdf0e10cSrcweir {
639cdf0e10cSrcweir sal_Int32 nVal = 1;
640cdf0e10cSrcweir if( pDataValues->Value >>= nVal )
641cdf0e10cSrcweir rSettings.maScaleY = Fraction( rSettings.maScaleY.GetNumerator(), nVal );
642cdf0e10cSrcweir }
643cdf0e10cSrcweir
644cdf0e10cSrcweir pDataValues++;
645cdf0e10cSrcweir }
646cdf0e10cSrcweir }
647cdf0e10cSrcweir
648cdf0e10cSrcweir pValues++;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir
651cdf0e10cSrcweir // putting the StatusIndicator that we got from the MediaDescriptor into our local FilterData copy
652cdf0e10cSrcweir if ( rSettings.mxStatusIndicator.is() )
653cdf0e10cSrcweir {
654cdf0e10cSrcweir rtl::OUString sStatusIndicator( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) );
655cdf0e10cSrcweir int i = rSettings.maFilterData.getLength();
656cdf0e10cSrcweir rSettings.maFilterData.realloc( i + 1 );
657cdf0e10cSrcweir rSettings.maFilterData[ i ].Name = sStatusIndicator;
658cdf0e10cSrcweir rSettings.maFilterData[ i ].Value <<= rSettings.mxStatusIndicator;
659cdf0e10cSrcweir }
660cdf0e10cSrcweir }
661cdf0e10cSrcweir
GetGraphic(ExportSettings & rSettings,Graphic & aGraphic,sal_Bool bVectorType)662cdf0e10cSrcweir bool GraphicExporter::GetGraphic( ExportSettings& rSettings, Graphic& aGraphic, sal_Bool bVectorType )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir if( !mpDoc || !mpUnoPage )
665cdf0e10cSrcweir return false;
666cdf0e10cSrcweir
667cdf0e10cSrcweir SdrPage* pPage = mpUnoPage->GetSdrPage();
668cdf0e10cSrcweir if( !pPage )
669cdf0e10cSrcweir return false;
670cdf0e10cSrcweir
671cdf0e10cSrcweir VirtualDevice aVDev;
672cdf0e10cSrcweir const MapMode aMap( mpDoc->GetScaleUnit(), Point(), rSettings.maScaleX, rSettings.maScaleY );
673cdf0e10cSrcweir
674cdf0e10cSrcweir SdrOutliner& rOutl=mpDoc->GetDrawOutliner(NULL);
675cdf0e10cSrcweir maOldCalcFieldValueHdl = rOutl.GetCalcFieldValueHdl();
676cdf0e10cSrcweir rOutl.SetCalcFieldValueHdl( LINK(this, GraphicExporter, CalcFieldValueHdl) );
677cdf0e10cSrcweir rOutl.SetBackgroundColor( pPage->GetPageBackgroundColor() );
678cdf0e10cSrcweir
679cdf0e10cSrcweir // #i102251#
680cdf0e10cSrcweir const sal_uInt32 nOldCntrl(rOutl.GetControlWord());
681cdf0e10cSrcweir sal_uInt32 nCntrl = nOldCntrl & ~EE_CNTRL_ONLINESPELLING;
682cdf0e10cSrcweir rOutl.SetControlWord(nCntrl);
683cdf0e10cSrcweir
684cdf0e10cSrcweir SdrObject* pTempBackgroundShape = 0;
685cdf0e10cSrcweir std::vector< SdrObject* > aShapes;
686cdf0e10cSrcweir bool bRet = true;
687cdf0e10cSrcweir
688cdf0e10cSrcweir // export complete page?
689cdf0e10cSrcweir if ( !mxShape.is() )
690cdf0e10cSrcweir {
691cdf0e10cSrcweir if( rSettings.mbExportOnlyBackground )
692cdf0e10cSrcweir {
693cdf0e10cSrcweir const SdrPageProperties* pCorrectProperties = pPage->getCorrectSdrPageProperties();
694cdf0e10cSrcweir
695cdf0e10cSrcweir if(pCorrectProperties)
696cdf0e10cSrcweir {
697cdf0e10cSrcweir pTempBackgroundShape = new SdrRectObj(Rectangle(Point(0,0), pPage->GetSize()));
698cdf0e10cSrcweir pTempBackgroundShape->SetMergedItemSet(pCorrectProperties->GetItemSet());
699cdf0e10cSrcweir pTempBackgroundShape->SetMergedItem(XLineStyleItem(XLINE_NONE));
700cdf0e10cSrcweir pTempBackgroundShape->NbcSetStyleSheet(pCorrectProperties->GetStyleSheet(), true);
701cdf0e10cSrcweir aShapes.push_back(pTempBackgroundShape);
702cdf0e10cSrcweir }
703cdf0e10cSrcweir }
704cdf0e10cSrcweir else
705cdf0e10cSrcweir {
706cdf0e10cSrcweir const Size aSize( pPage->GetSize() );
707cdf0e10cSrcweir
708cdf0e10cSrcweir // generate a bitmap to convert it to a pixel format.
709cdf0e10cSrcweir // For gif pictures there can also be a vector format used (bTranslucent)
710cdf0e10cSrcweir if ( !bVectorType && !rSettings.mbTranslucent )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir long nWidthPix = 0;
713cdf0e10cSrcweir long nHeightPix = 0;
714cdf0e10cSrcweir if ( rSettings.mnWidth > 0 && rSettings.mnHeight > 0 )
715cdf0e10cSrcweir {
716cdf0e10cSrcweir nWidthPix = rSettings.mnWidth;
717cdf0e10cSrcweir nHeightPix = rSettings.mnHeight;
718cdf0e10cSrcweir }
719cdf0e10cSrcweir else
720cdf0e10cSrcweir {
721cdf0e10cSrcweir const Size aSizePix( Application::GetDefaultDevice()->LogicToPixel( aSize, aMap ) );
722cdf0e10cSrcweir if (aSizePix.Width() > MAX_EXT_PIX || aSizePix.Height() > MAX_EXT_PIX)
723cdf0e10cSrcweir {
724cdf0e10cSrcweir if (aSizePix.Width() > MAX_EXT_PIX)
725cdf0e10cSrcweir nWidthPix = MAX_EXT_PIX;
726cdf0e10cSrcweir else
727cdf0e10cSrcweir nWidthPix = aSizePix.Width();
728cdf0e10cSrcweir if (aSizePix.Height() > MAX_EXT_PIX)
729cdf0e10cSrcweir nHeightPix = MAX_EXT_PIX;
730cdf0e10cSrcweir else
731cdf0e10cSrcweir nHeightPix = aSizePix.Height();
732cdf0e10cSrcweir
733cdf0e10cSrcweir double fWidthDif = aSizePix.Width() / nWidthPix;
734cdf0e10cSrcweir double fHeightDif = aSizePix.Height() / nHeightPix;
735cdf0e10cSrcweir
736cdf0e10cSrcweir if (fWidthDif > fHeightDif)
737cdf0e10cSrcweir nHeightPix = static_cast<long>(aSizePix.Height() / fWidthDif);
738cdf0e10cSrcweir else
739cdf0e10cSrcweir nWidthPix = static_cast<long>(aSizePix.Width() / fHeightDif);
740cdf0e10cSrcweir }
741cdf0e10cSrcweir else
742cdf0e10cSrcweir {
743cdf0e10cSrcweir nWidthPix = aSizePix.Width();
744cdf0e10cSrcweir nHeightPix = aSizePix.Height();
745cdf0e10cSrcweir }
746cdf0e10cSrcweir }
747cdf0e10cSrcweir
748cdf0e10cSrcweir boost::scoped_ptr< SdrView > pLocalView;
749cdf0e10cSrcweir if( PTR_CAST( FmFormModel, mpDoc ) )
750cdf0e10cSrcweir {
751cdf0e10cSrcweir pLocalView.reset( new FmFormView( PTR_CAST( FmFormModel, mpDoc ), &aVDev ) );
752cdf0e10cSrcweir }
753cdf0e10cSrcweir else
754cdf0e10cSrcweir {
755cdf0e10cSrcweir pLocalView.reset( new SdrView( mpDoc, &aVDev ) );
756cdf0e10cSrcweir }
757cdf0e10cSrcweir
758cdf0e10cSrcweir
759cdf0e10cSrcweir VirtualDevice* pVDev = CreatePageVDev( pPage, nWidthPix, nHeightPix );
760cdf0e10cSrcweir
761cdf0e10cSrcweir if( pVDev )
762cdf0e10cSrcweir {
763cdf0e10cSrcweir aGraphic = pVDev->GetBitmap( Point(), pVDev->GetOutputSize() );
764cdf0e10cSrcweir aGraphic.SetPrefMapMode( aMap );
765cdf0e10cSrcweir aGraphic.SetPrefSize( aSize );
766cdf0e10cSrcweir delete pVDev;
767cdf0e10cSrcweir }
768cdf0e10cSrcweir }
769cdf0e10cSrcweir // create a metafile to export a vector format
770cdf0e10cSrcweir else
771cdf0e10cSrcweir {
772cdf0e10cSrcweir GDIMetaFile aMtf;
773cdf0e10cSrcweir
774cdf0e10cSrcweir aVDev.SetMapMode( aMap );
775cdf0e10cSrcweir if( rSettings.mbUseHighContrast )
776cdf0e10cSrcweir aVDev.SetDrawMode( aVDev.GetDrawMode() | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
777cdf0e10cSrcweir aVDev.EnableOutput( sal_False );
778cdf0e10cSrcweir aMtf.Record( &aVDev );
779cdf0e10cSrcweir Size aNewSize;
780cdf0e10cSrcweir
781cdf0e10cSrcweir // create a view
782cdf0e10cSrcweir SdrView* pView;
783cdf0e10cSrcweir
784cdf0e10cSrcweir if( PTR_CAST( FmFormModel, mpDoc ) )
785cdf0e10cSrcweir {
786cdf0e10cSrcweir pView = new FmFormView( PTR_CAST( FmFormModel, mpDoc ), &aVDev );
787cdf0e10cSrcweir }
788cdf0e10cSrcweir else
789cdf0e10cSrcweir {
790cdf0e10cSrcweir pView = new SdrView( mpDoc, &aVDev );
791cdf0e10cSrcweir }
792cdf0e10cSrcweir
793cdf0e10cSrcweir pView->SetBordVisible( sal_False );
794cdf0e10cSrcweir pView->SetPageVisible( sal_False );
795cdf0e10cSrcweir pView->ShowSdrPage( pPage );
796cdf0e10cSrcweir
797cdf0e10cSrcweir if ( pView && pPage )
798cdf0e10cSrcweir {
799cdf0e10cSrcweir pView->SetBordVisible( sal_False );
800cdf0e10cSrcweir pView->SetPageVisible( sal_False );
801cdf0e10cSrcweir pView->ShowSdrPage( pPage );
802cdf0e10cSrcweir
803cdf0e10cSrcweir const Point aNewOrg( pPage->GetLftBorder(), pPage->GetUppBorder() );
804cdf0e10cSrcweir aNewSize = Size( aSize.Width() - pPage->GetLftBorder() - pPage->GetRgtBorder(),
805cdf0e10cSrcweir aSize.Height() - pPage->GetUppBorder() - pPage->GetLwrBorder() );
806cdf0e10cSrcweir const Rectangle aClipRect( aNewOrg, aNewSize );
807cdf0e10cSrcweir MapMode aVMap( aMap );
808cdf0e10cSrcweir
809cdf0e10cSrcweir aVDev.Push();
810cdf0e10cSrcweir aVMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) );
811cdf0e10cSrcweir aVDev.SetRelativeMapMode( aVMap );
812cdf0e10cSrcweir aVDev.IntersectClipRegion( aClipRect );
813cdf0e10cSrcweir
814cdf0e10cSrcweir // Use new StandardCheckVisisbilityRedirector
815cdf0e10cSrcweir ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage );
816cdf0e10cSrcweir
817cdf0e10cSrcweir pView->CompleteRedraw(&aVDev, Region(Rectangle(Point(), aNewSize)), &aRedirector);
818cdf0e10cSrcweir
819cdf0e10cSrcweir aVDev.Pop();
820cdf0e10cSrcweir
821cdf0e10cSrcweir aMtf.Stop();
822cdf0e10cSrcweir aMtf.WindStart();
823cdf0e10cSrcweir aMtf.SetPrefMapMode( aMap );
824cdf0e10cSrcweir aMtf.SetPrefSize( aNewSize );
825cdf0e10cSrcweir
826cdf0e10cSrcweir // AW: Here the current version was filtering out the META_CLIPREGION_ACTIONs
827cdf0e10cSrcweir // from the metafile. I asked some other developers why this was done, but no
828cdf0e10cSrcweir // one knew a direct reason. Since it's in for long time, it may be an old
829cdf0e10cSrcweir // piece of code. MetaFiles save and load ClipRegions with polygons with preserving
830cdf0e10cSrcweir // the polygons, so a resolution-indepent roundtrip is supported. Removed this
831cdf0e10cSrcweir // code since it destroys some MetaFiles where ClipRegions are used. Anyways,
832cdf0e10cSrcweir // just filtering them out is a hack, at least the encapsulated content would need
833cdf0e10cSrcweir // to be clipped geometrically.
834cdf0e10cSrcweir aGraphic = Graphic(aMtf);
835cdf0e10cSrcweir }
836cdf0e10cSrcweir
837cdf0e10cSrcweir if ( pView )
838cdf0e10cSrcweir {
839cdf0e10cSrcweir pView->HideSdrPage();
840cdf0e10cSrcweir delete pView;
841cdf0e10cSrcweir }
842cdf0e10cSrcweir
843cdf0e10cSrcweir if( rSettings.mbTranslucent )
844cdf0e10cSrcweir {
845cdf0e10cSrcweir Size aOutSize;
846cdf0e10cSrcweir aGraphic = GetBitmapFromMetaFile( aGraphic.GetGDIMetaFile(), sal_True, CalcSize( rSettings.mnWidth, rSettings.mnHeight, aNewSize, aOutSize ) );
847cdf0e10cSrcweir }
848cdf0e10cSrcweir }
849cdf0e10cSrcweir }
850cdf0e10cSrcweir }
851cdf0e10cSrcweir
852cdf0e10cSrcweir // export only single shape or shape collection
853cdf0e10cSrcweir else
854cdf0e10cSrcweir {
855cdf0e10cSrcweir // build list of SdrObject
856cdf0e10cSrcweir if( mxShapes.is() )
857cdf0e10cSrcweir {
858cdf0e10cSrcweir Reference< XShape > xShape;
859cdf0e10cSrcweir const sal_Int32 nCount = mxShapes->getCount();
860cdf0e10cSrcweir
861cdf0e10cSrcweir for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
862cdf0e10cSrcweir {
863cdf0e10cSrcweir mxShapes->getByIndex( nIndex ) >>= xShape;
864cdf0e10cSrcweir SdrObject* pObj = GetSdrObjectFromXShape( xShape );
865cdf0e10cSrcweir if( pObj )
866cdf0e10cSrcweir aShapes.push_back( pObj );
867cdf0e10cSrcweir }
868cdf0e10cSrcweir }
869cdf0e10cSrcweir else
870cdf0e10cSrcweir {
871cdf0e10cSrcweir // only one shape
872cdf0e10cSrcweir SdrObject* pObj = GetSdrObjectFromXShape( mxShape );
873cdf0e10cSrcweir if( pObj )
874cdf0e10cSrcweir aShapes.push_back( pObj );
875cdf0e10cSrcweir }
876cdf0e10cSrcweir
877cdf0e10cSrcweir if( aShapes.empty() )
878cdf0e10cSrcweir bRet = false;
879cdf0e10cSrcweir }
880cdf0e10cSrcweir
881cdf0e10cSrcweir if( bRet && !aShapes.empty() )
882cdf0e10cSrcweir {
883cdf0e10cSrcweir // special treatment for only one SdrGrafObj that has text
884cdf0e10cSrcweir sal_Bool bSingleGraphic = sal_False;
885cdf0e10cSrcweir
886cdf0e10cSrcweir if( 1 == aShapes.size() )
887cdf0e10cSrcweir {
888cdf0e10cSrcweir if( !bVectorType )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir SdrObject* pObj = aShapes.front();
891cdf0e10cSrcweir if( pObj && pObj->ISA( SdrGrafObj ) && !( (SdrGrafObj*) pObj )->HasText() )
892cdf0e10cSrcweir {
893cdf0e10cSrcweir aGraphic = ( (SdrGrafObj*) pObj )->GetTransformedGraphic();
894cdf0e10cSrcweir if ( aGraphic.GetType() == GRAPHIC_BITMAP )
895cdf0e10cSrcweir {
896cdf0e10cSrcweir Size aSizePixel( aGraphic.GetSizePixel() );
897cdf0e10cSrcweir if( rSettings.mnWidth && rSettings.mnHeight &&
898cdf0e10cSrcweir ( ( rSettings.mnWidth != aSizePixel.Width() ) ||
899cdf0e10cSrcweir ( rSettings.mnHeight != aSizePixel.Height() ) ) )
900cdf0e10cSrcweir {
901cdf0e10cSrcweir BitmapEx aBmpEx( aGraphic.GetBitmapEx() );
9022376739dSArmin Le Grand // export: use highest quality
9032376739dSArmin Le Grand aBmpEx.Scale( Size( rSettings.mnWidth, rSettings.mnHeight ), BMP_SCALE_LANCZOS );
904cdf0e10cSrcweir aGraphic = aBmpEx;
905cdf0e10cSrcweir }
90690cac51fSArmin Le Grand
90790cac51fSArmin Le Grand // #118804# only accept for bitmap graphics, else the
90890cac51fSArmin Le Grand // conversion to bitmap will happen anywhere without size control
90990cac51fSArmin Le Grand // as evtl. defined in rSettings.mnWidth/mnHeight
91090cac51fSArmin Le Grand bSingleGraphic = sal_True;
911cdf0e10cSrcweir }
912cdf0e10cSrcweir }
913cdf0e10cSrcweir }
914cdf0e10cSrcweir else if( rSettings.mbScrollText )
915cdf0e10cSrcweir {
916cdf0e10cSrcweir SdrObject* pObj = aShapes.front();
917cdf0e10cSrcweir if( pObj && pObj->ISA( SdrTextObj )
918cdf0e10cSrcweir && ( (SdrTextObj*) pObj )->HasText() )
919cdf0e10cSrcweir {
920cdf0e10cSrcweir Rectangle aScrollRectangle;
921cdf0e10cSrcweir Rectangle aPaintRectangle;
922cdf0e10cSrcweir
923cdf0e10cSrcweir const boost::scoped_ptr< GDIMetaFile > pMtf(
924cdf0e10cSrcweir ( (SdrTextObj*) pObj )->GetTextScrollMetaFileAndRectangle(
925cdf0e10cSrcweir aScrollRectangle, aPaintRectangle ) );
926cdf0e10cSrcweir
927cdf0e10cSrcweir // take the larger one of the two rectangles (that
928cdf0e10cSrcweir // should be the bound rect of the retrieved
929cdf0e10cSrcweir // metafile)
930cdf0e10cSrcweir Rectangle aTextRect;
931cdf0e10cSrcweir
932cdf0e10cSrcweir if( aScrollRectangle.IsInside( aPaintRectangle ) )
933cdf0e10cSrcweir aTextRect = aScrollRectangle;
934cdf0e10cSrcweir else
935cdf0e10cSrcweir aTextRect = aPaintRectangle;
936cdf0e10cSrcweir
937cdf0e10cSrcweir // setup pref size and mapmode
938cdf0e10cSrcweir pMtf->SetPrefSize( aTextRect.GetSize() );
939cdf0e10cSrcweir
940cdf0e10cSrcweir // set actual origin (mtf is at actual shape
941cdf0e10cSrcweir // output position)
942cdf0e10cSrcweir MapMode aLocalMapMode( aMap );
943cdf0e10cSrcweir aLocalMapMode.SetOrigin(
944cdf0e10cSrcweir Point( -aPaintRectangle.Left(),
945cdf0e10cSrcweir -aPaintRectangle.Top() ) );
946cdf0e10cSrcweir pMtf->SetPrefMapMode( aLocalMapMode );
947cdf0e10cSrcweir
948cdf0e10cSrcweir pMtf->AddAction( new MetaCommentAction(
949cdf0e10cSrcweir "XTEXT_SCROLLRECT", 0,
950cdf0e10cSrcweir reinterpret_cast<sal_uInt8 const*>(&aScrollRectangle),
951cdf0e10cSrcweir sizeof( Rectangle ) ) );
952cdf0e10cSrcweir pMtf->AddAction( new MetaCommentAction(
953cdf0e10cSrcweir "XTEXT_PAINTRECT", 0,
954cdf0e10cSrcweir reinterpret_cast<sal_uInt8 const*>(&aPaintRectangle),
955cdf0e10cSrcweir sizeof( Rectangle ) ) );
956cdf0e10cSrcweir
957cdf0e10cSrcweir aGraphic = Graphic( *pMtf );
958cdf0e10cSrcweir
959cdf0e10cSrcweir bSingleGraphic = sal_True;
960cdf0e10cSrcweir }
961cdf0e10cSrcweir }
962cdf0e10cSrcweir }
963cdf0e10cSrcweir
964cdf0e10cSrcweir if( !bSingleGraphic )
965cdf0e10cSrcweir {
966cdf0e10cSrcweir // create a metafile for all shapes
967cdf0e10cSrcweir VirtualDevice aOut;
968cdf0e10cSrcweir
969cdf0e10cSrcweir // calculate bound rect for all shapes
970cdf0e10cSrcweir Rectangle aBound;
971cdf0e10cSrcweir
972cdf0e10cSrcweir {
973cdf0e10cSrcweir std::vector< SdrObject* >::iterator aIter = aShapes.begin();
974cdf0e10cSrcweir const std::vector< SdrObject* >::iterator aEnd = aShapes.end();
975cdf0e10cSrcweir
976cdf0e10cSrcweir while( aIter != aEnd )
977cdf0e10cSrcweir {
978cdf0e10cSrcweir SdrObject* pObj = (*aIter++);
979cdf0e10cSrcweir Rectangle aR1(pObj->GetCurrentBoundRect());
980cdf0e10cSrcweir if (aBound.IsEmpty())
981cdf0e10cSrcweir aBound=aR1;
982cdf0e10cSrcweir else
983cdf0e10cSrcweir aBound.Union(aR1);
984cdf0e10cSrcweir }
985cdf0e10cSrcweir }
986cdf0e10cSrcweir
987cdf0e10cSrcweir aOut.EnableOutput( sal_False );
988cdf0e10cSrcweir aOut.SetMapMode( aMap );
989cdf0e10cSrcweir if( rSettings.mbUseHighContrast )
990cdf0e10cSrcweir aOut.SetDrawMode( aVDev.GetDrawMode() | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
991cdf0e10cSrcweir
992cdf0e10cSrcweir GDIMetaFile aMtf;
993cdf0e10cSrcweir aMtf.Clear();
994cdf0e10cSrcweir aMtf.Record( &aOut );
995cdf0e10cSrcweir
996cdf0e10cSrcweir MapMode aOutMap( aMap );
997cdf0e10cSrcweir aOutMap.SetOrigin( Point( -aBound.TopLeft().X(), -aBound.TopLeft().Y() ) );
998cdf0e10cSrcweir aOut.SetRelativeMapMode( aOutMap );
999cdf0e10cSrcweir
1000cdf0e10cSrcweir sdr::contact::DisplayInfo aDisplayInfo;
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir if(mpCurrentPage)
1003cdf0e10cSrcweir {
1004cdf0e10cSrcweir if(mpCurrentPage->TRG_HasMasterPage() && pPage->IsMasterPage())
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir // MasterPage is processed as another page's SubContent
1007cdf0e10cSrcweir aDisplayInfo.SetProcessLayers(mpCurrentPage->TRG_GetMasterPageVisibleLayers());
1008cdf0e10cSrcweir aDisplayInfo.SetSubContentActive(true);
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir
1012cdf0e10cSrcweir if(!aShapes.empty())
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir // more effective way to paint a vector of SdrObjects. Hand over the processed page
1015cdf0e10cSrcweir // to have it in the
1016cdf0e10cSrcweir sdr::contact::ObjectContactOfObjListPainter aMultiObjectPainter(aOut, aShapes, mpCurrentPage);
1017cdf0e10cSrcweir ImplExportCheckVisisbilityRedirector aCheckVisibilityRedirector(mpCurrentPage);
1018cdf0e10cSrcweir aMultiObjectPainter.SetViewObjectContactRedirector(&aCheckVisibilityRedirector);
1019cdf0e10cSrcweir
1020cdf0e10cSrcweir aMultiObjectPainter.ProcessDisplay(aDisplayInfo);
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir
1023cdf0e10cSrcweir aMtf.Stop();
1024cdf0e10cSrcweir aMtf.WindStart();
1025cdf0e10cSrcweir
1026cdf0e10cSrcweir const Size aExtSize( aOut.PixelToLogic( Size( 0, 0 ) ) );
1027cdf0e10cSrcweir Size aBoundSize( aBound.GetWidth() + ( aExtSize.Width() ),
1028cdf0e10cSrcweir aBound.GetHeight() + ( aExtSize.Height() ) );
1029cdf0e10cSrcweir
1030cdf0e10cSrcweir aMtf.SetPrefMapMode( aMap );
1031cdf0e10cSrcweir aMtf.SetPrefSize( aBoundSize );
1032cdf0e10cSrcweir
1033cdf0e10cSrcweir if( !bVectorType )
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir Size aOutSize;
1036cdf0e10cSrcweir aGraphic = GetBitmapFromMetaFile( aMtf, rSettings.mbTranslucent, CalcSize( rSettings.mnWidth, rSettings.mnHeight, aBoundSize, aOutSize ) );
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir else
1039cdf0e10cSrcweir {
1040cdf0e10cSrcweir aGraphic = aMtf;
1041cdf0e10cSrcweir }
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir }
1044cdf0e10cSrcweir
1045cdf0e10cSrcweir if(pTempBackgroundShape)
1046cdf0e10cSrcweir {
1047cdf0e10cSrcweir SdrObject::Free(pTempBackgroundShape);
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir rOutl.SetCalcFieldValueHdl( maOldCalcFieldValueHdl );
1051cdf0e10cSrcweir
1052cdf0e10cSrcweir // #i102251#
1053cdf0e10cSrcweir rOutl.SetControlWord(nOldCntrl);
1054cdf0e10cSrcweir
1055cdf0e10cSrcweir return bRet;
1056cdf0e10cSrcweir
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir // XFilter
filter(const Sequence<PropertyValue> & aDescriptor)1060cdf0e10cSrcweir sal_Bool SAL_CALL GraphicExporter::filter( const Sequence< PropertyValue >& aDescriptor )
1061cdf0e10cSrcweir throw(RuntimeException)
1062cdf0e10cSrcweir {
1063cdf0e10cSrcweir OGuard aGuard( Application::GetSolarMutex() );
1064cdf0e10cSrcweir
1065cdf0e10cSrcweir if( NULL == mpUnoPage )
1066cdf0e10cSrcweir return sal_False;
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir GraphicFilter* pFilter = GraphicFilter::GetGraphicFilter();
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir if( NULL == pFilter || NULL == mpUnoPage->GetSdrPage() || NULL == mpDoc )
1071cdf0e10cSrcweir return sal_False;
1072cdf0e10cSrcweir
1073cdf0e10cSrcweir // get the arguments from the descriptor
1074cdf0e10cSrcweir ExportSettings aSettings( mpDoc );
1075cdf0e10cSrcweir ParseSettings( aDescriptor, aSettings );
1076cdf0e10cSrcweir
1077cdf0e10cSrcweir const sal_uInt16 nFilter = aSettings.maMediaType.getLength()
1078cdf0e10cSrcweir ? pFilter->GetExportFormatNumberForMediaType( aSettings.maMediaType )
1079cdf0e10cSrcweir : pFilter->GetExportFormatNumberForShortName( aSettings.maFilterName );
1080cdf0e10cSrcweir sal_Bool bVectorType = !pFilter->IsExportPixelFormat( nFilter );
1081cdf0e10cSrcweir
1082cdf0e10cSrcweir // create the output stuff
1083cdf0e10cSrcweir Graphic aGraphic;
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir sal_uInt16 nStatus = GetGraphic( aSettings, aGraphic, bVectorType ) ? GRFILTER_OK : GRFILTER_FILTERERROR;
1086cdf0e10cSrcweir
1087cdf0e10cSrcweir if( nStatus == GRFILTER_OK )
1088cdf0e10cSrcweir {
1089cdf0e10cSrcweir // export graphic only if it has a size
1090cdf0e10cSrcweir const Size aGraphSize( aGraphic.GetPrefSize() );
1091cdf0e10cSrcweir if ( ( aGraphSize.Width() == 0 ) || ( aGraphSize.Height() == 0 ) )
1092cdf0e10cSrcweir {
1093cdf0e10cSrcweir nStatus = GRFILTER_FILTERERROR;
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir else
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir // now we have a graphic, so export it
1098cdf0e10cSrcweir if( aSettings.mxGraphicRenderer.is() )
1099cdf0e10cSrcweir {
1100cdf0e10cSrcweir // render graphic directly into given renderer
1101cdf0e10cSrcweir aSettings.mxGraphicRenderer->render( aGraphic.GetXGraphic() );
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir else if( aSettings.mxOutputStream.is() )
1104cdf0e10cSrcweir {
1105cdf0e10cSrcweir // TODO: Either utilize optional XSeekable functionality for the
1106cdf0e10cSrcweir // SvOutputStream, or adapt the graphic filter to not seek anymore.
1107cdf0e10cSrcweir SvMemoryStream aStream( 1024, 1024 );
1108cdf0e10cSrcweir
1109cdf0e10cSrcweir nStatus = pFilter->ExportGraphic( aGraphic, String(), aStream, nFilter, &aSettings.maFilterData );
1110cdf0e10cSrcweir
1111cdf0e10cSrcweir // copy temp stream to XOutputStream
1112cdf0e10cSrcweir SvOutputStream aOutputStream( aSettings.mxOutputStream );
1113cdf0e10cSrcweir aStream.Seek(0);
1114cdf0e10cSrcweir aOutputStream << aStream;
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir else
1117cdf0e10cSrcweir {
1118cdf0e10cSrcweir INetURLObject aURLObject( aSettings.maURL.Complete );
1119cdf0e10cSrcweir DBG_ASSERT( aURLObject.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
1120cdf0e10cSrcweir
1121cdf0e10cSrcweir nStatus = XOutBitmap::ExportGraphic( aGraphic, aURLObject, *pFilter, nFilter, &aSettings.maFilterData );
1122cdf0e10cSrcweir }
1123cdf0e10cSrcweir }
1124cdf0e10cSrcweir }
1125cdf0e10cSrcweir
1126cdf0e10cSrcweir if ( aSettings.mxInteractionHandler.is() && ( nStatus != GRFILTER_OK ) )
1127cdf0e10cSrcweir {
1128cdf0e10cSrcweir Any aInteraction;
1129cdf0e10cSrcweir Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > lContinuations(1);
1130cdf0e10cSrcweir ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
1131cdf0e10cSrcweir lContinuations[0] = Reference< XInteractionContinuation >(static_cast< XInteractionContinuation* >(pApprove), UNO_QUERY);
1132cdf0e10cSrcweir
1133cdf0e10cSrcweir GraphicFilterRequest aErrorCode;
1134cdf0e10cSrcweir aErrorCode.ErrCode = nStatus;
1135cdf0e10cSrcweir aInteraction <<= aErrorCode;
1136cdf0e10cSrcweir aSettings.mxInteractionHandler->handle( framework::InteractionRequest::CreateRequest( aInteraction, lContinuations ) );
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir return nStatus == GRFILTER_OK;
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir
cancel()1141cdf0e10cSrcweir void SAL_CALL GraphicExporter::cancel()
1142cdf0e10cSrcweir throw(RuntimeException)
1143cdf0e10cSrcweir {
1144cdf0e10cSrcweir }
1145cdf0e10cSrcweir
1146cdf0e10cSrcweir // XExporter
1147cdf0e10cSrcweir
1148cdf0e10cSrcweir /** the source 'document' could be a XDrawPage, a XShape or a generic XShapes */
setSourceDocument(const Reference<lang::XComponent> & xComponent)1149cdf0e10cSrcweir void SAL_CALL GraphicExporter::setSourceDocument( const Reference< lang::XComponent >& xComponent )
1150cdf0e10cSrcweir throw(IllegalArgumentException, RuntimeException)
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir OGuard aGuard( Application::GetSolarMutex() );
1153cdf0e10cSrcweir
1154cdf0e10cSrcweir mxShapes = NULL;
1155cdf0e10cSrcweir mpUnoPage = NULL;
1156cdf0e10cSrcweir
1157cdf0e10cSrcweir try
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir // any break inside this one loop while will throw a IllegalArgumentException
1160cdf0e10cSrcweir do
1161cdf0e10cSrcweir {
1162cdf0e10cSrcweir mxPage = Reference< XDrawPage >::query( xComponent );
1163cdf0e10cSrcweir mxShapes = Reference< XShapes >::query( xComponent );
1164cdf0e10cSrcweir mxShape = Reference< XShape >::query( xComponent );
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir // Step 1: try a generic XShapes
1167cdf0e10cSrcweir if( !mxPage.is() && !mxShape.is() && mxShapes.is() )
1168cdf0e10cSrcweir {
1169cdf0e10cSrcweir // we do not support empty shape collections
1170cdf0e10cSrcweir if( 0 == mxShapes->getCount() )
1171cdf0e10cSrcweir break;
1172cdf0e10cSrcweir
1173cdf0e10cSrcweir // get first shape to detect corresponding page and model
1174cdf0e10cSrcweir mxShapes->getByIndex(0) >>= mxShape;
1175cdf0e10cSrcweir }
1176cdf0e10cSrcweir else
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir mxShapes = NULL;
1179cdf0e10cSrcweir }
1180cdf0e10cSrcweir
1181cdf0e10cSrcweir // Step 2: try a shape
1182cdf0e10cSrcweir if( mxShape.is() )
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir if( NULL == GetSdrObjectFromXShape( mxShape ) )
1185cdf0e10cSrcweir break;
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir // get page for this shape
1188cdf0e10cSrcweir Reference< XChild > xChild( mxShape, UNO_QUERY );
1189cdf0e10cSrcweir if( !xChild.is() )
1190cdf0e10cSrcweir break;
1191cdf0e10cSrcweir
1192cdf0e10cSrcweir Reference< XInterface > xInt;
1193cdf0e10cSrcweir do
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir xInt = xChild->getParent();
1196cdf0e10cSrcweir mxPage = Reference< XDrawPage >::query( xInt );
1197cdf0e10cSrcweir if( !mxPage.is() )
1198cdf0e10cSrcweir xChild = Reference< XChild >::query( xInt );
1199cdf0e10cSrcweir }
1200cdf0e10cSrcweir while( !mxPage.is() && xChild.is() );
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir if( !mxPage.is() )
1203cdf0e10cSrcweir break;
1204cdf0e10cSrcweir }
1205cdf0e10cSrcweir
1206cdf0e10cSrcweir // Step 3: check the page
1207cdf0e10cSrcweir if( !mxPage.is() )
1208cdf0e10cSrcweir break;
1209cdf0e10cSrcweir
1210cdf0e10cSrcweir mpUnoPage = SvxDrawPage::getImplementation( mxPage );
1211cdf0e10cSrcweir
1212cdf0e10cSrcweir if( NULL == mpUnoPage || NULL == mpUnoPage->GetSdrPage() )
1213cdf0e10cSrcweir break;
1214cdf0e10cSrcweir
1215cdf0e10cSrcweir mpDoc = mpUnoPage->GetSdrPage()->GetModel();
1216cdf0e10cSrcweir
1217cdf0e10cSrcweir // Step 4: If we got a generic XShapes test all contained shapes
1218cdf0e10cSrcweir // if they belong to the same XDrawPage
1219cdf0e10cSrcweir
1220cdf0e10cSrcweir if( mxShapes.is() )
1221cdf0e10cSrcweir {
1222cdf0e10cSrcweir SdrPage* pPage = mpUnoPage->GetSdrPage();
1223cdf0e10cSrcweir SdrObject* pObj;
1224cdf0e10cSrcweir Reference< XShape > xShape;
1225cdf0e10cSrcweir
1226cdf0e10cSrcweir sal_Bool bOk = sal_True;
1227cdf0e10cSrcweir
1228cdf0e10cSrcweir const sal_Int32 nCount = mxShapes->getCount();
1229cdf0e10cSrcweir
1230cdf0e10cSrcweir // test all but the first shape if they have the same page than
1231cdf0e10cSrcweir // the first shape
1232cdf0e10cSrcweir for( sal_Int32 nIndex = 1; bOk && ( nIndex < nCount ); nIndex++ )
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir mxShapes->getByIndex( nIndex ) >>= xShape;
1235cdf0e10cSrcweir pObj = GetSdrObjectFromXShape( xShape );
1236cdf0e10cSrcweir bOk = pObj && pObj->GetPage() == pPage;
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir
1239cdf0e10cSrcweir if( !bOk )
1240cdf0e10cSrcweir break;
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir
1243cdf0e10cSrcweir // no errors so far
1244cdf0e10cSrcweir return;
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir while( 0 );
1247cdf0e10cSrcweir }
1248cdf0e10cSrcweir catch( Exception& )
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir
1252cdf0e10cSrcweir throw IllegalArgumentException();
1253cdf0e10cSrcweir }
1254cdf0e10cSrcweir
1255cdf0e10cSrcweir // XServiceInfo
getImplementationName()1256cdf0e10cSrcweir OUString SAL_CALL GraphicExporter::getImplementationName( )
1257cdf0e10cSrcweir throw(RuntimeException)
1258cdf0e10cSrcweir {
1259cdf0e10cSrcweir return GraphicExporter_getImplementationName();
1260cdf0e10cSrcweir }
1261cdf0e10cSrcweir
supportsService(const OUString & ServiceName)1262cdf0e10cSrcweir sal_Bool SAL_CALL GraphicExporter::supportsService( const OUString& ServiceName )
1263cdf0e10cSrcweir throw(RuntimeException)
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir Sequence< OUString > aSeq( GraphicExporter_getSupportedServiceNames() );
1266cdf0e10cSrcweir sal_Int32 nArgs = aSeq.getLength();
1267cdf0e10cSrcweir const OUString* pService = aSeq.getConstArray();
1268cdf0e10cSrcweir while( nArgs-- )
1269cdf0e10cSrcweir if( *pService++ == ServiceName )
1270cdf0e10cSrcweir return sal_True;
1271cdf0e10cSrcweir
1272cdf0e10cSrcweir return sal_False;
1273cdf0e10cSrcweir }
1274cdf0e10cSrcweir
getSupportedServiceNames()1275cdf0e10cSrcweir Sequence< OUString > SAL_CALL GraphicExporter::getSupportedServiceNames( )
1276cdf0e10cSrcweir throw(RuntimeException)
1277cdf0e10cSrcweir {
1278cdf0e10cSrcweir return GraphicExporter_getSupportedServiceNames();
1279cdf0e10cSrcweir }
1280cdf0e10cSrcweir
1281cdf0e10cSrcweir // XMimeTypeInfo
supportsMimeType(const OUString & MimeTypeName)1282cdf0e10cSrcweir sal_Bool SAL_CALL GraphicExporter::supportsMimeType( const OUString& MimeTypeName ) throw (RuntimeException)
1283cdf0e10cSrcweir {
1284cdf0e10cSrcweir const String aMimeTypeName( MimeTypeName );
1285cdf0e10cSrcweir
1286cdf0e10cSrcweir GraphicFilter* pFilter = GraphicFilter::GetGraphicFilter();
1287cdf0e10cSrcweir sal_uInt16 nCount = pFilter->GetExportFormatCount();
1288cdf0e10cSrcweir sal_uInt16 nFilter;
1289cdf0e10cSrcweir for( nFilter = 0; nFilter < nCount; nFilter++ )
1290cdf0e10cSrcweir {
1291cdf0e10cSrcweir if( aMimeTypeName.Equals( pFilter->GetExportFormatMediaType( nFilter ) ) )
1292cdf0e10cSrcweir {
1293cdf0e10cSrcweir return sal_True;
1294cdf0e10cSrcweir }
1295cdf0e10cSrcweir }
1296cdf0e10cSrcweir
1297cdf0e10cSrcweir return sal_False;
1298cdf0e10cSrcweir }
1299cdf0e10cSrcweir
getSupportedMimeTypeNames()1300cdf0e10cSrcweir Sequence< OUString > SAL_CALL GraphicExporter::getSupportedMimeTypeNames( ) throw (RuntimeException)
1301cdf0e10cSrcweir {
1302cdf0e10cSrcweir GraphicFilter* pFilter = GraphicFilter::GetGraphicFilter();
1303cdf0e10cSrcweir sal_uInt16 nCount = pFilter->GetExportFormatCount();
1304cdf0e10cSrcweir sal_uInt16 nFilter;
1305cdf0e10cSrcweir sal_uInt16 nFound = 0;
1306cdf0e10cSrcweir
1307cdf0e10cSrcweir Sequence< OUString > aSeq( nCount );
1308cdf0e10cSrcweir OUString* pStr = aSeq.getArray();
1309cdf0e10cSrcweir
1310cdf0e10cSrcweir for( nFilter = 0; nFilter < nCount; nFilter++ )
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir OUString aMimeType( pFilter->GetExportFormatMediaType( nFilter ) );
1313cdf0e10cSrcweir if( aMimeType.getLength() )
1314cdf0e10cSrcweir {
1315cdf0e10cSrcweir *pStr++ = aMimeType;
1316cdf0e10cSrcweir nFound++;
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir }
1319cdf0e10cSrcweir
1320cdf0e10cSrcweir if( nFound < nCount )
1321cdf0e10cSrcweir aSeq.realloc( nFound );
1322cdf0e10cSrcweir
1323cdf0e10cSrcweir return aSeq;
1324cdf0e10cSrcweir }
1325cdf0e10cSrcweir
SvxGetGraphicForShape(SdrObject & rShape,bool bVector)1326cdf0e10cSrcweir Graphic SvxGetGraphicForShape( SdrObject& rShape, bool bVector )
1327cdf0e10cSrcweir {
1328cdf0e10cSrcweir Graphic aGraphic;
1329cdf0e10cSrcweir try
1330cdf0e10cSrcweir {
1331cdf0e10cSrcweir rtl::Reference< GraphicExporter > xExporter( new GraphicExporter() );
1332cdf0e10cSrcweir Reference< XComponent > xComp( rShape.getUnoShape(), UNO_QUERY_THROW );
1333cdf0e10cSrcweir xExporter->setSourceDocument( xComp );
1334cdf0e10cSrcweir ExportSettings aSettings( rShape.GetModel() );
1335cdf0e10cSrcweir xExporter->GetGraphic( aSettings, aGraphic, bVector );
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir catch( Exception& )
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir DBG_ERROR("SvxGetGraphicForShape(), exception caught!");
1340cdf0e10cSrcweir }
1341cdf0e10cSrcweir return aGraphic;
1342cdf0e10cSrcweir }
1343cdf0e10cSrcweir
1344