added SVG support -- Peter Speck <speck@ruc.dk>
[rrdtool.git] / src / rrd_gfx.h
1 /****************************************************************************
2  * RRDtool 1.1.x  Copyright Tobias Oetiker, 1997 - 2001
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 #include <libart.h>
11
12 enum gfx_en { GFX_LINE=0,GFX_AREA,GFX_TEXT };
13 enum gfx_h_align_en { GFX_H_NULL=0, GFX_H_LEFT, GFX_H_RIGHT, GFX_H_CENTER };
14 enum gfx_v_align_en { GFX_V_NULL=0, GFX_V_TOP,  GFX_V_BOTTOM, GFX_V_CENTER };
15 typedef unsigned long gfx_color_t;
16
17 typedef struct  gfx_node_t {
18   enum gfx_en   type;         /* type of graph element */
19   gfx_color_t   color;        /* color of element  0xRRGGBBAA  alpha 0xff is solid*/
20   double        size;         /* font size, line width */
21   ArtVpath      *path;        /* path */
22   int           points;
23   int           points_max;
24   ArtSVP        *svp;         /* svp */
25   char *filename;             /* font or image filename */
26   char *text;
27   double        x,y;          /* position */
28   double      angle;
29   enum gfx_h_align_en halign; /* text alignement */
30   enum gfx_v_align_en valign; /* text alignement */
31   double        tabwidth; 
32   struct gfx_node_t  *next; 
33 } gfx_node_t;
34
35
36 typedef struct gfx_canvas_t 
37 {
38     struct gfx_node_t *firstnode;
39     struct gfx_node_t *lastnode;
40 } gfx_canvas_t;
41
42
43 gfx_canvas_t *gfx_new_canvas (void);
44
45 /* create a new line */
46 gfx_node_t   *gfx_new_line   (gfx_canvas_t *canvas, 
47                               double x0, double y0, 
48                               double x1, double y1,
49                               double width, gfx_color_t color);
50
51 /* create a new area */
52 gfx_node_t   *gfx_new_area   (gfx_canvas_t *canvas, 
53                               double x0, double y0,
54                               double x1, double y1,
55                               double x2, double y2,
56                               gfx_color_t  color);
57
58 /* add a point to a line or to an area */
59 int           gfx_add_point  (gfx_node_t *node, double x, double y);
60
61
62 /* create a text node */
63 gfx_node_t   *gfx_new_text   (gfx_canvas_t *canvas,  
64                               double x, double y, gfx_color_t color,
65                               char* font, double size,                        
66                               double tabwidth, double angle,
67                               enum gfx_h_align_en h_align,
68                               enum gfx_v_align_en v_align,
69                               char* text);
70
71 /* measure width of a text string */
72 double gfx_get_text_width ( double start, char* font, double size,                            
73                             double tabwidth, char* text);
74
75
76
77 /* turn graph into a png image */
78 int       gfx_render_png (gfx_canvas_t *canvas,
79                               art_u32 width, art_u32 height,
80                               double zoom,
81                               gfx_color_t background, FILE *fo);
82                                                                                           
83                                                                                          
84 /* free memory used by nodes this will also remove memory required for
85    node chain and associated material */
86 int           gfx_destroy    (gfx_canvas_t *canvas); 
87
88 #endif
89
90 /* turn graph into an svg image */
91 int       gfx_render_svg (gfx_canvas_t *canvas,
92                               art_u32 width, art_u32 height,
93                               double zoom,
94                               gfx_color_t background, FILE *fo);
95
96