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>
34 #include <tools/diagnose_ex.h>
35 
36 #include <canvas/canvastools.hxx>
37 
39 #include "dx_canvasfont.hxx"
40 #include "dx_impltools.hxx"
41 #include "dx_spritecanvas.hxx"
42 #include "dx_textlayout.hxx"
43 
44 
45 using namespace ::com::sun::star;
46 
47 namespace dxcanvas
48 {
50  mpTarget()
51  {}
52 
54  {
55  mpTarget.reset();
57  }
58 
60  {
61  ENSURE_OR_THROW( rTarget,
62  "BitmapCanvasHelper::setTarget(): Invalid target" );
63  ENSURE_OR_THROW( !mpTarget.get(),
64  "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
65 
66  mpTarget = rTarget;
67  CanvasHelper::setTarget(rTarget);
68  }
69 
71  const ::basegfx::B2ISize& rOutputOffset )
72  {
73  ENSURE_OR_THROW( rTarget,
74  "BitmapCanvasHelper::setTarget(): invalid target" );
75  ENSURE_OR_THROW( !mpTarget.get(),
76  "BitmapCanvasHelper::setTarget(): target set, old target would be overwritten" );
77 
78  mpTarget = rTarget;
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);
144 
146  }
147 
148  uno::Reference< rendering::XBitmap > BitmapCanvasHelper::getScaledBitmap( const geometry::RealSize2D& /*newSize*/,
149  bool /*beFast*/ )
150  {
151  // TODO(F1):
152  return uno::Reference< rendering::XBitmap >();
153  }
154 
155  uno::Sequence< sal_Int8 > BitmapCanvasHelper::getData( rendering::IntegerBitmapLayout& bitmapLayout,
156  const geometry::IntegerRectangle2D& rect )
157  {
158  SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getData()" );
159 
161  "::dxcanvas::BitmapCanvasHelper::getData(): disposed" );
162 
163  bitmapLayout = getMemoryLayout();
164  return mpTarget->getData(bitmapLayout,rect);
165  }
166 
167  void BitmapCanvasHelper::setData( const uno::Sequence< sal_Int8 >& data,
168  const rendering::IntegerBitmapLayout& bitmapLayout,
169  const geometry::IntegerRectangle2D& rect )
170  {
171  SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setData()" );
172 
174  "::dxcanvas::BitmapCanvasHelper::setData(): disposed" );
175 
176  mpTarget->setData(data,bitmapLayout,rect);
177  }
178 
179  void BitmapCanvasHelper::setPixel( const uno::Sequence< sal_Int8 >& color,
180  const rendering::IntegerBitmapLayout& bitmapLayout,
181  const geometry::IntegerPoint2D& pos )
182  {
183  SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::setPixel()" );
184 
186  "::dxcanvas::BitmapCanvasHelper::setPixel(): disposed" );
187 
188  mpTarget->setPixel(color,bitmapLayout,pos);
189  }
190 
191  uno::Sequence< sal_Int8 > BitmapCanvasHelper::getPixel( rendering::IntegerBitmapLayout& bitmapLayout,
192  const geometry::IntegerPoint2D& pos )
193  {
194  SAL_INFO( "canvas.directx", "::dxcanvas::BitmapCanvasHelper::getPixel()" );
195 
197  "::dxcanvas::BitmapCanvasHelper::getPixel(): disposed" );
198 
199  bitmapLayout = getMemoryLayout();
200  return mpTarget->getPixel(bitmapLayout,pos);
201  }
202 
203  uno::Reference< rendering::XBitmapPalette > BitmapCanvasHelper::getPalette()
204  {
205  // TODO(F1): Palette bitmaps NYI
206  return uno::Reference< rendering::XBitmapPalette >();
207  }
208 
209  rendering::IntegerBitmapLayout BitmapCanvasHelper::getMemoryLayout()
210  {
211  if( !mpTarget )
212  return rendering::IntegerBitmapLayout(); // we're disposed
213 
215  }
217  {
218  return mpTarget && mpTarget->hasAlpha();
219  }
220 }
221 
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
css::uno::Reference< css::rendering::XBitmapPalette > getPalette()
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)
std::shared_ptr< IBitmap > IBitmapSharedPtr
Definition: dx_ibitmap.hxx:59
css::uno::Sequence< sal_Int8 > getData(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerRectangle2D &rect)
void disposing()
Release all references.
void setTarget(const IBitmapSharedPtr &rTarget)
Set the target for rendering operations.
void setPixel(const css::uno::Sequence< sal_Int8 > &color, const css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerPoint2D &pos)
void setTarget(const GraphicsProviderSharedPtr &rTarget)
Set the target for rendering operations.
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)
geometry::IntegerSize2D integerSize2DFromB2ISize(const ::basegfx::B2IVector &rSize)
css::uno::Reference< css::rendering::XBitmap > getScaledBitmap(const css::geometry::RealSize2D &newSize, bool beFast)
T * mpTarget
::basegfx::B2ISize maOutputOffset
Current (transformation-independent) output buffer offset.
css::rendering::IntegerBitmapLayout getMemoryLayout()
rendering::IntegerBitmapLayout getStdMemoryLayout(const geometry::IntegerSize2D &rBmpSize)
css::rendering::XGraphicDevice * mpDevice
Phyical output device.
void disposing()
Release all references.
#define ENSURE_OR_THROW(c, m)
#define SAL_INFO(area, stream)
css::uno::Sequence< sal_Int8 > getPixel(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerPoint2D &pos)
css::geometry::IntegerSize2D getSize()
IBitmapSharedPtr mpTarget
Render target.
void setData(const css::uno::Sequence< sal_Int8 > &data, const css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerRectangle2D &rect)
std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr
Definition: dx_winstuff.hxx:61