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