2 * $Id: gp_cairo.h,v 1.4 2006/06/08 17:59:50 tlecomte Exp $
5 /* GNUPLOT - gp_cairo.h */
8 * Copyright 2005,2006 Timothee Lecomte
10 * Permission to use, copy, and distribute this software and its
11 * documentation for any purpose with or without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and
13 * that both that copyright notice and this permission notice appear
14 * in supporting documentation.
16 * Permission to modify the software is granted, but not the right to
17 * distribute the complete modified source code. Modifications are to
18 * be distributed as patches to the released version. Permission to
19 * distribute binaries produced by compiling modified sources is granted,
21 * 1. distribute the corresponding source modifications from the
22 * released version in the form of a patch file along with the binaries,
23 * 2. add special version identification to distinguish your version
24 * in addition to the base release version number,
25 * 3. provide your name and address as the primary contact for the
26 * support of your modified version, and
27 * 4. retain our contact information in regard to use of the base
29 * Permission to distribute the released version of the source code along
30 * with corresponding source modifications in the form of a patch file is
31 * granted with same provisions 2 through 4 for binary distributions.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
37 * Alternatively, the contents of this file may be used under the terms of the
38 * GNU General Public License Version 2 or later (the "GPL"), in which case the
39 * provisions of GPL are applicable instead of those above. If you wish to allow
40 * use of your version of this file only under the terms of the GPL and not
41 * to allow others to use your version of this file under the above gnuplot
42 * license, indicate your decision by deleting the provisions above and replace
43 * them with the notice and other provisions required by the GPL. If you do not
44 * delete the provisions above, a recipient may use your version of this file
45 * under either the GPL or the gnuplot license.
48 /* -----------------------------------------------------
49 * This code uses the cairo library, a 2D graphics library with
50 * support for multiple output devices.
51 * Cairo is distributed under the LGPL licence.
53 * See http://www.cairographics.org for details.
55 * It also uses the pango library, a text-layout rendering library.
56 * Pango is distributed under the LGPL licence.
58 * See http://www.pango.org for details.
59 * -----------------------------------------------------*/
61 /* ------------------------------------------------------
62 * This is the header for all cairo related functions,
63 * which provide drawing facilities to implement gnuplot's needs.
65 * In particular, we have here :
66 * - all the basic calls (lines, polygons for pm3d, custom patterns),
68 * - enhanced text mode
70 * The text rendering is done via pango.
71 * ------------------------------------------------------*/
73 #ifndef GNUPLOT_WXT_CAIRO_H
74 # define GNUPLOT_WXT_CAIRO_H
78 #endif /*__cplusplus*/
80 /* for JUSTIFY, set_encoding_id, *term definitions, color.h */
81 # include "term_api.h"
82 /* for rgb functions */
83 # include "getcolor.h"
87 /* oversampling scale */
88 #define GP_CAIRO_SCALE 20
90 /* linked list in reverse order used to draw polygons more efficiently */
91 typedef struct path_item {
95 struct path_item *previous;
98 /* plot structure containing all the information cairo needs to execute
99 * the drawing commands.
100 * Don't forget to update gp_cairo_initialize_plot when a new entry is added there. */
101 typedef struct plot_struct {
102 /* scaling and conversion between gnuplot and device coordinates.
103 * For a static terminal, scales are 1 and sizes are those of the term table.
104 * For an interactive terminal, they are used to handle window resizing.
105 * xmax and ymax are the sizes known by gnuplot.
106 * device_xmax and device_ymax are the device size, which may change when the window
108 * xmax and ymax are stored here in addition to term->xmax and term->ymax,
109 * to handle the case when another terminal is chosen (x11 for example), which
110 * may change these variables whereas we want to keep the one used for our plot */
111 double xscale, yscale;
112 int device_xmax, device_ymax;
115 /* either GP_CAIRO_SCALE or 1, depending on rendering */
116 int oversampling_scale;
118 /* handle vertical/horizontal lines properly */
119 double current_x, current_y;
120 double orig_current_x, orig_current_y;
122 /* style data used while processing gnuplot commands */
123 JUSTIFY justify_mode;
132 TBOOLEAN opened_path;
135 char fontname[MAX_ID_LEN + 1];
137 enum set_encoding_id encoding;
139 /* state of the cairo context creation */
142 TBOOLEAN antialiasing;
144 TBOOLEAN oversampling;
146 /* hinting option for horizontal and vertical lines :
147 * Hinting is the process of fitting outlines to the pixel grid
148 * in order to improve the appearance of the result.
149 * Since hinting outlines involves distorting them,
150 * it also reduces the faithfulness to the original outline shapes.
151 * hinting = 100 means full hinting
152 * hinting = 0 means no hinting */
155 /* cairo drawing context */
159 path_item *polygon_path_last;
161 /* flag set to true when the user hit ctrl-c */
171 /* correspondance between gnuplot's linetypes and colors */
172 rgb_color gp_cairo_linetype2color( int linetype );
174 /* functions to handle scaling between device and gnuplot coordinates */
175 double device_x(plot_struct *plot, double x);
176 double device_y(plot_struct *plot, double y);
177 double gnuplot_x(plot_struct *plot, double x);
178 double gnuplot_y(plot_struct *plot, double y);
180 /* initialize all fields of the plot structure */
181 void gp_cairo_initialize_plot(plot_struct *plot);
182 /* initialize the transformation matrix of the drawing context and other details */
183 /* Depends on the setting of xscale and yscale */
184 void gp_cairo_initialize_context(plot_struct *plot);
186 /* functions used to process gnuplot commands */
187 void gp_cairo_move(plot_struct *plot, int x, int y);
188 void gp_cairo_vector(plot_struct *plot, int x, int y);
189 void gp_cairo_stroke(plot_struct *plot);
190 void gp_cairo_draw_text(plot_struct *plot, int x1, int y1, const char* str);
191 void gp_cairo_draw_enhanced_text(plot_struct *plot, int x1, int y1, const char* str);
192 void gp_cairo_draw_point(plot_struct *plot, int x1, int y1, int style);
193 void gp_cairo_draw_fillbox(plot_struct *plot, int x, int y, int width, int height, int style);
194 void gp_cairo_draw_polygon(plot_struct *plot, int n, gpiPoint *corners);
195 void gp_cairo_end_polygon(plot_struct *plot);
197 void gp_cairo_draw_image(plot_struct *plot, coordval * image, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int M, int N, t_imagecolor color_mode);
198 #endif /*WITH_IMAGE*/
199 void gp_cairo_set_color(plot_struct *plot, rgb_color color);
200 void gp_cairo_set_linestyle(plot_struct *plot, int linestyle);
201 void gp_cairo_set_linetype(plot_struct *plot, int linetype);
202 void gp_cairo_set_pointsize(plot_struct *plot, double pointsize);
203 void gp_cairo_set_justify(plot_struct *plot, JUSTIFY mode);
204 void gp_cairo_set_font(plot_struct *plot, const char *name, int fontsize);
205 void gp_cairo_set_linewidth(plot_struct *plot, double linewidth);
206 void gp_cairo_set_textangle(plot_struct *plot, double angle);
208 /* erase the contents of the cairo drawing context */
209 void gp_cairo_clear(plot_struct *plot);
211 /* fill term->h_char, v_char, h_tic, v_tic
212 * Depends on plot->fontsize and fontname */
213 void gp_cairo_set_termvar(plot_struct *plot);
215 /* translate plot->encoding int to char* suitable for glib */
216 const char* gp_cairo_get_encoding(plot_struct *plot);
220 #endif /*__cplusplus*/
222 #endif /* gnuplot_wxt_cairo_h */