[PATCH 2/2] print: Use logical text extents to layout text in weight system box
Carl Worth
cworth at cworth.org
Thu Jan 31 19:58:44 PST 2013
The old code was computing locations based on relative portions of the
available height. The correct thing to do, (and done here in the
paych), 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 at cworth.org>
---
print.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/print.c b/print.c
index 50147f7..ca19fca 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);
--
1.7.10.4
More information about the subsurface
mailing list