1 /****************************************************************************
2 * RRDtool 1.2.16 Copyright by Tobi Oetiker, 1997-2006
3 ****************************************************************************
4 * rrd_gfx.h generic graphics adapter library
5 ****************************************************************************/
7 #ifndef RRD_GFX_H
8 #define RRD_GFX_H
9 #define LIBART_COMPILATION
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
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;
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;
49 typedef struct gfx_canvas_t
50 {
51 struct gfx_node_t *firstnode;
52 struct gfx_node_t *lastnode;
53 enum gfx_if_en imgformat; /* image format */
54 int interlaced; /* will the graph be interlaced? */
55 double zoom; /* zoom for graph */
56 double font_aa_threshold; /* no anti-aliasing for sizes <= */
57 enum gfx_aa_type_en aa_type; /* anti-aliasing type (normal/light/none) */
58 } gfx_canvas_t;
60 gfx_canvas_t *gfx_new_canvas (void);
62 /* create a new line */
63 gfx_node_t *gfx_new_line (gfx_canvas_t *canvas,
64 double X0, double Y0,
65 double X1, double Y1,
66 double width, gfx_color_t color);
68 gfx_node_t *gfx_new_dashed_line (gfx_canvas_t *canvas,
69 double X0, double Y0,
70 double X1, double Y1,
71 double width, gfx_color_t color,
72 double dash_on, double dash_off);
74 /* create a new area */
75 gfx_node_t *gfx_new_area (gfx_canvas_t *canvas,
76 double X0, double Y0,
77 double X1, double Y1,
78 double X2, double Y2,
79 gfx_color_t color);
81 /* add a point to a line or to an area */
82 int gfx_add_point (gfx_node_t *node, double x, double y);
84 /* close current path so it ends at the same point as it started */
85 void gfx_close_path (gfx_node_t *node);
88 /* create a text node */
89 gfx_node_t *gfx_new_text (gfx_canvas_t *canvas,
90 double x, double y, gfx_color_t color,
91 char* font, double size,
92 double tabwidth, double angle,
93 enum gfx_h_align_en h_align,
94 enum gfx_v_align_en v_align,
95 char* text);
97 /* measure width of a text string */
98 double gfx_get_text_width ( gfx_canvas_t *canvas,
99 double start, char* font, double size,
100 double tabwidth, char* text, int rotation);
102 /* save image to file */
103 int gfx_render (gfx_canvas_t *canvas,
104 art_u32 width, art_u32 height,
105 gfx_color_t background, FILE *fo);
107 /* free memory used by nodes this will also remove memory required for
108 node chain and associated material */
109 int gfx_destroy (gfx_canvas_t *canvas);
112 /* PNG support*/
113 int gfx_render_png (gfx_canvas_t *canvas,
114 art_u32 width, art_u32 height,
115 gfx_color_t background, FILE *fo);
116 double gfx_get_text_width_libart ( gfx_canvas_t *canvas, double start,
117 char* font, double size, double tabwidth,
118 char* text, int rotation );
120 /* SVG support */
121 int gfx_render_svg (gfx_canvas_t *canvas,
122 art_u32 width, art_u32 height,
123 gfx_color_t background, FILE *fo);
125 /* EPS support */
126 int gfx_render_eps (gfx_canvas_t *canvas,
127 art_u32 width, art_u32 height,
128 gfx_color_t background, FILE *fo);
130 /* PDF support */
131 int gfx_render_pdf (gfx_canvas_t *canvas,
132 art_u32 width, art_u32 height,
133 gfx_color_t background, FILE *fo);
135 #endif