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_GRAPHICTOOLS_HXX_ 25 #define _VCL_GRAPHICTOOLS_HXX_ 26 27 #include <vcl/dllapi.h> 28 #include <sal/types.h> 29 #include <rtl/string.hxx> 30 #include <tools/color.hxx> 31 #include <tools/poly.hxx> 32 #include <tools/stream.hxx> 33 #include <vcl/graph.hxx> 34 35 #ifndef INCLUDED_MEMORY 36 #include <memory> 37 #define INCLUDED_MEMORY 38 #endif 39 40 #ifndef INCLUDED_VECTOR 41 #include <vector> 42 #define INCLUDED_VECTOR 43 #endif 44 45 /** Encapsulates geometry and associated attributes of a graphical 'pen stroke' 46 47 @attention Widespread use is deprecated. See declarations above 48 for the way to go. Especially the copied enums from svx/xenum.hxx 49 are troublesome. 50 51 Use this class to store geometry and attributes of a graphical 52 'pen stroke', such as pen width, dashing etc. The geometry is the 53 so-called 'path' along which the stroke is traced, with the given 54 pen width. The cap type determines how the open ends of the path 55 should be drawn. If the geometry consists of more than one 56 segment, the join type determines in which way the segments are 57 joined. 58 */ 59 class VCL_DLLPUBLIC SvtGraphicStroke 60 { 61 public: 62 /// Style for open stroke ends 63 enum CapType 64 { 65 /// No additional cap 66 capButt=0, 67 /// Half-round cap at the line end, the center lying at the end point 68 capRound, 69 /// Half-square cap at the line end, the center lying at the end point 70 capSquare 71 }; 72 /// Style for joins of individual stroke segments 73 enum JoinType 74 { 75 /// Extend segment edges, until they cross 76 joinMiter=0, 77 /// Connect segments by a filled round arc 78 joinRound, 79 /// Connect segments by a direct straight line 80 joinBevel, 81 /// Perform no join, leads to visible gaps between thick line segments 82 joinNone 83 }; 84 enum 85 { 86 /// Width of stroke start/end arrow to exactly fit the joining stroke 87 normalizedArrowWidth=65536 88 }; 89 typedef ::std::vector< double > DashArray; 90 91 SvtGraphicStroke(); 92 /** All in one constructor 93 94 See accessor method descriptions for argument description 95 */ 96 SvtGraphicStroke( const Polygon& rPath, 97 const PolyPolygon& rStartArrow, 98 const PolyPolygon& rEndArrow, 99 double fTransparency, 100 double fStrokeWidth, 101 CapType aCap, 102 JoinType aJoin, 103 double fMiterLimit, 104 const DashArray& rDashArray ); // TODO: Dash array offset (position where to start, see PS) 105 106 // accessors 107 /// Query path to stroke 108 void getPath ( Polygon& ) const; 109 /** Get the polygon that is put at the start of the line 110 111 The polygon is in a special normalized position: the center of 112 the stroked path will meet the given polygon at (0,0) from 113 negative y values. Thus, an arrow would have its baseline on 114 the x axis, going upwards to positive y values. Furthermore, 115 the polygon is also scaled in a special way: the width of the 116 joining stroke is defined to be 117 SvtGraphicStroke::normalizedArrowWidth (0x10000), i.e. ranging 118 from x=-0x8000 to x=0x8000. So, if the arrow does have this 119 width, it has to fit every stroke with every stroke width 120 exactly. 121 */ 122 void getStartArrow ( PolyPolygon& ) const; 123 /** Get the polygon that is put at the end of the line 124 125 The polygon is in a special normalized position, and already 126 scaled to the desired size: the center of the stroked path 127 will meet the given polygon at (0,0) from negative y 128 values. Thus, an arrow would have its baseline on the x axis, 129 going upwards to positive y values. Furthermore, the polygon 130 is also scaled in a special way: the width of the joining 131 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth 132 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. So, if the 133 arrow does have this width, it has to fit every stroke with 134 every stroke width exactly. 135 */ 136 void getEndArrow ( PolyPolygon& ) const; 137 /** Get stroke transparency 138 139 @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent) 140 */ 141 double getTransparency () const; 142 /// Get width of the stroke 143 double getStrokeWidth () const; 144 /// Get the style in which open stroke ends are drawn 145 CapType getCapType () const; 146 /// Get the style in which the stroke segments are joined 147 JoinType getJoinType () const; 148 /// Get the maximum length of mitered joins 149 double getMiterLimit () const; 150 /// Get an array of "on" and "off" lengths for stroke dashing 151 void getDashArray ( DashArray& ) const; 152 /// Query a textual representation of the object's content 153 ::rtl::OString toString () const; 154 155 // mutators 156 /// Set path to stroke 157 void setPath ( const Polygon& ); 158 /** Set the polygon that is put at the start of the line 159 160 The polygon has to be in a special normalized position, and 161 already scaled to the desired size: the center of the stroked 162 path will meet the given polygon at (0,0) from negative y 163 values. Thus, an arrow would have its baseline on the x axis, 164 going upwards to positive y values. Furthermore, the polygon 165 also has to be scaled appropriately: the width of the joining 166 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth 167 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. If your 168 arrow does have this width, it will fit every stroke with 169 every stroke width exactly. 170 */ 171 void setStartArrow ( const PolyPolygon& ); 172 /** Set the polygon that is put at the end of the line 173 174 The polygon has to be in a special normalized position, and 175 already scaled to the desired size: the center of the stroked 176 path will meet the given polygon at (0,0) from negative y 177 values. Thus, an arrow would have its baseline on the x axis, 178 going upwards to positive y values. Furthermore, the polygon 179 also has to be scaled appropriately: the width of the joining 180 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth 181 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. If your 182 arrow does have this width, it will fit every stroke with 183 every stroke width exactly. 184 */ 185 void setEndArrow ( const PolyPolygon& ); 186 /** Set stroke transparency 187 188 @param fTrans 189 The transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent) 190 */ 191 void setTransparency ( double fTrans ); 192 /// Set width of the stroke 193 void setStrokeWidth ( double ); 194 /// Set the style in which open stroke ends are drawn 195 void setCapType ( CapType ); 196 /// Set the style in which the stroke segments are joined 197 void setJoinType ( JoinType ); 198 /// Set the maximum length of mitered joins 199 void setMiterLimit ( double ); 200 /// Set the array of "on" and "off" lengths for stroke dashing 201 void setDashArray ( const DashArray& ); 202 203 private: 204 // friends 205 VCL_DLLPUBLIC friend SvStream& operator<<( SvStream& rOStm, const SvtGraphicStroke& rClass ); 206 VCL_DLLPUBLIC friend SvStream& operator>>( SvStream& rIStm, SvtGraphicStroke& rClass ); 207 208 Polygon maPath; 209 PolyPolygon maStartArrow; 210 PolyPolygon maEndArrow; 211 double mfTransparency; 212 double mfStrokeWidth; 213 CapType maCapType; 214 JoinType maJoinType; 215 double mfMiterLimit; 216 DashArray maDashArray; 217 }; 218 219 /** Encapsulates geometry and associated attributes of a filled area 220 221 @attention Widespread use is deprecated. See declarations above 222 for the way to go. Especially the copied enums from svx/xenum.hxx 223 is troublesome. 224 225 Use this class to store geometry and attributes of a filled area, 226 such as fill color, transparency, texture or hatch. The geometry 227 is the so-called 'path', whose inner area will get filled 228 according to the attributes set. If the path is intersecting, or 229 one part of the path is lying fully within another part, then the 230 fill rule determines which parts are filled and which are not. 231 */ 232 class VCL_DLLPUBLIC SvtGraphicFill 233 { 234 public: 235 /// Type of fill algorithm used 236 enum FillRule 237 { 238 /** Non-zero winding rule 239 240 Fill shape scanline-wise. Starting at the left, determine 241 the winding number as follows: every segment crossed that 242 runs counter-clockwise adds one to the winding number, 243 every segment crossed that runs clockwise subtracts 244 one. The part of the scanline where the winding number is 245 non-zero gets filled. 246 */ 247 fillNonZero=0, 248 /** Even-odd fill rule 249 250 Fill shape scanline-wise. Starting at the left, count the 251 number of segments crossed. If this number is odd, the 252 part of the scanline is filled, otherwise not. 253 */ 254 fillEvenOdd 255 }; 256 /// Type of filling used 257 enum FillType 258 { 259 /// Fill with a specified solid color 260 fillSolid=0, 261 /// Fill with the specified gradient 262 fillGradient, 263 /// Fill with the specified hatch 264 fillHatch, 265 /// Fill with the specified texture (a Graphic object) 266 fillTexture 267 }; 268 /// Type of hatching used 269 enum HatchType 270 { 271 /// horizontal parallel lines, one unit apart 272 hatchSingle=0, 273 /// horizontal and verticall orthogonally crossing lines, one unit apart 274 hatchDouble, 275 /// three crossing lines, like HatchType::hatchDouble, but 276 /// with an additional diagonal line, rising to the upper 277 /// right corner. The first diagonal line goes through the 278 /// upper left corner, the other are each spaced a unit apart. 279 hatchTriple 280 }; 281 /// Type of gradient used 282 enum GradientType {gradientLinear=0, gradientRadial, gradientRectangular}; 283 /// Special values for gradient step count 284 enum { gradientStepsInfinite=0 }; 285 /** Homogeneous 2D transformation matrix 286 287 This is a 2x3 matrix representing an affine transformation on 288 the R^2, in the usual C/C++ row major form. It is structured as follows: 289 <pre> 290 a b t_x 291 c d t_y 292 0 0 1 293 </pre> 294 where the lowest line is not stored in the matrix, since it is 295 constant. Variables t_x and t_y contain translational 296 components, a to d rotation, scale and shear (for details, 297 look up your favorite linear algebra/computer graphics book). 298 */ 299 struct VCL_DLLPUBLIC Transform 300 { 301 enum { MatrixSize=6 }; 302 Transform(); 303 double matrix[MatrixSize]; 304 }; 305 306 SvtGraphicFill(); 307 /** All in one constructor 308 309 See accessor method descriptions for argument description 310 */ 311 SvtGraphicFill( const PolyPolygon& rPath, 312 Color aFillColor, 313 double fTransparency, 314 FillRule aFillRule, 315 FillType aFillType, // TODO: Multitexturing 316 const Transform& aFillTransform, 317 bool bTiling, 318 HatchType aHatchType, // TODO: vector of directions and start points 319 Color aHatchColor, 320 GradientType aGradientType, // TODO: Transparent gradients (orthogonal to normal ones) 321 Color aGradient1stColor, // TODO: vector of colors and offsets 322 Color aGradient2ndColor, 323 int aGradientStepCount, // numbers of steps to render the gradient. gradientStepsInfinite means infinitely many. 324 const Graphic& aFillGraphic ); 325 326 // accessors 327 /// Query path to fill 328 void getPath ( PolyPolygon& ) const; 329 /// Get color used for solid fills 330 Color getFillColor () const; 331 /** Get stroke transparency 332 333 @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent) 334 */ 335 double getTransparency () const; 336 /// Get fill rule used 337 FillRule getFillRule () const; 338 /** Get fill type used 339 340 Currently, only one of the fill types can be used 341 simultaneously. If you specify e.g. FillRule::fillGradient, 342 hatching, texture and solid fill color are ignored. 343 */ 344 FillType getFillType () const; 345 /** Get transformation applied to hatch, gradient or texture during fill 346 347 A fill operation generally starts at the top left position of 348 the object's bounding box. At that position (if tiling is on, 349 also all successive positions), the specified fill graphic is 350 rendered, after applying the fill transformation to it. For 351 example, if the fill transformation contains a translation, 352 the fill graphic is rendered at the object's bounding box's 353 top left corner plus the translation components. 354 355 */ 356 void getTransform ( Transform& ) const; 357 /// deprecated 358 bool IsTiling () const; 359 /** Query state of texture tiling 360 361 @return true, if texture is tiled, false, if output only once. 362 */ 363 bool isTiling () const; 364 /// Get type of hatch used 365 HatchType getHatchType () const; 366 /// Get color used for drawing the hatch 367 Color getHatchColor () const; 368 /// Get type of gradient used 369 GradientType getGradientType () const; 370 /// Get start color of the gradient 371 Color getGradient1stColor () const; 372 /// Get end color of the gradient 373 Color getGradient2ndColor () const; 374 /** Get the numbers of steps to render the gradient. 375 376 @return the step count. gradientStepsInfinite means infinitely many. 377 */ 378 int getGradientStepCount() const; 379 /** Get the texture graphic used 380 381 The Graphic object returned is used to fill the geometry, if 382 the FillType is fillTexture. The Graphic object is always 383 assumed to be of size 1x1, the transformation is used to scale 384 it to the appropriate size. 385 */ 386 void getGraphic ( Graphic& ) const; 387 /// Query a textual representation of the object's content 388 ::rtl::OString toString () const; 389 390 // mutators 391 /// Set path to fill 392 void setPath ( const PolyPolygon& rPath ); 393 /// Set color used for solid fills 394 void setFillColor ( Color aFillColor ); 395 /** Set stroke transparency 396 397 @param fTransparency 398 The transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent) 399 */ 400 void setTransparency ( double fTransparency ); 401 /// Set fill rule used 402 void setFillRule ( FillRule aFillRule ); 403 /** Set fill type used 404 405 Currently, only one of the fill types can be used 406 simultaneously. If you specify e.g. FillRule::fillGradient, 407 hatching, texture and solid fill color are ignored. 408 */ 409 void setFillType ( FillType aFillType ); 410 /// Set transformation applied to hatch, gradient or texture during fill 411 void setTransform ( const Transform& pTransform ); 412 /** Set state of texture tiling 413 414 @param bTiling 415 If set to true, texture is tiled, if set to false, texture is output only once. 416 */ 417 void setTiling ( bool bTiling = true ); 418 /// Set type of hatch used 419 void setHatchType ( HatchType aHatchType ); 420 /// Set color used for drawing the hatch 421 void setHatchColor ( Color aHatchColor ); 422 /// Set type of gradient used 423 void setGradientType ( GradientType aGradType ); 424 /// Set start color of the gradient 425 void setGradient1stColor ( Color aColor ); 426 /// Set end color of the gradient 427 void setGradient2ndColor ( Color aColor ); 428 /** Set the numbers of steps to render the gradient. 429 430 @param aCount 431 The step count. gradientStepsInfinite means use infinitely many. 432 */ 433 void setGradientStepCount( int aCount ); 434 /// Set the texture graphic used 435 void setGraphic ( const Graphic& rGraphic ); 436 437 private: 438 // friends 439 VCL_DLLPUBLIC friend SvStream& operator<<( SvStream& rOStm, const SvtGraphicFill& rClass ); 440 VCL_DLLPUBLIC friend SvStream& operator>>( SvStream& rIStm, SvtGraphicFill& rClass ); 441 442 PolyPolygon maPath; 443 Color maFillColor; 444 double mfTransparency; 445 FillRule maFillRule; 446 FillType maFillType; 447 Transform maFillTransform; 448 bool mbTiling; 449 HatchType maHatchType; 450 Color maHatchColor; 451 GradientType maGradientType; 452 Color maGradient1stColor; 453 Color maGradient2ndColor; 454 int maGradientStepCount; 455 Graphic maFillGraphic; 456 }; 457 458 #endif /* _VCL_GRAPHICTOOLS_HXX_ */ 459