LibreOffice Module canvas (master) 1
dx_bitmapcanvashelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21#include <sal/log.hxx>
22
23#include <algorithm>
24
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>
35
37
39#include "dx_canvasfont.hxx"
40#include "dx_impltools.hxx"
41#include "dx_spritecanvas.hxx"
42#include "dx_textlayout.hxx"
43
44
45using namespace ::com::sun::star;
46
47namespace dxcanvas
48{
50 mpTarget()
51 {}
52
54 {
55 mpTarget.reset();
57 }
58
60 {
62 "BitmapCanvasHelper::setTarget(): Invalid target" );
64 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
65
68 }
69
71 const ::basegfx::B2ISize& rOutputOffset )
72 {
74 "BitmapCanvasHelper::setTarget(): invalid target" );
76 "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
77
79 CanvasHelper::setTarget(rTarget,rOutputOffset);
80 }
81
83 {
84 if( needOutput() )
85 {
86 GraphicsSharedPtr pGraphics( mpTarget->getGraphics() );
87
88 Gdiplus::Color aClearColor = hasAlpha() ?
89 Gdiplus::Color( 0,255,255,255 ) : Gdiplus::Color(Gdiplus::ARGB(Gdiplus::Color::White));
90
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" );
98 }
99 }
100
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 )
105 {
106 ENSURE_OR_THROW( xLayoutetText.is(),
107 "BitmapCanvasHelper::drawTextLayout: layout is NULL");
108
109 if( needOutput() )
110 {
111 TextLayout* pTextLayout =
112 dynamic_cast< TextLayout* >( xLayoutetText.get() );
113
114 ENSURE_OR_THROW( pTextLayout,
115 "BitmapCanvasHelper::drawTextLayout(): TextLayout not compatible with this canvas" );
116
117 pTextLayout->draw( mpTarget->getGraphics(),
118 viewState,
119 renderState,
121 mpDevice,
122 mpTarget->hasAlpha() );
123 }
124
125 return uno::Reference< rendering::XCachedPrimitive >(nullptr);
126 }
127
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*/ )
136 {
137 // TODO(F2): copyRect NYI
138 }
139
140 geometry::IntegerSize2D BitmapCanvasHelper::getSize()
141 {
142 if( !mpTarget )
143 return geometry::IntegerSize2D(1, 1);
145 }
146
147 uno::Reference< rendering::XBitmap > BitmapCanvasHelper::getScaledBitmap( const geometry::RealSize2D& /*newSize*/,
148 bool /*beFast*/ )
149 {
150 // TODO(F1):
151 return uno::Reference< rendering::XBitmap >();
152 }
153
154 uno::Sequence< sal_Int8 > BitmapCanvasHelper::getData( rendering::IntegerBitmapLayout& bitmapLayout,
155 const geometry::IntegerRectangle2D& rect )
156 {
157 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getData()" );
158
160 "::dxcanvas::BitmapCanvasHelper::getData(): disposed" );
161
162 bitmapLayout = getMemoryLayout();
163 return mpTarget->getData(bitmapLayout,rect);
164 }
165
166 void BitmapCanvasHelper::setData( const uno::Sequence< sal_Int8 >& data,
167 const rendering::IntegerBitmapLayout& bitmapLayout,
168 const geometry::IntegerRectangle2D& rect )
169 {
170 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setData()" );
171
173 "::dxcanvas::BitmapCanvasHelper::setData(): disposed" );
174
175 mpTarget->setData(data,bitmapLayout,rect);
176 }
177
178 void BitmapCanvasHelper::setPixel( const uno::Sequence< sal_Int8 >& color,
179 const rendering::IntegerBitmapLayout& bitmapLayout,
180 const geometry::IntegerPoint2D& pos )
181 {
182 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setPixel()" );
183
185 "::dxcanvas::BitmapCanvasHelper::setPixel(): disposed" );
186
187 mpTarget->setPixel(color,bitmapLayout,pos);
188 }
189
190 uno::Sequence< sal_Int8 > BitmapCanvasHelper::getPixel( rendering::IntegerBitmapLayout& bitmapLayout,
191 const geometry::IntegerPoint2D& pos )
192 {
193 SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getPixel()" );
194
196 "::dxcanvas::BitmapCanvasHelper::getPixel(): disposed" );
197
198 bitmapLayout = getMemoryLayout();
199 return mpTarget->getPixel(bitmapLayout,pos);
200 }
201
202 uno::Reference< rendering::XBitmapPalette > BitmapCanvasHelper::getPalette()
203 {
204 // TODO(F1): Palette bitmaps NYI
205 return uno::Reference< rendering::XBitmapPalette >();
206 }
207
208 rendering::IntegerBitmapLayout BitmapCanvasHelper::getMemoryLayout()
209 {
210 if( !mpTarget )
211 return rendering::IntegerBitmapLayout(); // we're disposed
212
214 }
216 {
217 return mpTarget && mpTarget->hasAlpha();
218 }
219}
220
221/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::geometry::IntegerSize2D getSize()
css::rendering::IntegerBitmapLayout getMemoryLayout()
IBitmapSharedPtr mpTarget
Render target.
void setPixel(const css::uno::Sequence< sal_Int8 > &color, const css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerPoint2D &pos)
css::uno::Reference< css::rendering::XCachedPrimitive > drawTextLayout(const css::rendering::XCanvas *pCanvas, const css::uno::Reference< css::rendering::XTextLayout > &laidOutText, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Sequence< sal_Int8 > getData(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerRectangle2D &rect)
css::uno::Sequence< sal_Int8 > getPixel(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerPoint2D &pos)
css::uno::Reference< css::rendering::XBitmap > getScaledBitmap(const css::geometry::RealSize2D &newSize, bool beFast)
void disposing()
Release all references.
void copyRect(const css::rendering::XCanvas *pCanvas, const css::uno::Reference< css::rendering::XBitmapCanvas > &sourceCanvas, const css::geometry::RealRectangle2D &sourceRect, const css::rendering::ViewState &sourceViewState, const css::rendering::RenderState &sourceRenderState, const css::geometry::RealRectangle2D &destRect, const css::rendering::ViewState &destViewState, const css::rendering::RenderState &destRenderState)
css::uno::Reference< css::rendering::XBitmapPalette > getPalette()
void setData(const css::uno::Sequence< sal_Int8 > &data, const css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerRectangle2D &rect)
void setTarget(const IBitmapSharedPtr &rTarget)
Set the target for rendering operations.
css::rendering::XGraphicDevice * mpDevice
Phyical output device.
::basegfx::B2ISize maOutputOffset
Current (transformation-independent) output buffer offset.
void setTarget(const GraphicsProviderSharedPtr &rTarget)
Set the target for rendering operations.
void disposing()
Release all references.
bool draw(const GraphicsSharedPtr &rGraphics, const css::rendering::ViewState &rViewState, const css::rendering::RenderState &rRenderState, const ::basegfx::B2ISize &rOutputOffset, const css::uno::Reference< css::rendering::XGraphicDevice > &xGraphicDevice, bool bAlphaSurface) const
#define ENSURE_OR_THROW(c, m)
FilterGroup & rTarget
#define SAL_INFO(area, stream)
geometry::IntegerSize2D integerSize2DFromB2ISize(const ::basegfx::B2ISize &rSize)
rendering::IntegerBitmapLayout getStdMemoryLayout(const geometry::IntegerSize2D &rBmpSize)
std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr
Definition: dx_winstuff.hxx:58
std::shared_ptr< IBitmap > IBitmapSharedPtr
Definition: dx_ibitmap.hxx:58
T * mpTarget
size_t pos