aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstorycode/presentation.c14
-rw-r--r--libstorycode/presentation.h3
-rw-r--r--libstorycode/scparse_priv.h1
-rw-r--r--libstorycode/slide.c82
-rw-r--r--libstorycode/slide.h25
-rw-r--r--libstorycode/storycode.y89
-rw-r--r--src/pdfstorycode.c9
7 files changed, 177 insertions, 46 deletions
diff --git a/libstorycode/presentation.c b/libstorycode/presentation.c
index e393020..cafb368 100644
--- a/libstorycode/presentation.c
+++ b/libstorycode/presentation.c
@@ -95,3 +95,17 @@ void presentation_add_slide(Presentation *p, Slide *s)
p->slides[p->n_slides++] = s;
}
+
+
+int presentation_num_slides(Presentation *p)
+{
+ return p->n_slides;
+}
+
+
+Slide *presentation_slide(Presentation *p, int i)
+{
+ if ( i >= p->n_slides ) return NULL;
+ if ( i < 0 ) return NULL;
+ return p->slides[i];
+}
diff --git a/libstorycode/presentation.h b/libstorycode/presentation.h
index b45f79b..24e5e92 100644
--- a/libstorycode/presentation.h
+++ b/libstorycode/presentation.h
@@ -39,4 +39,7 @@ extern void presentation_add_stylesheet(Presentation *p, Stylesheet *ss);
extern void presentation_add_narrative(Presentation *p, Narrative *n);
extern void presentation_add_slide(Presentation *p, Slide *s);
+extern int presentation_num_slides(Presentation *p);
+extern Slide *presentation_slide(Presentation *p, int i);
+
#endif /* PRESENTATION_H */
diff --git a/libstorycode/scparse_priv.h b/libstorycode/scparse_priv.h
index 54dca40..fc73bcb 100644
--- a/libstorycode/scparse_priv.h
+++ b/libstorycode/scparse_priv.h
@@ -40,6 +40,7 @@ struct scpctx
/* Frame options */
struct frame_geom geom;
+ int geom_set;
};
#endif /* SCPARSE_PRIV_H */
diff --git a/libstorycode/slide.c b/libstorycode/slide.c
index 6ff5691..3f65ca8 100644
--- a/libstorycode/slide.c
+++ b/libstorycode/slide.c
@@ -45,9 +45,18 @@ struct slide_item
{
enum slide_item_type type;
- /* For SLIDE_ITEM_TEXT */
+ /* For TEXT */
char **paragraphs;
int n_paras;
+
+ /* For IMAGE */
+ char *filename;
+
+ /* For SLIDETITLE */
+ char *text;
+
+ /* For TEXT and IMAGE */
+ struct frame_geom geom;
};
@@ -75,14 +84,39 @@ void slide_free(Slide *s)
}
+static struct slide_item *add_item(Slide *s)
+{
+ struct slide_item *new_items;
+ new_items = realloc(s->items, (s->n_items+1)*sizeof(struct slide_item));
+ if ( new_items == NULL ) return NULL;
+ s->items = new_items;
+ return &s->items[s->n_items++];
+}
+
+
int slide_add_prestitle(Slide *s, char *prestitle)
{
+ struct slide_item *item;
+
+ item = add_item(s);
+ if ( item == NULL ) return 1;
+
+ item->type = SLIDE_ITEM_PRESTITLE;
return 0;
}
int slide_add_image(Slide *s, char *filename, struct frame_geom geom)
{
+ struct slide_item *item;
+
+ item = add_item(s);
+ if ( item == NULL ) return 1;
+
+ item->type = SLIDE_ITEM_IMAGE;
+ item->geom = geom;
+ item->filename = filename;
+
return 0;
}
@@ -90,21 +124,63 @@ int slide_add_image(Slide *s, char *filename, struct frame_geom geom)
int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom)
{
int i;
- printf("got text:\n");
+ struct slide_item *item;
+
+ item = add_item(s);
+ if ( item == NULL ) return 1;
+
+ item->type = SLIDE_ITEM_TEXT;
+ item->paragraphs = malloc(n_text*sizeof(char *));
+ if ( item->paragraphs == NULL ) {
+ s->n_items--;
+ return 1;
+ }
+
for ( i=0; i<n_text; i++ ) {
- printf("%3i: '%s'\n", i, text[i]);
+ item->n_paras = n_text;
+ item->paragraphs[i] = text[i];
}
+ item->n_paras = n_text;
+
+ item->geom = geom;
+
return 0;
}
int slide_add_footer(Slide *s)
{
+ struct slide_item *item;
+
+ item = add_item(s);
+ if ( item == NULL ) return 1;
+
+ item->type = SLIDE_ITEM_FOOTER;
+
return 0;
}
int slide_add_slidetitle(Slide *s, char *slidetitle)
{
+ struct slide_item *item;
+
+ item = add_item(s);
+ if ( item == NULL ) return 1;
+
+ item->type = SLIDE_ITEM_SLIDETITLE;
+ item->text = slidetitle;
+
return 0;
}
+
+
+void describe_slide(Slide *s)
+{
+ int i;
+
+ printf(" %i items\n", s->n_items);
+ for ( i=0; i<s->n_items; i++ ) {
+ printf("item %i: %i\n", i, s->items[i].type);
+ }
+}
diff --git a/libstorycode/slide.h b/libstorycode/slide.h
index c9be25a..f42562b 100644
--- a/libstorycode/slide.h
+++ b/libstorycode/slide.h
@@ -30,13 +30,26 @@
typedef struct _slide Slide;
typedef struct _slideitem SlideItem;
+enum length_unit
+{
+ LENGTH_FRAC,
+ LENGTH_UNIT
+};
+
+
+struct length
+{
+ double len;
+ enum length_unit unit;
+};
+
+
struct frame_geom
{
- double x;
- double y;
- double w;
- double h;
- /* FIXME: units */
+ struct length x;
+ struct length y;
+ struct length w;
+ struct length h;
};
@@ -49,5 +62,7 @@ extern int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom g
extern int slide_add_footer(Slide *s);
extern int slide_add_slidetitle(Slide *s, char *slidetitle);
+/* For debugging, not really part of API */
+extern void describe_slide(Slide *s);
#endif /* SLIDE_H */
diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y
index 433b158..576e223 100644
--- a/libstorycode/storycode.y
+++ b/libstorycode/storycode.y
@@ -40,6 +40,10 @@
Narrative *n;
Slide *s;
char *str;
+ struct length len;
+ struct frame_geom geom;
+ char character;
+ double val;
}
%{
@@ -79,46 +83,60 @@
%type <str> imageframe
%type <str> bulletpoint
%type <str> frameopt
-%type <str> geometry /* FIXME: Should have its own type */
+%type <geom> geometry
+%type <len> length
%type <str> slidetitle
+%type <character> UNIT
+%type <val> VALUE
%parse-param { struct scpctx *ctx };
%initial-action
{
- ctx->p = presentation_new();
-
- /* These are the objects currently being created. They will be
- * added to the presentation when they're complete */
- ctx->n = narrative_new();
- ctx->ss = stylesheet_new();
- ctx->s = slide_new();
-
- ctx->n_str = 0;
- ctx->max_str = 32;
- ctx->str = malloc(ctx->max_str*sizeof(char *));
- if ( ctx->str == NULL ) ctx->max_str = 0;
+ ctx->p = presentation_new();
+
+ /* These are the objects currently being created. They will be
+ * added to the presentation when they're complete */
+ ctx->n = narrative_new();
+ ctx->ss = stylesheet_new();
+ ctx->s = slide_new();
+
+ ctx->n_str = 0;
+ ctx->max_str = 32;
+ ctx->str = malloc(ctx->max_str*sizeof(char *));
+ if ( ctx->str == NULL ) ctx->max_str = 0;
+
+ frameopts_reset(ctx);
}
%{
- void frameopts_reset(struct scpctx *ctx)
- {
- }
-
- void str_reset(struct scpctx *ctx)
- {
- ctx->n_str = 0;
- }
-
- void add_str(struct scpctx *ctx, char *str)
- {
- if ( ctx->n_str == ctx->max_str ) {
- char **nstr = realloc(ctx->str, (ctx->max_str+32)*sizeof(char *));
- if ( nstr == NULL ) return;
- ctx->max_str += 32;
- }
-
- ctx->str[ctx->n_str++] = str;
- }
+void frameopts_reset(struct scpctx *ctx)
+{
+ ctx->geom_set = 0;
+ ctx->geom.x.len = 0.0;
+ ctx->geom.y.len = 0.0;
+ ctx->geom.w.len = 1.0;
+ ctx->geom.h.len = 1.0;
+ ctx->geom.x.unit = LENGTH_FRAC;
+ ctx->geom.y.unit = LENGTH_FRAC;
+ ctx->geom.w.unit = LENGTH_FRAC;
+ ctx->geom.h.unit = LENGTH_FRAC;
+}
+
+void str_reset(struct scpctx *ctx)
+{
+ ctx->n_str = 0;
+}
+
+void add_str(struct scpctx *ctx, char *str)
+{
+ if ( ctx->n_str == ctx->max_str ) {
+ char **nstr = realloc(ctx->str, (ctx->max_str+32)*sizeof(char *));
+ if ( nstr == NULL ) return;
+ ctx->max_str += 32;
+ }
+
+ ctx->str[ctx->n_str++] = str;
+}
%}
%%
@@ -212,7 +230,8 @@ frameopt:
;
geometry:
- length TIMES length PLUS length PLUS length { $$ = "geom"; printf("Geometry\n"); }
+ length TIMES length PLUS length PLUS length { $$.x = $1; $$.y = $3; $$.w = $5; $$.h = $7;
+ ctx->geom = $$; ctx->geom_set = 1; }
;
alignment:
@@ -226,7 +245,9 @@ slidetitle:
;
length:
- VALUE UNIT
+ VALUE UNIT { $$.len = $VALUE;
+ if ( $UNIT == 'f' ) $$.unit = LENGTH_UNIT;
+ if ( $UNIT == 'u' ) $$.unit = LENGTH_FRAC; }
;
diff --git a/src/pdfstorycode.c b/src/pdfstorycode.c
index 276a381..4c379f4 100644
--- a/src/pdfstorycode.c
+++ b/src/pdfstorycode.c
@@ -46,10 +46,11 @@ int main(int argc, char *argv[])
g_bytes_unref(bytes);
/* Render each slide to PDF */
-// for ( i=0; i<presentation_num_slides(p); i++ ) {
-// Slide *slide = presentation_slide(p, i);
-//
-// }
+ for ( i=0; i<presentation_num_slides(p); i++ ) {
+ Slide *slide = presentation_slide(p, i);
+ printf("slide %i:\n", i);
+ describe_slide(slide);
+ }
return 0;
}