merge the formfield patch from ooo-build
[ooovba.git] / drawinglayer / source / processor2d / helperchartrenderer.cxx
blob383f678e281fe07187d52254ffeed7896ddb53c1
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: helperchartrenderer.cxx,v $
7 * $Revision: 1.1.2.1 $
9 * last change: $Author: aw $ $Date: 2008/09/24 14:28:34 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <helperchartrenderer.hxx>
40 #include <drawinglayer/primitive2d/chartprimitive2d.hxx>
41 #include <svtools/chartprettypainter.hxx>
42 #include <com/sun/star/lang/XUnoTunnel.hpp>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #include <drawinglayer/geometry/viewinformation2d.hxx>
46 //////////////////////////////////////////////////////////////////////////////
48 using namespace com::sun::star;
50 //////////////////////////////////////////////////////////////////////////////
52 namespace drawinglayer
54 bool renderChartPrimitive2D(
55 const primitive2d::ChartPrimitive2D& rChartCandidate,
56 OutputDevice& rOutputDevice,
57 const geometry::ViewInformation2D& rViewInformation2D)
59 bool bChartRendered(false);
61 // code from chart PrettyPrinter
62 try
64 uno::Reference< lang::XMultiServiceFactory > xFact( rChartCandidate.getChartModel(), uno::UNO_QUERY );
65 OSL_ENSURE( xFact.is(), "Chart cannot be painted pretty!\n" );
67 if( xFact.is() )
69 uno::Reference< lang::XUnoTunnel > xChartRenderer( xFact->createInstance(
70 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ChartRenderer" ) ) ), uno::UNO_QUERY );
71 OSL_ENSURE( xChartRenderer.is(), "Chart cannot be painted pretty!\n" );
73 if( xChartRenderer.is() )
75 ChartPrettyPainter* pPrettyPainter = reinterpret_cast<ChartPrettyPainter*>(
76 xChartRenderer->getSomething( ChartPrettyPainter::getUnoTunnelId() ));
78 if( pPrettyPainter )
80 // create logic object range; do NOT use ObjectTransformation for this
81 // (rViewInformation2D.getObjectTransformation()), only the logic object
82 // size is wanted
83 basegfx::B2DRange aObjectRange(0.0, 0.0, 1.0, 1.0);
84 aObjectRange.transform(rChartCandidate.getTransformation());
85 const Rectangle aRectangle(
86 (sal_Int32)aObjectRange.getMinX(), (sal_Int32)aObjectRange.getMinY(),
87 (sal_Int32)aObjectRange.getMaxX(), (sal_Int32)aObjectRange.getMaxY());
89 // #i101811#
90 if(rViewInformation2D.getObjectTransformation().isIdentity())
92 // no embedding in another transfromation, just paint with existing
93 // MapMode. This is just a shortcut; using the below code will also
94 // work; it has just a neutral ObjectTransformation
95 bChartRendered = pPrettyPainter->DoPaint(&rOutputDevice, aRectangle);
97 else
99 // rViewInformation2D.getObjectTransformation() is used and
100 // needs to be expressed in the MapMode for the PrettyPainter;
101 // else it would call ChartModelHelper::setPageSize(...) with the
102 // changed size what really will change the chart model and leads
103 // to re-layouts and re-formattings
104 const MapMode aOldMapMode(rOutputDevice.GetMapMode());
105 basegfx::B2DVector aVTScale, aScale, aTranslate;
106 double fRotate, fShearX;
108 // get basic scaling with current MapMode (aVTScale), containing
109 // mapping for set MapUnit (e.g. for 100th mm, the basic scale is
110 // not 1.0, 1.0). This is needed since this scale is included in
111 // the ObjectToView Transformation and needs to be removed (see
112 // correction below) to re-create a MapMode
113 rOutputDevice.SetMapMode(aOldMapMode.GetMapUnit());
114 rOutputDevice.GetViewTransformation().decompose(aVTScale, aTranslate, fRotate, fShearX);
116 // get complete ObjectToView Transformation scale and translate from current
117 // transformation chain (combined view and object transform)
118 rViewInformation2D.getObjectToViewTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
120 // assert when shear and/or rotation is used
121 OSL_ENSURE(basegfx::fTools::equalZero(fRotate), "Chart PrettyPrinting with unsupportable rotation (!)");
122 OSL_ENSURE(basegfx::fTools::equalZero(fShearX), "Chart PrettyPrinting with unsupportable shear (!)");
124 // clean scale and translate from basic scaling (DPI, etc...)
125 // since this will implicitely be part of the to-be-created MapMode
126 const basegfx::B2DTuple aBasicCleaner(
127 basegfx::fTools::equalZero(aVTScale.getX()) ? 1.0 : 1.0 / aVTScale.getX(),
128 basegfx::fTools::equalZero(aVTScale.getY()) ? 1.0 : 1.0 / aVTScale.getY());
129 aScale *= aBasicCleaner;
130 aTranslate *= aBasicCleaner;
132 // for MapMode, take scale out of translation
133 const basegfx::B2DTuple aScaleRemover(
134 basegfx::fTools::equalZero(aScale.getX()) ? 1.0 : 1.0 / aScale.getX(),
135 basegfx::fTools::equalZero(aScale.getY()) ? 1.0 : 1.0 / aScale.getY());
136 aTranslate *= aScaleRemover;
138 // build new MapMode
139 const MapMode aNewMapMode(aOldMapMode.GetMapUnit(),
140 Point(basegfx::fround(aTranslate.getX()), basegfx::fround(aTranslate.getY())),
141 Fraction(aScale.getX()), Fraction(aScale.getY()));
143 // use, paint, restore
144 rOutputDevice.SetMapMode(aNewMapMode);
145 bChartRendered = pPrettyPainter->DoPaint(&rOutputDevice, aRectangle);
146 rOutputDevice.SetMapMode(aOldMapMode);
152 catch( uno::Exception& e )
154 (void)e;
155 DBG_ERROR( "Chart cannot be painted pretty!" );
158 return bChartRendered;
160 } // end of namespace drawinglayer
162 //////////////////////////////////////////////////////////////////////////////
163 // eof