1 /****************************************************************************
2 * RRDtool 1.2.1 Copyright by Tobi Oetiker, 1997-2005
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 #include <libart_lgpl/libart.h>
12 #include <libart_lgpl/art_rgba.h>
13 #include "art_rgba_svp.h"
15 enum gfx_if_en {IF_PNG=0,IF_SVG,IF_EPS,IF_PDF};
16 enum gfx_en { GFX_LINE=0,GFX_AREA,GFX_TEXT };
17 enum gfx_h_align_en { GFX_H_NULL=0, GFX_H_LEFT, GFX_H_RIGHT, GFX_H_CENTER };
18 enum gfx_v_align_en { GFX_V_NULL=0, GFX_V_TOP, GFX_V_BOTTOM, GFX_V_CENTER };
19 enum gfx_aa_type_en {AA_NORMAL=0,AA_LIGHT,AA_NONE};
20 typedef unsigned long gfx_color_t;
22 typedef struct gfx_node_t {
23 enum gfx_en type; /* type of graph element */
24 gfx_color_t color; /* color of element 0xRRGGBBAA alpha 0xff is solid*/
25 double size; /* font size, line width */
26 double dash_on, dash_off; /* dash line fragments lengths */
27 int closed_path;
28 int points;
29 int points_max;
30 char *filename; /* font or image filename */
31 char *text;
32 ArtVpath *path; /* path */
33 double x,y; /* position */
34 double angle; /* text angle */
35 enum gfx_h_align_en halign; /* text alignement */
36 enum gfx_v_align_en valign; /* text alignement */
37 double tabwidth;
38 struct gfx_node_t *next;
39 } gfx_node_t;
42 typedef struct gfx_canvas_t
43 {
44 struct gfx_node_t *firstnode;
45 struct gfx_node_t *lastnode;
46 enum gfx_if_en imgformat; /* image format */
47 int interlaced; /* will the graph be interlaced? */
48 double zoom; /* zoom for graph */
49 double font_aa_threshold; /* no anti-aliasing for sizes <= */
50 enum gfx_aa_type_en aa_type; /* anti-aliasing type (normal/light/none) */
51 } gfx_canvas_t;
53 gfx_canvas_t *gfx_new_canvas (void);
55 /* create a new line */
56 gfx_node_t *gfx_new_line (gfx_canvas_t *canvas,
57 double X0, double Y0,
58 double X1, double Y1,
59 double width, gfx_color_t color);
61 gfx_node_t *gfx_new_dashed_line (gfx_canvas_t *canvas,
62 double X0, double Y0,
63 double X1, double Y1,
64 double width, gfx_color_t color,
65 double dash_on, double dash_off);
67 /* create a new area */
68 gfx_node_t *gfx_new_area (gfx_canvas_t *canvas,
69 double X0, double Y0,
70 double X1, double Y1,
71 double X2, double Y2,
72 gfx_color_t color);
74 /* add a point to a line or to an area */
75 int gfx_add_point (gfx_node_t *node, double x, double y);
77 /* close current path so it ends at the same point as it started */
78 void gfx_close_path (gfx_node_t *node);
81 /* create a text node */
82 gfx_node_t *gfx_new_text (gfx_canvas_t *canvas,
83 double x, double y, gfx_color_t color,
84 char* font, double size,
85 double tabwidth, double angle,
86 enum gfx_h_align_en h_align,
87 enum gfx_v_align_en v_align,
88 char* text);
90 /* measure width of a text string */
91 double gfx_get_text_width ( gfx_canvas_t *canvas,
92 double start, char* font, double size,
93 double tabwidth, char* text, int rotation);
95 /* save image to file */
96 int gfx_render (gfx_canvas_t *canvas,
97 art_u32 width, art_u32 height,
98 gfx_color_t background, FILE *fo);
100 /* free memory used by nodes this will also remove memory required for
101 node chain and associated material */
102 int gfx_destroy (gfx_canvas_t *canvas);
105 /* PNG support*/
106 int gfx_render_png (gfx_canvas_t *canvas,
107 art_u32 width, art_u32 height,
108 gfx_color_t background, FILE *fo);
109 double gfx_get_text_width_libart ( gfx_canvas_t *canvas, double start,
110 char* font, double size, double tabwidth,
111 char* text, int rotation );
113 /* SVG support */
114 int gfx_render_svg (gfx_canvas_t *canvas,
115 art_u32 width, art_u32 height,
116 gfx_color_t background, FILE *fo);
118 /* EPS support */
119 int gfx_render_eps (gfx_canvas_t *canvas,
120 art_u32 width, art_u32 height,
121 gfx_color_t background, FILE *fo);
123 /* PDF support */
124 int gfx_render_pdf (gfx_canvas_t *canvas,
125 art_u32 width, art_u32 height,
126 gfx_color_t background, FILE *fo);
128 #endif