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