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_cleanup(struct style_results *r);
69 void style_begin(struct style_results *r, struct osm_object *o);
70 void style_end(struct style_results *r);
71 void style_enable_default_layer(struct style_results *r);
73 void style_set_by_layer(struct style_results *r, layer_t layer, struct style_prop *p);
75 void style_set(struct style_info *si, struct style_prop *p);
76 struct style_prop *style_get(struct style_info *si, prop_t key);
77 osm_val_t style_get_ident(struct style_info *si, prop_t key);
78 osm_val_t style_get_string(struct style_info *si, prop_t key);
79 bool style_get_number(struct style_info *si, prop_t key, double *dp);
80 bool style_get_color(struct style_info *si, prop_t key, color_t *colorp);
81 struct style_prop *style_get_and_check(struct style_info *si, prop_t key, uns allowed_types);
83 extern struct dict style_prop_dict, style_layer_dict;
85 static inline prop_t style_prop_encode(const char *key)
87 return dict_encode(&style_prop_dict, key);
90 static inline const char *style_prop_decode(prop_t id)
92 return dict_decode(&style_prop_dict, id);
95 static inline layer_t style_layer_encode(const char *key)
97 return dict_encode(&style_layer_dict, key);
100 static inline layer_t style_layer_encode_if_exists(const char *key)
102 return dict_encode_if_exists(&style_layer_dict, key);
105 static inline const char *style_layer_decode(layer_t id)
107 return dict_decode(&style_layer_dict, id);
110 void style_dump(struct style_results *r);
111 void style_dump_prop(struct style_prop *p);
113 void style_scale(struct style_info *si, double *wp, double *hp, prop_t width_prop, prop_t height_prop);