aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/storycode.c33
-rw-r--r--tests/render_test_sc1.c32
-rw-r--r--tests/storycode_test.c4
3 files changed, 61 insertions, 8 deletions
diff --git a/src/storycode.c b/src/storycode.c
index d843128..42e6db9 100644
--- a/src/storycode.c
+++ b/src/storycode.c
@@ -425,7 +425,7 @@ static struct frame *frame_new()
}
-static struct frame *add_subframe(struct frame *fr, char *sc)
+static struct frame *add_subframe(struct frame *fr)
{
struct frame *n;
@@ -437,9 +437,9 @@ static struct frame *add_subframe(struct frame *fr, char *sc)
if ( alloc_ro(fr) ) return NULL;
}
- fr->rendering_order[fr->num_ro++] = fr;
+ fr->rendering_order[fr->num_ro++] = n;
- return fr;
+ return n;
}
@@ -456,13 +456,35 @@ static void recursive_unpack(struct frame *fr, const char *sc)
b = sc_block_list_next(bl, iter) )
{
struct frame *sfr;
- sfr = add_subframe(fr, remove_blocks(sc, "f"));
+ sfr = add_subframe(fr);
+ sfr->sc = remove_blocks(b->contents, "f");
recursive_unpack(sfr, b->contents);
}
sc_block_list_free(bl);
}
+static void show_heirarchy(struct frame *fr, const char *t)
+{
+ int i;
+ char tn[1024];
+
+ strcpy(tn, t);
+ strcat(tn, " |-> ");
+
+ printf("%s%p %s\n", t, fr, fr->sc);
+
+ for ( i=0; i<fr->num_ro; i++ ) {
+ if ( fr->rendering_order[i] != fr ) {
+ show_heirarchy(fr->rendering_order[i], tn);
+ } else {
+ printf("%s<this frame>\n", tn);
+ }
+ }
+
+}
+
+
/* Unpack level 2 StoryCode (content + subframes) into frames */
struct frame *sc_unpack(const char *sc)
{
@@ -472,8 +494,9 @@ struct frame *sc_unpack(const char *sc)
if ( fr == NULL ) return NULL;
fr->sc = remove_blocks(sc, "f");
- printf("Top frame: '%s'\n", fr->sc);
recursive_unpack(fr, sc);
+ show_heirarchy(fr, "");
+
return fr;
}
diff --git a/tests/render_test_sc1.c b/tests/render_test_sc1.c
index 9cbf042..417720b 100644
--- a/tests/render_test_sc1.c
+++ b/tests/render_test_sc1.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
+#include <assert.h>
#include "../src/storycode.h"
#include "../src/render.h"
@@ -71,10 +72,39 @@ int main(int argc, char *argv[])
GtkWidget *window;
GtkWidget *drawingarea;
struct frame *fr;
+ struct style *sty;
+ struct style *sty2;
gtk_init(&argc, &argv);
- fr = sc_unpack("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur.\\f{Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.} Wibble Wobble.");
+ fr = sc_unpack("Lorem ipsum\\f{Donec ut libero} Wibble Wobble.");
+
+ sty = calloc(1, sizeof(struct style));
+ sty->lop.pad_l = 10.0;
+ sty->lop.pad_r = 10.0;
+ sty->lop.pad_t = 10.0;
+ sty->lop.pad_b = 10.0;
+ sty->lop.margin_l = 0.0;
+ sty->lop.margin_r = 0.0;
+ sty->lop.margin_t = 0.0;
+ sty->lop.margin_b = 0.0;
+ sty->name = strdup("Default");
+
+ sty2 = calloc(1, sizeof(struct style));
+ sty2->lop.pad_l = 0.0;
+ sty2->lop.pad_r = 0.0;
+ sty2->lop.pad_t = 0.0;
+ sty2->lop.pad_b = 0.0;
+ sty2->lop.margin_l = 20.0;
+ sty2->lop.margin_r = 20.0;
+ sty2->lop.margin_t = 20.0;
+ sty2->lop.margin_b = 20.0;
+ sty2->name = strdup("Default");
+
+ fr->style = sty;
+ fr->rendering_order[1]->style = sty2;
+
+ assert(fr->rendering_order[0] == fr);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
diff --git a/tests/storycode_test.c b/tests/storycode_test.c
index e9987ef..5fbde5a 100644
--- a/tests/storycode_test.c
+++ b/tests/storycode_test.c
@@ -35,8 +35,8 @@ int main(int argc, char *argv[])
SCBlockList *bl;
SCBlockListIterator *iter;
struct scblock *b;
- const char *tt = "\\bg[a=b]{wibble \\f{wobble}}\\bg{rwawr}Wobble"
- "\\f{wibble \\bg[muhu]{wobble}}";
+ const char *tt = "\\bg[a=b]{wibble \\f{wobble}}\\bg{rwawr}\\muhu Wobble"
+ "\\wibble{}\\f{wibble \\bg[muhu]{wobble}}\\frib[\\f] f";
printf("'%s' ->\n", tt);
bl = sc_find_blocks(tt, "bg");