2 * Hic Est Leo -- Styling
4 * (c) 2014 Martin Mares <mj@ucw.cz>
13 typedef u32 prop_t, layer_t; // See dictionaries below
18 // The other style are defined by style_layer_dict
21 struct style_results { // Computed style information for a given object in all layers
22 struct osm_object *obj;
24 struct style_info **layers;
25 uns num_active_layers;
26 layer_t *active_layers;
30 struct style_info { // Computed style information per layer
31 struct style_prop_table *hash; // Hash table of style properties
34 enum style_prop_type {
36 PROP_TYPE_STRING, // Quoted string hashed in osm_value_dict
37 PROP_TYPE_IDENT, // Unquoted string hashed in osm_value_dict
38 PROP_TYPE_NUMBER, // Floating-point number
39 PROP_TYPE_COLOR, // Color represented in RGB
40 PROP_TYPE_LIST, // List of values
44 prop_t key; // From style_prop_dict
45 enum style_prop_type type; // PROP_TYPE_xxx
50 clist *list; // Of style_val_list_entry
54 struct style_val_list_entry {
56 struct style_prop val; // val.key is unused
59 enum prop_keys { // Well-known properties
61 #define P(x,y) PROP_##x,
62 #include "dict-props.h"
66 void styles_init(void);
67 void style_init(struct style_results *r);
68 void style_begin(struct style_results *r, struct osm_object *o);
69 void style_end(struct style_results *r);
71 void style_set_by_layer(struct style_results *r, layer_t layer, struct style_prop *p);
73 void style_set(struct style_info *si, struct style_prop *p);
74 struct style_prop *style_get(struct style_info *si, prop_t key);
75 osm_val_t style_get_ident(struct style_info *si, prop_t key);
76 osm_val_t style_get_string(struct style_info *si, prop_t key);
77 bool style_get_number(struct style_info *si, prop_t key, double *dp);
78 bool style_get_color(struct style_info *si, prop_t key, color_t *colorp);
79 struct style_prop *style_get_and_check(struct style_info *si, prop_t key, uns allowed_types);
81 extern struct dict style_prop_dict, style_layer_dict;
83 static inline prop_t style_prop_encode(const char *key)
85 return dict_encode(&style_prop_dict, key);
88 static inline const char *style_prop_decode(prop_t id)
90 return dict_decode(&style_prop_dict, id);
93 static inline layer_t style_layer_encode(const char *key)
95 return dict_encode(&style_layer_dict, key);
98 static inline const char *style_layer_decode(layer_t id)
100 return dict_decode(&style_layer_dict, id);
103 void style_dump(struct style_results *r);
104 void style_dump_prop(struct style_prop *p);
106 void style_scale(struct style_info *si, double *wp, double *hp, prop_t width_prop, prop_t height_prop);