Fix scaling to fit paper
This commit is contained in:
parent
bd12c0502a
commit
2bc9fe4f1d
|
@ -1052,7 +1052,7 @@ on_action_print_draw_page (GtkPrintOperation *operation,
|
||||||
LdDiagramView *view;
|
LdDiagramView *view;
|
||||||
gdouble area_width_mm, area_height_mm;
|
gdouble area_width_mm, area_height_mm;
|
||||||
gdouble diagram_width_mm, diagram_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;
|
LdRectangle bounds;
|
||||||
|
|
||||||
cr = gtk_print_context_get_cairo_context (context);
|
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_width_mm = bounds.width * scale;
|
||||||
diagram_height_mm = bounds.height * scale;
|
diagram_height_mm = bounds.height * scale;
|
||||||
|
|
||||||
/* Scale to fit the paper. */
|
/* Scale to fit the paper, taking care to not divide by zero. */
|
||||||
if (area_width_mm < diagram_width_mm)
|
width_fit = (area_width_mm < diagram_width_mm)
|
||||||
scale *= area_width_mm / diagram_width_mm;
|
? area_width_mm / diagram_width_mm : 1;
|
||||||
if (area_height_mm < diagram_height_mm)
|
height_fit = (area_height_mm < diagram_height_mm)
|
||||||
scale *= 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_scale (cr, scale, scale);
|
||||||
cairo_translate (cr, -bounds.x, -bounds.y);
|
cairo_translate (cr, -bounds.x, -bounds.y);
|
||||||
|
|
Loading…
Reference in New Issue