1 /*
2  * gog-renderer.h : An abstract interface for rendering engines
3  *
4  * Copyright (C) 2003-2004 Jody Goldberg (jody@gnome.org)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) version 3.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21 #ifndef GOG_RENDERER_H
22 #define GOG_RENDERER_H
23 
24 #include <goffice/goffice.h>
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26 
27 #ifdef GOFFICE_WITH_LASEM
28 #include <lsmdomview.h>
29 #endif
30 
31 #include <cairo.h>
32 
33 G_BEGIN_DECLS
34 /* We need to define an hair line width for the svg and gnome_print renderer.
35  * 0.5 pt is approx. the dot size of a 150 dpi printer, if the plot is
36  * printed at scale 1:1 */
37 #define GOG_RENDERER_HAIRLINE_WIDTH_PTS	0.5
38 
39 #define GOG_RENDERER_GRIP_SIZE	4
40 
41 #define GOG_TYPE_RENDERER	  (gog_renderer_get_type ())
42 #define GOG_RENDERER(o)           (G_TYPE_CHECK_INSTANCE_CAST((o), GOG_TYPE_RENDERER, GogRenderer))
43 #define GOG_IS_RENDERER(o)        (G_TYPE_CHECK_INSTANCE_TYPE((o), GOG_TYPE_RENDERER))
44 #define GOG_RENDERER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GOG_TYPE_RENDERER, GogRendererClass))
45 
46 GType gog_renderer_get_type            (void);
47 
48 /* measurement */
49 double gog_renderer_line_size	  	(GogRenderer const *r, double width);
50 double gog_renderer_pt2r_x   	  	(GogRenderer const *r, double d);
51 double gog_renderer_pt2r_y   	  	(GogRenderer const *r, double d);
52 double gog_renderer_pt2r   	  	(GogRenderer const *r, double d);
53 
54 double gog_renderer_get_hairline_width_pts	(GogRenderer const *rend);
55 
56 void  gog_renderer_stroke_serie    	(GogRenderer *renderer, GOPath const *path);
57 void  gog_renderer_fill_serie		(GogRenderer *renderer, GOPath const *path, GOPath const *close_path);
58 
59 void  gog_renderer_draw_shape 		(GogRenderer *renderer, GOPath const *path);
60 void  gog_renderer_stroke_shape		(GogRenderer *renderer, GOPath const *path);
61 void  gog_renderer_fill_shape 		(GogRenderer *renderer, GOPath const *path);
62 
63 void  gog_renderer_draw_circle		(GogRenderer *rend, double x, double y, double r);
64 void  gog_renderer_stroke_circle 	(GogRenderer *rend, double x, double y, double r);
65 void  gog_renderer_fill_circle	 	(GogRenderer *rend, double x, double y, double r);
66 
67 void  gog_renderer_draw_rectangle	(GogRenderer *rend, GogViewAllocation const *rect);
68 void  gog_renderer_draw_rotated_rectangle (GogRenderer *rend, GogViewAllocation const *rect, gboolean rotate_bg);
69 void  gog_renderer_stroke_rectangle 	(GogRenderer *rend, GogViewAllocation const *rect);
70 void  gog_renderer_fill_rectangle 	(GogRenderer *rend, GogViewAllocation const *rect);
71 
72 void  gog_renderer_draw_grip	  		(GogRenderer *renderer, double x, double y);
73 void  gog_renderer_draw_selection_rectangle	(GogRenderer *renderer, GogViewAllocation const *rectangle);
74 
75 #define gog_renderer_in_grip(x,y,grip_x,grip_y) ((x) >= ((grip_x) - (GOG_RENDERER_GRIP_SIZE)) && \
76 						 (x) <= ((grip_x) + (GOG_RENDERER_GRIP_SIZE)) && \
77 						 (y) >= ((grip_y) - (GOG_RENDERER_GRIP_SIZE)) && \
78 						 (y) <= ((grip_y) + (GOG_RENDERER_GRIP_SIZE)))
79 
80 void  gog_renderer_draw_marker	  (GogRenderer *rend, double x, double y);
81 
82 typedef enum
83 {
84   GO_JUSTIFY_LEFT,
85   GO_JUSTIFY_RIGHT,
86   GO_JUSTIFY_CENTER,
87   GO_JUSTIFY_FILL
88 } GoJustification;
89 
90 void  gog_renderer_draw_text	  (GogRenderer *rend, char const *text,
91 				   GogViewAllocation const *pos,
92 				   GOAnchorType anchor,
93 				   gboolean use_markup,
94                                    GoJustification justification, double width);
95 
96 void  gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
97                                     GogViewAllocation const *pos, GOAnchorType anchor,
98                                     GOStyle *legend_style);
99 
100 void  gog_renderer_draw_gostring  (GogRenderer *rend,
101 				   GOString *str,
102 				   GogViewAllocation const *pos,
103 				   GOAnchorType anchor,
104                                    GoJustification justification, double width);
105 
106 void  gog_renderer_get_gostring_OBR   (GogRenderer *rend, GOString *str,
107 				       GOGeometryOBR *obr, double max_width);
108 void  gog_renderer_get_text_OBR   (GogRenderer *rend, char const *text,
109 				   gboolean use_markup, GOGeometryOBR *obr,
110                                    double max_width);
111 void gog_renderer_get_gostring_AABR (GogRenderer *rend, GOString *str,
112                                      GOGeometryAABR *aabr, double max_width);
113 void  gog_renderer_get_text_AABR  (GogRenderer *rend, char const *text,
114 				   gboolean use_markup, GOGeometryAABR *aabr,
115                                    double max_width);
116 
117 void  gog_renderer_draw_color_map	(GogRenderer *rend, GogAxisColorMap const *map,
118 	                                 int discrete, gboolean horizontal,
119 	                                 GogViewAllocation const *rect);
120 
121 void  gog_renderer_push_style     	(GogRenderer *rend, GOStyle const *style);
122 void  gog_renderer_pop_style      	(GogRenderer *rend);
123 
124 void  gog_renderer_push_clip 	  	(GogRenderer *rend, GOPath const *path);
125 void  gog_renderer_push_clip_rectangle 	(GogRenderer *rend, double x, double y, double w, double h);
126 void  gog_renderer_pop_clip       	(GogRenderer *rend);
127 
128 
129 /* Rendering with image cache */
130 gboolean	 gog_renderer_update		(GogRenderer *renderer, double w, double h);
131 cairo_surface_t *gog_renderer_get_cairo_surface	(GogRenderer *renderer);
132 GdkPixbuf 	*gog_renderer_get_pixbuf 	(GogRenderer *renderer);
133 void  		 gog_renderer_request_update 	(GogRenderer *renderer);
134 
135 /* One time rendering */
136 gboolean	 gog_renderer_render_to_cairo 	(GogRenderer *renderer, cairo_t *cairo,
137 						 double width, double height);
138 gboolean 	 gog_renderer_export_image 	(GogRenderer *renderer, GOImageFormat format,
139 						 GsfOutput *output, double x_dpi, double y_dpi);
140 
141 GogRenderer 	*gog_renderer_new 		(GogGraph *graph);
142 
143 double		 gog_renderer_get_scale		(GogRenderer *renderer);
144 #ifdef GOFFICE_WITH_LASEM
145 void		 gog_renderer_draw_equation	(GogRenderer *renderer, LsmDomView *mathml_view,
146 						 double x, double y);
147 #endif
148 
149 G_END_DECLS
150 
151 #endif /* GOG_RENDERER_H */
152