From 1d03eefe14cf26c266670998eaa0c8d9a46a16de Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 6 Nov 2011 17:29:45 +0100 Subject: Load/save image objects as well, rationalise "update" a bit --- src/loadsave.c | 1 + src/tool_image.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++------ src/tool_text.c | 2 -- 3 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/loadsave.c b/src/loadsave.c index 557e34a..1969265 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -547,6 +547,7 @@ static struct slide *tree_to_slide(struct presentation *p, struct ds_node *root) o = tree_to_object(p, root->children[i], s); if ( o != NULL ) { add_object_to_slide(s, o); + o->update_object(o); } } diff --git a/src/tool_image.c b/src/tool_image.c index 8e09c27..2cb5cde 100644 --- a/src/tool_image.c +++ b/src/tool_image.c @@ -118,11 +118,23 @@ static void delete_image_object(struct object *op) } -struct object *add_image_object(struct slide *s, double x, double y, - double bb_width, double bb_height, - char *filename, struct style *sty, - struct image_store *is, - struct image_toolinfo *ti) +static void serialize(struct object *op, struct serializer *ser) +{ + struct image_object *o = (struct image_object *)op; + + serialize_f(ser, "x", op->x); + serialize_f(ser, "y", op->y); + serialize_f(ser, "w", op->bb_width); + serialize_f(ser, "h", op->bb_height); + serialize_s(ser, "filename", o->image->filename); +} + + +static struct image_object *new_image_object(double x, double y, + double bb_width, double bb_height, + char *filename, struct style *sty, + struct image_store *is, + struct image_toolinfo *ti) { struct image_object *new; @@ -150,14 +162,30 @@ struct object *add_image_object(struct slide *s, double x, double y, new->base.render_object = render_image_object; new->base.delete_object = delete_image_object; new->base.update_object = update_image_object; + new->base.serialize = serialize; + + return new; +} + +struct object *add_image_object(struct slide *s, double x, double y, + double bb_width, double bb_height, + char *filename, struct style *sty, + struct image_store *is, + struct image_toolinfo *ti) +{ + struct image_object *new; + + new = new_image_object(x, y, bb_width, bb_height, + filename, sty, is, ti); + if ( new == NULL ) return NULL; + + new->base.parent = s; if ( add_object_to_slide(s, (struct object *)new) ) { free(new); return NULL; } - update_image(new); - return (struct object *)new; } @@ -314,9 +342,48 @@ static int valid_object(struct object *o) static struct object *deserialize(struct presentation *p, struct ds_node *root, - struct toolinfo *tip) + struct slide *s, struct toolinfo *tip) { - return NULL; + struct image_object *o; + double x, y, w, h; + char *filename; + struct image_toolinfo *ti = (struct image_toolinfo *)tip; + + if ( get_field_f(root, "x", &x) ) { + fprintf(stderr, + "Couldn't find x position for object '%s'\n", + root->key); + return NULL; + } + if ( get_field_f(root, "y", &y) ) { + fprintf(stderr, + "Couldn't find y position for object '%s'\n", + root->key); + return NULL; + } + if ( get_field_f(root, "w", &w) ) { + fprintf(stderr, + "Couldn't find width for object '%s'\n", + root->key); + return NULL; + } + if ( get_field_f(root, "h", &h) ) { + fprintf(stderr, + "Couldn't find height for object '%s'\n", + root->key); + return NULL; + } + if ( get_field_s(root, "filename", &filename) ) { + fprintf(stderr, "Couldn't find filename for object '%s'\n", + root->key); + return NULL; + } + + o = new_image_object(x, y, w, h, filename, + p->ss->styles[0], p->image_store, ti); + free(filename); + + return (struct object *)o; } diff --git a/src/tool_text.c b/src/tool_text.c index 6a57c07..9f09e05 100644 --- a/src/tool_text.c +++ b/src/tool_text.c @@ -758,9 +758,7 @@ static struct object *deserialize(struct presentation *p, struct ds_node *root, free(to->text); to->text = text; to->text_len = strlen(text); - o->parent = s; o->empty = 0; - update_text(to); return o; } -- cgit v1.2.3