Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / canvastools.hxx
blob08b5b6dba64882076ee37522777b9d3f60484a8d
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 .
20 #ifndef INCLUDED_VCL_CANVASTOOLS_HXX
21 #define INCLUDED_VCL_CANVASTOOLS_HXX
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/rendering/XColorSpace.hpp>
26 #include <basegfx/numeric/ftools.hxx>
28 #include <vcl/dllapi.h>
30 class Point;
31 class Size;
32 class Rectangle;
33 class Polygon;
34 namespace tools { class PolyPolygon; }
35 class Bitmap;
36 class BitmapEx;
37 class Color;
39 namespace basegfx
41 class B2DVector;
42 class B2DPoint;
43 class B2DRange;
44 class B2IVector;
45 class B2IPoint;
46 class B2IRange;
47 class B2DPolygon;
48 class B2DPolyPolygon;
51 namespace com { namespace sun { namespace star { namespace geometry
53 struct RealPoint2D;
54 struct RealSize2D;
55 struct RealRectangle2D;
56 struct IntegerPoint2D;
57 struct IntegerSize2D;
58 struct IntegerRectangle2D;
59 struct RealBezierSegment2D;
60 } } } }
62 namespace com { namespace sun { namespace star { namespace rendering
64 class XGraphicDevice;
65 class XBitmap;
66 class XIntegerBitmap;
67 class XIntegerReadOnlyBitmap;
68 class XPolyPolygon2D;
69 } } } }
71 namespace vcl
73 namespace unotools
75 // Bitmap conversions
78 /** Create an XBitmap from VCL BitmapEx
80 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
81 VCL_DLLPUBLIC xBitmapFromBitmapEx( const ::com::sun::star::uno::Reference<
82 ::com::sun::star::rendering::XGraphicDevice >& xGraphicDevice,
83 const ::BitmapEx& inputBitmap );
85 /** Create a BitmapEx from an XBitmap
87 ::BitmapEx VCL_DLLPUBLIC bitmapExFromXBitmap( const ::com::sun::star::uno::Reference<
88 ::com::sun::star::rendering::XIntegerReadOnlyBitmap >& xInputBitmap );
90 // Color conversions (vcl/tools Color <-> canvas standard color space)
93 /** Create a device-specific color sequence from VCL/Tools color
95 Note that this method assumes a color space equivalent to
96 the one returned from createStandardColorSpace()
98 ::com::sun::star::uno::Sequence< double >
99 VCL_DLLPUBLIC colorToStdColorSpaceSequence( const Color& rColor );
101 /** Convert color to device color sequence
103 @param rColor
104 Color to convert
106 @param xColorSpace
107 Color space to convert into
109 ::com::sun::star::uno::Sequence< double >
110 VCL_DLLPUBLIC colorToDoubleSequence( const Color& rColor,
111 const ::com::sun::star::uno::Reference<
112 ::com::sun::star::rendering::XColorSpace >& xColorSpace );
114 /** Convert from standard device color space to VCL/Tools color
116 Note that this method assumes a color space equivalent to
117 the one returned from createStandardColorSpace()
119 Color VCL_DLLPUBLIC stdColorSpaceSequenceToColor(
120 const ::com::sun::star::uno::Sequence< double >& rColor );
122 /** Convert color to device color sequence
124 @param rColor
125 Color sequence to convert from
127 @param xColorSpace
128 Color space to convert from
130 Color VCL_DLLPUBLIC doubleSequenceToColor( const ::com::sun::star::uno::Sequence< double >& rColor,
131 const ::com::sun::star::uno::Reference<
132 ::com::sun::star::rendering::XColorSpace >& xColorSpace );
134 /// Convert [0,1] double value to [0,255] int
135 inline sal_Int8 toByteColor( double val )
137 return sal::static_int_cast<sal_Int8>(
138 basegfx::fround(val*255.0));
141 /// Convert [0,255] int value to [0,1] double value
142 inline double toDoubleColor( sal_uInt8 val )
144 return val / 255.0;
147 /// Create a standard color space suitable for VCL RGB color
148 ::com::sun::star::uno::Reference<
149 ::com::sun::star::rendering::XColorSpace> VCL_DLLPUBLIC createStandardColorSpace();
151 // Geometry conversions (vcl/tools <-> x)
154 // geometry::Real
155 ::com::sun::star::geometry::RealSize2D VCL_DLLPUBLIC size2DFromSize( const Size& );
157 Size VCL_DLLPUBLIC sizeFromRealSize2D( const ::com::sun::star::geometry::RealSize2D& );
159 // geometry::Integer
160 ::com::sun::star::geometry::IntegerSize2D VCL_DLLPUBLIC integerSize2DFromSize( const Size& );
162 Size VCL_DLLPUBLIC sizeFromIntegerSize2D( const ::com::sun::star::geometry::IntegerSize2D& );
163 Point VCL_DLLPUBLIC pointFromIntegerPoint2D( const ::com::sun::star::geometry::IntegerPoint2D& );
164 Rectangle VCL_DLLPUBLIC rectangleFromIntegerRectangle2D( const ::com::sun::star::geometry::IntegerRectangle2D& );
166 // basegfx::B2D
167 Size VCL_DLLPUBLIC sizeFromB2DSize( const ::basegfx::B2DVector& );
168 Point VCL_DLLPUBLIC pointFromB2DPoint( const ::basegfx::B2DPoint& );
169 Rectangle VCL_DLLPUBLIC rectangleFromB2DRectangle( const ::basegfx::B2DRange& );
171 basegfx::B2DVector VCL_DLLPUBLIC b2DSizeFromSize( const Size& );
172 basegfx::B2DPoint VCL_DLLPUBLIC b2DPointFromPoint( const Point& );
173 basegfx::B2DRange VCL_DLLPUBLIC b2DRectangleFromRectangle( const Rectangle& );
175 // basegfx::B2I
176 Point VCL_DLLPUBLIC pointFromB2IPoint( const ::basegfx::B2IPoint& );
177 Rectangle VCL_DLLPUBLIC rectangleFromB2IRectangle( const ::basegfx::B2IRange& );
181 #endif // INCLUDED_VCL_CANVASTOOLS_HXX
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */