1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/stream.hxx>
29 #include <vcl/graph.hxx>
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
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
48 class VCL_DLLPUBLIC SvtGraphicStroke
51 /// Style for open stroke ends
56 /// Half-round cap at the line end, the center lying at the end point
58 /// Half-square cap at the line end, the center lying at the end point
61 /// Style for joins of individual stroke segments
64 /// Extend segment edges, until they cross
66 /// Connect segments by a filled round arc
68 /// Connect segments by a direct straight line
70 /// Perform no join, leads to visible gaps between thick line segments
75 /// Width of stroke start/end arrow to exactly fit the joining stroke
76 normalizedArrowWidth
=65536
78 typedef ::std::vector
< double > DashArray
;
81 /** All in one constructor
83 See accessor method descriptions for argument description
85 SvtGraphicStroke( const Polygon
& rPath
,
86 const tools::PolyPolygon
& rStartArrow
,
87 const tools::PolyPolygon
& rEndArrow
,
93 const DashArray
& rDashArray
); // TODO: Dash array offset (position where to start, see PS)
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
111 void getStartArrow ( tools::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 ( tools::PolyPolygon
& ) const;
126 /** Get stroke transparency
128 @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
130 double getTransparency () const { return mfTransparency
;}
131 /// Get width of the stroke
132 double getStrokeWidth () const { return mfStrokeWidth
;}
133 /// Get the style in which open stroke ends are drawn
134 CapType
getCapType () const { return maCapType
;}
135 /// Get the style in which the stroke segments are joined
136 JoinType
getJoinType () const { return maJoinType
;}
137 /// Get the maximum length of mitered joins
138 double getMiterLimit () const { return mfMiterLimit
;}
139 /// Get an array of "on" and "off" lengths for stroke dashing
140 void getDashArray ( DashArray
& ) const;
143 /// Set path to stroke
144 void setPath ( const Polygon
& );
145 /** Set the polygon that is put at the start of the line
147 The polygon has to be in a special normalized position, and
148 already scaled to the desired size: the center of the stroked
149 path will meet the given polygon at (0,0) from negative y
150 values. Thus, an arrow would have its baseline on the x axis,
151 going upwards to positive y values. Furthermore, the polygon
152 also has to be scaled appropriately: the width of the joining
153 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth
154 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. If your
155 arrow does have this width, it will fit every stroke with
156 every stroke width exactly.
158 void setStartArrow ( const tools::PolyPolygon
& );
159 /** Set the polygon that is put at the end of the line
161 The polygon has to be in a special normalized position, and
162 already scaled to the desired size: the center of the stroked
163 path will meet the given polygon at (0,0) from negative y
164 values. Thus, an arrow would have its baseline on the x axis,
165 going upwards to positive y values. Furthermore, the polygon
166 also has to be scaled appropriately: the width of the joining
167 stroke is defined to be SvtGraphicStroke::normalizedArrowWidth
168 (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. If your
169 arrow does have this width, it will fit every stroke with
170 every stroke width exactly.
172 void setEndArrow ( const tools::PolyPolygon
& );
173 /// Affine scaling in both X and Y dimensions
174 void scale ( double fScaleX
, double fScaleY
);
178 VCL_DLLPUBLIC
friend SvStream
& WriteSvtGraphicStroke( SvStream
& rOStm
, const SvtGraphicStroke
& rClass
);
179 VCL_DLLPUBLIC
friend SvStream
& ReadSvtGraphicStroke( SvStream
& rIStm
, SvtGraphicStroke
& rClass
);
182 tools::PolyPolygon maStartArrow
;
183 tools::PolyPolygon maEndArrow
;
184 double mfTransparency
;
185 double mfStrokeWidth
;
189 DashArray maDashArray
;
192 /** Encapsulates geometry and associated attributes of a filled area
194 @attention Widespread use is deprecated. See declarations above
195 for the way to go. Especially the copied enums from svx/xenum.hxx
198 Use this class to store geometry and attributes of a filled area,
199 such as fill color, transparency, texture or hatch. The geometry
200 is the so-called 'path', whose inner area will get filled
201 according to the attributes set. If the path is intersecting, or
202 one part of the path is lying fully within another part, then the
203 fill rule determines which parts are filled and which are not.
205 class VCL_DLLPUBLIC SvtGraphicFill
208 /// Type of fill algorithm used
211 /** Non-zero winding rule
213 Fill shape scanline-wise. Starting at the left, determine
214 the winding number as follows: every segment crossed that
215 runs counter-clockwise adds one to the winding number,
216 every segment crossed that runs clockwise subtracts
217 one. The part of the scanline where the winding number is
218 non-zero gets filled.
221 /** Even-odd fill rule
223 Fill shape scanline-wise. Starting at the left, count the
224 number of segments crossed. If this number is odd, the
225 part of the scanline is filled, otherwise not.
229 /// Type of filling used
232 /// Fill with a specified solid color
234 /// Fill with the specified gradient
236 /// Fill with the specified hatch
238 /// Fill with the specified texture (a Graphic object)
241 /// Type of hatching used
244 /// horizontal parallel lines, one unit apart
246 /// horizontal and verticall orthogonally crossing lines, one unit apart
248 /// three crossing lines, like HatchType::hatchDouble, but
249 /// with an additional diagonal line, rising to the upper
250 /// right corner. The first diagonal line goes through the
251 /// upper left corner, the other are each spaced a unit apart.
254 /// Type of gradient used
255 enum GradientType
{gradientLinear
=0, gradientRadial
, gradientRectangular
};
256 /// Special values for gradient step count
257 enum { gradientStepsInfinite
=0 };
258 /** Homogeneous 2D transformation matrix
260 This is a 2x3 matrix representing an affine transformation on
261 the R^2, in the usual C/C++ row major form. It is structured as follows:
267 where the lowest line is not stored in the matrix, since it is
268 constant. Variables t_x and t_y contain translational
269 components, a to d rotation, scale and shear (for details,
270 look up your favorite linear algebra/computer graphics book).
272 struct VCL_DLLPUBLIC Transform
274 enum { MatrixSize
=6 };
276 double matrix
[MatrixSize
];
280 /** All in one constructor
282 See accessor method descriptions for argument description
284 SvtGraphicFill( const tools::PolyPolygon
& rPath
,
286 double fTransparency
,
288 FillType aFillType
, // TODO: Multitexturing
289 const Transform
& aFillTransform
,
291 HatchType aHatchType
, // TODO: vector of directions and start points
293 GradientType aGradientType
, // TODO: Transparent gradients (orthogonal to normal ones)
294 Color aGradient1stColor
, // TODO: vector of colors and offsets
295 Color aGradient2ndColor
,
296 sal_Int32 aGradientStepCount
, // numbers of steps to render the gradient. gradientStepsInfinite means infinitely many.
297 const Graphic
& aFillGraphic
);
300 /// Query path to fill
301 void getPath ( tools::PolyPolygon
& ) const;
302 /// Get color used for solid fills
303 const Color
& getFillColor () const { return maFillColor
;}
304 /** Get stroke transparency
306 @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
308 double getTransparency () const { return mfTransparency
;}
309 /// Get fill rule used
310 FillRule
getFillRule () const { return maFillRule
;}
311 /** Get fill type used
313 Currently, only one of the fill types can be used
314 simultaneously. If you specify e.g. FillRule::fillGradient,
315 hatching, texture and solid fill color are ignored.
317 FillType
getFillType () const { return maFillType
;}
318 /** Get transformation applied to hatch, gradient or texture during fill
320 A fill operation generally starts at the top left position of
321 the object's bounding box. At that position (if tiling is on,
322 also all successive positions), the specified fill graphic is
323 rendered, after applying the fill transformation to it. For
324 example, if the fill transformation contains a translation,
325 the fill graphic is rendered at the object's bounding box's
326 top left corner plus the translation components.
329 void getTransform ( Transform
& ) const;
331 bool IsTiling () const { return mbTiling
;}
332 /** Query state of texture tiling
334 @return true, if texture is tiled, false, if output only once.
336 bool isTiling () const { return mbTiling
;}
337 /// Get type of gradient used
338 GradientType
getGradientType () const { return maGradientType
;}
340 /** Get the texture graphic used
342 The Graphic object returned is used to fill the geometry, if
343 the FillType is fillTexture. The Graphic object is always
344 assumed to be of size 1x1, the transformation is used to scale
345 it to the appropriate size.
347 void getGraphic ( Graphic
& ) const;
351 void setPath ( const tools::PolyPolygon
& rPath
);
355 VCL_DLLPUBLIC
friend SvStream
& WriteSvtGraphicFill( SvStream
& rOStm
, const SvtGraphicFill
& rClass
);
356 VCL_DLLPUBLIC
friend SvStream
& ReadSvtGraphicFill( SvStream
& rIStm
, SvtGraphicFill
& rClass
);
358 tools::PolyPolygon maPath
;
360 double mfTransparency
;
363 Transform maFillTransform
;
365 HatchType maHatchType
;
367 GradientType maGradientType
;
368 Color maGradient1stColor
;
369 Color maGradient2ndColor
;
370 sal_Int32 maGradientStepCount
;
371 Graphic maFillGraphic
;
374 #endif // INCLUDED_VCL_GRAPHICTOOLS_HXX
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */