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