LibreOffice Module canvas (master)  1
devicehelper.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 
24 #include <canvas/canvastools.hxx>
25 #include <rtl/instance.hxx>
26 #include <tools/stream.hxx>
27 #include <vcl/canvastools.hxx>
28 #include <vcl/dibtools.hxx>
29 
30 #include "canvasbitmap.hxx"
31 #include "devicehelper.hxx"
32 
33 using namespace ::com::sun::star;
34 
35 namespace vclcanvas
36 {
38  mpOutDev()
39  {}
40 
42  {
43  mpOutDev = rOutDev;
44  }
45 
46  geometry::RealSize2D DeviceHelper::getPhysicalResolution()
47  {
48  if( !mpOutDev )
50 
51  // Map a one-by-one millimeter box to pixel
52  OutputDevice& rOutDev = mpOutDev->getOutDev();
53  const MapMode aOldMapMode( rOutDev.GetMapMode() );
54  rOutDev.SetMapMode( MapMode(MapUnit::MapMM) );
55  const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) );
56  rOutDev.SetMapMode( aOldMapMode );
57 
58  return vcl::unotools::size2DFromSize( aPixelSize );
59  }
60 
61  geometry::RealSize2D DeviceHelper::getPhysicalSize()
62  {
63  if( !mpOutDev )
65 
66  // Map the pixel dimensions of the output window to millimeter
67  OutputDevice& rOutDev = mpOutDev->getOutDev();
68  const MapMode aOldMapMode( rOutDev.GetMapMode() );
69  rOutDev.SetMapMode( MapMode(MapUnit::MapMM) );
70  const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) );
71  rOutDev.SetMapMode( aOldMapMode );
72 
73  return vcl::unotools::size2DFromSize( aLogSize );
74  }
75 
76  uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
77  const uno::Reference< rendering::XGraphicDevice >& ,
78  const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
79  {
80  uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
81  if( !mpOutDev )
82  return xPoly; // we're disposed
83 
84  xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
86  // vcl only handles even_odd polygons
87  xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
88 
89  return xPoly;
90  }
91 
92  uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
93  const uno::Reference< rendering::XGraphicDevice >& ,
94  const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
95  {
96  uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
97  if( !mpOutDev )
98  return xPoly; // we're disposed
99 
100  xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
102  // vcl only handles even_odd polygons
103  xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
104 
105  return xPoly;
106  }
107 
108  uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
109  const uno::Reference< rendering::XGraphicDevice >& rDevice,
110  const geometry::IntegerSize2D& size )
111  {
112  if( !mpOutDev )
113  return uno::Reference< rendering::XBitmap >(); // we're disposed
114 
115  return uno::Reference< rendering::XBitmap >(
116  new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
117  false,
118  *rDevice,
119  mpOutDev ) );
120  }
121 
122  uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
123  const uno::Reference< rendering::XGraphicDevice >& ,
124  const geometry::IntegerSize2D& )
125  {
126  return uno::Reference< rendering::XVolatileBitmap >();
127  }
128 
129  uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
130  const uno::Reference< rendering::XGraphicDevice >& rDevice,
131  const geometry::IntegerSize2D& size )
132  {
133  if( !mpOutDev )
134  return uno::Reference< rendering::XBitmap >(); // we're disposed
135 
136  return uno::Reference< rendering::XBitmap >(
137  new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
138  true,
139  *rDevice,
140  mpOutDev ) );
141  }
142 
143  uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
144  const uno::Reference< rendering::XGraphicDevice >& ,
145  const geometry::IntegerSize2D& )
146  {
147  return uno::Reference< rendering::XVolatileBitmap >();
148  }
149 
151  {
152  // release all references
153  mpOutDev.reset();
154  }
155 
157  {
158  return css::uno::Any(false);
159  }
160 
162  {
163  if( !mpOutDev )
164  return uno::Any();
165 
166  return uno::Any(
167  reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) );
168  }
169 
171  {
172  return getDeviceHandle();
173  }
174 
175  namespace
176  {
177  struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
178  DeviceColorSpace>
179  {
180  uno::Reference<rendering::XColorSpace> operator()()
181  {
182  uno::Reference< rendering::XColorSpace > xColorSpace = canvas::tools::getStdColorSpace();
183  assert( xColorSpace.is() );
184  return xColorSpace;
185  }
186  };
187  }
188 
189  uno::Reference<rendering::XColorSpace> const & DeviceHelper::getColorSpace() const
190  {
191  // always the same
192  return DeviceColorSpace::get();
193  }
194 
196  {
197  static sal_Int32 nFilePostfixCount(0);
198 
199  if( !mpOutDev )
200  return;
201 
202  OUString aFilename = "dbg_frontbuffer" + OUString::number(nFilePostfixCount) + ".bmp";
203 
204  SvFileStream aStream( aFilename, StreamMode::STD_READWRITE );
205 
206  const ::Point aEmptyPoint;
207  OutputDevice& rOutDev = mpOutDev->getOutDev();
208  bool bOldMap( rOutDev.IsMapModeEnabled() );
209  rOutDev.EnableMapMode( false );
210  WriteDIB(rOutDev.GetBitmapEx(aEmptyPoint, rOutDev.GetOutputSizePixel()), aStream, false);
211  rOutDev.EnableMapMode( bOldMap );
212 
213  ++nFilePostfixCount;
214  }
215 
216 }
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
css::uno::Reference< css::rendering::XColorSpace > const & getColorSpace() const
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
bool IsMapModeEnabled() const
const MapMode & GetMapMode() const
css::uno::Any getSurfaceHandle() const
void EnableMapMode(bool bEnable=true)
void SetMapMode()
css::uno::Reference< css::rendering::XLinePolyPolygon2D > createCompatibleLinePolyPolygon(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< css::geometry::RealPoint2D > > &points)
css::uno::Any isAccelerated() const
Size sizeFromIntegerSize2D(const geometry::IntegerSize2D &rSize)
::basegfx::B2DPolyPolygon polyPolygonFromPoint2DSequenceSequence(const uno::Sequence< uno::Sequence< geometry::RealPoint2D > > &points)
css::geometry::RealSize2D getPhysicalResolution()
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void dumpScreenContent() const
called when DumpScreenContent property is enabled on XGraphicDevice, and writes out bitmaps of curren...
void disposing()
Dispose all internal references.
::basegfx::B2DPolyPolygon polyPolygonFromBezier2DSequenceSequence(const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > &curves)
css::uno::Reference< css::rendering::XBitmap > createCompatibleBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
void init(const OutDevProviderSharedPtr &rOutDev)
OutDevProviderSharedPtr mpOutDev
For retrieving device info.
css::uno::Any getDeviceHandle() const
geometry::RealSize2D size2DFromSize(const Size &rSize)
Size GetOutputSizePixel() const
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
geometry::RealSize2D createInfiniteSize2D()
Create a RealSize2D with both coordinate values set to +infinity.
Definition: canvastools.cxx:68
css::geometry::RealSize2D getPhysicalSize()
BitmapEx GetBitmapEx(const Point &rSrcPt, const Size &rSize) const
bool WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
css::uno::Reference< css::rendering::XBezierPolyPolygon2D > createCompatibleBezierPolyPolygon(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< css::geometry::RealBezierSegment2D > > &points)
css::uno::Reference< css::rendering::XBitmap > createCompatibleAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
uno::Reference< rendering::XIntegerBitmapColorSpace > const & getStdColorSpace()
Return a color space for a default RGBA integer format.