Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <helperchartrenderer.hxx>
30 : : #include <drawinglayer/primitive2d/chartprimitive2d.hxx>
31 : : #include <svtools/chartprettypainter.hxx>
32 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
33 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 : : #include <drawinglayer/geometry/viewinformation2d.hxx>
35 : :
36 : : //////////////////////////////////////////////////////////////////////////////
37 : :
38 : : using namespace com::sun::star;
39 : :
40 : : //////////////////////////////////////////////////////////////////////////////
41 : :
42 : : namespace drawinglayer
43 : : {
44 : 0 : bool renderChartPrimitive2D(
45 : : const primitive2d::ChartPrimitive2D& rChartCandidate,
46 : : OutputDevice& rOutputDevice,
47 : : const geometry::ViewInformation2D& rViewInformation2D)
48 : : {
49 : 0 : bool bChartRendered(false);
50 : :
51 : : // code from chart PrettyPrinter
52 : : try
53 : : {
54 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xFact( rChartCandidate.getChartModel(), uno::UNO_QUERY );
55 : : OSL_ENSURE( xFact.is(), "Chart cannot be painted pretty!\n" );
56 : :
57 [ # # ]: 0 : if( xFact.is() )
58 : : {
59 [ # # ]: 0 : uno::Reference< lang::XUnoTunnel > xChartRenderer( xFact->createInstance(
60 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ChartRenderer" ) ) ), uno::UNO_QUERY );
[ # # ]
61 : : OSL_ENSURE( xChartRenderer.is(), "Chart cannot be painted pretty!\n" );
62 : :
63 [ # # ]: 0 : if( xChartRenderer.is() )
64 : : {
65 : : ChartPrettyPainter* pPrettyPainter = reinterpret_cast<ChartPrettyPainter*>(
66 [ # # ][ # # ]: 0 : xChartRenderer->getSomething( ChartPrettyPainter::getUnoTunnelId() ));
[ # # ]
67 : :
68 [ # # ]: 0 : if( pPrettyPainter )
69 : : {
70 : : // create logic object range; do NOT use ObjectTransformation for this
71 : : // (rViewInformation2D.getObjectTransformation()), only the logic object
72 : : // size is wanted
73 [ # # ]: 0 : basegfx::B2DRange aObjectRange(0.0, 0.0, 1.0, 1.0);
74 [ # # ]: 0 : aObjectRange.transform(rChartCandidate.getTransformation());
75 : : const Rectangle aRectangle(
76 [ # # ][ # # ]: 0 : (sal_Int32)aObjectRange.getMinX(), (sal_Int32)aObjectRange.getMinY(),
77 [ # # ][ # # ]: 0 : (sal_Int32)aObjectRange.getMaxX(), (sal_Int32)aObjectRange.getMaxY());
[ # # ]
78 : :
79 : : // #i101811#
80 [ # # ][ # # ]: 0 : if(rViewInformation2D.getObjectTransformation().isIdentity())
[ # # ]
81 : : {
82 : : // no embedding in another transfromation, just paint with existing
83 : : // MapMode. This is just a shortcut; using the below code will also
84 : : // work; it has just a neutral ObjectTransformation
85 [ # # ]: 0 : bChartRendered = pPrettyPainter->DoPaint(&rOutputDevice, aRectangle);
86 : : }
87 : : else
88 : : {
89 : : // rViewInformation2D.getObjectTransformation() is used and
90 : : // needs to be expressed in the MapMode for the PrettyPainter;
91 : : // else it would call ChartModelHelper::setPageSize(...) with the
92 : : // changed size what really will change the chart model and leads
93 : : // to re-layouts and re-formatting
94 [ # # ]: 0 : const MapMode aOldMapMode(rOutputDevice.GetMapMode());
95 : 0 : basegfx::B2DVector aVTScale, aScale, aTranslate;
96 : : double fRotate, fShearX;
97 : :
98 : : // get basic scaling with current MapMode (aVTScale), containing
99 : : // mapping for set MapUnit (e.g. for 100th mm, the basic scale is
100 : : // not 1.0, 1.0). This is needed since this scale is included in
101 : : // the ObjectToView Transformation and needs to be removed (see
102 : : // correction below) to re-create a MapMode
103 [ # # ][ # # ]: 0 : rOutputDevice.SetMapMode(aOldMapMode.GetMapUnit());
[ # # ]
104 [ # # ][ # # ]: 0 : rOutputDevice.GetViewTransformation().decompose(aVTScale, aTranslate, fRotate, fShearX);
[ # # ]
105 : :
106 : : // get complete ObjectToView Transformation scale and translate from current
107 : : // transformation chain (combined view and object transform)
108 [ # # ][ # # ]: 0 : rViewInformation2D.getObjectToViewTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
109 : :
110 : : // assert when shear and/or rotation is used
111 : : OSL_ENSURE(basegfx::fTools::equalZero(fRotate), "Chart PrettyPrinting with unsupportable rotation (!)");
112 : : OSL_ENSURE(basegfx::fTools::equalZero(fShearX), "Chart PrettyPrinting with unsupportable shear (!)");
113 : :
114 : : // clean scale and translate from basic scaling (DPI, etc...)
115 : : // since this will implicitely be part of the to-be-created MapMode
116 : : const basegfx::B2DTuple aBasicCleaner(
117 : 0 : basegfx::fTools::equalZero(aVTScale.getX()) ? 1.0 : 1.0 / aVTScale.getX(),
118 [ # # ][ # # ]: 0 : basegfx::fTools::equalZero(aVTScale.getY()) ? 1.0 : 1.0 / aVTScale.getY());
119 : 0 : aScale *= aBasicCleaner;
120 : 0 : aTranslate *= aBasicCleaner;
121 : :
122 : : // for MapMode, take scale out of translation
123 : : const basegfx::B2DTuple aScaleRemover(
124 : 0 : basegfx::fTools::equalZero(aScale.getX()) ? 1.0 : 1.0 / aScale.getX(),
125 [ # # ][ # # ]: 0 : basegfx::fTools::equalZero(aScale.getY()) ? 1.0 : 1.0 / aScale.getY());
126 : 0 : aTranslate *= aScaleRemover;
127 : :
128 : : // build new MapMode
129 : : const MapMode aNewMapMode(aOldMapMode.GetMapUnit(),
130 : : Point(basegfx::fround(aTranslate.getX()), basegfx::fround(aTranslate.getY())),
131 [ # # ][ # # ]: 0 : Fraction(aScale.getX()), Fraction(aScale.getY()));
[ # # ]
132 : :
133 : : // use, paint, restore
134 [ # # ]: 0 : rOutputDevice.SetMapMode(aNewMapMode);
135 [ # # ]: 0 : bChartRendered = pPrettyPainter->DoPaint(&rOutputDevice, aRectangle);
136 [ # # ][ # # ]: 0 : rOutputDevice.SetMapMode(aOldMapMode);
[ # # ]
137 : : }
138 : : }
139 : 0 : }
140 [ # # ]: 0 : }
141 : : }
142 : 0 : catch( const uno::Exception& )
143 : : {
144 : : OSL_FAIL( "Chart cannot be painted pretty!" );
145 : : }
146 : :
147 : 0 : return bChartRendered;
148 : : }
149 : : } // end of namespace drawinglayer
150 : :
151 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|