]> mj.ucw.cz Git - leo.git/blob - sym.h
Simplify: Splitting of ways to non-branching segments
[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   struct symbol *(*clone)(struct symbol *src);
39 };
40
41 extern struct mempool *sym_mp;
42
43 /*
44  *  Default values for major-z-index:
45  *
46  *      1       area
47  *      2       casing
48  *      2.1     left/right casing
49  *      2.9     line pattern
50  *      3       line
51  *      4       point
52  *      4.9     line-text
53  *      5       point-text
54  */
55 typedef u32 z_index_t;
56
57 void sym_init(void);
58 void *sym_new(enum symbolizer_type type, struct osm_object *o, size_t size);
59 void sym_plan(struct symbol *sym, z_index_t zindex);
60 void sym_draw_all(struct svg *svg);
61 void sym_for_all_planned(void (*callback)(struct symbol *s, z_index_t zindex));
62 void sym_from_style(struct osm_object *o, struct style_results *sr, struct svg *svg);
63 z_index_t sym_zindex(struct osm_object *o, struct style_info *si, double default_mzi);
64 bool sym_same_attrs_p(struct symbol *x, struct symbol *y);
65 void sym_disable(struct symbol *s);
66 struct symbol *sym_clone(struct symbol *s);
67
68 /* sym-point.c handles point symbols and icons */
69
70 struct sym_point {
71   struct symbol s;
72   osm_val_t shape;
73   double size;
74   color_t stroke_color;
75   double stroke_width;
76   double stroke_opacity;
77   color_t fill_color;
78   double fill_opacity;
79   bool do_stroke;
80   bool do_fill;
81 };
82
83 // FIXME: Make sym_*_new() and symbolizer structs internal
84 extern struct symbolizer symbolizer_point;
85 struct sym_point *sym_point_new(struct osm_object *o);
86
87 struct sym_icon {
88   struct symbol s;
89   struct svg_icon_request sir;
90 };
91
92 extern struct symbolizer symbolizer_icon;
93 struct sym_icon *sym_icon_new(struct osm_object *o);
94
95 /* sym-line.c handles lines and areas */
96
97 struct sym_line {
98   struct symbol s;
99   double width;
100   color_t color;
101   double opacity;
102   osm_val_t line_cap;
103   osm_val_t line_join;
104   double miter_limit;
105   double *dash_pattern;                 // Growing array
106   double dash_offset;
107 };
108
109 extern struct symbolizer symbolizer_line;
110 struct sym_line *sym_line_new(struct osm_object *o);
111
112 struct sym_area {
113   struct symbol s;
114   color_t fill_color;
115   double fill_opacity;
116   struct svg_pattern *fill_pattern;
117 };
118
119 extern struct symbolizer symbolizer_area;
120 struct sym_area *sym_area_new(struct osm_object *o);
121
122 struct sym_lineimg {                    // Images along line
123   struct symbol s;
124   struct svg_icon_request sir;
125   osm_val_t align;
126   double offset;
127   double spacing;
128   double phase;
129 };
130
131 extern struct symbolizer symbolizer_lineimg;
132 struct sym_lineimg *sym_lineimg_new(struct osm_object *o);
133
134 /* sym-text.c */
135
136 struct sym_text {
137   struct symbol s;
138   osm_val_t text;
139   color_t text_color;
140   double x;
141   double y;
142   double rotate;                        // Rotation in degrees CCW
143   struct text_font *font;
144   double opacity;
145   color_t halo_color;
146   double halo_radius;
147   double halo_opacity;
148   struct sym_text *next_in_tile;        // See text_by_tile[]
149   struct sym_text *next_duplicate;
150   double tw, th, td;
151 };
152
153 extern struct symbolizer symbolizer_text;
154 struct sym_text *sym_text_new(struct osm_object *o);
155
156 void scale_text(struct svg *svg, double x, double y, osm_val_t text);
157
158 #endif