dcfe48f2d3366cd780877a8dcc93a822a6ab3c03
[rrdtool.git] / src / rrd_gfx.h
1 /****************************************************************************
2  * RRDtool 1.2.23  Copyright by Tobi Oetiker, 1997-2007
3  ****************************************************************************
4  * rrd_gfx.h generic graphics adapter library
5  ****************************************************************************/
6
7 #ifndef  RRD_GFX_H
8 #define RRD_GFX_H
9 #define LIBART_COMPILATION
10
11 #define y0 libart_y0
12 #define y1 libart_y1
13 #define gamma libart_gamma
14 #include <libart_lgpl/libart.h>
15 #include <libart_lgpl/art_rgba.h>
16 #include "art_rgba_svp.h"
17 #undef gamma
18 #undef y0
19 #undef y1
20
21
22 enum gfx_if_en { IF_PNG = 0, IF_SVG, IF_EPS, IF_PDF };
23 enum gfx_en { GFX_LINE = 0, GFX_AREA, GFX_TEXT };
24 enum gfx_h_align_en { GFX_H_NULL = 0, GFX_H_LEFT, GFX_H_RIGHT, GFX_H_CENTER };
25 enum gfx_v_align_en { GFX_V_NULL = 0, GFX_V_TOP, GFX_V_BOTTOM, GFX_V_CENTER };
26 enum gfx_aa_type_en { AA_NORMAL = 0, AA_LIGHT, AA_NONE };
27 typedef unsigned long gfx_color_t;
28
29 typedef struct gfx_node_t {
30     enum gfx_en type;   /* type of graph element */
31     gfx_color_t color;  /* color of element  0xRRGGBBAA  alpha 0xff is solid */
32     double    size;     /* font size, line width */
33     double    dash_on, dash_off;    /* dash line fragments lengths */
34     int       closed_path;
35     int       points;
36     int       points_max;
37     char     *filename; /* font or image filename */
38     char     *text;
39     ArtVpath *path;     /* path */
40     double    x, y;     /* position */
41     double    angle;    /* text angle */
42     enum gfx_h_align_en halign; /* text alignement */
43     enum gfx_v_align_en valign; /* text alignement */
44     double    tabwidth;
45     struct gfx_node_t *next;
46 } gfx_node_t;
47
48
49 typedef struct gfx_canvas_t {
50     struct gfx_node_t *firstnode;
51     struct gfx_node_t *lastnode;
52     enum gfx_if_en imgformat;   /* image format */
53     int       interlaced;   /* will the graph be interlaced? */
54     double    zoom;     /* zoom for graph */
55     double    font_aa_threshold;    /* no anti-aliasing for sizes <= */
56     enum gfx_aa_type_en aa_type;    /* anti-aliasing type (normal/light/none) */
57 } gfx_canvas_t;
58
59 gfx_canvas_t *gfx_new_canvas(
60     void);
61
62 /* create a new line */
63 gfx_node_t *gfx_new_line(
64     gfx_canvas_t * canvas,
65     double X0,
66     double Y0,
67     double X1,
68     double Y1,
69     double width,
70     gfx_color_t color);
71
72 gfx_node_t *gfx_new_dashed_line(
73     gfx_canvas_t * canvas,
74     double X0,
75     double Y0,
76     double X1,
77     double Y1,
78     double width,
79     gfx_color_t color,
80     double dash_on,
81     double dash_off);
82
83 /* create a new area */
84 gfx_node_t *gfx_new_area(
85     gfx_canvas_t * canvas,
86     double X0,
87     double Y0,
88     double X1,
89     double Y1,
90     double X2,
91     double Y2,
92     gfx_color_t color);
93
94 /* add a point to a line or to an area */
95 int       gfx_add_point(
96     gfx_node_t * node,
97     double x,
98     double y);
99
100 /* close current path so it ends at the same point as it started */
101 void      gfx_close_path(
102     gfx_node_t * node);
103
104
105 /* create a text node */
106 gfx_node_t *gfx_new_text(
107     gfx_canvas_t * canvas,
108     double x,
109     double y,
110     gfx_color_t color,
111     char *font,
112     double size,
113     double tabwidth,
114     double angle,
115     enum gfx_h_align_en h_align,
116     enum gfx_v_align_en v_align,
117     char *text);
118
119 /* measure width of a text string */
120 double    gfx_get_text_width(
121     gfx_canvas_t * canvas,
122     double start,
123     char *font,
124     double size,
125     double tabwidth,
126     char *text,
127     int rotation);
128
129 /* save image to file */
130 int       gfx_render(
131     gfx_canvas_t * canvas,
132     art_u32 width,
133     art_u32 height,
134     gfx_color_t background,
135     FILE * fo);
136
137 /* free memory used by nodes this will also remove memory required for
138    node chain and associated material */
139 int       gfx_destroy(
140     gfx_canvas_t * canvas);
141
142
143 /* PNG support*/
144 int       gfx_render_png(
145     gfx_canvas_t * canvas,
146     art_u32 width,
147     art_u32 height,
148     gfx_color_t background,
149     FILE * fo);
150 double    gfx_get_text_width_libart(
151     gfx_canvas_t * canvas,
152     double start,
153     char *font,
154     double size,
155     double tabwidth,
156     char *text,
157     int rotation);
158
159 /* SVG support */
160 int       gfx_render_svg(
161     gfx_canvas_t * canvas,
162     art_u32 width,
163     art_u32 height,
164     gfx_color_t background,
165     FILE * fo);
166
167 /* EPS support */
168 int       gfx_render_eps(
169     gfx_canvas_t * canvas,
170     art_u32 width,
171     art_u32 height,
172     gfx_color_t background,
173     FILE * fo);
174
175 /* PDF support */
176 int       gfx_render_pdf(
177     gfx_canvas_t * canvas,
178     art_u32 width,
179     art_u32 height,
180     gfx_color_t background,
181     FILE * fo);
182
183 #endif