aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-10-28 06:14:21 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-10-28 06:14:21 +0200
commit2bc9fe4f1dca8f5cfe82408961b81b8d9b03e1f1 (patch)
tree251f1474da9646ce8a97023551fd4aba654da2e3 /src
parentbd12c0502ab9a411cffc3a6ccc5ff8f97e9117b1 (diff)
downloadlogdiag-2bc9fe4f1dca8f5cfe82408961b81b8d9b03e1f1.tar.gz
logdiag-2bc9fe4f1dca8f5cfe82408961b81b8d9b03e1f1.tar.xz
logdiag-2bc9fe4f1dca8f5cfe82408961b81b8d9b03e1f1.zip
Fix scaling to fit paper
Diffstat (limited to 'src')
-rw-r--r--src/ld-window-main.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/ld-window-main.c b/src/ld-window-main.c
index 6616168..9108f0f 100644
--- a/src/ld-window-main.c
+++ b/src/ld-window-main.c
@@ -1052,7 +1052,7 @@ on_action_print_draw_page (GtkPrintOperation *operation,
LdDiagramView *view;
gdouble area_width_mm, area_height_mm;
gdouble diagram_width_mm, diagram_height_mm;
- gdouble diagram_to_export_units, scale;
+ gdouble diagram_to_export_units, scale, width_fit, height_fit;
LdRectangle bounds;
cr = gtk_print_context_get_cairo_context (context);
@@ -1067,11 +1067,13 @@ on_action_print_draw_page (GtkPrintOperation *operation,
diagram_width_mm = bounds.width * scale;
diagram_height_mm = bounds.height * scale;
- /* Scale to fit the paper. */
- if (area_width_mm < diagram_width_mm)
- scale *= area_width_mm / diagram_width_mm;
- if (area_height_mm < diagram_height_mm)
- scale *= area_height_mm / diagram_height_mm;
+ /* Scale to fit the paper, taking care to not divide by zero. */
+ width_fit = (area_width_mm < diagram_width_mm)
+ ? area_width_mm / diagram_width_mm : 1;
+ height_fit = (area_height_mm < diagram_height_mm)
+ ? area_height_mm / diagram_height_mm : 1;
+
+ scale *= MIN (width_fit, height_fit);
cairo_scale (cr, scale, scale);
cairo_translate (cr, -bounds.x, -bounds.y);