Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / directx / dx_bitmapcanvashelper.cxx
blob0221cecde14dcc8f26debd3f111ac70e99a68781
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <canvas/debug.hxx>
22 #include <tools/diagnose_ex.h>
24 #include <rtl/math.hxx>
26 #include <com/sun/star/rendering/TexturingMode.hpp>
27 #include <com/sun/star/rendering/CompositeOperation.hpp>
28 #include <com/sun/star/rendering/RepaintResult.hpp>
29 #include <com/sun/star/rendering/PathCapType.hpp>
30 #include <com/sun/star/rendering/PathJoinType.hpp>
32 #include <basegfx/matrix/b2dhommatrix.hxx>
33 #include <basegfx/point/b2dpoint.hxx>
34 #include <basegfx/tools/canvastools.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <canvas/canvastools.hxx>
39 #include "dx_spritecanvas.hxx"
40 #include "dx_impltools.hxx"
41 #include "dx_canvasfont.hxx"
42 #include "dx_textlayout.hxx"
43 #include "dx_bitmapcanvashelper.hxx"
45 #include <algorithm>
48 using namespace ::com::sun::star;
50 namespace dxcanvas
52 BitmapCanvasHelper::BitmapCanvasHelper() :
53 mpTarget()
56 void BitmapCanvasHelper::disposing()
58 mpTarget.reset();
59 CanvasHelper::disposing();
62 void BitmapCanvasHelper::setTarget( const IBitmapSharedPtr& rTarget )
64 ENSURE_OR_THROW( rTarget,
65 "BitmapCanvasHelper::setTarget(): Invalid target" );
66 ENSURE_OR_THROW( !mpTarget.get(),
67 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
69 mpTarget = rTarget;
70 CanvasHelper::setTarget(rTarget);
73 void BitmapCanvasHelper::setTarget( const IBitmapSharedPtr& rTarget,
74 const ::basegfx::B2ISize& rOutputOffset )
76 ENSURE_OR_THROW( rTarget,
77 "BitmapCanvasHelper::setTarget(): invalid target" );
78 ENSURE_OR_THROW( !mpTarget.get(),
79 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
81 mpTarget = rTarget;
82 CanvasHelper::setTarget(rTarget,rOutputOffset);
85 void BitmapCanvasHelper::clear()
87 if( needOutput() )
89 GraphicsSharedPtr pGraphics( mpTarget->getGraphics() );
91 Gdiplus::Color aClearColor = hasAlpha() ?
92 Gdiplus::Color( 0,255,255,255 ) : Gdiplus::Color((Gdiplus::ARGB)Gdiplus::Color::White);
94 ENSURE_OR_THROW(
95 Gdiplus::Ok == pGraphics->SetCompositingMode(
96 Gdiplus::CompositingModeSourceCopy ), // force set, don't blend
97 "BitmapCanvasHelper::clear(): GDI+ SetCompositingMode call failed" );
98 ENSURE_OR_THROW(
99 Gdiplus::Ok == pGraphics->Clear( aClearColor ),
100 "BitmapCanvasHelper::clear(): GDI+ Clear call failed" );
104 uno::Reference< rendering::XCachedPrimitive > BitmapCanvasHelper::drawTextLayout( const rendering::XCanvas* /*pCanvas*/,
105 const uno::Reference< rendering::XTextLayout >& xLayoutetText,
106 const rendering::ViewState& viewState,
107 const rendering::RenderState& renderState )
109 ENSURE_OR_THROW( xLayoutetText.is(),
110 "BitmapCanvasHelper::drawTextLayout: layout is NULL");
112 if( needOutput() )
114 TextLayout* pTextLayout =
115 dynamic_cast< TextLayout* >( xLayoutetText.get() );
117 ENSURE_OR_THROW( pTextLayout,
118 "BitmapCanvasHelper::drawTextLayout(): TextLayout not compatible with this canvas" );
120 pTextLayout->draw( mpTarget->getGraphics(),
121 viewState,
122 renderState,
123 maOutputOffset,
124 mpDevice,
125 mpTarget->hasAlpha() );
128 return uno::Reference< rendering::XCachedPrimitive >(NULL);
131 void BitmapCanvasHelper::copyRect( const rendering::XCanvas* /*pCanvas*/,
132 const uno::Reference< rendering::XBitmapCanvas >& /*sourceCanvas*/,
133 const geometry::RealRectangle2D& /*sourceRect*/,
134 const rendering::ViewState& /*sourceViewState*/,
135 const rendering::RenderState& /*sourceRenderState*/,
136 const geometry::RealRectangle2D& /*destRect*/,
137 const rendering::ViewState& /*destViewState*/,
138 const rendering::RenderState& /*destRenderState*/ )
140 // TODO(F2): copyRect NYI
143 geometry::IntegerSize2D BitmapCanvasHelper::getSize()
145 if( !mpTarget )
146 return geometry::IntegerSize2D(1, 1);
148 return basegfx::unotools::integerSize2DFromB2ISize(mpTarget->getSize());
151 uno::Reference< rendering::XBitmap > BitmapCanvasHelper::getScaledBitmap( const geometry::RealSize2D& /*newSize*/,
152 bool /*beFast*/ )
154 // TODO(F1):
155 return uno::Reference< rendering::XBitmap >();
158 uno::Sequence< sal_Int8 > BitmapCanvasHelper::getData( rendering::IntegerBitmapLayout& bitmapLayout,
159 const geometry::IntegerRectangle2D& rect )
161 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getData()" );
163 ENSURE_OR_THROW( mpTarget,
164 "::dxcanvas::BitmapCanvasHelper::getData(): disposed" );
166 if( !mpTarget )
167 return uno::Sequence< sal_Int8 >();
169 bitmapLayout = getMemoryLayout();
170 return mpTarget->getData(bitmapLayout,rect);
173 void BitmapCanvasHelper::setData( const uno::Sequence< sal_Int8 >& data,
174 const rendering::IntegerBitmapLayout& bitmapLayout,
175 const geometry::IntegerRectangle2D& rect )
177 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setData()" );
179 ENSURE_OR_THROW( mpTarget,
180 "::dxcanvas::BitmapCanvasHelper::setData(): disposed" );
182 if( !mpTarget )
183 return;
185 mpTarget->setData(data,bitmapLayout,rect);
188 void BitmapCanvasHelper::setPixel( const uno::Sequence< sal_Int8 >& color,
189 const rendering::IntegerBitmapLayout& bitmapLayout,
190 const geometry::IntegerPoint2D& pos )
192 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setPixel()" );
194 ENSURE_OR_THROW( mpTarget,
195 "::dxcanvas::BitmapCanvasHelper::setPixel(): disposed" );
197 if( !mpTarget )
198 return;
200 mpTarget->setPixel(color,bitmapLayout,pos);
203 uno::Sequence< sal_Int8 > BitmapCanvasHelper::getPixel( rendering::IntegerBitmapLayout& bitmapLayout,
204 const geometry::IntegerPoint2D& pos )
206 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getPixel()" );
208 ENSURE_OR_THROW( mpTarget,
209 "::dxcanvas::BitmapCanvasHelper::getPixel(): disposed" );
211 if( !mpTarget )
212 return uno::Sequence< sal_Int8 >();
214 bitmapLayout = getMemoryLayout();
215 return mpTarget->getPixel(bitmapLayout,pos);
218 uno::Reference< rendering::XBitmapPalette > BitmapCanvasHelper::getPalette()
220 // TODO(F1): Palette bitmaps NYI
221 return uno::Reference< rendering::XBitmapPalette >();
224 rendering::IntegerBitmapLayout BitmapCanvasHelper::getMemoryLayout()
226 if( !mpTarget )
227 return rendering::IntegerBitmapLayout(); // we're disposed
229 return ::canvas::tools::getStdMemoryLayout(getSize());
231 bool BitmapCanvasHelper::hasAlpha() const
233 return mpTarget && mpTarget->hasAlpha();
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */