diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-02-16 23:01:54 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-02-16 23:01:54 -0800 |
commit | f0ff972d91a6b765ab3cfa20c92a5c7191c421cf (patch) | |
tree | 4421a9f11f7744c2629b0c641f68fa8f0985beb8 /print.c | |
parent | f65afb9800784c9520b402bb5ebe9c87f12a6275 (diff) | |
download | subsurface-f0ff972d91a6b765ab3cfa20c92a5c7191c421cf.tar.gz |
Print: better calculation of the row height in table print
Instead of odd hard coded offsets we evaluate the height of a single line and
modify the height per row (and the vertical positioning of the text within that
row) by a fraction of that height.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'print.c')
-rw-r--r-- | print.c | 33 |
1 files changed, 17 insertions, 16 deletions
@@ -504,11 +504,11 @@ static void show_table_header(cairo_t *cr, PangoLayout *layout, double w) } static int show_table_cell(int i, cairo_t *cr, PangoLayout *layout, double colwidth, int height_count, - char *buffer, int len, double *curwidth) + char *buffer, int len, double *curwidth, double y) { PangoRectangle logic_ext; double inner_colwidth = 0.95 * colwidth; - cairo_move_to(cr, *curwidth / PANGO_SCALE, 0); + cairo_move_to(cr, *curwidth / PANGO_SCALE, y); pango_layout_set_width(layout, inner_colwidth * rel_width[i]); pango_layout_set_text(layout, buffer, len); pango_layout_set_justify(layout, 0); @@ -520,7 +520,7 @@ static int show_table_cell(int i, cairo_t *cr, PangoLayout *layout, double colwi return height_count; } -static int show_dive_table(struct dive *dive, cairo_t *cr, PangoLayout *layout, double w) +static int show_dive_table(struct dive *dive, cairo_t *cr, PangoLayout *layout, double w, double dy) { double depth; const char *unit; @@ -532,14 +532,14 @@ static int show_dive_table(struct dive *dive, cairo_t *cr, PangoLayout *layout, struct tm tm; char buffer[300]; - cairo_move_to(cr, 0, 0); + cairo_move_to(cr, 0, dy); // Col 1: Dive # (1/3 of the regular width) *buffer = 0; len = 0; if (dive->number) len = snprintf(buffer, sizeof(buffer), "#%d", dive->number); - height_count = show_table_cell(0, cr, layout, colwidth, height_count, buffer, len, &curwidth); + height_count = show_table_cell(0, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy); // Col 2: Date # (1 + 1/6 of the regular width) utc_mkdate(dive->when, &tm); @@ -551,27 +551,27 @@ static int show_dive_table(struct dive *dive, cairo_t *cr, PangoLayout *layout, tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min ); - height_count = show_table_cell(1, cr, layout, colwidth, height_count, buffer, len, &curwidth); + height_count = show_table_cell(1, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy); // Col 3: Depth (1/2 width) depth = get_depth_units(dive->maxdepth.mm, &decimals, &unit); len = snprintf(buffer, sizeof(buffer), "%.*f %s", decimals, depth, unit); - height_count = show_table_cell(2, cr, layout, colwidth, height_count, buffer, len, &curwidth); + height_count = show_table_cell(2, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy); // Col 4: Duration (1/2 width) len = snprintf(buffer, sizeof(buffer), _("%d min"),(dive->duration.seconds + 59) / 60); - height_count = show_table_cell(3, cr, layout, colwidth, height_count, buffer, len, &curwidth); + height_count = show_table_cell(3, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy); // Col 5: Master - height_count = show_table_cell(4, cr, layout, colwidth, height_count, dive->divemaster ? : "", -1, &curwidth); + height_count = show_table_cell(4, cr, layout, colwidth, height_count, dive->divemaster ? : "", -1, &curwidth, dy); // Col 6: Buddy - height_count = show_table_cell(5, cr, layout, colwidth, height_count, dive->buddy ? : "", -1, &curwidth); + height_count = show_table_cell(5, cr, layout, colwidth, height_count, dive->buddy ? : "", -1, &curwidth, dy); // Col 7: Location - height_count = show_table_cell(6, cr, layout, colwidth, height_count, dive->location ? : "", -1, &curwidth); + height_count = show_table_cell(6, cr, layout, colwidth, height_count, dive->location ? : "", -1, &curwidth, dy); /* Return the biggest column height, will be used to plot the frame and * and translate the next row */ @@ -739,7 +739,7 @@ static void draw_table(GtkPrintOperation *operation, int i, nr, maxwidth, maxheight; int n_dive_per_page = 35; cairo_t *cr; - double w, h, max_ext; + double w, h, max_ext, delta_y; struct dive *dive; PangoFontDescription *font; PangoLayout *layout; @@ -773,18 +773,19 @@ static void draw_table(GtkPrintOperation *operation, /* Get the height for an only line but move two down */ pango_layout_get_extents(layout, NULL, &logic_ext); - cairo_translate (cr, 0, (2 * logic_ext.height) / (double) PANGO_SCALE); + delta_y = logic_ext.height; + cairo_translate (cr, 0, 2 * delta_y / (double) PANGO_SCALE); for (i = 0; i < n_dive_per_page; i++) { dive = get_dive_for_printing(nr+i); if (!dive) return; /* Write the dive data and get the max. height of the row */ - max_ext = show_dive_table(dive, cr, layout, w*2); + max_ext = show_dive_table(dive, cr, layout, w*2, delta_y / 4 / PANGO_SCALE); /* Draw a frame for each row */ - print_table_frame (cr, -0.05, 0, w, (max_ext + 5) / PANGO_SCALE); + print_table_frame (cr, -0.05, 0, w, (max_ext + delta_y / 2) / PANGO_SCALE); /* and move down by the max. height of it */ - cairo_translate (cr, 0, (max_ext + 5) / PANGO_SCALE); + cairo_translate (cr, 0, (max_ext + delta_y / 2) / PANGO_SCALE); } cairo_restore (cr); pango_font_description_free(font); |