aboutsummaryrefslogtreecommitdiff
path: root/src/slide_render.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-09-25 19:29:11 +0200
committerThomas White <taw@bitwiz.org.uk>2011-09-25 19:29:11 +0200
commit1dbcef5a7428a7132b746653af671b3a15fc7951 (patch)
tree4b902092d0c011739017f26989779d2538c37d57 /src/slide_render.c
parente26dcd2049ae065f5a821f087abd736ba553dcad (diff)
First part of new concept for styles and layout elements
Diffstat (limited to 'src/slide_render.c')
-rw-r--r--src/slide_render.c107
1 files changed, 70 insertions, 37 deletions
diff --git a/src/slide_render.c b/src/slide_render.c
index 3a34f6a..8c438d4 100644
--- a/src/slide_render.c
+++ b/src/slide_render.c
@@ -35,38 +35,37 @@
#include "stylesheet.h"
-static void render_text_object(cairo_t *cr, struct object *o)
+static void calculate_size_from_style(struct object *o,
+ double *peright, double *pebottom,
+ double *pmw, double *pmh)
{
- double ebottom, eright, mw, mh;
double max_width, max_height;
- double xo, yo;
- PangoRectangle ink, logical;
-
- o->layout = pango_cairo_create_layout(cr);
- pango_layout_set_text(o->layout, o->text, -1);
- o->fontdesc = pango_font_description_from_string(o->style->font);
- pango_layout_set_font_description(o->layout, o->fontdesc);
+ double ebottom, eright, mw, mh;
- eright = o->parent->slide_width - o->le->margin_right;
- ebottom = o->parent->slide_height - o->le->margin_bottom;
+ eright = o->parent->slide_width - o->style->margin_right;
+ ebottom = o->parent->slide_height - o->style->margin_bottom;
mw = o->parent->slide_width;
mh = o->parent->slide_height;
- max_width = mw - o->le->margin_left - o->le->margin_right;
+ *peright = eright; *pebottom = ebottom;
+ *pmw = mw; *pmh = mh;
+
+ max_width = mw - o->style->margin_left - o->style->margin_right;
/* Use the provided maximum width if it exists and is smaller */
- if ( o->le->use_max_width && (o->le->max_width < max_width) ) {
- max_width = o->le->max_width;
+ if ( o->style->use_max_width && (o->style->max_width < max_width) )
+ {
+ max_width = o->style->max_width;
}
- max_height = mh - o->le->margin_top - o->le->margin_bottom;
+ max_height = mh - o->style->margin_top - o->style->margin_bottom;
pango_layout_set_width(o->layout, max_width*PANGO_SCALE);
pango_layout_set_height(o->layout, max_height*PANGO_SCALE);
pango_layout_set_wrap(o->layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_ellipsize(o->layout, PANGO_ELLIPSIZE_MIDDLE);
- switch ( o->le->halign ) {
+ switch ( o->style->halign ) {
case J_LEFT :
pango_layout_set_alignment(o->layout, PANGO_ALIGN_LEFT);
break;
@@ -77,66 +76,100 @@ static void render_text_object(cairo_t *cr, struct object *o)
pango_layout_set_alignment(o->layout, PANGO_ALIGN_CENTER);
break;
}
+}
- pango_cairo_update_layout(cr, o->layout);
+
+static void calculate_position_from_style(struct object *o,
+ double eright, double ebottom,
+ double mw, double mh)
+{
+ double xo, yo;
+ PangoRectangle ink, logical;
pango_layout_get_extents(o->layout, &ink, &logical);
- o->bb_width = ink.width / PANGO_SCALE;
- o->bb_height = logical.height/PANGO_SCALE;
xo = ink.x/PANGO_SCALE; yo = logical.y/PANGO_SCALE;
- switch ( o->le->halign ) {
+ switch ( o->style->halign ) {
case J_LEFT :
- o->x = -xo + o->le->margin_left;
+ o->x = -xo + o->style->margin_left;
break;
case J_RIGHT :
o->x = -xo + eright - o->bb_width;
break;
case J_CENTER :
- o->x = mw/2.0 - o->bb_width/2.0 - xo + o->le->offset_x;
+ o->x = mw/2.0 - o->bb_width/2.0 - xo + o->style->offset_x;
break;
}
- if ( o->le->halign == J_CENTER ) {
+ if ( o->style->halign == J_CENTER ) {
- if ( o->x+xo < o->le->margin_left ) {
- o->x = o->le->margin_left - xo;
+ if ( o->x+xo < o->style->margin_left ) {
+ o->x = o->style->margin_left - xo;
}
- if ( o->x+xo + o->bb_width > mw-o->le->margin_right ) {
- o->x = mw-o->le->margin_right - xo - o->bb_width;
+ if ( o->x+xo + o->bb_width > mw-o->style->margin_right ) {
+ o->x = mw-o->style->margin_right - xo - o->bb_width;
}
}
- switch ( o->le->valign ) {
+ switch ( o->style->valign ) {
case V_TOP :
- o->y = o->le->margin_top;
+ o->y = o->style->margin_top;
break;
case V_BOTTOM :
o->y = ebottom - o->bb_height;
break;
case V_CENTER :
- o->y = mh/2.0 - o->bb_height/2.0 + yo - o->le->offset_y;
+ o->y = mh/2.0 - o->bb_height/2.0 + yo - o->style->offset_y;
break;
}
- if ( o->le->valign == V_CENTER ) {
+ if ( o->style->valign == V_CENTER ) {
- if ( o->y < o->le->margin_top ) {
- o->y = o->le->margin_top;
+ if ( o->y < o->style->margin_top ) {
+ o->y = o->style->margin_top;
}
- if ( o->y+yo + o->bb_height > mh - o->le->margin_bottom ) {
- o->y = mh-o->le->margin_bottom - yo - o->bb_height;
+ if ( o->y+yo + o->bb_height > mh - o->style->margin_bottom ) {
+ o->y = mh-o->style->margin_bottom - yo - o->bb_height;
}
}
+ o->x += xo;
+ o->y += yo;
+}
+
+
+static void render_text_object(cairo_t *cr, struct object *o)
+{
+ PangoRectangle ink, logical;
+ double eright, ebottom, mw, mh;
+
+ o->layout = pango_cairo_create_layout(cr);
+ pango_layout_set_text(o->layout, o->text, -1);
+ o->fontdesc = pango_font_description_from_string(o->style->font);
+ pango_layout_set_font_description(o->layout, o->fontdesc);
+
+ if ( o->style != o->parent->parent->ss->styles[0] )
+ {
+ calculate_size_from_style(o, &eright, &ebottom, &mw, &mh);
+ }
+
+ pango_cairo_update_layout(cr, o->layout);
+
+ pango_layout_get_extents(o->layout, &ink, &logical);
+ o->bb_width = ink.width / PANGO_SCALE;
+ o->bb_height = logical.height/PANGO_SCALE;
+
+ if ( o->style != o->parent->parent->ss->styles[0] )
+ {
+ calculate_position_from_style(o, eright, ebottom, mw, mh);
+ }
+
cairo_move_to(cr, o->x, o->y);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
pango_cairo_show_layout(cr, o->layout);
- o->x += xo;
- o->y += yo;
}