]> mj.ucw.cz Git - leo.git/blob - sym.h
Labelling: Bugfixes in get_closure
[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   struct symbol* (*copy)(struct symbol *sym);
37   bool (*look_same)(struct symbol *s1, struct symbol *s2);
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_from_style(struct osm_object *o, struct style_results *sr, struct svg *svg);
61 z_index_t sym_zindex(struct osm_object *o, struct style_info *si, double default_mzi);
62
63 struct symbol * sym_copy(struct symbol *sym);
64 bool sym_look_same(struct symbol *s1, struct symbol *s2);
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   double x;
80   double y;
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