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