xref: /aoo42x/main/vcl/inc/vcl/canvastools.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _VCL_CANVASTOOLS_HXX
29 #define _VCL_CANVASTOOLS_HXX
30 
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/rendering/XColorSpace.hpp>
34 #include <basegfx/numeric/ftools.hxx>
35 
36 #include <vcl/dllapi.h>
37 
38 class Point;
39 class Size;
40 class Rectangle;
41 class Polygon;
42 class PolyPolygon;
43 class Bitmap;
44 class BitmapEx;
45 class Color;
46 
47 namespace basegfx
48 {
49     class B2DVector;
50     class B2DPoint;
51     class B2DRange;
52     class B2IVector;
53     class B2IPoint;
54     class B2IRange;
55     class B2DPolygon;
56     class B2DPolyPolygon;
57 }
58 
59 namespace com { namespace sun { namespace star { namespace geometry
60 {
61     struct RealPoint2D;
62     struct RealSize2D;
63     struct RealRectangle2D;
64     struct IntegerPoint2D;
65     struct IntegerSize2D;
66     struct IntegerRectangle2D;
67     struct RealBezierSegment2D;
68 } } } }
69 
70 namespace com { namespace sun { namespace star { namespace rendering
71 {
72     class  XGraphicDevice;
73     class  XBitmap;
74     class  XIntegerBitmap;
75     class  XIntegerReadOnlyBitmap;
76     class  XPolyPolygon2D;
77 } } } }
78 
79 namespace vcl
80 {
81     namespace unotools
82     {
83         // Polygon conversions
84         // ===================================================================
85 
86         /** Create an XPolyPolygon from VCL/Tools polygon
87          */
88         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
89 	    	VCL_DLLPUBLIC xPolyPolygonFromPolygon( const ::com::sun::star::uno::Reference<
90                                                          ::com::sun::star::rendering::XGraphicDevice >& 	xGraphicDevice,
91                                                    const ::Polygon&											inputPolygon );
92 
93         /** Create an XPolyPolygon from VCL/Tools polyPolygon
94          */
95         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
96 	    	VCL_DLLPUBLIC xPolyPolygonFromPolyPolygon( const ::com::sun::star::uno::Reference<
97                                                              ::com::sun::star::rendering::XGraphicDevice >& 	xGraphicDevice,
98                                                        const ::PolyPolygon&										inputPolyPolygon );
99 
100         /** Create an VCL/Tools polygon from a point sequence
101          */
102         ::Polygon VCL_DLLPUBLIC polygonFromPoint2DSequence(
103             const ::com::sun::star::uno::Sequence<
104             	::com::sun::star::geometry::RealPoint2D >& rPoints );
105 
106         /** Create an VCL/Tools polyPolygon from a point sequence sequence
107          */
108         ::PolyPolygon VCL_DLLPUBLIC polyPolygonFromPoint2DSequenceSequence(
109             const ::com::sun::star::uno::Sequence<
110             	::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& rPoints );
111 
112         /** Create an VCL/Tools polygon from a bezier segment sequence
113          */
114         ::Polygon VCL_DLLPUBLIC polygonFromBezier2DSequence(
115             const ::com::sun::star::uno::Sequence<
116             	::com::sun::star::geometry::RealBezierSegment2D >& rPoints );
117 
118         /** Create an VCL/Tools polyPolygon from a bezier segment sequence sequence
119          */
120         ::PolyPolygon VCL_DLLPUBLIC polyPolygonFromBezier2DSequenceSequence(
121             const ::com::sun::star::uno::Sequence<
122             	::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > >& rPoints );
123 
124         // Bitmap conversions
125         // ===================================================================
126 
127         /** Create an XBitmap from VCL Bitmap
128          */
129         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
130 	    	VCL_DLLPUBLIC xBitmapFromBitmap( const ::com::sun::star::uno::Reference<
131                                                    ::com::sun::star::rendering::XGraphicDevice >& 	xGraphicDevice,
132                                              const ::Bitmap&										inputBitmap );
133 
134         /** Create an XBitmap from VCL BitmapEx
135          */
136         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
137 	    	VCL_DLLPUBLIC xBitmapFromBitmapEx( const ::com::sun::star::uno::Reference<
138                                                      ::com::sun::star::rendering::XGraphicDevice >& 	xGraphicDevice,
139                                                const ::BitmapEx&										inputBitmap );
140 
141         /** Create a BitmapEx from an XBitmap
142          */
143         ::BitmapEx VCL_DLLPUBLIC bitmapExFromXBitmap( const ::com::sun::star::uno::Reference<
144                                                             ::com::sun::star::rendering::XIntegerReadOnlyBitmap >& xInputBitmap );
145 
146         /** get a unique identifier for identification in XUnoTunnel interface
147          */
148          enum TunnelIdentifierType { Id_BitmapEx = 0 };
149          const com::sun::star::uno::Sequence< sal_Int8 > VCL_DLLPUBLIC getTunnelIdentifier( TunnelIdentifierType eType );
150 
151         // Color conversions (vcl/tools Color <-> canvas standard color space)
152         // ===================================================================
153 
154         /** Create a device-specific color sequence from VCL/Tools color
155 
156             Note that this method assumes a color space equivalent to
157             the one returned from createStandardColorSpace()
158          */
159         ::com::sun::star::uno::Sequence< double >
160             VCL_DLLPUBLIC colorToStdColorSpaceSequence( const Color& rColor );
161 
162         /** Convert color to device color sequence
163 
164             @param rColor
165             Color to convert
166 
167             @param xColorSpace
168             Color space to convert into
169          */
170         ::com::sun::star::uno::Sequence< double >
171         VCL_DLLPUBLIC colorToDoubleSequence( const Color&                                      rColor,
172                                              const ::com::sun::star::uno::Reference<
173                                                    ::com::sun::star::rendering::XColorSpace >& xColorSpace );
174 
175         /** Convert from standard device color space to VCL/Tools color
176 
177             Note that this method assumes a color space equivalent to
178             the one returned from createStandardColorSpace()
179          */
180         Color VCL_DLLPUBLIC stdColorSpaceSequenceToColor(
181             const ::com::sun::star::uno::Sequence< double >& rColor );
182 
183         /** Convert color to device color sequence
184 
185             @param rColor
186             Color sequence to convert from
187 
188             @param xColorSpace
189             Color space to convert from
190          */
191         Color VCL_DLLPUBLIC doubleSequenceToColor( const ::com::sun::star::uno::Sequence< double >   rColor,
192                                                    const ::com::sun::star::uno::Reference<
193                                                          ::com::sun::star::rendering::XColorSpace >& xColorSpace );
194 
195         /// Convert [0,1] double value to [0,255] int
196         inline sal_Int8 toByteColor( double val )
197         {
198             return sal::static_int_cast<sal_Int8>(
199                 basegfx::fround(val*255.0));
200         }
201 
202         /// Convert [0,255] int value to [0,1] double value
203         inline double toDoubleColor( sal_uInt8 val )
204         {
205             return val / 255.0;
206         }
207 
208         /// Create a standard color space suitable for VCL RGB color
209         ::com::sun::star::uno::Reference<
210             ::com::sun::star::rendering::XColorSpace> VCL_DLLPUBLIC createStandardColorSpace();
211 
212         // Geometry conversions (vcl/tools <-> x)
213         // ===================================================================
214 
215         // geometry::Real
216         ::com::sun::star::geometry::RealSize2D  		VCL_DLLPUBLIC size2DFromSize( const Size& );
217         ::com::sun::star::geometry::RealPoint2D 		VCL_DLLPUBLIC point2DFromPoint( const Point& );
218         ::com::sun::star::geometry::RealRectangle2D 	VCL_DLLPUBLIC rectangle2DFromRectangle( const Rectangle& );
219 
220         Size  											VCL_DLLPUBLIC sizeFromRealSize2D( const ::com::sun::star::geometry::RealSize2D& );
221         Point 											VCL_DLLPUBLIC pointFromRealPoint2D( const ::com::sun::star::geometry::RealPoint2D& );
222         Rectangle 										VCL_DLLPUBLIC rectangleFromRealRectangle2D( const ::com::sun::star::geometry::RealRectangle2D& );
223 
224         // geometry::Integer
225         ::com::sun::star::geometry::IntegerSize2D  		VCL_DLLPUBLIC integerSize2DFromSize( const Size& );
226         ::com::sun::star::geometry::IntegerPoint2D 		VCL_DLLPUBLIC integerPoint2DFromPoint( const Point& );
227         ::com::sun::star::geometry::IntegerRectangle2D 	VCL_DLLPUBLIC integerRectangle2DFromRectangle( const Rectangle& );
228 
229         Size  											VCL_DLLPUBLIC sizeFromIntegerSize2D( const ::com::sun::star::geometry::IntegerSize2D& );
230         Point 											VCL_DLLPUBLIC pointFromIntegerPoint2D( const ::com::sun::star::geometry::IntegerPoint2D& );
231         Rectangle 										VCL_DLLPUBLIC rectangleFromIntegerRectangle2D( const ::com::sun::star::geometry::IntegerRectangle2D& );
232 
233         // basegfx::B2D
234         Size  						VCL_DLLPUBLIC sizeFromB2DSize( const ::basegfx::B2DVector& );
235         Point 						VCL_DLLPUBLIC pointFromB2DPoint( const ::basegfx::B2DPoint& );
236         Rectangle 					VCL_DLLPUBLIC rectangleFromB2DRectangle( const ::basegfx::B2DRange& );
237 
238         basegfx::B2DVector  		VCL_DLLPUBLIC b2DSizeFromSize( const Size& );
239         basegfx::B2DPoint			VCL_DLLPUBLIC b2DPointFromPoint( const Point& );
240         basegfx::B2DRange			VCL_DLLPUBLIC b2DRectangleFromRectangle( const Rectangle& );
241 
242         // basegfx::B2I
243         Size  						VCL_DLLPUBLIC sizeFromB2ISize( const ::basegfx::B2IVector& );
244         Point 						VCL_DLLPUBLIC pointFromB2IPoint( const ::basegfx::B2IPoint& );
245         Rectangle 					VCL_DLLPUBLIC rectangleFromB2IRectangle( const ::basegfx::B2IRange& );
246 
247         basegfx::B2IVector  		VCL_DLLPUBLIC b2ISizeFromSize( const Size& );
248         basegfx::B2IPoint			VCL_DLLPUBLIC b2IPointFromPoint( const Point& );
249         basegfx::B2IRange			VCL_DLLPUBLIC b2IRectangleFromRectangle( const Rectangle& );
250     }
251 }
252 
253 #endif /* _VCL_CANVASTOOLS_HXX */
254