2 * Hic Est Leo -- Main Program
4 * (c) 2014 Martin Mares <mj@ucw.cz>
21 uns debug_dump_source, debug_dump_after_proj, debug_dump_after_scaling;
22 uns debug_dump_multipolygons, debug_dump_css, debug_dump_styling, debug_dump_symbols;
24 static struct cf_section debug_cf = {
26 CF_UNS("DumpSource", &debug_dump_source),
27 CF_UNS("DumpAfterProj", &debug_dump_after_proj),
28 CF_UNS("DumpAfterScaling", &debug_dump_after_scaling),
29 CF_UNS("DumpMultipolygons", &debug_dump_multipolygons),
30 CF_UNS("DumpCSS", &debug_dump_css),
31 CF_UNS("DumpStyling", &debug_dump_styling),
32 CF_UNS("DumpSymbols", &debug_dump_symbols),
37 static const struct opt_section options = {
39 OPT_HELP("Hic Est Leo -- Experimental Map Renderer"),
48 // FIXME: Make generic
49 static void draw_scale(struct svg *svg)
52 double width = dist * map_scale;
53 double x = page_width - 10 - width;
56 svg_push_element(svg, "g");
57 svg_set_attr(svg, "id", "scale");
58 svg_set_attr_format(svg, "transform", "translate(%.6g,%.6g)", x * svg->scale, y * svg->scale);
60 for (int outline=1; outline>=0; outline--)
62 svg_push_element(svg, "g");
63 svg_set_attr(svg, "stroke-linecap", "square");
66 svg_set_attr_dimen(svg, "stroke-width", 1.5);
67 svg_set_attr_color(svg, "stroke", 0xffffff);
71 svg_set_attr_dimen(svg, "stroke-width", 0.5);
72 svg_set_attr_color(svg, "stroke", 0);
75 svg_push_element(svg, "line");
76 svg_set_attr_dimen(svg, "x1", 0);
77 svg_set_attr_dimen(svg, "y1", 0);
78 svg_set_attr_dimen(svg, "x2", width);
79 svg_set_attr_dimen(svg, "y2", 0);
82 for (int i=0; i<=10; i++)
97 svg_push_element(svg, "line");
98 svg_set_attr_dimen(svg, "x1", width * i/10);
99 svg_set_attr_dimen(svg, "y1", 0);
100 svg_set_attr_dimen(svg, "x2", width * i/10);
101 svg_set_attr_dimen(svg, "y1", -tick);
108 scale_text(svg, 0, 5, osm_val_encode("0"));
109 scale_text(svg, width, 5, osm_val_encode("1 km"));
113 int main(int argc UNUSED, char **argv)
115 cf_def_file = "map.cf";
116 cf_declare_section("Debug", &debug_cf, 0);
117 opt_parse(&options, argv+1);
122 msg(L_INFO, "Parsing OSM");
123 osm_xml_parse(map_xml_input);
124 if (debug_dump_source)
126 puts("=== Source data ===");
129 osm_make_multipolygons();
131 msg(L_INFO, "Projecting");
132 osm_project(map_projection);
133 if (debug_dump_after_proj)
135 puts("=== Map after projection ===");
140 if (debug_dump_after_scaling)
142 puts("=== Map after scaling ===");
146 struct css_sheet *ss = css_load(map_style_sheet);
149 puts("=== Stylesheet ===");
153 struct svg *svg = svg_open(map_svg_output);
156 svg_set_attr_dimen(svg, "width", page_width);
157 svg_set_attr_dimen(svg, "height", page_height);
161 svg_set_attr_dimen(svg, "width", page_height);
162 svg_set_attr_dimen(svg, "height", page_width);
165 struct style_results r;
169 msg(L_INFO, "Applying stylesheet");
170 for (uns i = OSM_TYPE_NODE; i <= OSM_TYPE_MULTIPOLYGON; i++)
171 CLIST_FOR_EACH(struct osm_object *, o, osm_obj_list[i])
173 if (debug_dump_styling)
175 puts("===============================");
178 if (!map_object_visible_p(o))
180 if (debug_dump_styling)
181 printf("--> invisible\n");
186 if (debug_dump_styling)
188 sym_from_style(o, &r, svg);
194 svg_push_element(svg, "defs");
195 svg_push_element(svg, "clipPath");
196 svg_set_attr(svg, "id", "boundary");
198 svg_path_move_to(svg, page_offset_x, page_offset_y);
199 svg_path_line_to_rel(svg, page_map_width, 0);
200 svg_path_line_to_rel(svg, 0, page_map_height);
201 svg_path_line_to_rel(svg, -page_map_width, 0);
208 svg_push_element(svg, "g");
209 svg_set_attr_format(svg, "clip-path", "url(#boundary)");
211 svg_set_attr_format(svg, "transform", "translate(%.6g,0) rotate(90)", page_height * svg->scale);
214 // FIXME: Replace by generic logo drawing facility
216 struct svg_icon *logo = svg_icon_load(svg, "../logo/kocka-s-okrajem.svg");
223 double logo_width = 36.12;
224 double logo_height = 36.12 / logo->width * logo->height;
225 struct svg_icon_request sir = {
227 .x = page_width - 12 - logo_width / 2,
228 .y = 10 + logo_height / 2,
230 .height = logo_height,
232 svg_icon_put(svg, &sir);
242 svg_push_element(svg, "rect");
243 svg_set_attr_dimen(svg, "x", page_offset_x);
244 svg_set_attr_dimen(svg, "y", page_offset_y);
245 svg_set_attr_dimen(svg, "width", page_map_width);
246 svg_set_attr_dimen(svg, "height", page_map_height);
247 svg_set_attr(svg, "fill", "none");
248 svg_set_attr(svg, "stroke", "blue");
249 svg_set_attr_dimen(svg, "stroke-width", 0.2);
255 msg(L_INFO, "Finished");