Fixed printout

This commit is contained in:
Matthias Koefferlein
2022-09-18 21:53:38 +02:00
parent 029284f48a
commit ee3facfa13
3 changed files with 43 additions and 7 deletions
+12 -1
View File
@@ -1529,6 +1529,8 @@ MainWindow::cm_print ()
if (current_view ()) { if (current_view ()) {
int scale_factor = 3;
// choose a resolution around 300dpi // choose a resolution around 300dpi
double rf = floor (0.5 + 300.0 / mp_printer->resolution ()); double rf = floor (0.5 + 300.0 / mp_printer->resolution ());
mp_printer->setResolution (int (floor (0.5 + mp_printer->resolution () * rf))); 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.setBottom (text_rect.bottom () - hh / 2);
text_rect.setTop (text_rect.top () + 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.drawImage (QPoint (page_rect.left (), page_rect.top () + hh * 2), img);
painter.setFont (header_font); painter.setFont (header_font);
@@ -1237,9 +1237,9 @@ LAYBASIC_PUBLIC Class<lay::LayoutViewBase> decl_LayoutViewBase ("lay", "LayoutVi
"@param filename The file to which to write the screenshot to.\n" "@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 width The width of the image to render in pixel.\n"
"@param height The height 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 linewidth The line width scale factor (usually 1) or 0 for 1/resolution.\n"
"@param oversampling The oversampling factor (1..3) or 0 for default.\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, i.e 1/oversampling) or 0 for default.\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 target_box The box to draw or an empty box for default.\n"
"@param monochrome If true, monochrome images will be produced.\n" "@param monochrome If true, monochrome images will be produced.\n"
"\n" "\n"
@@ -1248,6 +1248,31 @@ LAYBASIC_PUBLIC Class<lay::LayoutViewBase> decl_LayoutViewBase ("lay", "LayoutVi
"The image is drawn synchronously with the given width and height. Drawing may take some time. " "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" "Monochrome images don't have background or annotation objects currently.\n"
"\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" "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"), gsi::method_ext ("#save_as", &save_as2, gsi::arg ("index"), gsi::arg ("filename"), gsi::arg ("gzip"), gsi::arg ("options"),
+3 -3
View File
@@ -877,12 +877,12 @@ LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int l
if (oversampling <= 0) { if (oversampling <= 0) {
oversampling = m_oversampling; oversampling = m_oversampling;
} }
if (linewidth <= 0) {
linewidth = 1;
}
if (resolution <= 0.0) { if (resolution <= 0.0) {
resolution = 1.0 / oversampling; resolution = 1.0 / oversampling;
} }
if (linewidth <= 0) {
linewidth = 1.0 / resolution + 0.5;
}
if (! background.is_valid ()) { if (! background.is_valid ()) {
background = background_color (); background = background_color ();
} }