1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
25 #include <basegfx/matrix/b2dhommatrix.hxx>
26 #include <basegfx/point/b2dpoint.hxx>
27 #include <basegfx/utils/canvastools.hxx>
28 #include <com/sun/star/rendering/CompositeOperation.hpp>
29 #include <com/sun/star/rendering/PathCapType.hpp>
30 #include <com/sun/star/rendering/PathJoinType.hpp>
31 #include <com/sun/star/rendering/RepaintResult.hpp>
32 #include <com/sun/star/rendering/TexturingMode.hpp>
33 #include <rtl/math.hxx>
34 #include <comphelper/diagnose_ex.hxx>
36 #include <canvas/canvastools.hxx>
38 #include "dx_bitmapcanvashelper.hxx"
39 #include "dx_canvasfont.hxx"
40 #include "dx_impltools.hxx"
41 #include "dx_spritecanvas.hxx"
42 #include "dx_textlayout.hxx"
45 using namespace ::com::sun::star
;
49 BitmapCanvasHelper::BitmapCanvasHelper() :
53 void BitmapCanvasHelper::disposing()
56 CanvasHelper::disposing();
59 void BitmapCanvasHelper::setTarget( const IBitmapSharedPtr
& rTarget
)
61 ENSURE_OR_THROW( rTarget
,
62 "BitmapCanvasHelper::setTarget(): Invalid target" );
63 ENSURE_OR_THROW( !mpTarget
,
64 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
67 CanvasHelper::setTarget(rTarget
);
70 void BitmapCanvasHelper::setTarget( const IBitmapSharedPtr
& rTarget
,
71 const ::basegfx::B2ISize
& rOutputOffset
)
73 ENSURE_OR_THROW( rTarget
,
74 "BitmapCanvasHelper::setTarget(): invalid target" );
75 ENSURE_OR_THROW( !mpTarget
,
76 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
79 CanvasHelper::setTarget(rTarget
,rOutputOffset
);
82 void BitmapCanvasHelper::clear()
86 GraphicsSharedPtr
pGraphics( mpTarget
->getGraphics() );
88 Gdiplus::Color aClearColor
= hasAlpha() ?
89 Gdiplus::Color( 0,255,255,255 ) : Gdiplus::Color(Gdiplus::ARGB(Gdiplus::Color::White
));
92 Gdiplus::Ok
== pGraphics
->SetCompositingMode(
93 Gdiplus::CompositingModeSourceCopy
), // force set, don't blend
94 "BitmapCanvasHelper::clear(): GDI+ SetCompositingMode call failed" );
96 Gdiplus::Ok
== pGraphics
->Clear( aClearColor
),
97 "BitmapCanvasHelper::clear(): GDI+ Clear call failed" );
101 uno::Reference
< rendering::XCachedPrimitive
> BitmapCanvasHelper::drawTextLayout( const rendering::XCanvas
* /*pCanvas*/,
102 const uno::Reference
< rendering::XTextLayout
>& xLayoutetText
,
103 const rendering::ViewState
& viewState
,
104 const rendering::RenderState
& renderState
)
106 ENSURE_OR_THROW( xLayoutetText
.is(),
107 "BitmapCanvasHelper::drawTextLayout: layout is NULL");
111 TextLayout
* pTextLayout
=
112 dynamic_cast< TextLayout
* >( xLayoutetText
.get() );
114 ENSURE_OR_THROW( pTextLayout
,
115 "BitmapCanvasHelper::drawTextLayout(): TextLayout not compatible with this canvas" );
117 pTextLayout
->draw( mpTarget
->getGraphics(),
122 mpTarget
->hasAlpha() );
125 return uno::Reference
< rendering::XCachedPrimitive
>(nullptr);
128 void BitmapCanvasHelper::copyRect( const rendering::XCanvas
* /*pCanvas*/,
129 const uno::Reference
< rendering::XBitmapCanvas
>& /*sourceCanvas*/,
130 const geometry::RealRectangle2D
& /*sourceRect*/,
131 const rendering::ViewState
& /*sourceViewState*/,
132 const rendering::RenderState
& /*sourceRenderState*/,
133 const geometry::RealRectangle2D
& /*destRect*/,
134 const rendering::ViewState
& /*destViewState*/,
135 const rendering::RenderState
& /*destRenderState*/ )
137 // TODO(F2): copyRect NYI
140 geometry::IntegerSize2D
BitmapCanvasHelper::getSize()
143 return geometry::IntegerSize2D(1, 1);
144 return basegfx::unotools::integerSize2DFromB2ISize(mpTarget
->getSize());
147 uno::Reference
< rendering::XBitmap
> BitmapCanvasHelper::getScaledBitmap( const geometry::RealSize2D
& /*newSize*/,
151 return uno::Reference
< rendering::XBitmap
>();
154 uno::Sequence
< sal_Int8
> BitmapCanvasHelper::getData( rendering::IntegerBitmapLayout
& bitmapLayout
,
155 const geometry::IntegerRectangle2D
& rect
)
157 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getData()" );
159 ENSURE_OR_THROW( mpTarget
,
160 "::dxcanvas::BitmapCanvasHelper::getData(): disposed" );
162 bitmapLayout
= getMemoryLayout();
163 return mpTarget
->getData(bitmapLayout
,rect
);
166 void BitmapCanvasHelper::setData( const uno::Sequence
< sal_Int8
>& data
,
167 const rendering::IntegerBitmapLayout
& bitmapLayout
,
168 const geometry::IntegerRectangle2D
& rect
)
170 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setData()" );
172 ENSURE_OR_THROW( mpTarget
,
173 "::dxcanvas::BitmapCanvasHelper::setData(): disposed" );
175 mpTarget
->setData(data
,bitmapLayout
,rect
);
178 void BitmapCanvasHelper::setPixel( const uno::Sequence
< sal_Int8
>& color
,
179 const rendering::IntegerBitmapLayout
& bitmapLayout
,
180 const geometry::IntegerPoint2D
& pos
)
182 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setPixel()" );
184 ENSURE_OR_THROW( mpTarget
,
185 "::dxcanvas::BitmapCanvasHelper::setPixel(): disposed" );
187 mpTarget
->setPixel(color
,bitmapLayout
,pos
);
190 uno::Sequence
< sal_Int8
> BitmapCanvasHelper::getPixel( rendering::IntegerBitmapLayout
& bitmapLayout
,
191 const geometry::IntegerPoint2D
& pos
)
193 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getPixel()" );
195 ENSURE_OR_THROW( mpTarget
,
196 "::dxcanvas::BitmapCanvasHelper::getPixel(): disposed" );
198 bitmapLayout
= getMemoryLayout();
199 return mpTarget
->getPixel(bitmapLayout
,pos
);
202 uno::Reference
< rendering::XBitmapPalette
> BitmapCanvasHelper::getPalette()
204 // TODO(F1): Palette bitmaps NYI
205 return uno::Reference
< rendering::XBitmapPalette
>();
208 rendering::IntegerBitmapLayout
BitmapCanvasHelper::getMemoryLayout()
211 return rendering::IntegerBitmapLayout(); // we're disposed
213 return ::canvas::tools::getStdMemoryLayout(getSize());
215 bool BitmapCanvasHelper::hasAlpha() const
217 return mpTarget
&& mpTarget
->hasAlpha();
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */