aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-04-06 22:46:30 +0200
committerThomas White <taw@bitwiz.me.uk>2019-04-06 22:46:30 +0200
commitb82f2beadfbd4deb1bd89566a8115c26e82cd0f9 (patch)
tree8b7785a642dcc051bcefde2af2175a7f0660281d
parent42b06297f2e311057c1dea19d5c14cc44e126da6 (diff)
Save slides
-rw-r--r--libstorycode/storycode.c110
-rw-r--r--libstorycode/storycode.h4
-rw-r--r--libstorycode/stylesheet.c27
3 files changed, 115 insertions, 26 deletions
diff --git a/libstorycode/storycode.c b/libstorycode/storycode.c
index f9094f7..5b4901d 100644
--- a/libstorycode/storycode.c
+++ b/libstorycode/storycode.c
@@ -66,11 +66,121 @@ static int write_string(GOutputStream *fh, char *str)
}
+char unitc(enum length_unit unit)
+{
+ if ( unit == LENGTH_FRAC ) return 'f';
+ if ( unit == LENGTH_UNIT ) return 'u';
+ return '?';
+}
+
+
+const char *bgcolc(enum gradient bggrad)
+{
+ if ( bggrad == GRAD_NONE ) return "";
+ if ( bggrad == GRAD_HORIZ ) return "HORIZONTAL ";
+ if ( bggrad == GRAD_VERT ) return "VERTICAL ";
+ return "?";
+}
+
+
+const char *alignc(enum alignment ali)
+{
+ if ( ali == ALIGN_LEFT ) return "left";
+ if ( ali == ALIGN_CENTER ) return "center";
+ if ( ali == ALIGN_RIGHT ) return "right";
+ return "?";
+}
+
+
+static const char *maybe_alignment(enum alignment ali)
+{
+ if ( ali == ALIGN_INHERIT ) return "";
+ if ( ali == ALIGN_LEFT ) return "[left]";
+ if ( ali == ALIGN_CENTER ) return "[center]";
+ if ( ali == ALIGN_RIGHT ) return "[right]";
+ return "[?]";
+}
+
+
+static void write_text(GOutputStream *fh, SlideItem *item, int geom,
+ const char *t)
+{
+ char tmp[256];
+ size_t indent;
+ int i;
+
+ if ( geom ) {
+ snprintf(tmp, 255, " %s[%.4g%cx%.4g%c+%.4g%c+%.4g%c]%s", t,
+ item->geom.w.len, unitc(item->geom.w.unit),
+ item->geom.h.len, unitc(item->geom.h.unit),
+ item->geom.x.len, unitc(item->geom.x.unit),
+ item->geom.y.len, unitc(item->geom.y.unit),
+ maybe_alignment(item->align));
+ } else {
+ snprintf(tmp, 255, " %s%s",
+ t ,maybe_alignment(item->align));
+ }
+
+ indent = strlen(tmp);
+ write_string(fh, tmp);
+ write_string(fh, ": ");
+ write_string(fh, item->paras[0].text);
+ write_string(fh, "\n");
+ for ( i=0; i<indent; i++ ) tmp[i] = ' ';
+ for ( i=1; i<item->n_paras; i++ ) {
+ write_string(fh, tmp);
+ write_string(fh, ": ");
+ write_string(fh, item->paras[i].text);
+ write_string(fh, "\n");
+ }
+}
+
+
+static void write_image(GOutputStream *fh, SlideItem *item)
+{
+ char tmp[256];
+
+ snprintf(tmp, 255, " IMAGE[%.4g%cx%.4g%c+%.4g%c+%.4g%c]",
+ item->geom.w.len, unitc(item->geom.w.unit),
+ item->geom.h.len, unitc(item->geom.h.unit),
+ item->geom.x.len, unitc(item->geom.x.unit),
+ item->geom.y.len, unitc(item->geom.y.unit));
+
+ write_string(fh, tmp);
+ write_string(fh, ": ");
+ write_string(fh, item->filename);
+ write_string(fh, "\n");
+}
+
+
static int write_slide(GOutputStream *fh, Slide *s)
{
int i;
for ( i=0; i<s->n_items; i++ ) {
+ switch ( s->items[i].type ) {
+
+ case SLIDE_ITEM_TEXT:
+ write_text(fh, &s->items[i], 1, "TEXT");
+ break;
+
+ case SLIDE_ITEM_PRESTITLE:
+ write_text(fh, &s->items[i], 0, "PRESTITLE");
+ break;
+
+ case SLIDE_ITEM_SLIDETITLE:
+ write_text(fh, &s->items[i], 0, "SLIDETITLE");
+ break;
+
+ case SLIDE_ITEM_FOOTER:
+ write_string(fh, " FOOTER\n");
+ break;
+
+ case SLIDE_ITEM_IMAGE:
+ write_image(fh, &s->items[i]);
+ break;
+
+ }
}
return 0;
diff --git a/libstorycode/storycode.h b/libstorycode/storycode.h
index c3d5d5b..df9f79c 100644
--- a/libstorycode/storycode.h
+++ b/libstorycode/storycode.h
@@ -29,6 +29,10 @@
#include "narrative.h"
+extern const char *alignc(enum alignment ali);
+extern const char *bgcolc(enum gradient bggrad);
+extern char unitc(enum length_unit unit);
+
extern Narrative *storycode_parse_presentation(const char *sc);
extern int storycode_write_presentation(Narrative *n, GOutputStream *fh);
diff --git a/libstorycode/stylesheet.c b/libstorycode/stylesheet.c
index 3fdb7af..e3aecee 100644
--- a/libstorycode/stylesheet.c
+++ b/libstorycode/stylesheet.c
@@ -31,6 +31,7 @@
#include <stdio.h>
#include "stylesheet.h"
+#include "storycode.h"
enum style_mask
{
@@ -423,32 +424,6 @@ static void add_text(char **text, size_t *len, size_t *lenmax, const char *prefi
}
-static char unitc(enum length_unit unit)
-{
- if ( unit == LENGTH_FRAC ) return 'f';
- if ( unit == LENGTH_UNIT ) return 'u';
- return '?';
-}
-
-
-static const char *bgcolc(enum gradient bggrad)
-{
- if ( bggrad == GRAD_NONE ) return "";
- if ( bggrad == GRAD_HORIZ ) return "HORIZONTAL ";
- if ( bggrad == GRAD_VERT ) return "VERTICAL ";
- return "?";
-}
-
-
-static const char *alignc(enum alignment ali)
-{
- if ( ali == ALIGN_LEFT ) return "left";
- if ( ali == ALIGN_CENTER ) return "center";
- if ( ali == ALIGN_RIGHT ) return "right";
- return "?";
-}
-
-
static void add_style(char **text, size_t *len, size_t *lenmax, const char *prefix,
struct style *sty)
{