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>
This commit is contained in:
Carl Worth 2013-02-01 14:58:44 +11:00 committed by Dirk Hohndel
parent a6fd407626
commit 393c88f087

10
print.c
View file

@ -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);