xref: /AOO41X/main/canvas/source/vcl/impltools.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _VCLCANVAS_TOOLS_HXX
29*cdf0e10cSrcweir #define _VCLCANVAS_TOOLS_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <osl/mutex.hxx>
32*cdf0e10cSrcweir #include <vos/mutex.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <vcl/svapp.hxx>
35*cdf0e10cSrcweir #include <vcl/outdev.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
40*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <canvas/vclwrapper.hxx>
43*cdf0e10cSrcweir #include "outdevprovider.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir class OutputDevice;
47*cdf0e10cSrcweir class Point;
48*cdf0e10cSrcweir class Size;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace basegfx
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     namespace matrix
53*cdf0e10cSrcweir     {
54*cdf0e10cSrcweir         class B2DHomMatrix;
55*cdf0e10cSrcweir     }
56*cdf0e10cSrcweir     namespace vector
57*cdf0e10cSrcweir     {
58*cdf0e10cSrcweir         class B2DVector;
59*cdf0e10cSrcweir     }
60*cdf0e10cSrcweir     namespace point
61*cdf0e10cSrcweir     {
62*cdf0e10cSrcweir         class B2DPoint;
63*cdf0e10cSrcweir     }
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace awt
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir     struct Point;
69*cdf0e10cSrcweir     struct Size;
70*cdf0e10cSrcweir     struct Rectangle;
71*cdf0e10cSrcweir } } } }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace drawing
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     struct HomogenMatrix3;
76*cdf0e10cSrcweir } } } }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace geometry
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     struct RealPoint2D;
81*cdf0e10cSrcweir     struct RealSize2D;
82*cdf0e10cSrcweir     struct RealRectangle2D;
83*cdf0e10cSrcweir } } } }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace rendering
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     struct RenderState;
88*cdf0e10cSrcweir     struct ViewState;
89*cdf0e10cSrcweir     class  XCanvas;
90*cdf0e10cSrcweir     class  XBitmap;
91*cdf0e10cSrcweir     class  XPolyPolygon2D;
92*cdf0e10cSrcweir } } } }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir namespace vclcanvas
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     namespace tools
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         ::BitmapEx
100*cdf0e10cSrcweir         bitmapExFromXBitmap( const ::com::sun::star::uno::Reference<
101*cdf0e10cSrcweir                              ::com::sun::star::rendering::XBitmap >& );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir         /** Setup VCL font and output position
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         	@returns false, if no text output should happen
106*cdf0e10cSrcweir          */
107*cdf0e10cSrcweir         bool setupFontTransform( ::Point&													o_rPoint,
108*cdf0e10cSrcweir                                  ::Font& 													io_rVCLFont,
109*cdf0e10cSrcweir                                  const ::com::sun::star::rendering::ViewState& 		viewState,
110*cdf0e10cSrcweir                                  const ::com::sun::star::rendering::RenderState& 	renderState,
111*cdf0e10cSrcweir                                  ::OutputDevice&											rOutDev );
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir         /** Predicate, to determine whether polygon is actually an axis-aligned rectangle
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         	@return true, if the polygon is a rectangle.
116*cdf0e10cSrcweir          */
117*cdf0e10cSrcweir         bool isRectangle( const PolyPolygon& rPolyPoly );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         // Little helper to encapsulate locking into policy class
121*cdf0e10cSrcweir         class LocalGuard
122*cdf0e10cSrcweir         {
123*cdf0e10cSrcweir         public:
124*cdf0e10cSrcweir             LocalGuard() :
125*cdf0e10cSrcweir                 aGuard( Application::GetSolarMutex() )
126*cdf0e10cSrcweir             {
127*cdf0e10cSrcweir         	}
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir             /// To be compatible with CanvasBase mutex concept
130*cdf0e10cSrcweir             LocalGuard( const ::osl::Mutex& ) :
131*cdf0e10cSrcweir                 aGuard( Application::GetSolarMutex() )
132*cdf0e10cSrcweir             {
133*cdf0e10cSrcweir         	}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         private:
136*cdf0e10cSrcweir             ::vos::OGuard aGuard;
137*cdf0e10cSrcweir         };
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         class OutDevStateKeeper
140*cdf0e10cSrcweir         {
141*cdf0e10cSrcweir         public:
142*cdf0e10cSrcweir             explicit OutDevStateKeeper( OutputDevice& rOutDev ) :
143*cdf0e10cSrcweir                 mpOutDev( &rOutDev ),
144*cdf0e10cSrcweir                 mbMappingWasEnabled( mpOutDev->IsMapModeEnabled() )
145*cdf0e10cSrcweir             {
146*cdf0e10cSrcweir                 init();
147*cdf0e10cSrcweir         	}
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir             explicit OutDevStateKeeper( const OutDevProviderSharedPtr& rOutDev ) :
150*cdf0e10cSrcweir                 mpOutDev( rOutDev.get() ? &(rOutDev->getOutDev()) : NULL ),
151*cdf0e10cSrcweir                 mbMappingWasEnabled( mpOutDev ? mpOutDev->IsMapModeEnabled() : false )
152*cdf0e10cSrcweir             {
153*cdf0e10cSrcweir                 init();
154*cdf0e10cSrcweir         	}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir             ~OutDevStateKeeper()
157*cdf0e10cSrcweir             {
158*cdf0e10cSrcweir                 if( mpOutDev )
159*cdf0e10cSrcweir                 {
160*cdf0e10cSrcweir                     mpOutDev->EnableMapMode( mbMappingWasEnabled );
161*cdf0e10cSrcweir                     mpOutDev->Pop();
162*cdf0e10cSrcweir                 }
163*cdf0e10cSrcweir         	}
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         private:
166*cdf0e10cSrcweir             void init()
167*cdf0e10cSrcweir             {
168*cdf0e10cSrcweir                 if( mpOutDev )
169*cdf0e10cSrcweir                 {
170*cdf0e10cSrcweir                     mpOutDev->Push();
171*cdf0e10cSrcweir                     mpOutDev->EnableMapMode(sal_False);
172*cdf0e10cSrcweir                 }
173*cdf0e10cSrcweir             }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir             OutputDevice*	mpOutDev;
176*cdf0e10cSrcweir             const bool		mbMappingWasEnabled;
177*cdf0e10cSrcweir         };
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         ::Point mapRealPoint2D( const ::com::sun::star::geometry::RealPoint2D& 	rPoint,
180*cdf0e10cSrcweir                                 const ::com::sun::star::rendering::ViewState& 	rViewState,
181*cdf0e10cSrcweir                                 const ::com::sun::star::rendering::RenderState&	rRenderState );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         ::PolyPolygon mapPolyPolygon( const ::basegfx::B2DPolyPolygon& 							rPoly,
184*cdf0e10cSrcweir                                       const ::com::sun::star::rendering::ViewState& 	rViewState,
185*cdf0e10cSrcweir                                       const ::com::sun::star::rendering::RenderState&	rRenderState );
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         enum ModulationMode
188*cdf0e10cSrcweir         {
189*cdf0e10cSrcweir             MODULATE_NONE,
190*cdf0e10cSrcweir             MODULATE_WITH_DEVICECOLOR
191*cdf0e10cSrcweir         };
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         ::BitmapEx transformBitmap( const BitmapEx& 									rBitmap,
194*cdf0e10cSrcweir                                     const ::basegfx::B2DHomMatrix& 						rTransform,
195*cdf0e10cSrcweir                                     const ::com::sun::star::uno::Sequence< double >&	rDeviceColor,
196*cdf0e10cSrcweir                                     ModulationMode										eModulationMode );
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	}
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir #endif /* _VCLCANVAS_TOOLS_HXX */
202