xref: /AOO41X/main/canvas/source/vcl/impltools.hxx (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _VCLCANVAS_TOOLS_HXX
25 #define _VCLCANVAS_TOOLS_HXX
26 
27 #include <osl/mutex.hxx>
28 #include <vos/mutex.hxx>
29 
30 #include <vcl/svapp.hxx>
31 #include <vcl/outdev.hxx>
32 
33 #include <basegfx/polygon/b2dpolypolygon.hxx>
34 
35 #include <com/sun/star/uno/Reference.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 
38 #include <canvas/vclwrapper.hxx>
39 #include "outdevprovider.hxx"
40 
41 
42 class OutputDevice;
43 class Point;
44 class Size;
45 
46 namespace basegfx
47 {
48     namespace matrix
49     {
50         class B2DHomMatrix;
51     }
52     namespace vector
53     {
54         class B2DVector;
55     }
56     namespace point
57     {
58         class B2DPoint;
59     }
60 }
61 
62 namespace com { namespace sun { namespace star { namespace awt
63 {
64     struct Point;
65     struct Size;
66     struct Rectangle;
67 } } } }
68 
69 namespace com { namespace sun { namespace star { namespace drawing
70 {
71     struct HomogenMatrix3;
72 } } } }
73 
74 namespace com { namespace sun { namespace star { namespace geometry
75 {
76     struct RealPoint2D;
77     struct RealSize2D;
78     struct RealRectangle2D;
79 } } } }
80 
81 namespace com { namespace sun { namespace star { namespace rendering
82 {
83     struct RenderState;
84     struct ViewState;
85     class  XCanvas;
86     class  XBitmap;
87     class  XPolyPolygon2D;
88 } } } }
89 
90 
91 namespace vclcanvas
92 {
93     namespace tools
94     {
95         ::BitmapEx
96         bitmapExFromXBitmap( const ::com::sun::star::uno::Reference<
97                              ::com::sun::star::rendering::XBitmap >& );
98 
99         /** Setup VCL font and output position
100 
101             @returns false, if no text output should happen
102          */
103         bool setupFontTransform( ::Point&                                                   o_rPoint,
104                                  ::Font&                                                    io_rVCLFont,
105                                  const ::com::sun::star::rendering::ViewState&      viewState,
106                                  const ::com::sun::star::rendering::RenderState&    renderState,
107                                  ::OutputDevice&                                            rOutDev );
108 
109         /** Predicate, to determine whether polygon is actually an axis-aligned rectangle
110 
111             @return true, if the polygon is a rectangle.
112          */
113         bool isRectangle( const PolyPolygon& rPolyPoly );
114 
115 
116         // Little helper to encapsulate locking into policy class
117         class LocalGuard
118         {
119         public:
LocalGuard()120             LocalGuard() :
121                 aGuard( Application::GetSolarMutex() )
122             {
123             }
124 
125             /// To be compatible with CanvasBase mutex concept
LocalGuard(const::osl::Mutex &)126             LocalGuard( const ::osl::Mutex& ) :
127                 aGuard( Application::GetSolarMutex() )
128             {
129             }
130 
131         private:
132             ::vos::OGuard aGuard;
133         };
134 
135         class OutDevStateKeeper
136         {
137         public:
OutDevStateKeeper(OutputDevice & rOutDev)138             explicit OutDevStateKeeper( OutputDevice& rOutDev ) :
139                 mpOutDev( &rOutDev ),
140                 mbMappingWasEnabled( mpOutDev->IsMapModeEnabled() ),
141                 mnAntiAliasing( mpOutDev->GetAntialiasing() )
142             {
143                 init();
144             }
145 
OutDevStateKeeper(const OutDevProviderSharedPtr & rOutDev)146             explicit OutDevStateKeeper( const OutDevProviderSharedPtr& rOutDev ) :
147                 mpOutDev( rOutDev.get() ? &(rOutDev->getOutDev()) : NULL ),
148                 mbMappingWasEnabled( mpOutDev ? mpOutDev->IsMapModeEnabled() : false ),
149                 mnAntiAliasing( mpOutDev ? mpOutDev->GetAntialiasing() : 0 )
150             {
151                 init();
152             }
153 
~OutDevStateKeeper()154             ~OutDevStateKeeper()
155             {
156                 if( mpOutDev )
157                 {
158                     mpOutDev->EnableMapMode( mbMappingWasEnabled );
159                     mpOutDev->SetAntialiasing( mnAntiAliasing );
160 
161                     mpOutDev->Pop();
162                 }
163             }
164 
165         private:
init()166             void init()
167             {
168                 if( mpOutDev )
169                 {
170                     mpOutDev->Push();
171                     mpOutDev->EnableMapMode(sal_False);
172                     mpOutDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
173                 }
174             }
175 
176             OutputDevice*       mpOutDev;
177             const bool          mbMappingWasEnabled;
178             const sal_uInt16    mnAntiAliasing;
179         };
180 
181         ::Point mapRealPoint2D( const ::com::sun::star::geometry::RealPoint2D&  rPoint,
182                                 const ::com::sun::star::rendering::ViewState&   rViewState,
183                                 const ::com::sun::star::rendering::RenderState& rRenderState );
184 
185         ::PolyPolygon mapPolyPolygon( const ::basegfx::B2DPolyPolygon&                          rPoly,
186                                       const ::com::sun::star::rendering::ViewState&     rViewState,
187                                       const ::com::sun::star::rendering::RenderState&   rRenderState );
188 
189         enum ModulationMode
190         {
191             MODULATE_NONE,
192             MODULATE_WITH_DEVICECOLOR
193         };
194 
195         ::BitmapEx transformBitmap( const BitmapEx&                                     rBitmap,
196                                     const ::basegfx::B2DHomMatrix&                      rTransform,
197                                     const ::com::sun::star::uno::Sequence< double >&    rDeviceColor,
198                                     ModulationMode                                      eModulationMode );
199 
200     }
201 }
202 
203 #endif /* _VCLCANVAS_TOOLS_HXX */
204