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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_cppcanvas.hxx" 30 31 #include <rtl/instance.hxx> 32 #include <osl/getglobalmutex.hxx> 33 #include <osl/diagnose.h> 34 35 #include <com/sun/star/rendering/InterpolationMode.hpp> 36 37 #include <basegfx/polygon/b2dpolygon.hxx> 38 #include <basegfx/polygon/b2dpolypolygon.hxx> 39 #include <basegfx/tools/canvastools.hxx> 40 41 #include <cppcanvas/basegfxfactory.hxx> 42 43 #include "implpolypolygon.hxx" 44 #include "implbitmap.hxx" 45 #include "impltext.hxx" 46 47 48 using namespace ::com::sun::star; 49 50 namespace cppcanvas 51 { 52 /* Singleton handling */ 53 struct InitInstance2 54 { 55 BaseGfxFactory* operator()() 56 { 57 return new BaseGfxFactory(); 58 } 59 }; 60 61 BaseGfxFactory& BaseGfxFactory::getInstance() 62 { 63 return *rtl_Instance< BaseGfxFactory, InitInstance2, ::osl::MutexGuard, 64 ::osl::GetGlobalMutex >::create( 65 InitInstance2(), ::osl::GetGlobalMutex()); 66 } 67 68 BaseGfxFactory::BaseGfxFactory() 69 { 70 } 71 72 BaseGfxFactory::~BaseGfxFactory() 73 { 74 } 75 76 PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas, 77 const ::basegfx::B2DPolygon& rPoly ) const 78 { 79 OSL_ENSURE( rCanvas.get() != NULL && 80 rCanvas->getUNOCanvas().is(), 81 "BaseGfxFactory::createPolyPolygon(): Invalid canvas" ); 82 83 if( rCanvas.get() == NULL ) 84 return PolyPolygonSharedPtr(); 85 86 uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); 87 if( !xCanvas.is() ) 88 return PolyPolygonSharedPtr(); 89 90 return PolyPolygonSharedPtr( 91 new internal::ImplPolyPolygon( rCanvas, 92 ::basegfx::unotools::xPolyPolygonFromB2DPolygon( 93 xCanvas->getDevice(), 94 rPoly) ) ); 95 } 96 97 PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas, 98 const ::basegfx::B2DPolyPolygon& rPolyPoly ) const 99 { 100 OSL_ENSURE( rCanvas.get() != NULL && 101 rCanvas->getUNOCanvas().is(), 102 "BaseGfxFactory::createPolyPolygon(): Invalid canvas" ); 103 104 if( rCanvas.get() == NULL ) 105 return PolyPolygonSharedPtr(); 106 107 uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); 108 if( !xCanvas.is() ) 109 return PolyPolygonSharedPtr(); 110 111 return PolyPolygonSharedPtr( 112 new internal::ImplPolyPolygon( rCanvas, 113 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 114 xCanvas->getDevice(), 115 rPolyPoly) ) ); 116 } 117 118 BitmapSharedPtr BaseGfxFactory::createBitmap( const CanvasSharedPtr& rCanvas, 119 const ::basegfx::B2ISize& rSize ) const 120 { 121 OSL_ENSURE( rCanvas.get() != NULL && 122 rCanvas->getUNOCanvas().is(), 123 "BaseGfxFactory::createBitmap(): Invalid canvas" ); 124 125 if( rCanvas.get() == NULL ) 126 return BitmapSharedPtr(); 127 128 uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); 129 if( !xCanvas.is() ) 130 return BitmapSharedPtr(); 131 132 return BitmapSharedPtr( 133 new internal::ImplBitmap( rCanvas, 134 xCanvas->getDevice()->createCompatibleBitmap( 135 ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) ); 136 } 137 138 BitmapSharedPtr BaseGfxFactory::createAlphaBitmap( const CanvasSharedPtr& rCanvas, 139 const ::basegfx::B2ISize& rSize ) const 140 { 141 OSL_ENSURE( rCanvas.get() != NULL && 142 rCanvas->getUNOCanvas().is(), 143 "BaseGfxFactory::createBitmap(): Invalid canvas" ); 144 145 if( rCanvas.get() == NULL ) 146 return BitmapSharedPtr(); 147 148 uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); 149 if( !xCanvas.is() ) 150 return BitmapSharedPtr(); 151 152 return BitmapSharedPtr( 153 new internal::ImplBitmap( rCanvas, 154 xCanvas->getDevice()->createCompatibleAlphaBitmap( 155 ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) ); 156 } 157 158 TextSharedPtr BaseGfxFactory::createText( const CanvasSharedPtr& rCanvas, const ::rtl::OUString& rText ) const 159 { 160 return TextSharedPtr( new internal::ImplText( rCanvas, 161 rText ) ); 162 } 163 164 } 165