Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / graphictools.hxx
blob01f1e7ae8fda981075082c1702421306f33e2812
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_GRAPHICTOOLS_HXX
21 #define INCLUDED_VCL_GRAPHICTOOLS_HXX
23 #include <vcl/dllapi.h>
24 #include <sal/types.h>
25 #include <rtl/string.hxx>
26 #include <tools/color.hxx>
27 #include <tools/poly.hxx>
28 #include <vcl/graph.hxx>
30 #include <memory>
31 #include <vector>
33 class SvStream;
35 /** Encapsulates geometry and associated attributes of a graphical 'pen stroke'
37 @attention Widespread use is deprecated. See declarations above
38 for the way to go. Especially the copied enums from svx/xenum.hxx
39 are troublesome.
41 Use this class to store geometry and attributes of a graphical
42 'pen stroke', such as pen width, dashing etc. The geometry is the
43 so-called 'path' along which the stroke is traced, with the given
44 pen width. The cap type determines how the open ends of the path
45 should be drawn. If the geometry consists of more than one
46 segment, the join type determines in which way the segments are
47 joined.
49 class VCL_DLLPUBLIC SvtGraphicStroke
51 public:
52 /// Style for open stroke ends
53 enum CapType
55 /// No additional cap
56 capButt=0,
57 /// Half-round cap at the line end, the center lying at the end point
58 capRound,
59 /// Half-square cap at the line end, the center lying at the end point
60 capSquare
62 /// Style for joins of individual stroke segments
63 enum JoinType
65 /// Extend segment edges, until they cross
66 joinMiter=0,
67 /// Connect segments by a filled round arc
68 joinRound,
69 /// Connect segments by a direct straight line
70 joinBevel,
71 /// Perform no join, leads to visible gaps between thick line segments
72 joinNone
74 typedef ::std::vector< double > DashArray;
76 SvtGraphicStroke();
77 /** All in one constructor
79 See accessor method descriptions for argument description
81 SvtGraphicStroke( const tools::Polygon& rPath,
82 const tools::PolyPolygon& rStartArrow,
83 const tools::PolyPolygon& rEndArrow,
84 double fTransparency,
85 double fStrokeWidth,
86 CapType aCap,
87 JoinType aJoin,
88 double fMiterLimit,
89 const DashArray& rDashArray ); // TODO: Dash array offset (position where to start, see PS)
91 // accessors
92 /// Query path to stroke
93 void getPath ( tools::Polygon& ) const;
94 /** Get the polygon that is put at the start of the line
96 The polygon is in a special normalized position: the center of
97 the stroked path will meet the given polygon at (0,0) from
98 negative y values. Thus, an arrow would have its baseline on
99 the x axis, going upwards to positive y values. Furthermore,
100 the polygon is also scaled in a special way: the width of the
101 joining stroke is defined to be
102 SvtGraphicStroke::normalizedArrowWidth (0x10000), i.e. ranging
103 from x=-0x8000 to x=0x8000. So, if the arrow does have this
104 width, it has to fit every stroke with every stroke width
105 exactly.
107 void getStartArrow ( tools::PolyPolygon& ) const;
108 /** Get the polygon that is put at the end of the line
110 The polygon is in a special normalized position, and already
111 scaled to the desired size: the center of the stroked path
112 will meet the given polygon at (0,0) from negative y
113 values. Thus, an arrow would have its baseline on the x axis,
114 going upwards to positive y values. Furthermore, the polygon
115 is also scaled in a special way: the width of the joining
116 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth
117 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. So, if the
118 arrow does have this width, it has to fit every stroke with
119 every stroke width exactly.
121 void getEndArrow ( tools::PolyPolygon& ) const;
122 /** Get stroke transparency
124 @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
126 double getTransparency () const { return mfTransparency;}
127 /// Get width of the stroke
128 double getStrokeWidth () const { return mfStrokeWidth;}
129 /// Get the style in which open stroke ends are drawn
130 CapType getCapType () const { return maCapType;}
131 /// Get the style in which the stroke segments are joined
132 JoinType getJoinType () const { return maJoinType;}
133 /// Get the maximum length of mitered joins
134 double getMiterLimit () const { return mfMiterLimit;}
135 /// Get an array of "on" and "off" lengths for stroke dashing
136 void getDashArray ( DashArray& ) const;
138 // mutators
139 /// Set path to stroke
140 void setPath ( const tools::Polygon& );
141 /** Set the polygon that is put at the start of the line
143 The polygon has to be in a special normalized position, and
144 already scaled to the desired size: the center of the stroked
145 path will meet the given polygon at (0,0) from negative y
146 values. Thus, an arrow would have its baseline on the x axis,
147 going upwards to positive y values. Furthermore, the polygon
148 also has to be scaled appropriately: the width of the joining
149 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth
150 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. If your
151 arrow does have this width, it will fit every stroke with
152 every stroke width exactly.
154 void setStartArrow ( const tools::PolyPolygon& );
155 /** Set the polygon that is put at the end of the line
157 The polygon has to be in a special normalized position, and
158 already scaled to the desired size: the center of the stroked
159 path will meet the given polygon at (0,0) from negative y
160 values. Thus, an arrow would have its baseline on the x axis,
161 going upwards to positive y values. Furthermore, the polygon
162 also has to be scaled appropriately: the width of the joining
163 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth
164 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. If your
165 arrow does have this width, it will fit every stroke with
166 every stroke width exactly.
168 void setEndArrow ( const tools::PolyPolygon& );
169 /// Affine scaling in both X and Y dimensions
170 void scale ( double fScaleX, double fScaleY );
172 private:
173 // friends
174 VCL_DLLPUBLIC friend SvStream& WriteSvtGraphicStroke( SvStream& rOStm, const SvtGraphicStroke& rClass );
175 VCL_DLLPUBLIC friend SvStream& ReadSvtGraphicStroke( SvStream& rIStm, SvtGraphicStroke& rClass );
177 tools::Polygon maPath;
178 tools::PolyPolygon maStartArrow;
179 tools::PolyPolygon maEndArrow;
180 double mfTransparency;
181 double mfStrokeWidth;
182 CapType maCapType;
183 JoinType maJoinType;
184 double mfMiterLimit;
185 DashArray maDashArray;
188 /** Encapsulates geometry and associated attributes of a filled area
190 @attention Widespread use is deprecated. See declarations above
191 for the way to go. Especially the copied enums from svx/xenum.hxx
192 is troublesome.
194 Use this class to store geometry and attributes of a filled area,
195 such as fill color, transparency, texture or hatch. The geometry
196 is the so-called 'path', whose inner area will get filled
197 according to the attributes set. If the path is intersecting, or
198 one part of the path is lying fully within another part, then the
199 fill rule determines which parts are filled and which are not.
201 class VCL_DLLPUBLIC SvtGraphicFill
203 public:
204 /// Type of fill algorithm used
205 enum FillRule
207 /** Non-zero winding rule
209 Fill shape scanline-wise. Starting at the left, determine
210 the winding number as follows: every segment crossed that
211 runs counter-clockwise adds one to the winding number,
212 every segment crossed that runs clockwise subtracts
213 one. The part of the scanline where the winding number is
214 non-zero gets filled.
216 fillNonZero=0,
217 /** Even-odd fill rule
219 Fill shape scanline-wise. Starting at the left, count the
220 number of segments crossed. If this number is odd, the
221 part of the scanline is filled, otherwise not.
223 fillEvenOdd
225 /// Type of filling used
226 enum FillType
228 /// Fill with a specified solid color
229 fillSolid=0,
230 /// Fill with the specified gradient
231 fillGradient,
232 /// Fill with the specified hatch
233 fillHatch,
234 /// Fill with the specified texture (a Graphic object)
235 fillTexture
237 /// Type of hatching used
238 enum HatchType
240 /// horizontal parallel lines, one unit apart
241 hatchSingle=0,
242 /// horizontal and vertical orthogonally crossing lines, one unit apart
243 hatchDouble,
244 /// three crossing lines, like HatchType::hatchDouble, but
245 /// with an additional diagonal line, rising to the upper
246 /// right corner. The first diagonal line goes through the
247 /// upper left corner, the other are each spaced a unit apart.
248 hatchTriple
250 /// Type of gradient used
251 enum class GradientType {Linear, Radial, Rectangular};
252 /// Special values for gradient step count
253 enum { gradientStepsInfinite=0 };
254 /** Homogeneous 2D transformation matrix
256 This is a 2x3 matrix representing an affine transformation on
257 the R^2, in the usual C/C++ row major form. It is structured as follows:
258 <pre>
259 a b t_x
260 c d t_y
261 0 0 1
262 </pre>
263 where the lowest line is not stored in the matrix, since it is
264 constant. Variables t_x and t_y contain translational
265 components, a to d rotation, scale and shear (for details,
266 look up your favorite linear algebra/computer graphics book).
268 struct VCL_DLLPUBLIC Transform
270 enum { MatrixSize=6 };
271 Transform();
272 double matrix[MatrixSize];
275 SvtGraphicFill();
276 /** All in one constructor
278 See accessor method descriptions for argument description
280 SvtGraphicFill( const tools::PolyPolygon& rPath,
281 Color aFillColor,
282 double fTransparency,
283 FillRule aFillRule,
284 FillType aFillType, // TODO: Multitexturing
285 const Transform& aFillTransform,
286 bool bTiling,
287 HatchType aHatchType, // TODO: vector of directions and start points
288 Color aHatchColor,
289 GradientType aGradientType, // TODO: Transparent gradients (orthogonal to normal ones)
290 Color aGradient1stColor, // TODO: vector of colors and offsets
291 Color aGradient2ndColor,
292 sal_Int32 aGradientStepCount, // numbers of steps to render the gradient. gradientStepsInfinite means infinitely many.
293 const Graphic& aFillGraphic );
295 // accessors
296 /// Query path to fill
297 void getPath ( tools::PolyPolygon& ) const;
298 /// Get color used for solid fills
299 const Color& getFillColor () const { return maFillColor;}
300 /** Get stroke transparency
302 @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
304 double getTransparency () const { return mfTransparency;}
305 /// Get fill rule used
306 FillRule getFillRule () const { return maFillRule;}
307 /** Get fill type used
309 Currently, only one of the fill types can be used
310 simultaneously. If you specify e.g. FillRule::fillGradient,
311 hatching, texture and solid fill color are ignored.
313 FillType getFillType () const { return maFillType;}
314 /** Get transformation applied to hatch, gradient or texture during fill
316 A fill operation generally starts at the top left position of
317 the object's bounding box. At that position (if tiling is on,
318 also all successive positions), the specified fill graphic is
319 rendered, after applying the fill transformation to it. For
320 example, if the fill transformation contains a translation,
321 the fill graphic is rendered at the object's bounding box's
322 top left corner plus the translation components.
325 void getTransform ( Transform& ) const;
326 /// deprecated
327 bool IsTiling () const { return mbTiling;}
328 /** Query state of texture tiling
330 @return true, if texture is tiled, false, if output only once.
332 bool isTiling () const { return mbTiling;}
333 /// Get type of gradient used
334 GradientType getGradientType () const { return maGradientType;}
336 /** Get the texture graphic used
338 The Graphic object returned is used to fill the geometry, if
339 the FillType is fillTexture. The Graphic object is always
340 assumed to be of size 1x1, the transformation is used to scale
341 it to the appropriate size.
343 void getGraphic ( Graphic& ) const;
345 // mutators
346 /// Set path to fill
347 void setPath ( const tools::PolyPolygon& rPath );
349 private:
350 // friends
351 VCL_DLLPUBLIC friend SvStream& WriteSvtGraphicFill( SvStream& rOStm, const SvtGraphicFill& rClass );
352 VCL_DLLPUBLIC friend SvStream& ReadSvtGraphicFill( SvStream& rIStm, SvtGraphicFill& rClass );
354 tools::PolyPolygon maPath;
355 Color maFillColor;
356 double mfTransparency;
357 FillRule maFillRule;
358 FillType maFillType;
359 Transform maFillTransform;
360 bool mbTiling;
361 HatchType maHatchType;
362 Color maHatchColor;
363 GradientType maGradientType;
364 Color maGradient1stColor;
365 Color maGradient2ndColor;
366 sal_Int32 maGradientStepCount;
367 Graphic maFillGraphic;
370 #endif // INCLUDED_VCL_GRAPHICTOOLS_HXX
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */