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