From 2bc9fe4f1dca8f5cfe82408961b81b8d9b03e1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 28 Oct 2021 06:14:21 +0200 Subject: Fix scaling to fit paper --- src/ld-window-main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/ld-window-main.c') 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); -- cgit v1.2.3