aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/frame.c23
-rw-r--r--src/frame.h2
-rw-r--r--src/render.c156
-rw-r--r--src/sc_interp.c7
4 files changed, 80 insertions, 108 deletions
diff --git a/src/frame.c b/src/frame.c
index 2906c40..9b3ab06 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -78,6 +78,29 @@ struct frame *frame_new()
}
+void renew_frame(struct frame *fr)
+{
+ int i;
+
+ if ( fr == NULL ) return;
+
+ for ( i=0; i<fr->n_lines; i++ ) {
+ // wrap_line_free(&fr->lines[i]);
+ }
+ free(fr->lines);
+ fr->lines = NULL;
+ fr->n_lines = 0;
+ fr->max_lines = 0;
+
+ if ( fr->boxes != NULL ) {
+ free(fr->boxes->boxes);
+ free(fr->boxes);
+ }
+ fr->boxes = malloc(sizeof(struct wrap_line));
+ initialise_line(fr->boxes);
+}
+
+
struct frame *add_subframe(struct frame *fr)
{
struct frame *n;
diff --git a/src/frame.h b/src/frame.h
index beb8187..791156d 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -80,7 +80,7 @@ struct frame
extern struct frame *frame_new(void);
extern struct frame *add_subframe(struct frame *fr);
-
+extern void renew_frame(struct frame *fr);
extern void show_hierarchy(struct frame *fr, const char *t);
#endif /* FRAME_H */
diff --git a/src/render.c b/src/render.c
index 68c101e..8e1645e 100644
--- a/src/render.c
+++ b/src/render.c
@@ -300,57 +300,6 @@ 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, PangoContext *pc, SCBlock *scblocks,
- SCBlock *stylesheet)
-{
- SCInterpreter *scin;
- int i;
-
- scin = sc_interp_new(pc, fr);
- if ( scin == NULL ) {
- fprintf(stderr, "Failed to set up interpreter.\n");
- return 1;
- }
-
- sc_interp_run_stylesheet(scin, stylesheet);
-
- for ( i=0; i<fr->n_lines; i++ ) {
- // wrap_line_free(&fr->lines[i]);
- }
- free(fr->lines);
- fr->lines = NULL;
- fr->n_lines = 0;
- fr->max_lines = 0;
-
- if ( fr->boxes != NULL ) {
- free(fr->boxes->boxes);
- free(fr->boxes);
- }
- fr->boxes = malloc(sizeof(struct wrap_line));
- initialise_line(fr->boxes);
-
- /* SCBlocks -> frames and wrap boxes (preferably re-using frames) */
- sc_interp_add_blocks(scin, fr->scblocks);
-
- recursive_wrap_and_draw(fr, cr, is, isz);
-
- sc_interp_destroy(scin);
-
- return 0;
-}
-
-
-void recursive_buffer_free(struct frame *fr)
-{
- int i;
-
- for ( i=0; i<fr->num_children; i++ ) {
- recursive_buffer_free(fr->children[i]);
- }
-}
-
-
void free_render_buffers(struct slide *s)
{
if ( s->rendered_edit != NULL ) cairo_surface_destroy(s->rendered_edit);
@@ -375,6 +324,52 @@ void free_render_buffers_except_thumb(struct slide *s)
}
+
+static void render_slide_to_surface(struct slide *s, cairo_surface_t *surf,
+ cairo_t *cr, enum is_size isz,
+ double scale, double w, double h,
+ ImageStore *is)
+{
+ PangoFontMap *fontmap;
+ PangoContext *pc;
+ SCInterpreter *scin;
+
+ cairo_scale(cr, scale, scale);
+
+ cairo_rectangle(cr, 0.0, 0.0, w, h);
+ cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+ cairo_fill(cr);
+
+ cairo_font_options_t *fopts;
+ fopts = cairo_font_options_create();
+ cairo_font_options_set_hint_style(fopts, CAIRO_HINT_STYLE_FULL);
+ cairo_font_options_set_hint_metrics(fopts, CAIRO_HINT_METRICS_DEFAULT);
+ cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_GRAY);
+ cairo_set_font_options(cr, fopts);
+
+ /* Find and load font */
+ fontmap = pango_cairo_font_map_get_default();
+ pc = pango_font_map_create_context(fontmap);
+ pango_cairo_update_context(cr, pc);
+
+ scin = sc_interp_new(pc, s->top);
+ if ( scin == NULL ) {
+ fprintf(stderr, "Failed to set up interpreter.\n");
+ return;
+ }
+
+ /* "The rendering pipeline" */
+ sc_interp_run_stylesheet(scin, s->parent->stylesheet);
+ renew_frame(s->top);
+ sc_interp_add_blocks(scin, s->scblocks);
+ recursive_wrap_and_draw(s->top, cr, is, isz);
+
+ sc_interp_destroy(scin);
+ cairo_font_options_destroy(fopts);
+ g_object_unref(pc);
+}
+
+
/**
* render_slide:
* @s: A slide.
@@ -391,8 +386,6 @@ cairo_surface_t *render_slide(struct slide *s, int w, double ww, double hh,
cairo_t *cr;
int h;
double scale;
- PangoFontMap *fontmap;
- PangoContext *pc;
h = (hh/ww)*w;
scale = w/ww;
@@ -404,33 +397,8 @@ cairo_surface_t *render_slide(struct slide *s, int w, double ww, double hh,
surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
cr = cairo_create(surf);
-
- cairo_scale(cr, scale, scale);
-
- cairo_rectangle(cr, 0.0, 0.0, w, h);
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
- cairo_fill(cr);
-
- cairo_font_options_t *fopts;
- fopts = cairo_font_options_create();
- cairo_font_options_set_hint_style(fopts, CAIRO_HINT_STYLE_FULL);
- cairo_font_options_set_hint_metrics(fopts, CAIRO_HINT_METRICS_DEFAULT);
- cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_GRAY);
- cairo_set_font_options(cr, fopts);
-
- /* Find and load font */
- fontmap = pango_cairo_font_map_get_default();
- pc = pango_font_map_create_context(fontmap);
- pango_cairo_update_context(cr, pc);
-
- render_frame(cr, s->top, is, isz, pc, s->parent->scblocks,
- s->parent->stylesheet);
-
- cairo_font_options_destroy(fopts);
- g_object_unref(pc);
+ render_slide_to_surface(s, surf, cr, isz, scale, w, h, is);
cairo_destroy(cr);
- recursive_buffer_free(s->top);
-
return surf;
}
@@ -440,43 +408,29 @@ int export_pdf(struct presentation *p, const char *filename)
int i;
double r;
double w = 2048.0;
+ double scale;
cairo_surface_t *surf;
cairo_t *cr;
- double scale;
- PangoFontMap *fontmap;
- PangoContext *pc;
r = p->slide_height / p->slide_width;
surf = cairo_pdf_surface_create(filename, w, w*r);
-
if ( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS ) {
fprintf(stderr, "Couldn't create Cairo surface\n");
return 1;
}
cr = cairo_create(surf);
-
scale = w / p->slide_width;
- cairo_scale(cr, scale, scale);
-
- cairo_font_options_t *fopts;
- fopts = cairo_font_options_create();
- cairo_font_options_set_hint_style(fopts, CAIRO_HINT_STYLE_FULL);
- cairo_font_options_set_hint_metrics(fopts, CAIRO_HINT_METRICS_DEFAULT);
- cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_GRAY);
- cairo_set_font_options(cr, fopts);
-
- /* Find and load font */
- fontmap = pango_cairo_font_map_get_default();
- pc = pango_font_map_create_context(fontmap);
- pango_cairo_update_context(cr, pc);
for ( i=0; i<p->num_slides; i++ ) {
struct slide *s;
s = p->slides[i];
+
+ cairo_save(cr);
+
cairo_rectangle(cr, 0.0, 0.0, p->slide_width, p->slide_height);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_fill(cr);
@@ -486,16 +440,16 @@ int export_pdf(struct presentation *p, const char *filename)
s->top->w = w;
s->top->h = w*r;
- render_frame(cr, s->top, p->is, ISZ_SLIDESHOW, pc,
- s->parent->scblocks, s->parent->stylesheet);
+ render_slide_to_surface(s, surf, cr, ISZ_SLIDESHOW, scale,
+ w, w*r, p->is);
+
+ cairo_restore(cr);
cairo_show_page(cr);
}
cairo_surface_finish(surf);
- cairo_font_options_destroy(fopts);
- g_object_unref(pc);
cairo_destroy(cr);
return 0;
diff --git a/src/sc_interp.c b/src/sc_interp.c
index c5f25d1..e6f5680 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -563,12 +563,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
struct frame *fr = sc_block_frame(bl);
- if ( fr != NULL ) {
- free(fr->boxes->boxes);
- free(fr->boxes);
- fr->boxes = malloc(sizeof(struct wrap_line));
- initialise_line(fr->boxes);
- }
+ renew_frame(fr);
if ( fr == NULL ) {
fr = add_subframe(sc_interp_get_frame(scin));