From eaa134e8ea9e71489af1b5090bdee122d5b8d659 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 20 May 2018 04:33:34 -0400 Subject: Print: Match document size against known paper sizes Custom paper sizes work with some printer drivers but not others. EPSON's ESC/P-R CUPS driver for example scales a custom-sized document to ISO A4. (It apparently used to just bail on unknown page sizes.) Matching the document size against a known paper size in Inkscape prevents the driver from scaling to the wrong paper size. Fixes an issue discussed in comments 3, 4, 5, and 6 of . --- src/ui/dialog/print.cpp | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'src/ui/dialog/print.cpp') diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index 934477343..606b48f8a 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -5,8 +5,10 @@ /* Authors: * Kees Cook * Abhishek Sharma + * Patrick McDermott * * Copyright (C) 2007 Kees Cook + * Copyright (C) 2017 Patrick McDermott * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -14,6 +16,8 @@ #include "config.h" #endif +#include + #include #include "preferences.h" @@ -50,18 +54,38 @@ Print::Print(SPDocument *doc, SPItem *base) : title += jobname; _printop->set_job_name(title); - // set up paper size to match the document size _printop->set_unit(Gtk::UNIT_POINTS); Glib::RefPtr page_setup = Gtk::PageSetup::create(); - gdouble doc_width = _doc->getWidth().value("pt"); - gdouble doc_height = _doc->getHeight().value("pt"); - Gtk::PaperSize paper_size; - if (doc_width > doc_height) { - page_setup->set_orientation(Gtk::PAGE_ORIENTATION_PORTRAIT); - paper_size = Gtk::PaperSize("custom", "custom", doc_height, doc_width, Gtk::UNIT_POINTS); + + // get document width, height, and orientation + // height must be larger than width, as in GTK+'s known paper sizes + gdouble doc_width; + gdouble doc_height; + if (_doc->getWidth().value("pt") > _doc->getHeight().value("pt")) { + page_setup->set_orientation(Gtk::PAGE_ORIENTATION_LANDSCAPE); + doc_width = _doc->getHeight().value("pt"); + doc_height = _doc->getWidth().value("pt"); } else { page_setup->set_orientation(Gtk::PAGE_ORIENTATION_PORTRAIT); - paper_size = Gtk::PaperSize("custom", "custom", doc_width, doc_height, Gtk::UNIT_POINTS); + doc_width = _doc->getWidth().value("pt"); + doc_height = _doc->getHeight().value("pt"); + } + + // attempt to match document size against known paper sizes + Gtk::PaperSize paper_size("custom", "custom", doc_width, doc_height, Gtk::UNIT_POINTS); + std::vector known_sizes = Gtk::PaperSize::get_paper_sizes(false); + for (auto& size : known_sizes) { + if (fabs(size.get_width(Gtk::UNIT_POINTS) - doc_width) >= 1.0) { + // width (short edge) doesn't match + continue; + } + if (fabs(size.get_height(Gtk::UNIT_POINTS) - doc_height) >= 1.0) { + // height (short edge) doesn't match + continue; + } + // size matches + paper_size = size; + break; } page_setup->set_paper_size(paper_size); -- cgit v1.2.3