1 /*
2  * go-path.h
3  *
4  * Copyright © 2002 University of Southern California
5  * Copyright © 2005 Red Hat, Inc.
6  * Copyright © 2006 Emmanuel Pacaud (emmanuel.pacaud@lapp.in2p3.fr)
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) version 3.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
21  * USA
22  *
23  * This code is an adaptation of the path code which can be found in
24  * the cairo library (http://cairographics.org).
25  *
26  * Contributor(s):
27  *	Carl D. Worth <cworth@cworth.org>
28  *	Emmanuel Pacaud <emmanuel.pacaud@lapp.in2p3.fr>
29  */
30 
31 #ifndef GO_PATH_H
32 #define GO_PATH_H
33 
34 #include <glib.h>
35 
36 G_BEGIN_DECLS
37 
38 typedef enum {
39 	GO_PATH_DIRECTION_FORWARD,
40 	GO_PATH_DIRECTION_BACKWARD
41 } GOPathDirection;
42 
43 typedef enum {
44 	GO_PATH_OPTIONS_SNAP_COORDINATES 	= 1<<0,
45 	GO_PATH_OPTIONS_SNAP_WIDTH		= 1<<1,
46 	GO_PATH_OPTIONS_SHARP			= 3
47 } GOPathOptions;
48 
49 typedef struct {
50 	double x;
51 	double y;
52 } GOPathPoint;
53 
54 typedef void (*GOPathMoveToFunc) 	(void *closure, GOPathPoint const *point);
55 typedef void (*GOPathLineToFunc) 	(void *closure, GOPathPoint const *point);
56 typedef void (*GOPathCurveToFunc) 	(void *closure, GOPathPoint const *point0,
57 					 		GOPathPoint const *point1,
58 							GOPathPoint const *point2);
59 typedef void (*GOPathClosePathFunc) 	(void *closure);
60 
61 GType   go_path_get_type (void);
62 
63 #define GO_TYPE_PATH go_path_get_type ()
64 #define GO_IS_PATH(x) ((x) != NULL)
65 
66 GOPath *go_path_new 	      	(void);
67 GOPath *go_path_new_from_svg    (char const *src);
68 GOPath *go_path_new_from_odf_enhanced_path (char const *src, GHashTable const *variables);
69 void 	go_path_clear	      	(GOPath *path);
70 GOPath *go_path_ref          	(GOPath *path);
71 void    go_path_free          	(GOPath *path);
72 
73 void    	go_path_set_options  	(GOPath *path, GOPathOptions options);
74 GOPathOptions   go_path_get_options  	(GOPath const *path);
75 
76 void 	go_path_move_to 	(GOPath *path, double x, double y);
77 void 	go_path_line_to 	(GOPath *path, double x, double y);
78 void 	go_path_curve_to 	(GOPath *path, double x0, double y0,
79 				 	       double x1, double y1,
80 				 	       double x2, double y2);
81 void 	go_path_close 		(GOPath *path);
82 
83 void 	go_path_ring_wedge 	(GOPath *path, double cx, double cy,
84 				 	       double rx_out, double ry_out,
85 					       double rx_in, double ry_in,
86 					       double th0, double th1);
87 void    go_path_pie_wedge 	(GOPath *path, double cx, double cy,
88 				 	       double rx, double ry,
89 				 	       double th0, double th1);
90 void    go_path_arc	 	(GOPath *path,
91 				 double cx, double cy,
92 				 double rx, double ry,
93 				 double th0, double th1);
94 void    go_path_arc_to	 	(GOPath *path,
95 				 double cx, double cy,
96 				 double rx, double ry,
97 				 double th0, double th1);
98 void	go_path_rectangle	(GOPath *path, double x, double y,
99 				 double width, double height);
100 
101 void	go_path_interpret	(GOPath const *path,
102 				 GOPathDirection direction,
103 				 GOPathMoveToFunc move_to,
104 				 GOPathLineToFunc line_to,
105 				 GOPathCurveToFunc curve_to,
106 				 GOPathClosePathFunc close_path,
107 				 void *closure);
108 void	go_path_interpret_full (GOPath const *path,
109 	             gssize start, gssize end,
110 				 GOPathDirection direction,
111 				 GOPathMoveToFunc move_to,
112 				 GOPathLineToFunc line_to,
113 				 GOPathCurveToFunc curve_to,
114 				 GOPathClosePathFunc close_path,
115 				 void *closure);
116 
117 void    go_path_to_cairo	(GOPath const *path,
118 				 GOPathDirection direction,
119 				 cairo_t *cr);
120 
121 GOPath *go_path_copy		(GOPath const *path);
122 GOPath *go_path_copy_restricted	(GOPath const *path, gssize start, gssize end);
123 GOPath *go_path_append		(GOPath *path1, GOPath const *path2);
124 GOPath *go_path_scale       (GOPath *path, double scale_x, double scale_y);
125 char   *go_path_to_svg      (GOPath *path);
126 
127 G_END_DECLS
128 
129 #endif
130