From ee3facfa13fea5dc4d5b2c7607ed115a81dd542d Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 18 Sep 2022 21:53:38 +0200 Subject: [PATCH] Fixed printout --- src/lay/lay/layMainWindow.cc | 13 +++++++- .../laybasic/gsiDeclLayLayoutViewBase.cc | 31 +++++++++++++++++-- src/laybasic/laybasic/layLayoutCanvas.cc | 6 ++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index 79bc45a17..ff2ec5db3 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -1529,6 +1529,8 @@ MainWindow::cm_print () if (current_view ()) { + int scale_factor = 3; + // choose a resolution around 300dpi double rf = floor (0.5 + 300.0 / mp_printer->resolution ()); mp_printer->setResolution (int (floor (0.5 + mp_printer->resolution () * rf))); @@ -1559,7 +1561,16 @@ MainWindow::cm_print () text_rect.setBottom (text_rect.bottom () - hh / 2); text_rect.setTop (text_rect.top () + hh / 2); - QImage img = current_view ()->get_image_with_options (page_rect.width (), page_rect.height () - 4 * hh, 1, 1, 1.0 / 3.0, Qt::white, Qt::black, Qt::black, db::DBox (), false); + QImage img = current_view ()->get_image_with_options (page_rect.width (), + page_rect.height () - 4 * hh, + scale_factor, + 1, + 1.0 / scale_factor, + tl::Color (QColor (Qt::white)), // foreground + tl::Color (QColor (Qt::black)), // background + tl::Color (QColor (Qt::black)), // active + db::DBox (), + false); painter.drawImage (QPoint (page_rect.left (), page_rect.top () + hh * 2), img); painter.setFont (header_font); diff --git a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc index b932c43e6..dc10d5ba7 100644 --- a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc +++ b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc @@ -1237,9 +1237,9 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase ("lay", "LayoutVi "@param filename The file to which to write the screenshot to.\n" "@param width The width of the image to render in pixel.\n" "@param height The height of the image to render in pixel.\n" - "@param linewidth The width of a line in pixels (usually 1) or 0 for default.\n" - "@param oversampling The oversampling factor (1..3) or 0 for default.\n" - "@param resolution The resolution (pixel size compared to a screen pixel, i.e 1/oversampling) or 0 for default.\n" + "@param linewidth The line width scale factor (usually 1) or 0 for 1/resolution.\n" + "@param oversampling The oversampling factor (1..3) or 0 for the oversampling the view was configured with.\n" + "@param resolution The resolution (pixel size compared to a screen pixel) or 0 for 1/oversampling.\n" "@param target_box The box to draw or an empty box for default.\n" "@param monochrome If true, monochrome images will be produced.\n" "\n" @@ -1248,6 +1248,31 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase ("lay", "LayoutVi "The image is drawn synchronously with the given width and height. Drawing may take some time. " "Monochrome images don't have background or annotation objects currently.\n" "\n" + "The 'linewidth' factor scales the layout style line widths.\n" + "\n" + "The 'oversampling' factor will use multiple passes passes to create a single image pixels. An " + "oversampling factor of 2 uses 2x2 virtual pixels to generate an output pixel. This results in a " + "smoother image. This however comes with a corresponding memory and run time penalty. " + "When using oversampling, you can set linewidth and resolution to 0. This way, line widths and stipple " + "pattern are scaled such that the resulting image is equivalent to the standard image.\n" + "\n" + "The 'resolution' is the pixel size used to translate font sizes and stipple pattern. A resolution of 0.5 " + "renders twice as large fonts and stipple pattern. When combining this value with an oversampling factor of 2 " + "and a line width factor of 2, the resulting image is an oversampled version of the standard image.\n" + "\n" + "Examples:\n" + "\n" + "@code\n" + "# standard image 500x500 pixels (oversampling as configured in the view)\n" + "layout_view.save_image_with_options(\"image.png\", 500, 500)\n" + "\n" + "# 2x oversampled image with 500x500 pixels\n" + "layout_view.save_image_with_options(\"image.png\", 500, 500, 0, 2, 0)\n" + "\n" + "# 2x scaled image with 1000x1000 pixels\n" + "layout_view.save_image_with_options(\"image.png\", 1000, 1000, 2, 1, 0.5)\n" + "@/code\n" + "\n" "This method has been introduced in 0.23.10.\n" ) + gsi::method_ext ("#save_as", &save_as2, gsi::arg ("index"), gsi::arg ("filename"), gsi::arg ("gzip"), gsi::arg ("options"), diff --git a/src/laybasic/laybasic/layLayoutCanvas.cc b/src/laybasic/laybasic/layLayoutCanvas.cc index 058b77bb7..47f5ce1d1 100644 --- a/src/laybasic/laybasic/layLayoutCanvas.cc +++ b/src/laybasic/laybasic/layLayoutCanvas.cc @@ -877,12 +877,12 @@ LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int l if (oversampling <= 0) { oversampling = m_oversampling; } - if (linewidth <= 0) { - linewidth = 1; - } if (resolution <= 0.0) { resolution = 1.0 / oversampling; } + if (linewidth <= 0) { + linewidth = 1.0 / resolution + 0.5; + } if (! background.is_valid ()) { background = background_color (); }