Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _VCL_GRAPHICTOOLS_HXX_
21 : #define _VCL_GRAPHICTOOLS_HXX_
22 :
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>
30 :
31 : #include <memory>
32 : #include <vector>
33 :
34 : /** Encapsulates geometry and associated attributes of a graphical 'pen stroke'
35 :
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.
39 :
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.
47 : */
48 283 : class VCL_DLLPUBLIC SvtGraphicStroke
49 : {
50 : public:
51 : /// Style for open stroke ends
52 : enum CapType
53 : {
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
60 : };
61 : /// Style for joins of individual stroke segments
62 : enum JoinType
63 : {
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
72 : };
73 : enum
74 : {
75 : /// Width of stroke start/end arrow to exactly fit the joining stroke
76 : normalizedArrowWidth=65536
77 : };
78 : typedef ::std::vector< double > DashArray;
79 :
80 : SvtGraphicStroke();
81 : /** All in one constructor
82 :
83 : See accessor method descriptions for argument description
84 : */
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)
94 :
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
99 :
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.
110 : */
111 : void getStartArrow ( PolyPolygon& ) const;
112 : /** Get the polygon that is put at the end of the line
113 :
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.
124 : */
125 : void getEndArrow ( PolyPolygon& ) const;
126 : /** Get stroke transparency
127 :
128 : @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
129 : */
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;
141 :
142 : // mutators
143 : /// Set path to stroke
144 : void setPath ( const Polygon& );
145 : /** Set the polygon that is put at the start of the line
146 :
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.
157 : */
158 : void setStartArrow ( const PolyPolygon& );
159 : /** Set the polygon that is put at the end of the line
160 :
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.
171 : */
172 : void setEndArrow ( const PolyPolygon& );
173 : /// Affine scaling in both X and Y dimensions
174 : void scale ( double fScaleX, double fScaleY );
175 :
176 : private:
177 : // friends
178 : VCL_DLLPUBLIC friend SvStream& operator<<( SvStream& rOStm, const SvtGraphicStroke& rClass );
179 : VCL_DLLPUBLIC friend SvStream& operator>>( SvStream& rIStm, SvtGraphicStroke& rClass );
180 :
181 : Polygon maPath;
182 : PolyPolygon maStartArrow;
183 : PolyPolygon maEndArrow;
184 : double mfTransparency;
185 : double mfStrokeWidth;
186 : CapType maCapType;
187 : JoinType maJoinType;
188 : double mfMiterLimit;
189 : DashArray maDashArray;
190 : };
191 :
192 : /** Encapsulates geometry and associated attributes of a filled area
193 :
194 : @attention Widespread use is deprecated. See declarations above
195 : for the way to go. Especially the copied enums from svx/xenum.hxx
196 : is troublesome.
197 :
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.
204 : */
205 0 : class VCL_DLLPUBLIC SvtGraphicFill
206 : {
207 : public:
208 : /// Type of fill algorithm used
209 : enum FillRule
210 : {
211 : /** Non-zero winding rule
212 :
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.
219 : */
220 : fillNonZero=0,
221 : /** Even-odd fill rule
222 :
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.
226 : */
227 : fillEvenOdd
228 : };
229 : /// Type of filling used
230 : enum FillType
231 : {
232 : /// Fill with a specified solid color
233 : fillSolid=0,
234 : /// Fill with the specified gradient
235 : fillGradient,
236 : /// Fill with the specified hatch
237 : fillHatch,
238 : /// Fill with the specified texture (a Graphic object)
239 : fillTexture
240 : };
241 : /// Type of hatching used
242 : enum HatchType
243 : {
244 : /// horizontal parallel lines, one unit apart
245 : hatchSingle=0,
246 : /// horizontal and verticall orthogonally crossing lines, one unit apart
247 : hatchDouble,
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.
252 : hatchTriple
253 : };
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
259 :
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:
262 : <pre>
263 : a b t_x
264 : c d t_y
265 : 0 0 1
266 : </pre>
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).
271 : */
272 : struct VCL_DLLPUBLIC Transform
273 : {
274 : enum { MatrixSize=6 };
275 : Transform();
276 : double matrix[MatrixSize];
277 : };
278 :
279 : SvtGraphicFill();
280 : /** All in one constructor
281 :
282 : See accessor method descriptions for argument description
283 : */
284 : SvtGraphicFill( const PolyPolygon& rPath,
285 : Color aFillColor,
286 : double fTransparency,
287 : FillRule aFillRule,
288 : FillType aFillType, // TODO: Multitexturing
289 : const Transform& aFillTransform,
290 : bool bTiling,
291 : HatchType aHatchType, // TODO: vector of directions and start points
292 : Color aHatchColor,
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 );
298 :
299 : // accessors
300 : /// Query path to fill
301 : void getPath ( PolyPolygon& ) const;
302 : /// Get color used for solid fills
303 : Color getFillColor () const;
304 : /** Get stroke transparency
305 :
306 : @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
307 : */
308 : double getTransparency () const;
309 : /// Get fill rule used
310 : FillRule getFillRule () const;
311 : /** Get fill type used
312 :
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.
316 : */
317 : FillType getFillType () const;
318 : /** Get transformation applied to hatch, gradient or texture during fill
319 :
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.
327 :
328 : */
329 : void getTransform ( Transform& ) const;
330 : /// deprecated
331 : bool IsTiling () const;
332 : /** Query state of texture tiling
333 :
334 : @return true, if texture is tiled, false, if output only once.
335 : */
336 : bool isTiling () const;
337 : /// Get type of gradient used
338 : GradientType getGradientType () const;
339 :
340 : /** Get the texture graphic used
341 :
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.
346 : */
347 : void getGraphic ( Graphic& ) const;
348 :
349 : // mutators
350 : /// Set path to fill
351 : void setPath ( const PolyPolygon& rPath );
352 :
353 : private:
354 : // friends
355 : VCL_DLLPUBLIC friend SvStream& operator<<( SvStream& rOStm, const SvtGraphicFill& rClass );
356 : VCL_DLLPUBLIC friend SvStream& operator>>( SvStream& rIStm, SvtGraphicFill& rClass );
357 :
358 : PolyPolygon maPath;
359 : Color maFillColor;
360 : double mfTransparency;
361 : FillRule maFillRule;
362 : FillType maFillType;
363 : Transform maFillTransform;
364 : bool mbTiling;
365 : HatchType maHatchType;
366 : Color maHatchColor;
367 : GradientType maGradientType;
368 : Color maGradient1stColor;
369 : Color maGradient2ndColor;
370 : sal_Int32 maGradientStepCount;
371 : Graphic maFillGraphic;
372 : };
373 :
374 : #endif /* _VCL_GRAPHICTOOLS_HXX_ */
375 :
376 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|