aboutsummaryrefslogtreecommitdiffstats
path: root/print.c
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2013-02-01 14:58:44 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-01 16:13:05 +1100
commit393c88f087d40578558b104dd42ff2076e198188 (patch)
tree5e41e7b0c8539428e8baf8722fdc05a18541890d /print.c
parenta6fd4076267be5aabe8adc7da56105e520371476 (diff)
downloadsubsurface-393c88f087d40578558b104dd42ff2076e198188.tar.gz
print: Use logical text extents to layout text in weight system box
The old code was computing locations based on relative portions of the available height. The correct thing to do, (and done here in the patch), is to advance by the logical height of rendered text each time. What's stll missing is anything to guarantee that the text drawn will fit in the box. The correct answer here is along one of two lines: 1. Use the logical text extents to decide what size to draw the box. 2. Use a pre-computed box size and choose a font size that will fit Either approach will involve a fairly substantial reworking of the rendering code in print.c. Signed-off-by: Carl Worth <cworth@cworth.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'print.c')
-rw-r--r--print.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/print.c b/print.c
index 50147f78a..ca19fcaea 100644
--- a/print.c
+++ b/print.c
@@ -289,6 +289,7 @@ static void print_weight_data (struct dive *dive, cairo_t *cr, int maxwidth, int
const char *unit_weight, *desc;
char buffer[80];
PangoLayout *layout;
+ PangoRectangle ink_extents, logical_extents;
cairo_save(cr);
@@ -305,7 +306,8 @@ static void print_weight_data (struct dive *dive, cairo_t *cr, int maxwidth, int
pango_cairo_show_layout(cr, layout);
/* Detail of the weight */
- cairo_translate (cr, 0, height / (3 * (double) PANGO_SCALE));
+ pango_layout_get_extents(layout, &ink_extents, &logical_extents);
+ cairo_translate (cr, 0, logical_extents.height / (double) PANGO_SCALE);
set_font(layout, font, FONT_SMALL - 3, PANGO_ALIGN_LEFT);
weightsystemcounter = 0;
for (i=0; i< MAX_WEIGHTSYSTEMS; i++){
@@ -317,19 +319,19 @@ static void print_weight_data (struct dive *dive, cairo_t *cr, int maxwidth, int
pango_layout_set_text(layout, buffer, -1);
pango_cairo_show_layout(cr, layout);
cairo_move_to(cr,(2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), _("%.*f %s\n"),
+ snprintf(buffer, sizeof(buffer), _("%.*f %s"),
decimals,
systemweight,
unit_weight);
pango_layout_set_text(layout, buffer, -1);
pango_cairo_show_layout(cr, layout);
weightsystemcounter++;
- cairo_translate (cr, 0, height / (4 * (double) PANGO_SCALE));
+ pango_layout_get_extents(layout, &ink_extents, &logical_extents);
+ cairo_translate (cr, 0, logical_extents.height / (double) PANGO_SCALE);
}
}
/* Total weight of the system */
totalweight = get_weight_units(total_weight(dive), &decimals, &unit_weight);
- cairo_translate (cr, 0, height / (4 * (double) PANGO_SCALE));
cairo_move_to (cr, 0, 0);
snprintf(buffer, sizeof(buffer), _("Total Weight:"));
pango_layout_set_text(layout, buffer, -1);