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