diff options
author | Thomas White <taw@bitwiz.org.uk> | 2012-10-08 21:09:16 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2012-10-08 21:09:16 +0200 |
commit | 43f4a4df59d960442df2faedfd50e5c7c7a55d99 (patch) | |
tree | 2ee01715b93ae567a01854485299ac33c6878131 /src/layout.c | |
parent | d52c17c36ada874e6a0702808577a603331af095 (diff) |
Create PangoLayout when laying out the frame
Because it's necessary to know how much space the contents take up
Diffstat (limited to 'src/layout.c')
-rw-r--r-- | src/layout.c | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/src/layout.c b/src/layout.c index a257112..ae7a5e8 100644 --- a/src/layout.c +++ b/src/layout.c @@ -42,7 +42,8 @@ static void copy_lop_from_style(struct frame *fr, struct style *style) } -static void layout_subframe(struct frame *fr, double w, double h) +static void layout_subframe(struct frame *fr, double w, double h, + PangoContext *pc) { int i; @@ -53,6 +54,8 @@ static void layout_subframe(struct frame *fr, double w, double h) struct frame *child; double child_w, child_h; + double offs_x, offs_y; + PangoFontDescription *fontdesc; child = fr->rendering_order[i]; @@ -60,21 +63,72 @@ static void layout_subframe(struct frame *fr, double w, double h) copy_lop_from_style(child, child->style); - child->offs_x = child->lop.margin_l + fr->lop.pad_l; - child->offs_y = child->lop.margin_t + fr->lop.pad_r; + /* First, calculate the region inside which the child frame must + * fit, having excluded the padding of its parent and its own + * margins. */ + offs_x = child->lop.margin_l + fr->lop.pad_l; + offs_y = child->lop.margin_t + fr->lop.pad_r; child_w = w - (child->lop.margin_l + child->lop.margin_r); child_h = h - (child->lop.margin_t + child->lop.margin_b); child_w -= (fr->lop.pad_l + fr->lop.pad_r); child_h -= (fr->lop.pad_t + fr->lop.pad_b); - layout_subframe(child, child_w, child_h); + /* Put the contents inside, and see how much space is needed */ + if ( child->pl == NULL ) { + child->pl = pango_layout_new(pc); + pango_layout_set_justify(child->pl, 1); + pango_layout_set_ellipsize(child->pl, 1); + } + pango_layout_set_width(child->pl, child_w*PANGO_SCALE); + pango_layout_set_height(child->pl, child_h*PANGO_SCALE); + + /* FIXME: Check for Level 1 markup e.g. image */ + pango_layout_set_text(child->pl, child->sc, -1); + + fontdesc = pango_font_description_from_string("Sans 12"); + pango_layout_set_font_description(child->pl, fontdesc); + pango_font_description_free(fontdesc); + + /* Now, apply the minimum size if given */ + if ( child->lop.min_w > 0.0 ) { + if ( child_w < child->lop.min_w ) { + child_w = child->lop.min_w; + } + } + if ( child->lop.min_h > 0.0 ) { + if ( child_h < child->lop.min_h ) { + child_h = child->lop.min_h; + } + } + + /* Finally, apply the gravity */ + switch ( child->lop.grav ) + { + case DIR_NONE : + break; + + case DIR_UL : + case DIR_U : + case DIR_UR : + case DIR_R : + case DIR_DR : + case DIR_D : + case DIR_DL : + case DIR_L : + break; + } + + /* Record values and recurse */ + child->offs_x = offs_x; + child->offs_y = offs_y; + layout_subframe(child, child_w, child_h, pc); } } -void layout_frame(struct frame *fr, double w, double h) +void layout_frame(struct frame *fr, double w, double h, PangoContext *pc) { copy_lop_from_style(fr, fr->style); - layout_subframe(fr, w, h); + layout_subframe(fr, w, h, pc); } |