]> mj.ucw.cz Git - leo.git/blob - sym.h
f5d75241ea6d6000b1ba12b6abb5a2d1859eaefc
[leo.git] / sym.h
1 /*
2  *      Hic Est Leo -- Symbolizers
3  *
4  *      (c) 2014 Martin Mares <mj@ucw.cz>
5  */
6
7 #ifndef _LEO_SYM_H
8 #define _LEO_SYM_H
9
10 #include "osm.h"
11 #include "style.h"
12 #include "svg.h"
13
14 enum symbolizer_type {
15   SYMBOLIZER_INVALID,
16   SYMBOLIZER_POINT,
17   SYMBOLIZER_ICON,
18   SYMBOLIZER_LINE,
19   SYMBOLIZER_AREA,
20   SYMBOLIZER_TEXT,
21   SYMBOLIZER_LINEIMG,
22   SYMBOLIZER_DISABLED,
23   SYMBOLIZER_MAX,
24 };
25
26 struct symbol {
27   enum symbolizer_type type;
28   struct osm_object *o;
29   // Symbolizer-dependent data follow
30 };
31
32 struct symbolizer {
33   const char *name;
34   void (*draw)(struct symbol *sym, struct svg *svg);
35   void (*gen)(struct osm_object *o, struct style_info *si, struct svg *svg);
36   void (*init)(void);
37   bool (*same_p)(struct symbol *x, struct symbol *y);
38 };
39
40 extern struct mempool *sym_mp;
41
42 /*
43  *  Default values for major-z-index:
44  *
45  *      1       area
46  *      2       casing
47  *      2.1     left/right casing
48  *      2.9     line pattern
49  *      3       line
50  *      4       point
51  *      4.9     line-text
52  *      5       point-text
53  */
54 typedef u32 z_index_t;
55
56 void sym_init(void);
57 void *sym_new(enum symbolizer_type type, struct osm_object *o, size_t size);
58 void sym_plan(struct symbol *sym, z_index_t zindex);
59 void sym_draw_all(struct svg *svg);
60 void sym_for_all_planned(void (*callback)(struct symbol *s));
61 void sym_from_style(struct osm_object *o, struct style_results *sr, struct svg *svg);
62 z_index_t sym_zindex(struct osm_object *o, struct style_info *si, double default_mzi);
63 bool sym_same_attrs_p(struct symbol *x, struct symbol *y);
64 void sym_disable(struct symbol *s);
65
66 /* sym-point.c handles point symbols and icons */
67
68 struct sym_point {
69   struct symbol s;
70   osm_val_t shape;
71   double size;
72   color_t stroke_color;
73   double stroke_width;
74   double stroke_opacity;
75   color_t fill_color;
76   double fill_opacity;
77   bool do_stroke;
78   bool do_fill;
79 };
80
81 // FIXME: Make sym_*_new() and symbolizer structs internal
82 extern struct symbolizer symbolizer_point;
83 struct sym_point *sym_point_new(struct osm_object *o);
84
85 struct sym_icon {
86   struct symbol s;
87   struct svg_icon_request sir;
88 };
89
90 extern struct symbolizer symbolizer_icon;
91 struct sym_icon *sym_icon_new(struct osm_object *o);
92
93 /* sym-line.c handles lines and areas */
94
95 struct sym_line {
96   struct symbol s;
97   double width;
98   color_t color;
99   double opacity;
100   osm_val_t line_cap;
101   osm_val_t line_join;
102   double miter_limit;
103   double *dash_pattern;                 // Growing array
104   double dash_offset;
105 };
106
107 extern struct symbolizer symbolizer_line;
108 struct sym_line *sym_line_new(struct osm_object *o);
109
110 struct sym_area {
111   struct symbol s;
112   color_t fill_color;
113   double fill_opacity;
114   struct svg_pattern *fill_pattern;
115 };
116
117 extern struct symbolizer symbolizer_area;
118 struct sym_area *sym_area_new(struct osm_object *o);
119
120 struct sym_lineimg {                    // Images along line
121   struct symbol s;
122   struct svg_icon_request sir;
123   osm_val_t align;
124   double offset;
125   double spacing;
126   double phase;
127 };
128
129 extern struct symbolizer symbolizer_lineimg;
130 struct sym_lineimg *sym_lineimg_new(struct osm_object *o);
131
132 /* sym-text.c */
133
134 struct sym_text {
135   struct symbol s;
136   osm_val_t text;
137   color_t text_color;
138   double x;
139   double y;
140   double rotate;                        // Rotation in degrees CCW
141   struct text_font *font;
142   double opacity;
143   color_t halo_color;
144   double halo_radius;
145   double halo_opacity;
146   struct sym_text *next_in_tile;        // See text_by_tile[]
147   struct sym_text *next_duplicate;
148   double tw, th, td;
149 };
150
151 extern struct symbolizer symbolizer_text;
152 struct sym_text *sym_text_new(struct osm_object *o);
153
154 void scale_text(struct svg *svg, double x, double y, osm_val_t text);
155
156 #endif