191c99ff4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 391c99ff4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 491c99ff4SAndrew Rist * or more contributor license agreements. See the NOTICE file 591c99ff4SAndrew Rist * distributed with this work for additional information 691c99ff4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 791c99ff4SAndrew Rist * to you under the Apache License, Version 2.0 (the 891c99ff4SAndrew Rist * "License"); you may not use this file except in compliance 991c99ff4SAndrew Rist * with the License. You may obtain a copy of the License at 1091c99ff4SAndrew Rist * 1191c99ff4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1291c99ff4SAndrew Rist * 1391c99ff4SAndrew Rist * Unless required by applicable law or agreed to in writing, 1491c99ff4SAndrew Rist * software distributed under the License is distributed on an 1591c99ff4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1691c99ff4SAndrew Rist * KIND, either express or implied. See the License for the 1791c99ff4SAndrew Rist * specific language governing permissions and limitations 1891c99ff4SAndrew Rist * under the License. 1991c99ff4SAndrew Rist * 2091c99ff4SAndrew Rist *************************************************************/ 2191c99ff4SAndrew Rist 2291c99ff4SAndrew 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: LocalGuard()120cdf0e10cSrcweir LocalGuard() : 121cdf0e10cSrcweir aGuard( Application::GetSolarMutex() ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir /// To be compatible with CanvasBase mutex concept LocalGuard(const::osl::Mutex &)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: OutDevStateKeeper(OutputDevice & rOutDev)138cdf0e10cSrcweir explicit OutDevStateKeeper( OutputDevice& rOutDev ) : 139cdf0e10cSrcweir mpOutDev( &rOutDev ), 140*5f27b83cSArmin Le Grand mbMappingWasEnabled( mpOutDev->IsMapModeEnabled() ), 141*5f27b83cSArmin Le Grand mnAntiAliasing( mpOutDev->GetAntialiasing() ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir init(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir OutDevStateKeeper(const OutDevProviderSharedPtr & rOutDev)146cdf0e10cSrcweir explicit OutDevStateKeeper( const OutDevProviderSharedPtr& rOutDev ) : 147cdf0e10cSrcweir mpOutDev( rOutDev.get() ? &(rOutDev->getOutDev()) : NULL ), 148*5f27b83cSArmin Le Grand mbMappingWasEnabled( mpOutDev ? mpOutDev->IsMapModeEnabled() : false ), 149*5f27b83cSArmin Le Grand mnAntiAliasing( mpOutDev ? mpOutDev->GetAntialiasing() : 0 ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir init(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir ~OutDevStateKeeper()154cdf0e10cSrcweir ~OutDevStateKeeper() 155cdf0e10cSrcweir { 156cdf0e10cSrcweir if( mpOutDev ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir mpOutDev->EnableMapMode( mbMappingWasEnabled ); 159*5f27b83cSArmin Le Grand mpOutDev->SetAntialiasing( mnAntiAliasing ); 160*5f27b83cSArmin Le Grand 161cdf0e10cSrcweir mpOutDev->Pop(); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir private: init()166cdf0e10cSrcweir void init() 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if( mpOutDev ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir mpOutDev->Push(); 171cdf0e10cSrcweir mpOutDev->EnableMapMode(sal_False); 172*5f27b83cSArmin Le Grand mpOutDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176*5f27b83cSArmin Le Grand OutputDevice* mpOutDev; 177*5f27b83cSArmin Le Grand const bool mbMappingWasEnabled; 178*5f27b83cSArmin Le Grand const sal_uInt16 mnAntiAliasing; 179cdf0e10cSrcweir }; 180cdf0e10cSrcweir 181cdf0e10cSrcweir ::Point mapRealPoint2D( const ::com::sun::star::geometry::RealPoint2D& rPoint, 182cdf0e10cSrcweir const ::com::sun::star::rendering::ViewState& rViewState, 183cdf0e10cSrcweir const ::com::sun::star::rendering::RenderState& rRenderState ); 184cdf0e10cSrcweir 185cdf0e10cSrcweir ::PolyPolygon mapPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly, 186cdf0e10cSrcweir const ::com::sun::star::rendering::ViewState& rViewState, 187cdf0e10cSrcweir const ::com::sun::star::rendering::RenderState& rRenderState ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir enum ModulationMode 190cdf0e10cSrcweir { 191cdf0e10cSrcweir MODULATE_NONE, 192cdf0e10cSrcweir MODULATE_WITH_DEVICECOLOR 193cdf0e10cSrcweir }; 194cdf0e10cSrcweir 195cdf0e10cSrcweir ::BitmapEx transformBitmap( const BitmapEx& rBitmap, 196cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransform, 197cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< double >& rDeviceColor, 198cdf0e10cSrcweir ModulationMode eModulationMode ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir } 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir #endif /* _VCLCANVAS_TOOLS_HXX */ 204