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