Initial release of Maemo 5 port of gnuplot
[gnuplot] / src / wxterminal / gp_cairo.h
1 /*
2  * $Id: gp_cairo.h,v 1.4 2006/06/08 17:59:50 tlecomte Exp $
3  */
4
5 /* GNUPLOT - gp_cairo.h */
6
7 /*[
8  * Copyright 2005,2006   Timothee Lecomte
9  *
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.
15  *
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,
20  * provided you
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
28  *    software.
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.
32  *
33  * This software is provided "as is" without express or implied warranty
34  * to the extent permitted by applicable law.
35  *
36  *
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.
46 ]*/
47
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.
52  *
53  * See http://www.cairographics.org for details.
54
55  * It also uses the pango library, a text-layout rendering library.
56  * Pango is distributed under the LGPL licence.
57  *
58  * See http://www.pango.org for details.
59  * -----------------------------------------------------*/
60
61 /* ------------------------------------------------------
62  * This is the header for all cairo related functions,
63  * which provide drawing facilities to implement gnuplot's needs.
64  *
65  * In particular, we have here :
66  * - all the basic calls (lines, polygons for pm3d, custom patterns),
67  * - image support,
68  * - enhanced text mode
69  *
70  * The text rendering is done via pango.
71  * ------------------------------------------------------*/
72
73 #ifndef GNUPLOT_WXT_CAIRO_H
74 # define GNUPLOT_WXT_CAIRO_H
75
76 #ifdef __cplusplus
77 extern "C" {
78 #endif /*__cplusplus*/
79
80 /* for JUSTIFY, set_encoding_id, *term definitions, color.h */
81 # include "term_api.h"
82 /* for rgb functions */
83 # include "getcolor.h"
84
85 # include <cairo.h>
86
87 /* oversampling scale */
88 #define GP_CAIRO_SCALE 20
89
90 /* linked list in reverse order used to draw polygons more efficiently */
91 typedef struct path_item {
92         gpiPoint *corners;
93         int n;
94         rgb_color color;
95         struct path_item *previous;
96 } path_item;
97
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
107          * is resized.
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;
113         int xmax, ymax;
114
115         /* either GP_CAIRO_SCALE or 1, depending on rendering */
116         int oversampling_scale;
117
118         /* handle vertical/horizontal lines properly */
119         double current_x, current_y;
120         double orig_current_x, orig_current_y;
121         
122         /* style data used while processing gnuplot commands */
123         JUSTIFY justify_mode;
124         int linetype;
125         double linewidth;
126         int linestyle;
127         double pointsize;
128         double text_angle;
129         rgb_color color;
130
131         /* "polyline" */
132         TBOOLEAN opened_path;
133
134         /* font handling */
135         char fontname[MAX_ID_LEN + 1];
136         double fontsize;
137         enum set_encoding_id encoding;
138
139         /* state of the cairo context creation */
140         TBOOLEAN success;
141
142         TBOOLEAN antialiasing;
143
144         TBOOLEAN oversampling;
145
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 */
153         int hinting;
154
155         /* cairo drawing context */
156         cairo_t *cr;
157
158         /* polygons list */
159         path_item *polygon_path_last;
160
161         /* flag set to true when the user hit ctrl-c */
162         TBOOLEAN interrupt;
163 } plot_struct;
164
165 /* linetype enums */
166 enum {
167 GP_CAIRO_SOLID,
168 GP_CAIRO_DASH
169 };
170
171 /* correspondance between gnuplot's linetypes and colors */
172 rgb_color gp_cairo_linetype2color( int linetype );
173
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);
179
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);
185
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);
196 #ifdef WITH_IMAGE
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);
207
208 /* erase the contents of the cairo drawing context */
209 void gp_cairo_clear(plot_struct *plot);
210
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);
214
215 /* translate plot->encoding int to char* suitable for glib */
216 const char* gp_cairo_get_encoding(plot_struct *plot);
217
218 #ifdef __cplusplus
219 }
220 #endif /*__cplusplus*/
221
222 #endif /* gnuplot_wxt_cairo_h */