aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2014-09-07 15:42:53 +0200
committerThomas White <taw@bitwiz.org.uk>2014-09-07 15:42:53 +0200
commit013f650a3ddccd1b2f23840bee909236b7a03a35 (patch)
tree40d151be33056a3eb16b70a23e3f008eea4001af /src
parent0702209973603d5523d3599e86e4c70ca828a0d9 (diff)
Factorise style sheet
Diffstat (limited to 'src')
-rw-r--r--src/presentation.c9
-rw-r--r--src/presentation.h1
-rw-r--r--src/render.c13
-rw-r--r--src/sc_interp.c191
-rw-r--r--src/sc_interp.h7
5 files changed, 136 insertions, 85 deletions
diff --git a/src/presentation.c b/src/presentation.c
index 919aad2..f490539 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -38,6 +38,7 @@
#include "notes.h"
#include "inhibit_screensaver.h"
#include "render.h"
+#include "sc_interp.h"
static int num_presentations = 0;
@@ -295,6 +296,8 @@ struct presentation *new_presentation()
new->completely_empty = 1;
+ new->stylesheet = NULL;
+
new->n_menu_rebuild = 0;
new->menu_rebuild_list = NULL;
new->menu_path_list = NULL;
@@ -433,6 +436,8 @@ int load_presentation(struct presentation *p, const char *filename)
return r; /* Error */
}
+ find_stylesheet(p);
+
block = p->scblocks;
while ( block != NULL ) {
@@ -446,9 +451,9 @@ int load_presentation(struct presentation *p, const char *filename)
if ( s != NULL ) {
- s->scblocks = block;
+ s->scblocks = sc_block_child(block);
s->top = frame_new();
- s->top->scblocks = s->scblocks;
+ s->top->scblocks = sc_block_child(block);
}
diff --git a/src/presentation.h b/src/presentation.h
index 8add695..d2dd4c0 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -193,6 +193,7 @@ struct presentation
unsigned int num_slides;
struct slide **slides;
+ SCBlock *stylesheet;
SCBlock *scblocks;
struct inhibit_sys *inhibit;
diff --git a/src/render.c b/src/render.c
index ebafe32..f4bcc70 100644
--- a/src/render.c
+++ b/src/render.c
@@ -303,7 +303,8 @@ static int recursive_wrap_and_draw(struct frame *fr, cairo_t *cr,
static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is,
enum is_size isz, struct slide_constants *scc,
struct presentation_constants *pcc,
- PangoContext *pc, SCBlock *scblocks)
+ PangoContext *pc, SCBlock *scblocks,
+ SCBlock *stylesheet)
{
SCInterpreter *scin;
int i;
@@ -314,6 +315,8 @@ static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is,
return 1;
}
+ sc_interp_run_stylesheet(scin, stylesheet);
+
for ( i=0; i<fr->n_lines; i++ ) {
// wrap_line_free(&fr->lines[i]);
}
@@ -330,7 +333,7 @@ static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is,
initialise_line(fr->boxes);
/* SCBlocks -> frames and wrap boxes (preferably re-using frames) */
- sc_interp_add_blocks(scin, scblocks, fr->scblocks);
+ sc_interp_add_blocks(scin, fr->scblocks);
recursive_wrap_and_draw(fr, cr, is, isz);
@@ -423,7 +426,8 @@ cairo_surface_t *render_slide(struct slide *s, int w, double ww, double hh,
pango_cairo_update_context(cr, pc);
render_frame(cr, s->top, is, isz, s->constants,
- s->parent->constants, pc, s->parent->scblocks);
+ s->parent->constants, pc, s->parent->scblocks,
+ s->parent->stylesheet);
cairo_font_options_destroy(fopts);
g_object_unref(pc);
@@ -486,7 +490,8 @@ int export_pdf(struct presentation *p, const char *filename)
s->top->h = w*r;
render_frame(cr, s->top, p->is, ISZ_SLIDESHOW, s->constants,
- s->parent->constants, pc, s->parent->scblocks);
+ s->parent->constants, pc, s->parent->scblocks,
+ s->parent->stylesheet);
cairo_show_page(cr);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index bbd1e75..d59c509 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -72,8 +72,6 @@ struct _scinterp
struct sc_state *state;
int j; /* Index of the current state */
int max_state;
-
- int output;
};
@@ -260,8 +258,6 @@ SCInterpreter *sc_interp_new(PangoContext *pc, struct frame *top)
scin->s_constants = NULL;
scin->p_constants = NULL;
- scin->output = 0;
-
st = &scin->state[0];
st->n_macros = 0;
st->max_macros = 16;
@@ -496,20 +492,17 @@ static int parse_image_options(const char *opth, struct frame *parent,
static void maybe_recurse_before(SCInterpreter *scin, SCBlock *child)
{
- if ( !scin->output ) return;
if ( child == NULL ) return;
sc_interp_save(scin);
}
-static void maybe_recurse_after(SCInterpreter *scin, SCBlock *child,
- SCBlock *output)
+static void maybe_recurse_after(SCInterpreter *scin, SCBlock *child)
{
- if ( !scin->output ) return;
if ( child == NULL ) return;
- sc_interp_add_blocks(scin, child, output);
+ sc_interp_add_blocks(scin, child);
sc_interp_restore(scin);
}
@@ -529,7 +522,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
} else if ( strcmp(name, "bgcol") == 0 ) {
maybe_recurse_before(scin, child);
set_frame_bgcolour(sc_interp_get_frame(scin), options);
- maybe_recurse_after(scin, child, NULL);
+ maybe_recurse_after(scin, child);
} else if ( strcmp(name, "image")==0 ) {
double w, h;
@@ -585,7 +578,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
maybe_recurse_before(scin, child);
set_frame(scin, fr);
- maybe_recurse_after(scin, child, NULL);
+ maybe_recurse_after(scin, child);
} else {
return 0;
@@ -595,6 +588,93 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
}
+static int check_macro(const char *name, SCInterpreter *scin)
+{
+ int i;
+ struct sc_state *st = &scin->state[scin->j];
+
+ for ( i=0; i<st->n_macros; i++ ) {
+ if ( strcmp(st->macros[i].name, name) == 0 ) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+
+static void exec_macro(const char *name, SCInterpreter *scin)
+{
+ int i;
+ struct sc_state *st = &scin->state[scin->j];
+
+ for ( i=0; i<st->n_macros; i++ ) {
+ if ( strcmp(st->macros[i].name, name) == 0 ) {
+ sc_interp_add_blocks(scin, st->macros[i].bl);
+ return;
+ }
+ }
+}
+
+
+int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
+{
+ printf("Running this --------->\n");
+ show_sc_blocks(bl);
+ printf("<------------\n");
+
+ while ( bl != NULL ) {
+
+ const char *name = sc_block_name(bl);
+ const char *options = sc_block_options(bl);
+ SCBlock *child = sc_block_child(bl);
+
+ if ((sc_interp_get_frame(scin) != NULL)
+ && check_outputs(bl, scin) ) {
+ /* Block handled as output thing */
+
+ } else if ( name == NULL ) {
+ /* Dummy to ensure name != NULL below */
+
+ } else if ( strcmp(name, "font") == 0 ) {
+ maybe_recurse_before(scin, child);
+ set_font(scin, options);
+ maybe_recurse_after(scin, child);
+
+ } else if ( strcmp(name, "fgcol") == 0 ) {
+ maybe_recurse_before(scin, child);
+ set_colour(scin, options);
+ maybe_recurse_after(scin, child);
+
+ } else if ( check_macro(name, scin) ) {
+ maybe_recurse_before(scin, child);
+ exec_macro(name, scin);
+ maybe_recurse_after(scin, child);
+
+ } else if ( strcmp(name, "pad") == 0 ) {
+ maybe_recurse_before(scin, child);
+ /* FIXME: Implement padding */
+ maybe_recurse_after(scin, child);
+
+ } else if ( strcmp(name, "slide") == 0 ) {
+ maybe_recurse_before(scin, child);
+ maybe_recurse_after(scin, child);
+
+ } else {
+
+ fprintf(stderr, "Don't know what to do with this:\n");
+ show_sc_block(bl, "");
+
+ }
+
+ bl = sc_block_next(bl);
+
+ }
+
+ return 0;
+}
+
+
static int add_macro(struct macro *m, char *mname, SCBlock *bl)
{
m->name = mname;
@@ -645,94 +725,51 @@ static int try_add_macro(SCInterpreter *scin, const char *options, SCBlock *bl)
}
-static int check_macro(const char *name, SCInterpreter *scin)
-{
- int i;
- struct sc_state *st = &scin->state[scin->j];
-
- for ( i=0; i<st->n_macros; i++ ) {
- if ( strcmp(st->macros[i].name, name) == 0 ) {
- return 1;
- }
- }
-
- return 0;
-}
-
-
-static void exec_macro(const char *name, SCInterpreter *scin)
+void sc_interp_run_stylesheet(SCInterpreter *scin, SCBlock *bl)
{
- int i;
- struct sc_state *st = &scin->state[scin->j];
-
- for ( i=0; i<st->n_macros; i++ ) {
- if ( strcmp(st->macros[i].name, name) == 0 ) {
- sc_interp_add_blocks(scin, st->macros[i].bl, NULL);
- return;
- }
+ if ( strcmp(sc_block_name(bl), "stylesheet") != 0 ) {
+ fprintf(stderr, "Style sheet isn't a style sheet.\n");
+ return;
}
-}
+ bl = sc_block_child(bl);
-int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, SCBlock *output)
-{
while ( bl != NULL ) {
const char *name = sc_block_name(bl);
const char *options = sc_block_options(bl);
- SCBlock *child = sc_block_child(bl);
- if ( bl == output ) scin->output = 1;
-
- if ( scin->output && (sc_interp_get_frame(scin) != NULL)
- && check_outputs(bl, scin) ) {
- /* Block handled as output thing */
-
- } else if ( name == NULL ) {
- /* Dummy to ensure name != NULL below */
-
- } else if ( strcmp(name, "ss") == 0 ) {
+ if ( (name != NULL) && (strcmp(name, "ss") == 0) ) {
try_add_macro(scin, options, sc_block_child(bl));
+ }
- } else if ( strcmp(name, "font") == 0 ) {
- maybe_recurse_before(scin, child);
- set_font(scin, options);
- maybe_recurse_after(scin, child, output);
-
- } else if ( strcmp(name, "fgcol") == 0 ) {
- maybe_recurse_before(scin, child);
- set_colour(scin, options);
- maybe_recurse_after(scin, child, output);
+ bl = sc_block_next(bl);
- } else if ( check_macro(name, scin) ) {
- maybe_recurse_before(scin, child);
- exec_macro(name, scin);
- maybe_recurse_after(scin, child, output);
+ }
+}
- } else if ( strcmp(name, "notes") == 0 ) {
- /* FIXME: Do something with notes */
- } else if ( strcmp(name, "pad") == 0 ) {
- maybe_recurse_before(scin, child);
- /* FIXME: Implement padding */
- maybe_recurse_after(scin, child, output);
+void find_stylesheet(struct presentation *p)
+{
+ SCBlock *bl = p->scblocks;
- } else if ( strcmp(name, "slide") == 0 ) {
- maybe_recurse_before(scin, child);
- maybe_recurse_after(scin, child, output);
+ if ( p->stylesheet != NULL ) {
+ fprintf(stderr, "Duplicate style sheet!\n");
+ return;
+ }
- } else {
+ while ( bl != NULL ) {
- fprintf(stderr, "Don't know what to do with this:\n");
- show_sc_block(bl, "");
+ const char *name = sc_block_name(bl);
+ if ( (name != NULL) && (strcmp(name, "stylesheet") == 0) ) {
+ p->stylesheet = bl;
+ return;
}
- if ( bl == output ) return 0;
bl = sc_block_next(bl);
}
- return 0;
+ fprintf(stderr, "No style sheet.\n");
}
-
diff --git a/src/sc_interp.h b/src/sc_interp.h
index 19c5ed8..067fd60 100644
--- a/src/sc_interp.h
+++ b/src/sc_interp.h
@@ -29,6 +29,7 @@
#include <pango/pangocairo.h>
+struct presentation;
typedef struct _scinterp SCInterpreter;
extern SCInterpreter *sc_interp_new(PangoContext *pc, struct frame *top);
@@ -37,8 +38,10 @@ extern void sc_interp_destroy(SCInterpreter *scin);
extern void sc_interp_save(SCInterpreter *scin);
extern void sc_interp_restore(SCInterpreter *scin);
-extern int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl,
- SCBlock *last);
+extern int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl);
+
+extern void find_stylesheet(struct presentation *p);
+extern void sc_interp_run_stylesheet(SCInterpreter *scin, SCBlock *bl);
/* Get the current state of the interpreter */
extern struct frame *sc_interp_get_frame(SCInterpreter *scin);