diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/frame.h | 4 | ||||
-rw-r--r-- | src/mainwindow.c | 41 | ||||
-rw-r--r-- | src/mainwindow.h | 2 | ||||
-rw-r--r-- | src/render.c | 154 | ||||
-rw-r--r-- | src/render.h | 3 | ||||
-rw-r--r-- | src/slideshow.c | 8 | ||||
-rw-r--r-- | src/stylesheet.c | 10 |
7 files changed, 153 insertions, 69 deletions
diff --git a/src/frame.h b/src/frame.h index bc70e04..2e645a6 100644 --- a/src/frame.h +++ b/src/frame.h @@ -100,6 +100,10 @@ struct frame double w; double h; + /* Size of frame in pixels */ + int pix_w; + int pix_h; + PangoLayout *pl; /* True if this frame should be deleted on the next mouse click */ diff --git a/src/mainwindow.c b/src/mainwindow.c index 5cc8eab..d798256 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -41,43 +41,36 @@ /* Update a slide, once it's been edited in some way. */ -static void rerender_slide(struct presentation *p, PangoContext *pc) +void rerender_slide(struct presentation *p) { - int w, h; struct slide *s = p->cur_edit_slide; free_render_buffers(s); - w = p->thumb_slide_width; - h = (p->slide_height/p->slide_width) * w; - s->rendered_thumb = render_slide(s, w, h); + s->rendered_thumb = render_slide(s, s->parent->thumb_slide_width, + p->slide_width, p->slide_height); - w = p->edit_slide_width; - h = (p->slide_height/p->slide_width) * w; - s->rendered_edit = render_slide(s, w, h); + s->rendered_edit = render_slide(s, s->parent->edit_slide_width, + p->slide_width, p->slide_height); - w = s->parent->proj_slide_width; - h = (s->parent->slide_height/s->parent->slide_width) * w; - s->rendered_proj = render_slide(s, w, h); + s->rendered_proj = render_slide(s, s->parent->proj_slide_width, + p->slide_width, p->slide_height); } /* Ensure that "edit" and "proj" renderings are in order */ -static void render_edit_and_proj(struct presentation *p, PangoContext *pc) +static void render_edit_and_proj(struct presentation *p) { - int w, h; struct slide *s = p->cur_edit_slide; if ( s->rendered_edit == NULL ) { - w = p->edit_slide_width; - h = (p->slide_height/p->slide_width) * w; - s->rendered_edit = render_slide(s, w, h); + s->rendered_edit = render_slide(s, s->parent->edit_slide_width, + p->slide_width, p->slide_height); } if ( s->rendered_proj == NULL ) { - w = s->parent->proj_slide_width; - h = (s->parent->slide_height/s->parent->slide_width) * w; - s->rendered_proj = render_slide(s, w, h); + s->rendered_proj = render_slide(s, s->parent->proj_slide_width, + p->slide_width, p->slide_height); } } @@ -183,7 +176,7 @@ static gint open_response_sig(GtkWidget *d, gint response, show_error(p, "Failed to open presentation"); } p->cur_edit_slide = p->slides[0]; - rerender_slide(p, p->pc); + rerender_slide(p); update_toolbar(p); } else { @@ -446,7 +439,7 @@ void change_edit_slide(struct presentation *p, struct slide *np) } p->cur_edit_slide = np; - render_edit_and_proj(p, p->pc); + render_edit_and_proj(p); set_selection(p, NULL); update_toolbar(p); @@ -538,7 +531,7 @@ static gint open_notes_sig(GtkWidget *widget, struct presentation *p) static void do_slide_update(struct presentation *p, PangoContext *pc) { - rerender_slide(p, p->pc); + rerender_slide(p); redraw_editor(p); if ( (p->slideshow != NULL) && (p->cur_edit_slide == p->cur_proj_slide) ) @@ -911,7 +904,7 @@ static void insert_text(struct frame *fr, char *t, struct presentation *p) memcpy(fr->sc, tmp, fr->sc_len); free(tmp); - rerender_slide(p, p->pc); + rerender_slide(p); fr->pos += tlen; p->cursor_pos = fr->pos; redraw_editor(p); @@ -1059,7 +1052,7 @@ static gint realise_sig(GtkWidget *da, struct presentation *p) /* FIXME: Can do this "properly" by setting up a separate font map */ p->pc = gtk_widget_get_pango_context(da); - rerender_slide(p, p->pc); + rerender_slide(p); return FALSE; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 89badd4..ae8209a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,6 +28,8 @@ #endif +extern void rerender_slide(struct presentation *p); + extern int open_mainwindow(struct presentation *p); extern void change_edit_slide(struct presentation *p, struct slide *np); extern void redraw_editor(struct presentation *p); diff --git a/src/render.c b/src/render.c index a2ecaac..8a3207c 100644 --- a/src/render.c +++ b/src/render.c @@ -65,7 +65,7 @@ static void draw_outline(cairo_t *cr, struct wrap_box *box) cairo_set_line_width(cr, 0.1); cairo_stroke(cr); - snprintf(tmp, 31, "%i", box->sc_offset); + snprintf(tmp, 31, "%lli", (long long int)box->sc_offset); cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cr, 10.0); @@ -182,8 +182,46 @@ static void render_lines(struct frame *fr, cairo_t *cr) } +static void run_render_sc(cairo_t *cr, struct frame *fr, const char *sc) +{ + SCBlockList *bl; + SCBlockListIterator *iter; + struct scblock *b; + + bl = sc_find_blocks(sc, "bgcol"); + + if ( bl == NULL ) { + printf("Failed to find blocks.\n"); + return; + } + + for ( b = sc_block_list_first(bl, &iter); + b != NULL; + b = sc_block_list_next(bl, iter) ) + { + GdkColor col; + + if ( b->contents == NULL ) continue; + gdk_color_parse(b->contents, &col); + cairo_rectangle(cr, 0, 0, fr->w, fr->h); + gdk_cairo_set_source_color(cr, &col); + cairo_fill(cr); + + } + sc_block_list_free(bl); +} + + + +static void do_background(cairo_t *cr, struct frame *fr) +{ + run_render_sc(cr, fr, fr->style->sc_prologue); + run_render_sc(cr, fr, fr->sc); +} + + /* Render Level 1 Storycode (no subframes) */ -static int render_sc(struct frame *fr) +static int render_sc(struct frame *fr, double scale) { int i; cairo_t *cr; @@ -202,9 +240,13 @@ static int render_sc(struct frame *fr) /* Create surface and Cairo stuff */ if ( fr->contents != NULL ) cairo_surface_destroy(fr->contents); + /* Rounding to get the bitmap size */ fr->contents = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - fr->w, fr->h); + fr->pix_w, fr->pix_h); cr = cairo_create(fr->contents); + cairo_scale(cr, scale, scale); + + do_background(cr, fr); cairo_font_options_t *fopts; fopts = cairo_font_options_create(); @@ -216,6 +258,7 @@ static int render_sc(struct frame *fr) /* Find and load font */ fontmap = pango_cairo_font_map_get_default(); pc = pango_font_map_create_context(fontmap); + pango_cairo_update_context(cr, pc); /* Set up lines */ if ( wrap_contents(fr, pc) ) { @@ -236,7 +279,7 @@ static int render_sc(struct frame *fr) } -static int render_frame(struct frame *fr, cairo_t *cr) +static int render_frame(struct frame *fr, double scale) { if ( fr->num_children > 0 ) { @@ -259,7 +302,7 @@ static int render_frame(struct frame *fr, cairo_t *cr) switch ( ch->lop.w_units ) { case UNITS_SLIDE : - ch->w = ch->lop.w - mtot; + ch->w = ch->lop.w; break; case UNITS_FRAC : @@ -273,7 +316,7 @@ static int render_frame(struct frame *fr, cairo_t *cr) switch ( ch->lop.h_units ) { case UNITS_SLIDE : - ch->h = ch->lop.h - mtot; + ch->h = ch->lop.h; break; case UNITS_FRAC : @@ -282,7 +325,10 @@ static int render_frame(struct frame *fr, cairo_t *cr) } - render_frame(ch, cr); + /* Rounding to get bitmap size */ + ch->pix_w = ch->w*scale; + ch->pix_h = ch->h*scale; + render_frame(ch, scale); ch->x = ch->lop.x + fr->lop.pad_l + ch->lop.margin_l; ch->y = ch->lop.y + fr->lop.pad_t + ch->lop.margin_t; @@ -291,7 +337,7 @@ static int render_frame(struct frame *fr, cairo_t *cr) } else { - render_sc(fr); + render_sc(fr, scale); } @@ -338,33 +384,29 @@ void free_render_buffers_except_thumb(struct slide *s) } - -static void do_composite(struct frame *fr, cairo_t *cr) +static void do_composite(struct frame *fr, cairo_t *cr, double scale) { if ( fr->contents == NULL ) return; - cairo_save(cr); - cairo_rectangle(cr, fr->x, fr->y, fr->w, fr->h); - cairo_clip(cr); - cairo_set_source_surface(cr, fr->contents, fr->x, fr->y); - cairo_paint(cr); - cairo_restore(cr); + cairo_rectangle(cr, scale*fr->x, scale*fr->y, fr->pix_w, fr->pix_h); + cairo_set_source_surface(cr, fr->contents, scale*fr->x, scale*fr->y); + cairo_fill(cr); +// cairo_rectangle(cr, scale*fr->x, scale*fr->y, fr->pix_w, fr->pix_h); // cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); -// cairo_rectangle(cr, fr->x+0.5, fr->y+0.5, fr->w, fr->h); // cairo_stroke(cr); } static int composite_frames_at_level(struct frame *fr, cairo_t *cr, - int level, int cur_level) + int level, int cur_level, double scale) { int i; if ( level == cur_level ) { /* This frame is at the right level, so composite it */ - do_composite(fr, cr); + do_composite(fr, cr, scale); return 1; } else { @@ -373,7 +415,8 @@ static int composite_frames_at_level(struct frame *fr, cairo_t *cr, for ( i=0; i<fr->num_children; i++ ) { n += composite_frames_at_level(fr->children[i], cr, - level, cur_level+1); + level, cur_level+1, + scale); } return n; @@ -382,22 +425,73 @@ static int composite_frames_at_level(struct frame *fr, cairo_t *cr, } -static void composite_slide(struct slide *s, cairo_t *cr) +static void composite_slide(struct slide *s, cairo_t *cr, double scale) { int level = 0; int more = 0; do { - more = composite_frames_at_level(s->top, cr, level, 0); + more = composite_frames_at_level(s->top, cr, level, 0, scale); level++; } while ( more != 0 ); } -cairo_surface_t *render_slide(struct slide *s, int w, int h) +static void show_heirarchy(struct frame *fr, const char *t) +{ + int i; + char tn[1024]; + + strcpy(tn, t); + strcat(tn, " |-> "); + + printf("%s%p %s (%i x %i) / (%.2f x %.2f)\n", t, fr, fr->sc, + fr->pix_w, fr->pix_h, fr->w, fr->h); + + for ( i=0; i<fr->num_children; i++ ) { + if ( fr->children[i] != fr ) { + show_heirarchy(fr->children[i], tn); + } else { + printf("%s<this frame>\n", tn); + } + } + +} + + + +/** + * render_slide: + * @s: A slide. + * @w: Width of the bitmap to produce + * @ww: Width of the slide in Cairo units + * @hh: Height of the slide in Cairo units + * + * Render the entire slide. + */ +cairo_surface_t *render_slide(struct slide *s, int w, double ww, double hh) { cairo_surface_t *surf; cairo_t *cr; + int h; + double scale; + + h = (hh/ww)*w; + scale = w/ww; + + if ( s->top->style != NULL ) { + memcpy(&s->top->lop, &s->top->style->lop, + sizeof(struct layout_parameters)); + } + s->top->lop.x = 0.0; + s->top->lop.y = 0.0; + s->top->lop.w = ww; + s->top->lop.h = hh; + s->top->w = ww; + s->top->h = hh; + s->top->pix_w = w; + s->top->pix_h = h; + render_frame(s->top, scale); surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); @@ -412,19 +506,9 @@ cairo_surface_t *render_slide(struct slide *s, int w, int h) cairo_set_line_width(cr, 1.0); cairo_stroke(cr); - if ( s->top->style != NULL ) { - memcpy(&s->top->lop, &s->top->style->lop, - sizeof(struct layout_parameters)); - } - s->top->lop.x = 0.0; - s->top->lop.y = 0.0; - s->top->lop.w = w; - s->top->lop.h = h; - s->top->w = w; - s->top->h = h; - render_frame(s->top, cr); + show_heirarchy(s->top, ""); - composite_slide(s, cr); + composite_slide(s, cr, scale); cairo_destroy(cr); recursive_buffer_free(s->top); diff --git a/src/render.h b/src/render.h index 217a7d3..0ddb58d 100644 --- a/src/render.h +++ b/src/render.h @@ -29,7 +29,8 @@ #include "presentation.h" -extern cairo_surface_t *render_slide(struct slide *s, int w, int h); +extern cairo_surface_t *render_slide(struct slide *s, int w, + double ww, double hh); extern void free_render_buffers(struct slide *s); extern void free_render_buffers_except_thumb(struct slide *s); diff --git a/src/slideshow.c b/src/slideshow.c index 0b2b865..6594be8 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -58,7 +58,6 @@ static gint ss_destroy_sig(GtkWidget *widget, struct presentation *p) static gboolean ss_draw_sig(GtkWidget *da, cairo_t *cr, struct presentation *p) { - GtkAllocation allocation; double xoff, yoff; double width, height; @@ -79,9 +78,8 @@ static gboolean ss_draw_sig(GtkWidget *da, cairo_t *cr, struct presentation *p) h = p->proj_slide_width * p->slide_height / p->slide_width; /* Get the overall size */ - gtk_widget_get_allocation(da, &allocation); - xoff = (allocation.width - p->proj_slide_width)/2.0; - yoff = (allocation.height - h)/2.0; + xoff = (width - p->proj_slide_width)/2.0; + yoff = (height - h)/2.0; /* Draw the slide from the cache */ cairo_rectangle(cr, xoff, yoff, p->proj_slide_width, h); @@ -258,6 +256,8 @@ void try_start_slideshow(struct presentation *p) } /* FIXME: Sensible (configurable) choice of monitor */ + rerender_slide(p); + p->slideshow = n; p->slideshow_linked = 1; gtk_window_fullscreen(GTK_WINDOW(n)); diff --git a/src/stylesheet.c b/src/stylesheet.c index c886ba1..4aa4e74 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -108,17 +108,17 @@ void default_stylesheet(StyleSheet *ss) sty->lop.margin_r = 0.0; sty->lop.margin_t = 0.0; sty->lop.margin_b = 0.0; - sty->lop.pad_l = 0.0; - sty->lop.pad_r = 0.0; - sty->lop.pad_t = 0.0; - sty->lop.pad_b = 0.0; + sty->lop.pad_l = 40.0; + sty->lop.pad_r = 40.0; + sty->lop.pad_t = 40.0; + sty->lop.pad_b = 40.0; sty->lop.w = 1.0; sty->lop.w_units = UNITS_FRAC; sty->lop.h = 100.0; sty->lop.h_units = UNITS_SLIDE; sty->lop.x = 0.0; sty->lop.y = 300.0; - sty->sc_prologue = strdup("\\font[Sans 40]"); + sty->sc_prologue = strdup("\\font[Sorts Mill Goudy 64]"); add_to_template(titlepage, sty); sty = new_style(ss, "Slide title"); |