From 1298c9733a60c9f2ee3e45bbfc93725e1a91803c Mon Sep 17 00:00:00 2001 From: Photon89 Date: Mon, 29 Dec 2025 19:41:58 +0100 Subject: [PATCH 1/3] Fix PDF and PS export, #788 --- .../resources/modules/Shutter/Pixbuf/Save.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm b/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm index ce52c39a..15991ffa 100644 --- a/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm +++ b/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm @@ -80,10 +80,19 @@ sub set_quality_setting { sub save_pdf_ps_svg { my $self = shift; my $filename = shift; + my $filetype = shift; my $pixbuf = shift; + + my $surface = undef; #0.8? => 72 / 90 dpi - my $surface = Cairo::SvgSurface->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); + if ($filetype eq 'pdf') { + $surface = Cairo::PdfSurface->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); + } elsif ($filetype eq 'ps') { + $surface = Cairo::PsSurface->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); + } elsif ($filetype eq 'svg') { + $surface = Cairo::SvgSurface->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); + } my $cr = Cairo::Context->create($surface); $cr->scale(0.8, 0.8); Gtk3::Gdk::cairo_set_source_pixbuf($cr, $pixbuf, 0, 0); @@ -175,7 +184,7 @@ sub save_pixbuf_to_file { } elsif ($filetype eq 'pdf' || $filetype eq 'ps' || $filetype eq 'svg') { - $self->save_pdf_ps_svg($filename, $pixbuf); + $self->save_pdf_ps_svg($filename, $filetype, $pixbuf); print "Saving file $filename, $filetype\n" if $self->{_common}->get_debug; From c141d8e3b04ef4430c8c964fac81bb713dd24b82 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Mon, 29 Dec 2025 21:52:00 +0000 Subject: [PATCH 2/3] less repetition --- .../resources/modules/Shutter/Pixbuf/Save.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm b/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm index 15991ffa..d239a768 100644 --- a/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm +++ b/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm @@ -84,15 +84,15 @@ sub save_pdf_ps_svg { my $pixbuf = shift; my $surface = undef; + + my $class = { + pdf => 'Cairo::PdfSurface', + ps => 'Cairo::PsSurface', + svg => 'Cairo::SvgSurface', + }->{$filetype}; #0.8? => 72 / 90 dpi - if ($filetype eq 'pdf') { - $surface = Cairo::PdfSurface->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); - } elsif ($filetype eq 'ps') { - $surface = Cairo::PsSurface->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); - } elsif ($filetype eq 'svg') { - $surface = Cairo::SvgSurface->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); - } + $surface = $class->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); my $cr = Cairo::Context->create($surface); $cr->scale(0.8, 0.8); Gtk3::Gdk::cairo_set_source_pixbuf($cr, $pixbuf, 0, 0); From 5bdc90588e388833457231fb0b1b211c9ff9def0 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Mon, 29 Dec 2025 21:53:01 +0000 Subject: [PATCH 3/3] move var closer to init --- share/shutter/resources/modules/Shutter/Pixbuf/Save.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm b/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm index d239a768..14366cb6 100644 --- a/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm +++ b/share/shutter/resources/modules/Shutter/Pixbuf/Save.pm @@ -83,8 +83,6 @@ sub save_pdf_ps_svg { my $filetype = shift; my $pixbuf = shift; - my $surface = undef; - my $class = { pdf => 'Cairo::PdfSurface', ps => 'Cairo::PsSurface', @@ -92,7 +90,7 @@ sub save_pdf_ps_svg { }->{$filetype}; #0.8? => 72 / 90 dpi - $surface = $class->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); + my $surface = $class->create($filename, $pixbuf->get_width * 0.8, $pixbuf->get_height * 0.8); my $cr = Cairo::Context->create($surface); $cr->scale(0.8, 0.8); Gtk3::Gdk::cairo_set_source_pixbuf($cr, $pixbuf, 0, 0);