aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/narrative_window.c10
-rw-r--r--src/presentation.c27
-rw-r--r--src/sc_interp.c44
-rw-r--r--src/sc_interp.h2
4 files changed, 75 insertions, 8 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 1bf9791..9058403 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -632,10 +632,10 @@ static void nw_update_titlebar(NarrativeWindow *nw)
static int create_thumbnail(SCInterpreter *scin, SCBlock *bl,
double *w, double *h, void **bvp, void *vp)
{
+ struct presentation *p = vp;
SCBlock *b;
- /* FIXME: Should come from presentation. 320/256 for 4:3 */
- *w = 480.0;
+ *w = 270.0*(p->slide_width / p->slide_height);
*h = 270.0;
b = sc_interp_get_macro_real_block(scin);
@@ -656,10 +656,10 @@ static cairo_surface_t *render_thumbnail(int w, int h, void *bvp, void *vp)
scblocks = sc_block_child(scblocks);
stylesheets[0] = p->stylesheet;
stylesheets[1] = NULL;
+
/* FIXME: Cache like crazy here */
- /* FIXME: Get size from presentation. 1024/768 for 4:3 */
- surf = render_sc(scblocks, w, h, 1280.0, 720.0, stylesheets, NULL,
- p->is, 0, &top, p->lang);
+ surf = render_sc(scblocks, w, h, p->slide_width, p->slide_height,
+ stylesheets, NULL, p->is, 0, &top, p->lang);
frame_free(top);
return surf;
diff --git a/src/presentation.c b/src/presentation.c
index eda8b7e..1549e0d 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -110,9 +110,9 @@ struct presentation *new_presentation(const char *imagestore)
new->scblocks = NULL;
- /* FIXME: Should come from presentation. 1024/768 for 4:3 */
- new->slide_width = 1280.0;
- new->slide_height = 720.0;
+ /* Default slide size */
+ new->slide_width = 1024.0;
+ new->slide_height = 768.0;
new->completely_empty = 1;
new->saved = 1;
@@ -408,6 +408,26 @@ static void install_stylesheet(struct presentation *p)
}
+static void set_slide_size_from_stylesheet(struct presentation *p)
+{
+ SCInterpreter *scin;
+ double w, h;
+ int r;
+
+ if ( p->stylesheet == NULL ) return;
+
+ scin = sc_interp_new(NULL, NULL, NULL, NULL);
+ sc_interp_run_stylesheet(scin, p->stylesheet); /* ss == NULL is OK */
+ r = sc_interp_get_slide_size(scin, &w, &h);
+ sc_interp_destroy(scin);
+
+ if ( r == 0 ) {
+ p->slide_width = w;
+ p->slide_height = h;
+ }
+}
+
+
int load_presentation(struct presentation *p, const char *filename)
{
int r = 0;
@@ -435,6 +455,7 @@ int load_presentation(struct presentation *p, const char *filename)
}
install_stylesheet(p);
+ set_slide_size_from_stylesheet(p);
assert(p->filename == NULL);
p->filename = strdup(filename);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index e3b584f..31c1f77 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -61,6 +61,10 @@ struct sc_state
int height;
float paraspace[4];
+ int have_size;
+ double slide_width;
+ double slide_height;
+
struct frame *fr; /* The current frame */
int n_macros;
@@ -601,6 +605,7 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang,
st->paraspace[2] = 0.0;
st->paraspace[3] = 0.0;
st->fontdesc = NULL;
+ st->have_size = 0;
scin->lang = lang;
@@ -633,6 +638,20 @@ void sc_interp_destroy(SCInterpreter *scin)
}
+static int parse_double(const char *a, float v[2])
+{
+ int nn;
+
+ nn = sscanf(a, "%fx%f", &v[0], &v[1]);
+ if ( nn != 2 ) {
+ fprintf(stderr, "Invalid size '%s'\n", a);
+ return 1;
+ }
+
+ return 0;
+}
+
+
static int parse_tuple(const char *a, float v[4])
{
int nn;
@@ -676,6 +695,19 @@ static void set_paraspace(SCInterpreter *scin, const char *opts)
}
+static void set_slide_size(SCInterpreter *scin, const char *opts)
+{
+ float p[2];
+ struct sc_state *st = &scin->state[scin->j];
+
+ if ( parse_double(opts, p) ) return;
+
+ st->slide_width = p[0];
+ st->slide_height = p[1];
+ st->have_size = 1;
+}
+
+
void update_geom(struct frame *fr)
{
char geom[256];
@@ -1314,6 +1346,9 @@ void sc_interp_run_stylesheet(SCInterpreter *scin, SCBlock *bl)
} else if ( strcmp(name, "paraspace") == 0 ) {
set_paraspace(scin, options);
+ } else if ( strcmp(name, "slidesize") == 0 ) {
+ set_slide_size(scin, options);
+
}
bl = sc_block_next(bl);
@@ -1322,6 +1357,15 @@ void sc_interp_run_stylesheet(SCInterpreter *scin, SCBlock *bl)
}
+int sc_interp_get_slide_size(SCInterpreter *scin, double *w, double *h)
+{
+ if ( !scin->state->have_size ) return 1;
+ *w = scin->state->slide_width;
+ *h = scin->state->slide_height;
+ return 0;
+}
+
+
struct template_id *sc_interp_get_templates(SCInterpreter *scin, int *np)
{
struct template_id *list;
diff --git a/src/sc_interp.h b/src/sc_interp.h
index 2ae7ee4..a666970 100644
--- a/src/sc_interp.h
+++ b/src/sc_interp.h
@@ -87,4 +87,6 @@ struct template_id
extern struct template_id *sc_interp_get_templates(SCInterpreter *scin,
int *np);
+extern int sc_interp_get_slide_size(SCInterpreter *scin, double *w, double *h);
+
#endif /* SC_INTERP_H */