2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / common tools sub-project
\r
9 * GPAC is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation; either version 2, or (at your option)
\r
12 * any later version.
\r
14 * GPAC is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public
\r
20 * License along with this library; see the file COPYING. If not, write to
\r
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
\r
26 #ifndef _GF_PATH2D_H_
\r
27 #define _GF_PATH2D_H_
\r
30 * \file <gpac/path2d.h>
\r
31 * \brief 2D Vectorial Path functions.
\r
40 #include <gpac/math.h>
\r
41 #include <gpac/constants.h>
\r
45 *\addtogroup path_grp path2d
\r
47 *\brief Vectorial 2D Path manipulation functions
\r
49 *This section documents the 2D path object used in the GPAC framework.
\r
54 /*!\brief 2D Path Object
\r
56 *The 2D path object is used to construct complex 2D shapes for later drawing
\r
61 /*! number of contours in path*/
\r
63 /*! number of points in path and alloc size*/
\r
64 u32 n_points, n_alloc_points;
\r
67 /*! point tags (one per point)*/
\r
69 /*! contour end points*/
\r
71 /*! path bbox - NEVER USE WITHOUT FIRST CALLING \ref gf_path_get_bounds*/
\r
75 /*! fineness to use whenever flattening the path - default is \ref FIX_ONE*/
\r
81 * \brief path constructor
\r
83 * Constructs an empty 2D path object
\r
84 * \return new path object
\r
86 GF_Path *gf_path_new();
\r
88 * \brief path destructor
\r
90 * Destructs a 2D path object
\r
91 * \param gp the target path
\r
93 void gf_path_del(GF_Path *gp);
\r
97 * Resets the 2D path object
\r
98 * \param gp the target path
\r
100 void gf_path_reset(GF_Path *gp);
\r
102 * \brief path copy constuctor
\r
104 * Resets a copy of a 2D path object
\r
105 * \param gp the target path
\r
106 * \return new path copy
\r
108 GF_Path *gf_path_clone(GF_Path *gp);
\r
110 * \brief path close
\r
112 * Closes current path contour
\r
113 * \param gp the target path
\r
114 * \return error code if any error, \ref GF_OK otherwise
\r
116 GF_Err gf_path_close(GF_Path *gp);
\r
118 * \brief path moveTo
\r
120 * Starts a new contour from the specified point
\r
121 * \param gp the target path
\r
122 * \param x x-coordinate of the new point
\r
123 * \param y y-coordinate of the new point
\r
124 * \return error code if any error, \ref GF_OK otherwise
\r
126 GF_Err gf_path_add_move_to(GF_Path *gp, Fixed x, Fixed y);
\r
128 * \brief starts new contour
\r
130 * Starts a new contour from the specified point
\r
131 * \param gp the target path
\r
132 * \param pt pointer to the new start point
\r
133 * \return error code if any error, \ref GF_OK otherwise
\r
135 GF_Err gf_path_add_move_to_vec(GF_Path *gp, GF_Point2D *pt);
\r
137 * \brief adds line to path
\r
139 * Adds a line from the current point in path to the specified point
\r
140 * \param gp the target path
\r
141 * \param x x-coordinate of the line end
\r
142 * \param y y-coordinate of the line end
\r
143 * \return error code if any error, \ref GF_OK otherwise
\r
145 GF_Err gf_path_add_line_to(GF_Path *gp, Fixed x, Fixed y);
\r
147 * \brief adds line to path
\r
149 * Adds a line from the current point in path to the specified point
\r
150 * \param gp the target path
\r
151 * \param pt line end
\r
152 * \return error code if any error, \ref GF_OK otherwise
\r
154 GF_Err gf_path_add_line_to_vec(GF_Path *gp, GF_Point2D *pt);
\r
156 * \brief adds cubic to path
\r
158 * Adds a cubic bezier curve to the current contour, starting from the current path point
\r
159 * \param gp the target path
\r
160 * \param c1_x x-coordinate of the first control point of the cubic curve
\r
161 * \param c1_y y-coordinate of the first control point of the cubic curve
\r
162 * \param c2_x x-coordinate of the second control point of the cubic curve
\r
163 * \param c2_y y-coordinate of the second control point of the cubic curve
\r
164 * \param x x-coordinate of the end point of the cubic curve
\r
165 * \param y y-coordinate of the end point of the cubic curve
\r
166 * \return error code if any error, \ref GF_OK otherwise
\r
168 GF_Err gf_path_add_cubic_to(GF_Path *gp, Fixed c1_x, Fixed c1_y, Fixed c2_x, Fixed c2_y, Fixed x, Fixed y);
\r
170 * \brief adds cubic to path
\r
172 * Adds a cubic bezier curve to the current contour, starting from the current path point
\r
173 * \param gp the target path
\r
174 * \param c1 first control point of the cubic curve
\r
175 * \param c2 second control point of the cubic curve
\r
176 * \param pt end point of the cubic curve
\r
177 * \return error code if any error, \ref GF_OK otherwise
\r
179 GF_Err gf_path_add_cubic_to_vec(GF_Path *gp, GF_Point2D *c1, GF_Point2D *c2, GF_Point2D *pt);
\r
181 * \brief adds quadratic to path
\r
183 * Adds a quadratic bezier curve to the current contour, starting from the current path point
\r
184 * \param gp the target path
\r
185 * \param c_x x-coordinate of the control point of the quadratic curve
\r
186 * \param c_y y-coordinate of the control point of the quadratic curve
\r
187 * \param x x-coordinate of the end point of the cubic quadratic
\r
188 * \param y y-coordinate of the end point of the cubic quadratic
\r
189 * \return error code if any error, \ref GF_OK otherwise
\r
191 GF_Err gf_path_add_quadratic_to(GF_Path *gp, Fixed c_x, Fixed c_y, Fixed x, Fixed y);
\r
193 * \brief adds quadratic to path
\r
195 * Adds a quadratic bezier curve to the current contour, starting from the current path point
\r
196 * \param gp the target path
\r
197 * \param c control point of the quadratic curve
\r
198 * \param pt end point of the cubic quadratic
\r
199 * \return error code if any error, \ref GF_OK otherwise
\r
201 GF_Err gf_path_add_quadratic_to_vec(GF_Path *gp, GF_Point2D *c, GF_Point2D *pt);
\r
203 * \brief adds rectangle to path
\r
205 * Adds a rectangle contour to the path
\r
206 * \param gp the target path
\r
207 * \param cx x-coordinate of the rectangle center
\r
208 * \param cy y-coordinate of the rectangle center
\r
209 * \param w width of the rectangle
\r
210 * \param h height of the rectangle
\r
211 * \return error code if any error, \ref GF_OK otherwise
\r
213 GF_Err gf_path_add_rect_center(GF_Path *gp, Fixed cx, Fixed cy, Fixed w, Fixed h);
\r
215 * \brief adds rectangle to path
\r
217 * Adds a rectangle contour to the path
\r
218 * \param gp the target path
\r
219 * \param ox left-most coordinate of the rectangle
\r
220 * \param oy top-most coordinate of the rectangle
\r
221 * \param w width of the rectangle
\r
222 * \param h height of the rectangle
\r
223 * \return error code if any error, \ref GF_OK otherwise
\r
225 GF_Err gf_path_add_rect(GF_Path *gp, Fixed ox, Fixed oy, Fixed w, Fixed h);
\r
227 * \brief adds ellipse to path
\r
229 * Adds an ellipse contour to the path
\r
230 * \param gp the target path
\r
231 * \param cx x-coordinate of the ellipse center
\r
232 * \param cy y-coordinate of the ellipse center
\r
233 * \param a_axis length of the horizontal ellipse axis
\r
234 * \param b_axis length of the vertical ellipse axis
\r
235 * \return error code if any error, \ref GF_OK otherwise
\r
237 GF_Err gf_path_add_ellipse(GF_Path *gp, Fixed cx, Fixed cy, Fixed a_axis, Fixed b_axis);
\r
239 * \brief adds N-bezier curve to path
\r
241 * Adds an N-degree bezier curve to the path, starting from the current point
\r
242 * \param gp the target path
\r
243 * \param pts points used to define the curve
\r
244 * \param nb_pts number of points used to define the curve. The degree of the curve is therefore (nb_pts-1).
\r
245 * \return error code if any error, \ref GF_OK otherwise
\r
246 * \note the fineness of the path must be set before calling this function.
\r
248 GF_Err gf_path_add_bezier(GF_Path *gp, GF_Point2D *pts, u32 nb_pts);
\r
250 * \brief adds arc as described in MPEG-4 BIFS to path
\r
252 * Adds an arc contour to the path from focal and end points.
\r
253 * \param gp the target path
\r
254 * \param end_x x-coordinate of the arc end point
\r
255 * \param end_y y-coordinate of the arc end point
\r
256 * \param fa_x x-coordinate of the arc first focal point
\r
257 * \param fa_y y-coordinate of the arc first focal point
\r
258 * \param fb_x x-coordinate of the arc second focal point
\r
259 * \param fb_y y-coordinate of the arc second focal point
\r
260 * \param cw if 1, the arc will be clockwise, otherwise counter-clockwise.
\r
261 * \return error code if any error, \ref GF_OK otherwise
\r
263 GF_Err gf_path_add_arc_to(GF_Path *gp, Fixed end_x, Fixed end_y, Fixed fa_x, Fixed fa_y, Fixed fb_x, Fixed fb_y, Bool cw);
\r
265 * \brief adds arc as described in SVG to path
\r
267 * Adds an arc contour to the path from end point, radii and 3 parameters.
\r
268 * \param gp the target path
\r
269 * \param end_x x-coordinate of the arc end point
\r
270 * \param end_y y-coordinate of the arc end point
\r
271 * \param r_x x-axis radius
\r
272 * \param r_y y-axis radius
\r
273 * \param x_axis_rotation angle for the x-axis
\r
274 * \param large_arc_flag large or short arc selection
\r
275 * \param sweep_flag if 1, the arc will be clockwise, otherwise counter-clockwise.
\r
276 * \return error code if any error, \ref GF_OK otherwise
\r
278 GF_Err gf_path_add_svg_arc_to(GF_Path *gp, Fixed end_x, Fixed end_y, Fixed r_x, Fixed r_y, Fixed x_axis_rotation, Bool large_arc_flag, Bool sweep_flag);
\r
280 * \brief adds arc to path
\r
282 * Adds an arc contour to the path.
\r
283 * \param gp the target path
\r
284 * \param radius radius of the arc
\r
285 * \param start_angle start angle of the arc in radians
\r
286 * \param end_angle end angle of the arc in radians
\r
287 * \param close_type closing type: 0 for open arc, 1 for close arc, 2 for pie
\r
288 * \return error code if any error, \ref GF_OK otherwise
\r
290 GF_Err gf_path_add_arc(GF_Path *gp, Fixed radius, Fixed start_angle, Fixed end_angle, u32 close_type);
\r
293 * \brief concatenates path
\r
295 * Adds a sub-path to the path with a given transform.
\r
296 * \param gp the target path
\r
297 * \param subpath the path to add
\r
298 * \param mat Matrix for subpath
\r
299 * \return error code if any error, \ref GF_OK otherwise
\r
301 GF_Err gf_path_add_subpath(GF_Path *gp, GF_Path *subpath, GF_Matrix2D *mx);
\r
303 * \brief gets path control bounds
\r
305 * Gets the path control bounds, i.e. the rectangle covering all lineTo and bezier control points.
\r
306 * \param gp the target path
\r
307 * \param rc pointer to rectangle receiving the control rectangle
\r
308 * \return error code if any error, \ref GF_OK otherwise
\r
310 GF_Err gf_path_get_control_bounds(GF_Path *gp, GF_Rect *rc);
\r
312 * \brief gets path bounds
\r
314 * Gets the path bounds, i.e. the rectangle covering all points in path except bezier control points.
\r
315 * \param gp the target path
\r
316 * \param rc pointer to rectangle receiving the control rectangle
\r
317 * \return error code if any error, \ref GF_OK otherwise
\r
319 GF_Err gf_path_get_bounds(GF_Path *gp, GF_Rect *rc);
\r
321 * \brief flattens path
\r
323 * Flattens the path, i.e. transform all bezier curves to lines according to the path flatness.
\r
324 * \param gp the target path
\r
326 void gf_path_flatten(GF_Path *gp);
\r
328 * \brief gets flatten copy of path
\r
330 * Gets a flatten copy of the path.
\r
331 * \param gp the target path
\r
332 * \return the flatten path
\r
334 GF_Path *gf_path_get_flatten(GF_Path *gp);
\r
336 * \brief point over path testing
\r
338 * Tests if a point is over a path or not, according to the path filling rule.
\r
339 * \param gp the target path
\r
340 * \param x x-coordinate of the point to check
\r
341 * \param y y-coordinate of the point to check
\r
342 * \return 1 if the point is over the path, 0 otherwise.
\r
344 Bool gf_path_point_over(GF_Path *gp, Fixed x, Fixed y);
\r
347 * \brief path init testing
\r
349 * Tests if the path is empty or not.
\r
350 * \param gp the target path
\r
351 * \return 1 if the path is empty, 0 otherwise.
\r
353 Bool gf_path_is_empty(GF_Path *gp);
\r
356 * \brief path iterator
\r
358 * The path iterator object is used to compute the length of a given path as well
\r
359 * as transformation matrices along this path.
\r
361 typedef struct _path_iterator GF_PathIterator;
\r
364 * \brief path iterator constructor
\r
366 * Creates a new path iterator from a given path
\r
367 * \param gp the target path
\r
368 * \return the path iterator object.
\r
370 GF_PathIterator *gf_path_iterator_new(GF_Path *gp);
\r
372 * \brief path iterator destructor
\r
374 * Destructs the path iterator object
\r
375 * \param it the target path iterator
\r
377 void gf_path_iterator_del(GF_PathIterator *it);
\r
380 * \brief get path length
\r
382 * Gets a path length from its iterator
\r
383 * \param it the target path iterator
\r
384 * \return the length of the path
\r
386 Fixed gf_path_iterator_get_length(GF_PathIterator *it);
\r
388 *\brief gets transformation matrix at given point on path
\r
390 * Gets the transformation of a given point on the path, given by offset from origin.
\r
391 *The transform is so that a local system is translated to the given point, its x-axis tangent
\r
392 *to the path and in the same direction. The path direction is from first point to last point
\r
394 * \param it the target path iterator
\r
395 * \param offset length on the path in local system unit
\r
396 * \param follow_tangent indicates if transformation shall be computed if offset indicates a point outside the path (<0 or >path_length). In which case the path shall be virtually extended by the tangent at origin (offset <0) or at end (offset>path_length). Otherwise the transformation is not computed and 0 is returned.
\r
397 * \param mat matrix to be transformed (transformation shall be appended) - the matrix shall not be initialized
\r
398 * \param smooth_edges indicates if discontinuities shall be smoothed. If not set, the rotation angle THETA is the slope (DX/DY) of the current segment found.
\r
399 * \param length_after_point if set and smooth_edges is set, the amount of the object that lies on next segment shall be computed according to length_after_point.
\r
402 len_last: length of current checked segment
\r
403 len1: length of all previous segments so that len1 + len_last >= offset then if (offset + length_after_point > len1 + len_last) {
\r
404 ratio = (len1 + len_last - offset) / length_after_point;
\r
405 then THETA = ratio * slope(L1) + (1-ratio) * slope(L2)
\r
407 Of course care must be taken for PI/2 angles and similar situations
\r
410 * \return 1 if matrix has been updated, 0 otherwise, if failure or if point is out of path without tangent extension.
\r
412 Bool gf_path_iterator_get_transform(GF_PathIterator *it, Fixed offset, Bool follow_tangent, GF_Matrix2D *mat, Bool smooth_edges, Fixed length_after_point);
\r
416 /*! brief gets convexity type for a 2D polygon
\r
418 * Gets the convexity type of the given 2D polygon
\r
419 * \param pts the points of the polygon
\r
420 * \param nb_pts number of points in the polygon
\r
421 * \return the convexity type of the polygon
\r
423 u32 gf_polygone2d_get_convexity(GF_Point2D *pts, u32 nb_pts);
\r
426 /* 2D Path constants */
\r
429 *2D Path point tags
\r
434 /*/! Point is on curve (moveTo, lineTo, end of splines)*/
\r
435 GF_PATH_CURVE_ON = 1,
\r
436 /*! Point is a contour close*/
\r
438 /*! Point is a quadratic control point*/
\r
439 GF_PATH_CURVE_CONIC = 0,
\r
440 /*! Point is a cubic control point*/
\r
441 GF_PATH_CURVE_CUBIC = 2,
\r
451 /*! Path is filled using the zero-nonzero rule. If not set, filling uses odd/even rule*/
\r
452 GF_PATH_FILL_ZERO_NONZERO = 1,
\r
453 /*! When set bbox must be recomputed.
\r
454 \note Read only, used to avoid wasting time on bounds calculation*/
\r
455 GF_PATH_BBOX_DIRTY = 2,
\r
456 /*! Indicates the path is flattened flattened
\r
457 \note Read only, used to avoid wasting time on flattening*/
\r
458 GF_PATH_FLATTENED = 4,
\r
462 * 2D Polygon convexity type
\r
467 /*! Polygon is either complex or unknown*/
\r
468 GF_POLYGON_COMPLEX,
\r
469 /*! Polygon is complex, starting in counter-clockwise order*/
\r
470 GF_POLYGON_COMPLEX_CCW,
\r
471 /*! Polygon is complex, starting in clockwise order*/
\r
472 GF_POLYGON_COMPLEX_CW,
\r
473 /*! Polygon is a counter-clockwise convex polygon*/
\r
474 GF_POLYGON_CONVEX_CCW,
\r
475 /*! Polygon is a clockwise convex polygon*/
\r
476 GF_POLYGON_CONVEX_CW,
\r
477 /*! Polygon is a convex line (degenerated path with all segments aligned)*/
\r
478 GF_POLYGON_CONVEX_LINE
\r
482 * Stencil alignment type for outlining
\r
487 /*! outline is centered on the path (default)*/
\r
488 GF_PATH_LINE_CENTER = 0,
\r
489 /*! outline is inside the path*/
\r
490 GF_PATH_LINE_INSIDE,
\r
491 /*! outline is outside the path*/
\r
492 GF_PATH_LINE_OUTSIDE,
\r
496 * Line cap type for outlining
\r
501 /*! End of line is flat (default)*/
\r
502 GF_LINE_CAP_FLAT = 0,
\r
503 /*! End of line is round*/
\r
505 /*! End of line is square*/
\r
506 GF_LINE_CAP_SQUARE,
\r
507 /*! End of line is triangle*/
\r
508 GF_LINE_CAP_TRIANGLE,
\r
512 * Line join type for outlining
\r
517 /*! Line join is a miter join (default)*/
\r
518 GF_LINE_JOIN_MITER = 0,
\r
519 /*! Line join is a round join*/
\r
520 GF_LINE_JOIN_ROUND,
\r
521 /*! Line join is a bevel join*/
\r
522 GF_LINE_JOIN_BEVEL,
\r
523 /*! Line join is a miter then bevel join*/
\r
524 GF_LINE_JOIN_MITER_SVG
\r
528 * Dash types for outlining
\r
533 /*! No dashing is used (default)*/
\r
534 GF_DASH_STYLE_PLAIN = 0,
\r
535 /*! Predefined dash pattern is used*/
\r
536 GF_DASH_STYLE_DASH,
\r
537 /*! Predefined dot pattern is used*/
\r
539 /*! Predefined dash-dot pattern is used*/
\r
540 GF_DASH_STYLE_DASH_DOT,
\r
541 /*! Predefined dash-dash-dot pattern is used*/
\r
542 GF_DASH_STYLE_DASH_DASH_DOT,
\r
543 /*! Predefined dash-dot-dot pattern is used*/
\r
544 GF_DASH_STYLE_DASH_DOT_DOT,
\r
545 /*! Custom pattern is used. Dash lengths are given in percentage of the pen width*/
\r
546 GF_DASH_STYLE_CUSTOM,
\r
547 /*! SVG pattern is used. Dash lengths are given in the same unit as the pen width
\r
548 and dash offset follows SVG specs (offset in dash pattern)*/
\r
553 /*!\brief Custom dash pattern
\r
555 *The custom dash pattern object is used to specify custom dashes when outlining a path.
\r
559 /*! Number of dashes in the pattern*/
\r
561 /*! Value of the pattern dashes. Unit depends on the dash type*/
\r
565 /*!\brief Pen properties
\r
567 *The pen properties object is used to specify several parameters used when building
\r
568 *the vectorial outline of a path.
\r
572 /*! The width of the outline*/
\r
574 /*! The style of the lines ends*/
\r
576 /*! The style of the lines joins*/
\r
578 /*! The alignment of the outline with regard to the path*/
\r
580 /*! The dash style of the line*/
\r
582 /*! The miter limit of the line joins*/
\r
584 /*! The initial dash offset in the outline. All points before this offset will be
\r
585 * ignored when building the outline*/
\r
587 /*! The dash pattern used for curstom dashing*/
\r
588 GF_DashSettings *dash_set;
\r
589 /*! The author-specified path length. Ignored if <= 0*/
\r
593 /*! brief builds the vectorial outline of a path
\r
595 * Builds the vectorial outline of a path for the given settings. The outline of a path is a path.
\r
596 * \param path the desired path to outline
\r
597 * \param pen the properties of the virtual pen used for outlining
\r
598 * \return the outline of the path
\r
600 GF_Path *gf_path_get_outline(GF_Path *path, GF_PenSettings pen);
\r
610 #endif /*_GF_PATH2D_H_*/
\r