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