]> mj.ucw.cz Git - leo.git/blob - svg.h
Updated UCW::Configure to the version from current LibUCW
[leo.git] / svg.h
1 /*
2  *      Hic Est Leo -- SVG Output
3  *
4  *      (c) 2014 Martin Mares <mj@ucw.cz>
5  */
6
7 #ifndef _LEO_SVG_H
8 #define _LEO_SVG_H
9
10 // FIXME: Passing SVG pointers everywhere is ugly, using global context less so.
11
12 struct svg {
13   struct fastbuf *fb;
14   struct svg_element **stack;
15   struct mempool *pool;
16   struct fbpool *fb_pool;
17   struct fastbuf *str_fb;       // fb_pool cast to the right type
18   double scale;                 // 1mm is converted to this many px
19   uns icon_counter;
20   struct icon_table *icon_hash;
21   uns pattern_counter;
22 };
23
24 struct svg_element {
25   byte type;                    // XML_NODE_xxx
26   byte flags;                   // SVG_EF_xxx
27   byte rfu[2];
28   int indent;                   // -1 = inline
29   const char *name;
30   clist attrs;
31 };
32
33 struct svg_attr {
34   cnode n;
35   const char *key, *val;
36 };
37
38 enum svg_element_flags {
39   SVG_EF_FLAT = 1,
40   SVG_EF_START_TAG = 2,         // Internal: start tag has been already printed
41   SVG_EF_HAS_CHILDREN = 4,
42 };
43
44 struct svg *svg_open(char *filename);
45 void svg_close(struct svg *svg);
46
47 struct svg_element *svg_push_element(struct svg *svg, const char *name);
48 struct svg_element *svg_push_chars(struct svg *svg);
49 struct svg_element *svg_push_comment(struct svg *svg);
50 void svg_pop(struct svg *svg);
51
52 void svg_set_attr(struct svg *svg, const char *key, const char *val);
53 void svg_set_attr_ref(struct svg *svg, const char *key, const char *val);
54 void svg_set_attr_int(struct svg *svg, const char *key, int val);
55 void svg_set_attr_float(struct svg *svg, const char *key, double val);
56 void svg_set_attr_dimen(struct svg *svg, const char *key, double val);
57 void svg_set_attr_color(struct svg *svg, const char *key, color_t color);
58 void svg_set_attr_format(struct svg *svg, const char *key, const char *fmt, ...) FORMAT_CHECK(printf,3,4);
59
60 struct fastbuf *svg_fb_open(struct svg *svg);
61 const char *svg_fb_close(struct svg *svg);
62 void svg_fb_close_as_attr(struct svg *svg, const char *key);
63
64 struct svg_element *svg_push_path(struct svg *svg);
65 void svg_path_end(struct svg *svg);
66 void svg_path_move_to(struct svg *svg, double x, double y);
67 void svg_path_move_to_rel(struct svg *svg, double x, double y);
68 void svg_path_line_to(struct svg *svg, double x, double y);
69 void svg_path_line_to_rel(struct svg *svg, double x, double y);
70 void svg_path_close(struct svg *svg);
71
72 char *svg_format_dimen(struct svg *svg, double val);
73
74 /* svg-icon.c */
75
76 struct svg_icon {
77   uns id;
78   double width, height;
79   struct xml_context *ctx;
80   struct xml_node *root;
81   clist patterns;
82   char name[1];
83 };
84
85 struct svg_icon *svg_icon_load(struct svg *svg, const char *name);
86 void svg_icon_dump_library(struct svg *svg);
87
88 void svg_icon_init(struct svg *svg);            // Called from svg_open()
89 void svg_icon_cleanup(struct svg *svg);         // Called from svg_close()
90
91 struct svg_icon_request {
92   struct svg_icon *icon;
93   double x, y;
94   double width, height;
95 };
96
97 void svg_icon_put(struct svg *svg, struct svg_icon_request *sir);
98
99 struct svg_pattern_request {
100   struct svg_icon *icon;
101   double width, height;
102 };
103
104 struct svg_pattern {
105   cnode n;
106   uns id;
107   struct svg_icon *icon;
108   double width, height;
109   char *paint_server;
110 };
111
112 struct svg_pattern *svg_icon_to_pattern(struct svg *svg, struct svg_pattern_request *spr);
113
114 #endif