diff options
| author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2018-05-20 08:33:34 +0000 |
|---|---|---|
| committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2018-05-20 08:33:34 +0000 |
| commit | eaa134e8ea9e71489af1b5090bdee122d5b8d659 (patch) | |
| tree | 0936e05f378a0c33e5a9b3fc1bd4ff68dd04cbbd /src/ui/dialog/print.cpp | |
| parent | Print: C++ify (diff) | |
| download | inkscape-eaa134e8ea9e71489af1b5090bdee122d5b8d659.tar.gz inkscape-eaa134e8ea9e71489af1b5090bdee122d5b8d659.zip | |
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
<https://bugs.launchpad.net/inkscape/+bug/630635>.
Diffstat (limited to 'src/ui/dialog/print.cpp')
| -rw-r--r-- | src/ui/dialog/print.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
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 <kees@outflux.net> * 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 <cmath> + #include <gtkmm.h> #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<Gtk::PageSetup> 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<Gtk::PaperSize> 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); |
