diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-11-10 21:01:44 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-11-10 21:01:44 +0100 |
commit | 5482598ad1ee3f42333d63b74b12aaa43f6ac963 (patch) | |
tree | 4f34a7ae2ad160af5e2733e0343a86834706a049 /src/stylesheet.c | |
parent | b3dba22613de912b01ae27ba30c73dfe4c05a340 (diff) |
Move stylesheet deserialization to stylesheet.c
Diffstat (limited to 'src/stylesheet.c')
-rw-r--r-- | src/stylesheet.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/stylesheet.c b/src/stylesheet.c index a164029..ffbc099 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -586,6 +586,83 @@ void default_stylesheet(StyleSheet *ss) } +static int read_style(struct style *sty, struct ds_node *root) +{ + char *align; + + get_field_f(root, "margin_left", &sty->margin_left); + get_field_f(root, "margin_right", &sty->margin_right); + get_field_f(root, "margin_top", &sty->margin_top); + get_field_f(root, "margin_bottom", &sty->margin_bottom); + + get_field_i(root, "use_max_width", &sty->use_max_width); + get_field_f(root, "max_width", &sty->max_width); + + get_field_f(root, "offset_x", &sty->offset_x); + get_field_f(root, "offset_y", &sty->offset_y); + + get_field_s(root, "font", &sty->font); + get_field_s(root, "colour", &sty->colour); + get_field_f(root, "alpha", &sty->alpha); + + get_field_s(root, "halign", &align); + sty->halign = str_to_halign(align); + free(align); + get_field_s(root, "valign", &align); + sty->valign = str_to_valign(align); + free(align); + + return 0; +} + + +StyleSheet *tree_to_stylesheet(struct ds_node *root) +{ + StyleSheet *ss; + struct ds_node *node; + int i; + + ss = new_stylesheet(); + if ( ss == NULL ) return NULL; + + node = find_node(root, "styles"); + if ( node == NULL ) { + fprintf(stderr, "Couldn't find styles\n"); + free_stylesheet(ss); + return NULL; + } + + for ( i=0; i<node->n_children; i++ ) { + + struct style *ns; + char *v; + + get_field_s(node->children[i], "name", &v); + if ( v == NULL ) { + fprintf(stderr, "No name for style '%s'\n", + node->children[i]->key); + continue; + } + + ns = new_style(ss, v); + if ( ns == NULL ) { + fprintf(stderr, "Couldn't create style for '%s'\n", + node->children[i]->key); + continue; + } + + if ( read_style(ns, node->children[i]) ) { + fprintf(stderr, "Couldn't read style '%s'\n", v); + continue; + } + + } + + return ss; +} + + + StyleSheet *new_stylesheet() { StyleSheet *ss; |