1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chartprettypainter.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svtools.hxx"
35 #include <svtools/chartprettypainter.hxx>
37 #include <tools/globname.hxx>
38 #include <sot/clsids.hxx>
39 // header for function rtl_createUuid
41 #include <vcl/pdfextoutdevdata.hxx>
43 #include <com/sun/star/lang/XUnoTunnel.hpp>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <svtools/embedhlp.hxx>
47 using namespace ::com::sun::star
;
49 ChartPrettyPainter::ChartPrettyPainter()
53 ChartPrettyPainter::~ChartPrettyPainter()
57 bool ChartPrettyPainter::DoPaint(OutputDevice
* /*pOutDev*/, const Rectangle
& /*rLogicObjectRect*/) const
63 const uno::Sequence
<sal_Int8
>& ChartPrettyPainter::getUnoTunnelId()
65 static uno::Sequence
<sal_Int8
> * pSeq
= 0;
68 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
71 static uno::Sequence
< sal_Int8
> aSeq( 16 );
72 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
79 bool ChartPrettyPainter::IsChart( const svt::EmbeddedObjectRef
& xObjRef
)
84 SvGlobalName
aObjClsId( xObjRef
->getClassID() );
86 SvGlobalName(SO3_SCH_CLASSID_30
) == aObjClsId
87 || SvGlobalName(SO3_SCH_CLASSID_40
) == aObjClsId
88 || SvGlobalName(SO3_SCH_CLASSID_50
) == aObjClsId
89 || SvGlobalName(SO3_SCH_CLASSID_60
) == aObjClsId
)
97 bool ChartPrettyPainter::ShouldPrettyPaintChartOnThisDevice( OutputDevice
* pOutDev
)
101 //at least the print preview in calc has a paint loop due to too much invalidate calls deep in sdr
102 //to avoid the paint loop we use the metafile replacement in this case instead of direct rendering
103 if( OUTDEV_WINDOW
== pOutDev
->GetOutDevType() )
105 if( OUTDEV_PRINTER
== pOutDev
->GetOutDevType() )
107 vcl::PDFExtOutDevData
* pPDFData
= PTR_CAST( vcl::PDFExtOutDevData
, pOutDev
->GetExtOutDevData() );
113 bool ChartPrettyPainter::DoPrettyPaintChart( uno::Reference
< frame::XModel
> xChartModel
, OutputDevice
* pOutDev
, const Rectangle
& rLogicObjectRect
)
115 //charts must be painted resolution dependent!! #i82893#, #i75867#
116 if( !xChartModel
.is() || !ShouldPrettyPaintChartOnThisDevice( pOutDev
) )
121 uno::Reference
< lang::XMultiServiceFactory
> xFact( xChartModel
, uno::UNO_QUERY
);
122 OSL_ENSURE( xFact
.is(), "Chart cannot be painted pretty!\n" );
125 uno::Reference
< lang::XUnoTunnel
> xChartRenderer( xFact
->createInstance(
126 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ChartRenderer" ) ) ), uno::UNO_QUERY
);
127 OSL_ENSURE( xChartRenderer
.is(), "Chart cannot be painted pretty!\n" );
128 if( xChartRenderer
.is() )
130 ChartPrettyPainter
* pPrettyPainter
= reinterpret_cast<ChartPrettyPainter
*>(
131 xChartRenderer
->getSomething( ChartPrettyPainter::getUnoTunnelId() ));
133 return pPrettyPainter
->DoPaint(pOutDev
, rLogicObjectRect
);
137 catch( uno::Exception
& e
)
140 DBG_ERROR( "Chart cannot be painted pretty!" );