Save stuff
authorThomas White <taw@bitwiz.org.uk>
Thu, 23 May 2013 20:35:10 +0000 (22:35 +0200)
committerThomas White <taw@bitwiz.org.uk>
Thu, 23 May 2013 20:35:10 +0000 (22:35 +0200)
src/loadsave.c
src/loadsave.h
src/presentation.c
src/stylesheet.c

index 86202ee..8ee089a 100644 (file)
@@ -623,6 +623,13 @@ void serialize_b(struct serializer *ser, const char *key, int val)
 }
 
 
+void serialize_i(struct serializer *ser, const char *key, int val)
+{
+       check_prefix_output(ser);
+       fprintf(ser->fh, "%s = %i\n", key, val);
+}
+
+
 void serialize_end(struct serializer *ser)
 {
        free(ser->stack[--ser->stack_depth]);
index cea4e0c..77327cc 100644 (file)
@@ -64,6 +64,7 @@ extern void serialize_start(struct serializer *s, const char *id);
 extern void serialize_s(struct serializer *s, const char *key, const char *val);
 extern void serialize_f(struct serializer *s, const char *key, double val);
 extern void serialize_b(struct serializer *s, const char *key, int val);
+extern void serialize_i(struct serializer *s, const char *key, int val);
 extern void serialize_end(struct serializer *s);
 
 extern int get_field_f(struct ds_node *root, const char *key, double *val);
index 7bf09d9..9e13108 100644 (file)
@@ -255,6 +255,47 @@ struct presentation *new_presentation()
 }
 
 
+static char *packed_sc(struct frame *fr)
+{
+       char *sc;
+       int i;
+       size_t len = 0;
+
+       if ( fr->sc != NULL ) {
+               len += strlen(fr->sc)+1;
+               sc = malloc(len);
+               memcpy(sc, fr->sc, len+1);
+       } else {
+               len = 0;
+               sc = malloc(1);
+               sc[0] = '\0';
+       }
+
+       for ( i=0; i<fr->num_children; i++ ) {
+
+               char *ch_sc;
+               char *scn;
+               size_t ch_len;
+
+               ch_sc = packed_sc(fr->children[i]);
+               ch_len = strlen(ch_sc);
+
+               len += ch_len + 64;
+               scn = malloc(len + ch_len);
+               snprintf(scn, len, "%s\\f[%.1fx%.1f+%.1f+%.1f]{%s}", sc,
+                        fr->children[i]->lop.w, fr->children[i]->lop.h,
+                        fr->children[i]->lop.x, fr->children[i]->lop.y,
+                        ch_sc);
+               free(ch_sc);
+               free(sc);
+               sc = scn;
+
+       }
+
+       return sc;
+}
+
+
 int save_presentation(struct presentation *p, const char *filename)
 {
        FILE *fh;
@@ -289,13 +330,16 @@ int save_presentation(struct presentation *p, const char *filename)
 
                struct slide *s;
                char s_id[32];
+               char *sc;
 
                s = p->slides[i];
 
                snprintf(s_id, 31, "%i", i);
                serialize_start(&ser, s_id);
 
-               /* FIXME: Save stuff */
+               sc = packed_sc(s->top);
+               serialize_s(&ser, "sc", sc);
+               free(sc);
 
                serialize_end(&ser);
 
index bb3880f..f736d91 100644 (file)
@@ -294,6 +294,38 @@ StyleSheet *load_stylesheet(const char *filename)
 }
 
 
+static const char *units(LengthUnits un)
+{
+       switch ( un ) {
+               case UNITS_SLIDE : return "u";
+               case UNITS_FRAC : return "fr";
+       }
+       return "annoyingly unspecified units";
+}
+
+
+static void serialize_f_units(struct serializer *s, const char *key, double val,
+                              LengthUnits un)
+{
+       char tmp[64];
+
+       snprintf(tmp, 63, "%.2f %s", val, units(un));
+       serialize_s(s, key, tmp);
+}
+
+
+static int style_number(StyleSheet *ss, struct style *s)
+{
+       int i;
+
+       for ( i=0; i<ss->n_styles; i++ ) {
+               if ( ss->styles[i] == s ) return i;
+       }
+
+       return -1;
+}
+
+
 void write_stylesheet(StyleSheet *ss, struct serializer *ser)
 {
        int i;
@@ -312,10 +344,44 @@ void write_stylesheet(StyleSheet *ss, struct serializer *ser)
                serialize_f(ser, "margin_r", s->lop.margin_r);
                serialize_f(ser, "margin_t", s->lop.margin_t);
                serialize_f(ser, "margin_b", s->lop.margin_b);
+               serialize_f(ser, "pad_l", s->lop.pad_l);
+               serialize_f(ser, "pad_r", s->lop.pad_r);
+               serialize_f(ser, "pad_t", s->lop.pad_t);
+               serialize_f(ser, "pad_b", s->lop.pad_b);
+               serialize_f_units(ser, "w", s->lop.w, s->lop.w_units);
+               serialize_f_units(ser, "h", s->lop.h, s->lop.h_units);
+               serialize_s(ser, "prologue", s->sc_prologue);
+               serialize_end(ser);
+
+       }
+       serialize_end(ser);
+
+       serialize_start(ser, "templates");
+       for ( i=0; i<ss->n_templates; i++ ) {
+
+               struct slide_template *t = ss->templates[i];
+               char id[32];
+               int j;
+
+               snprintf(id, 31, "%i", i);
+
+               serialize_start(ser, id);
+               serialize_s(ser, "name", t->name);
+               for ( j=0; j<t->n_styles; j++ ) {
+
+                       struct style *s = t->styles[j];
+                       char id[32];
+
+                       snprintf(id, 31, "sty%i", i);
+
+                       serialize_i(ser, id, style_number(ss, s));
+
+               }
                serialize_end(ser);
 
        }
        serialize_end(ser);
+
 }