diff options
author | Thomas White <taw@bitwiz.org.uk> | 2013-01-27 19:40:12 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2013-01-27 19:40:12 +0100 |
commit | bdd8fab8bc3482c5629619ae3d89018c39e2a263 (patch) | |
tree | 5bbabdaa4c1eccbd5adf3ba1d16750a2a46f29b9 | |
parent | 6b115264f47f86a61c7e2f38d7621a1d3f30c7a3 (diff) |
Back to basics..
-rw-r--r-- | src/frame.h | 10 | ||||
-rw-r--r-- | src/render.c | 169 | ||||
-rw-r--r-- | src/stylesheet.c | 13 | ||||
-rw-r--r-- | tests/render_test.c | 9 | ||||
-rw-r--r-- | tests/render_test_sc1.c | 2 |
5 files changed, 36 insertions, 167 deletions
diff --git a/src/frame.h b/src/frame.h index b0a01bb..8327f56 100644 --- a/src/frame.h +++ b/src/frame.h @@ -57,12 +57,10 @@ struct layout_parameters double pad_t; double pad_b; - Direction grav; - - double min_w_u; - double min_h_u; - double min_w_frac; - double min_h_frac; + double x; + double y; + double w; + double h; }; diff --git a/src/render.c b/src/render.c index 99b2fa2..f879b99 100644 --- a/src/render.c +++ b/src/render.c @@ -3,7 +3,7 @@ * * Colloquium - A tiny presentation program * - * Copyright (c) 2012 Thomas White <taw@bitwiz.org.uk> + * Copyright (c) 2013 Thomas White <taw@bitwiz.org.uk> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -221,13 +221,14 @@ static void initialise_line(struct wrap_line *l) static void dispatch_line(struct renderstuff *s) { + s->n_lines++; + if ( s->n_lines == s->max_lines ) { s->max_lines += 32; alloc_lines(s); if ( s->n_lines == s->max_lines ) return; } - s->n_lines++; initialise_line(&s->lines[s->n_lines]); } @@ -413,11 +414,10 @@ static void render_lines(struct renderstuff *s) /* Render Level 1 Storycode (no subframes) */ -static int render_sc(struct frame *fr, double max_w, double max_h) +static int render_sc(struct frame *fr) { PangoFontDescription *fontdesc; struct renderstuff s; - double w, h; PangoAttribute *attr_font; SCBlockList *bl; SCBlockListIterator *iter; @@ -433,7 +433,7 @@ static int render_sc(struct frame *fr, double max_w, double max_h) return 0; } - s.wrap_w = max_w - fr->lop.pad_l - fr->lop.pad_r; + s.wrap_w = fr->w - fr->lop.pad_l - fr->lop.pad_r; s.lines = NULL; s.n_lines = 0; s.max_lines = 64; @@ -461,37 +461,10 @@ static int render_sc(struct frame *fr, double max_w, double max_h) sc_block_list_free(bl); dispatch_line(&s); - /* Determine size used */ - w = 0.0; h = 0.0; - for ( i=0; i<s.n_lines; i++ ) { - if ( s.lines[i].width > w ) w = s.lines[i].width; - h += s.lines[i].height; - } - w /= PANGO_SCALE; - h /= PANGO_SCALE; - w += fr->lop.pad_l + fr->lop.pad_r; - h += fr->lop.pad_t + fr->lop.pad_b; - - /* Impose minimum and maximum widths */ - if ( w < fr->lop.min_w_u ) { - w = fr->lop.min_w_u; - } - if ( w < max_w * fr->lop.min_w_frac ) { - w = fr->lop.min_w_frac * max_w; - } - if ( w > max_w ) w = max_w; - - if ( h < fr->lop.min_h_u ) { - h = fr->lop.min_h_u; - } - if ( h < max_h * fr->lop.min_h_frac ) { - h = fr->lop.min_h_frac * max_h; - } - if ( h > max_h ) h = max_h; - - /* Having decided on the size, create surface and render the contents */ + /* Create surface and render the contents */ if ( fr->contents != NULL ) cairo_surface_destroy(fr->contents); - fr->contents = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + fr->contents = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + fr->w, fr->h); s.cr = cairo_create(fr->contents); cairo_font_options_t *fopts; @@ -514,100 +487,11 @@ static int render_sc(struct frame *fr, double max_w, double max_h) pango_attr_list_unref(s.attrs); g_object_unref(s.pc); - fr->w = w; - fr->h = h; - - return 0; -} - - -static int get_max_size(struct frame *fr, struct frame *parent, - int this_subframe, double fixed_x, double fixed_y, - double parent_max_width, double parent_max_height, - double *p_width, double *p_height) -{ - double w, h; - int i; - - w = parent_max_width - parent->lop.pad_l - parent->lop.pad_r; - w -= fr->lop.margin_l + fr->lop.margin_r; - - h = parent_max_height - parent->lop.pad_t - parent->lop.pad_b; - h -= fr->lop.margin_t + fr->lop.margin_b; - - for ( i=0; i<this_subframe; i++ ) { - - //struct frame *ch; - - //ch = parent->children[i]; - - /* FIXME: Shrink if this frame overlaps */ - switch ( fr->lop.grav ) - { - case DIR_UL: - /* Fix top left corner */ - break; - - case DIR_U: - case DIR_UR: - case DIR_R: - case DIR_DR: - case DIR_D: - case DIR_DL: - case DIR_L: - fprintf(stderr, "Gravity not implemented.\n"); - break; - - case DIR_NONE: - break; - } - } - - *p_width = w; - *p_height = h; return 0; } -static void position_frame(struct frame *fr, struct frame *parent) -{ - const double frame_gw = fr->w + fr->lop.margin_l + fr->lop.margin_r; - const double frame_gh = fr->h + fr->lop.margin_t + fr->lop.margin_b; - - switch ( fr->lop.grav ) - { - case DIR_UL: - fr->x = parent->x + parent->lop.pad_l + fr->lop.margin_l; - fr->y = parent->y + parent->lop.pad_t + fr->lop.margin_t; - break; - - case DIR_U: - fr->x = parent->x + parent->lop.pad_l + fr->lop.margin_l + - (parent->w - parent->lop.pad_l - parent->lop.pad_r)/2.0 - - frame_gw/2.0; - fr->y = 0.0; - break; - - case DIR_UR: - fr->x = parent-_x + parent->lop - break - - case DIR_R: - case DIR_DR: - case DIR_D: - case DIR_DL: - case DIR_L: - case DIR_NONE: - fprintf(stderr, "Gravity not implemented.\n"); - break; - - break; - } -} - - -static int render_frame(struct frame *fr, cairo_t *cr, - double max_w, double max_h) +static int render_frame(struct frame *fr, cairo_t *cr) { if ( fr->num_children > 0 ) { @@ -616,39 +500,26 @@ static int render_frame(struct frame *fr, cairo_t *cr, /* Render all subframes */ for ( i=0; i<fr->num_children; i++ ) { - double x, y, child_max_w, child_max_h; struct frame *ch = fr->children[i]; - int changed; if ( ch->style != NULL ) { memcpy(&ch->lop, &ch->style->lop, sizeof(struct layout_parameters)); } - get_max_size(ch, fr, i, x, y, max_w, max_h, - &child_max_w, &child_max_h); - - do { - - /* Render it and hence (recursively) find out - * how much space it actually needs.*/ - render_frame(ch, cr, child_max_w, child_max_h); - - changed = get_max_size(ch, fr, i, x, y, - max_w, max_h, - &child_max_w, - &child_max_h); + ch->w = ch->lop.w; + ch->h = ch->lop.h; - } while ( changed ); + render_frame(ch, cr); - /* Position the frame within the parent */ - position_frame(ch, fr); + ch->x = ch->lop.x; + ch->y = ch->lop.y; } } else { - render_sc(fr, max_w, max_h); + render_sc(fr); } @@ -755,13 +626,13 @@ cairo_surface_t *render_slide(struct slide *s, int w, int h) cairo_set_line_width(cr, 1.0); cairo_stroke(cr); - s->top->lop.min_w_u = 0.0; - s->top->lop.min_h_u = 0.0; - s->top->lop.min_w_frac = 1.0; - s->top->lop.min_h_frac = 1.0; + 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, w, h); + render_frame(s->top, cr); composite_slide(s, cr); diff --git a/src/stylesheet.c b/src/stylesheet.c index 3fde53c..e8907dd 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -57,10 +57,10 @@ struct style *new_style(StyleSheet *ss, const char *name) sty->name = strdup(name); /* DS9K compatibility */ - sty->lop.min_w_u = 0.0; - sty->lop.min_h_u = 0.0; - sty->lop.min_w_frac = 0.0; - sty->lop.min_w_frac = 0.0; + sty->lop.x = 0.0; + sty->lop.y = 0.0; + sty->lop.w = 100.0; + sty->lop.h = 100.0; n = ss->n_styles; styles_new = realloc(ss->styles, (n+1)*sizeof(sty)); @@ -107,7 +107,6 @@ void default_stylesheet(StyleSheet *ss) sty->lop.margin_r = 20.0; sty->lop.margin_t = 20.0; sty->lop.margin_b = 20.0; - sty->lop.grav = DIR_U; add_to_template(titlepage, sty); sty = new_style(ss, "Content"); @@ -115,7 +114,6 @@ void default_stylesheet(StyleSheet *ss) sty->lop.margin_r = 20.0; sty->lop.margin_t = 20.0; sty->lop.margin_b = 20.0; - sty->lop.grav = DIR_NONE; add_to_template(slide, sty); sty = new_style(ss, "Slide title"); @@ -123,8 +121,6 @@ void default_stylesheet(StyleSheet *ss) sty->lop.margin_r = 20.0; sty->lop.margin_t = 20.0; sty->lop.margin_b = 20.0; - sty->lop.grav = DIR_U; - sty->lop.min_w_frac = 1.0; add_to_template(slide, sty); sty = new_style(ss, "Content"); @@ -132,7 +128,6 @@ void default_stylesheet(StyleSheet *ss) sty->lop.margin_r = 20.0; sty->lop.margin_t = 20.0; sty->lop.margin_b = 20.0; - sty->lop.grav = DIR_NONE; add_to_template(acknowledgements, sty); } diff --git a/tests/render_test.c b/tests/render_test.c index 1d667a7..5fbb29d 100644 --- a/tests/render_test.c +++ b/tests/render_test.c @@ -87,6 +87,10 @@ int main(int argc, char *argv[]) sty1->lop.margin_r = 0.0; sty1->lop.margin_t = 0.0; sty1->lop.margin_b = 0.0; + sty1->lop.x = 0.0; + sty1->lop.y = 0.0; + sty1->lop.w = 100.0; + sty1->lop.h = 100.0; sty1->name = strdup("Default"); sty2 = calloc(1, sizeof(struct style)); @@ -98,7 +102,10 @@ int main(int argc, char *argv[]) sty2->lop.margin_r = 5.0; sty2->lop.margin_t = 5.0; sty2->lop.margin_b = 5.0; - sty2->lop.grav = DIR_UL; + sty2->lop.x = 0.0; + sty2->lop.y = 0.0; + sty2->lop.w = 100.0; + sty2->lop.h = 100.0; sty2->name = strdup("Text frame"); fr2 = calloc(1, sizeof(struct frame)); diff --git a/tests/render_test_sc1.c b/tests/render_test_sc1.c index 67e8e14..36f0690 100644 --- a/tests/render_test_sc1.c +++ b/tests/render_test_sc1.c @@ -87,7 +87,6 @@ int main(int argc, char *argv[]) sty->lop.margin_r = 0.0; sty->lop.margin_t = 0.0; sty->lop.margin_b = 0.0; - sty->lop.grav = DIR_UL; sty->name = strdup("Default"); sty2 = calloc(1, sizeof(struct style)); @@ -99,7 +98,6 @@ int main(int argc, char *argv[]) sty2->lop.margin_r = 20.0; sty2->lop.margin_t = 20.0; sty2->lop.margin_b = 20.0; - sty2->lop.grav = DIR_UL; sty2->name = strdup("Subframe1"); fr->style = sty; |