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: 120 LocalGuard() : 121 aGuard( Application::GetSolarMutex() ) 122 { 123 } 124 125 /// To be compatible with CanvasBase mutex concept 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: 138 explicit OutDevStateKeeper( OutputDevice& rOutDev ) : 139 mpOutDev( &rOutDev ), 140 mbMappingWasEnabled( mpOutDev->IsMapModeEnabled() ) 141 { 142 init(); 143 } 144 145 explicit OutDevStateKeeper( const OutDevProviderSharedPtr& rOutDev ) : 146 mpOutDev( rOutDev.get() ? &(rOutDev->getOutDev()) : NULL ), 147 mbMappingWasEnabled( mpOutDev ? mpOutDev->IsMapModeEnabled() : false ) 148 { 149 init(); 150 } 151 152 ~OutDevStateKeeper() 153 { 154 if( mpOutDev ) 155 { 156 mpOutDev->EnableMapMode( mbMappingWasEnabled ); 157 mpOutDev->Pop(); 158 } 159 } 160 161 private: 162 void init() 163 { 164 if( mpOutDev ) 165 { 166 mpOutDev->Push(); 167 mpOutDev->EnableMapMode(sal_False); 168 } 169 } 170 171 OutputDevice* mpOutDev; 172 const bool mbMappingWasEnabled; 173 }; 174 175 ::Point mapRealPoint2D( const ::com::sun::star::geometry::RealPoint2D& rPoint, 176 const ::com::sun::star::rendering::ViewState& rViewState, 177 const ::com::sun::star::rendering::RenderState& rRenderState ); 178 179 ::PolyPolygon mapPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly, 180 const ::com::sun::star::rendering::ViewState& rViewState, 181 const ::com::sun::star::rendering::RenderState& rRenderState ); 182 183 enum ModulationMode 184 { 185 MODULATE_NONE, 186 MODULATE_WITH_DEVICECOLOR 187 }; 188 189 ::BitmapEx transformBitmap( const BitmapEx& rBitmap, 190 const ::basegfx::B2DHomMatrix& rTransform, 191 const ::com::sun::star::uno::Sequence< double >& rDeviceColor, 192 ModulationMode eModulationMode ); 193 194 } 195 } 196 197 #endif /* _VCLCANVAS_TOOLS_HXX */ 198