merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / directx / dx_bitmapcanvashelper.cxx
blob58db13b30a6e0b8ce48e51a5431e9c8357b01106
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_bitmapcanvashelper.cxx,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
37 #include <rtl/logfile.hxx>
38 #include <rtl/math.hxx>
40 #include <com/sun/star/rendering/TexturingMode.hpp>
41 #include <com/sun/star/rendering/CompositeOperation.hpp>
42 #include <com/sun/star/rendering/RepaintResult.hpp>
43 #include <com/sun/star/rendering/PathCapType.hpp>
44 #include <com/sun/star/rendering/PathJoinType.hpp>
46 #include <basegfx/matrix/b2dhommatrix.hxx>
47 #include <basegfx/point/b2dpoint.hxx>
48 #include <basegfx/tools/canvastools.hxx>
50 #include <comphelper/sequence.hxx>
51 #include <canvas/canvastools.hxx>
53 #include "dx_spritecanvas.hxx"
54 #include "dx_impltools.hxx"
55 #include "dx_canvasfont.hxx"
56 #include "dx_textlayout.hxx"
57 #include "dx_bitmapcanvashelper.hxx"
59 #include <algorithm>
62 using namespace ::com::sun::star;
64 namespace dxcanvas
66 BitmapCanvasHelper::BitmapCanvasHelper() :
67 mpTarget()
70 void BitmapCanvasHelper::disposing()
72 mpTarget.reset();
73 CanvasHelper::disposing();
76 void BitmapCanvasHelper::setTarget( const IBitmapSharedPtr& rTarget )
78 ENSURE_OR_THROW( rTarget,
79 "BitmapCanvasHelper::setTarget(): Invalid target" );
80 ENSURE_OR_THROW( !mpTarget.get(),
81 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
83 mpTarget = rTarget;
84 CanvasHelper::setTarget(rTarget);
87 void BitmapCanvasHelper::setTarget( const IBitmapSharedPtr& rTarget,
88 const ::basegfx::B2ISize& rOutputOffset )
90 ENSURE_OR_THROW( rTarget,
91 "BitmapCanvasHelper::setTarget(): invalid target" );
92 ENSURE_OR_THROW( !mpTarget.get(),
93 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
95 mpTarget = rTarget;
96 CanvasHelper::setTarget(rTarget,rOutputOffset);
99 void BitmapCanvasHelper::clear()
101 if( needOutput() )
103 GraphicsSharedPtr pGraphics( mpTarget->getGraphics() );
105 Gdiplus::Color aClearColor = hasAlpha() ?
106 Gdiplus::Color( 0,255,255,255 ) : Gdiplus::Color((Gdiplus::ARGB)Gdiplus::Color::White);
108 ENSURE_OR_THROW(
109 Gdiplus::Ok == pGraphics->SetCompositingMode(
110 Gdiplus::CompositingModeSourceCopy ), // force set, don't blend
111 "BitmapCanvasHelper::clear(): GDI+ SetCompositingMode call failed" );
112 ENSURE_OR_THROW(
113 Gdiplus::Ok == pGraphics->Clear( aClearColor ),
114 "BitmapCanvasHelper::clear(): GDI+ Clear call failed" );
118 uno::Reference< rendering::XCachedPrimitive > BitmapCanvasHelper::drawTextLayout( const rendering::XCanvas* /*pCanvas*/,
119 const uno::Reference< rendering::XTextLayout >& xLayoutetText,
120 const rendering::ViewState& viewState,
121 const rendering::RenderState& renderState )
123 ENSURE_OR_THROW( xLayoutetText.is(),
124 "BitmapCanvasHelper::drawTextLayout: layout is NULL");
126 if( needOutput() )
128 TextLayout* pTextLayout =
129 dynamic_cast< TextLayout* >( xLayoutetText.get() );
131 ENSURE_OR_THROW( pTextLayout,
132 "BitmapCanvasHelper::drawTextLayout(): TextLayout not compatible with this canvas" );
134 pTextLayout->draw( mpTarget->getGraphics(),
135 viewState,
136 renderState,
137 maOutputOffset,
138 mpDevice,
139 mpTarget->hasAlpha() );
142 return uno::Reference< rendering::XCachedPrimitive >(NULL);
145 void BitmapCanvasHelper::copyRect( const rendering::XCanvas* /*pCanvas*/,
146 const uno::Reference< rendering::XBitmapCanvas >& /*sourceCanvas*/,
147 const geometry::RealRectangle2D& /*sourceRect*/,
148 const rendering::ViewState& /*sourceViewState*/,
149 const rendering::RenderState& /*sourceRenderState*/,
150 const geometry::RealRectangle2D& /*destRect*/,
151 const rendering::ViewState& /*destViewState*/,
152 const rendering::RenderState& /*destRenderState*/ )
154 // TODO(F2): copyRect NYI
157 geometry::IntegerSize2D BitmapCanvasHelper::getSize()
159 if( !mpTarget )
160 return geometry::IntegerSize2D(1, 1);
162 return basegfx::unotools::integerSize2DFromB2ISize(mpTarget->getSize());
165 uno::Reference< rendering::XBitmap > BitmapCanvasHelper::getScaledBitmap( const geometry::RealSize2D& /*newSize*/,
166 sal_Bool /*beFast*/ )
168 // TODO(F1):
169 return uno::Reference< rendering::XBitmap >();
172 uno::Sequence< sal_Int8 > BitmapCanvasHelper::getData( rendering::IntegerBitmapLayout& bitmapLayout,
173 const geometry::IntegerRectangle2D& rect )
175 RTL_LOGFILE_CONTEXT( aLog, "::dxcanvas::BitmapCanvasHelper::getData()" );
177 ENSURE_OR_THROW( mpTarget,
178 "::dxcanvas::BitmapCanvasHelper::getData(): disposed" );
180 if( !mpTarget )
181 return uno::Sequence< sal_Int8 >();
183 bitmapLayout = getMemoryLayout();
184 return mpTarget->getData(bitmapLayout,rect);
187 void BitmapCanvasHelper::setData( const uno::Sequence< sal_Int8 >& data,
188 const rendering::IntegerBitmapLayout& bitmapLayout,
189 const geometry::IntegerRectangle2D& rect )
191 RTL_LOGFILE_CONTEXT( aLog, "::dxcanvas::BitmapCanvasHelper::setData()" );
193 ENSURE_OR_THROW( mpTarget,
194 "::dxcanvas::BitmapCanvasHelper::setData(): disposed" );
196 if( !mpTarget )
197 return;
199 mpTarget->setData(data,bitmapLayout,rect);
202 void BitmapCanvasHelper::setPixel( const uno::Sequence< sal_Int8 >& color,
203 const rendering::IntegerBitmapLayout& bitmapLayout,
204 const geometry::IntegerPoint2D& pos )
206 RTL_LOGFILE_CONTEXT( aLog, "::dxcanvas::BitmapCanvasHelper::setPixel()" );
208 ENSURE_OR_THROW( mpTarget,
209 "::dxcanvas::BitmapCanvasHelper::setPixel(): disposed" );
211 if( !mpTarget )
212 return;
214 mpTarget->setPixel(color,bitmapLayout,pos);
217 uno::Sequence< sal_Int8 > BitmapCanvasHelper::getPixel( rendering::IntegerBitmapLayout& bitmapLayout,
218 const geometry::IntegerPoint2D& pos )
220 RTL_LOGFILE_CONTEXT( aLog, "::dxcanvas::BitmapCanvasHelper::getPixel()" );
222 ENSURE_OR_THROW( mpTarget,
223 "::dxcanvas::BitmapCanvasHelper::getPixel(): disposed" );
225 if( !mpTarget )
226 return uno::Sequence< sal_Int8 >();
228 bitmapLayout = getMemoryLayout();
229 return mpTarget->getPixel(bitmapLayout,pos);
232 uno::Reference< rendering::XBitmapPalette > BitmapCanvasHelper::getPalette()
234 // TODO(F1): Palette bitmaps NYI
235 return uno::Reference< rendering::XBitmapPalette >();
238 rendering::IntegerBitmapLayout BitmapCanvasHelper::getMemoryLayout()
240 if( !mpTarget )
241 return rendering::IntegerBitmapLayout(); // we're disposed
243 return ::canvas::tools::getStdMemoryLayout(getSize());
245 bool BitmapCanvasHelper::hasAlpha() const
247 return mpTarget ? mpTarget->hasAlpha() : false;