]> mj.ucw.cz Git - leo.git/blob - sym.h
Labelling: Changes in overlap counting to decrease complexity
[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   double x;
75   double y;
76 };
77
78 // FIXME: Make sym_*_new() and symbolizer structs internal
79 extern struct symbolizer symbolizer_point;
80 struct sym_point *sym_point_new(struct osm_object *o);
81
82 struct sym_icon {
83   struct symbol s;
84   struct svg_icon_request sir;
85 };
86
87 extern struct symbolizer symbolizer_icon;
88 struct sym_icon *sym_icon_new(struct osm_object *o);
89
90 /* sym-line.c handles lines and areas */
91
92 struct sym_line {
93   struct symbol s;
94   double width;
95   color_t color;
96   double opacity;
97   osm_val_t line_cap;
98   osm_val_t line_join;
99   double miter_limit;
100   double *dash_pattern;                 // Growing array
101   double dash_offset;
102 };
103
104 extern struct symbolizer symbolizer_line;
105 struct sym_line *sym_line_new(struct osm_object *o);
106
107 struct sym_area {
108   struct symbol s;
109   color_t fill_color;
110   double fill_opacity;
111   struct svg_pattern *fill_pattern;
112 };
113
114 extern struct symbolizer symbolizer_area;
115 struct sym_area *sym_area_new(struct osm_object *o);
116
117 struct sym_lineimg {                    // Images along line
118   struct symbol s;
119   struct svg_icon_request sir;
120   osm_val_t align;
121   double offset;
122   double spacing;
123   double phase;
124 };
125
126 extern struct symbolizer symbolizer_lineimg;
127 struct sym_lineimg *sym_lineimg_new(struct osm_object *o);
128
129 /* sym-text.c */
130
131 struct sym_text {
132   struct symbol s;
133   osm_val_t text;
134   color_t text_color;
135   double x;
136   double y;
137   double rotate;                        // Rotation in degrees CCW
138   struct text_font *font;
139   double opacity;
140   color_t halo_color;
141   double halo_radius;
142   double halo_opacity;
143   struct sym_text *next_in_tile;        // See text_by_tile[]
144   struct sym_text *next_duplicate;
145   double tw, th, td;
146 };
147
148 extern struct symbolizer symbolizer_text;
149 struct sym_text *sym_text_new(struct osm_object *o);
150
151 void scale_text(struct svg *svg, double x, double y, osm_val_t text);
152
153 #endif