Add support for Encapsulated PostScript to rem2pdf.

This commit is contained in:
Dianne Skoll
2024-08-01 09:57:16 -04:00
parent c6de5a2c8f
commit e993bf59cf

View File

@@ -62,6 +62,7 @@ my $settings = {
margin_right => 36, margin_right => 36,
svg => 0, svg => 0,
ps => 0, ps => 0,
eps => 0,
verbose => 0, verbose => 0,
}; };
@@ -83,6 +84,7 @@ Options:
--small-calendars=N Choose location for small calendars --small-calendars=N Choose location for small calendars
--svg Output SVG instead of PDF --svg Output SVG instead of PDF
--ps Output PostScript instead of PDF --ps Output PostScript instead of PDF
--eps Output encapsulated PostScript instead of PDF
-cN Synonym for --small-calendars=N -cN Synonym for --small-calendars=N
--left-numbers, -x Print day numbers on the left --left-numbers, -x Print day numbers on the left
--fill-page, -e Fill the entire page --fill-page, -e Fill the entire page
@@ -117,6 +119,7 @@ my $ret = GetOptions('landscape|l' => \$settings->{landscape},
'left-numbers|x' => \$settings->{numbers_on_left}, 'left-numbers|x' => \$settings->{numbers_on_left},
'svg' => \$settings->{svg}, 'svg' => \$settings->{svg},
'ps' => \$settings->{ps}, 'ps' => \$settings->{ps},
'eps' => \$settings->{eps},
'fill-page|e' => \$settings->{fill_entire_page}, 'fill-page|e' => \$settings->{fill_entire_page},
'media|m=s' => \$settings->{media}, 'media|m=s' => \$settings->{media},
'width|w=i' => \$settings->{width}, 'width|w=i' => \$settings->{width},
@@ -181,8 +184,10 @@ if ($settings->{landscape}) {
$settings->{height} = $tmp; $settings->{height} = $tmp;
} }
if ($settings->{svg} && $settings->{ps}) { if ($settings->{svg} && $settings->{ps} ||
print STDERR "Only one of --ps or --svg may be used.\n"; $settings->{svg} && $settings->{eps} ||
$settings->{eps} && $settings->{ps}) {
print STDERR "Only one of --eps, --ps or --svg may be used.\n";
exit(1); exit(1);
} }
@@ -201,9 +206,13 @@ my $surface;
if ($settings->{svg}) { if ($settings->{svg}) {
$surface = Cairo::SvgSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef, $surface = Cairo::SvgSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef,
$settings->{width}, $settings->{height}); $settings->{width}, $settings->{height});
} elsif ($settings->{ps}) { } elsif ($settings->{ps} || $settings->{eps}) {
$surface = Cairo::PsSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef, $surface = Cairo::PsSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef,
$settings->{width}, $settings->{height}); $settings->{width}, $settings->{height});
if ($settings->{eps}) {
$surface->set_eps(1);
$settings->{ps} = 1;
}
} else { } else {
$surface = Cairo::PdfSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef, $surface = Cairo::PdfSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef,
$settings->{width}, $settings->{height}); $settings->{width}, $settings->{height});
@@ -216,7 +225,8 @@ eval { $surface->set_metadata('creator', 'rem2pdf (https://dianne.skoll.ca/proje
eval { $surface->set_metadata('subject', 'Calendar'); }; eval { $surface->set_metadata('subject', 'Calendar'); };
if ($settings->{ps}) { if ($settings->{ps}) {
$surface->dsc_comment('%%Creator: rem2pdf (https://dianne.skoll.ca/projects/remind/)'); $surface->dsc_comment('%%Title: Calendar');
$surface->dsc_comment('%%Producer: rem2pdf (https://dianne.skoll.ca/projects/remind/)');
$surface->dsc_comment('%%Orientation: ' . (($settings->{landscape}) ? 'Landscape' : 'Portrait')); $surface->dsc_comment('%%Orientation: ' . (($settings->{landscape}) ? 'Landscape' : 'Portrait'));
$surface->dsc_begin_setup(); $surface->dsc_begin_setup();
} }
@@ -245,9 +255,9 @@ while(1) {
} }
last; last;
} }
if ($settings->{svg} && $done_one) { if (($settings->{eps} || $settings->{svg}) && $done_one) {
if (!$warned) { if (!$warned) {
print STDERR "WARNING: --svg can only output one page; ignoring subsequent\nmonths in a multi-month calendar.\n"; print STDERR "WARNING: --eps and --svg can only output one page; ignoring subsequent\nmonths in a multi-month calendar.\n";
$warned = 1; $warned = 1;
} }
next; next;
@@ -317,6 +327,7 @@ rem2pdf - draw a PDF, SVG or PostScript calendar from Remind output
remind -pp [options] file | rem2pdf [options] > output.pdf remind -pp [options] file | rem2pdf [options] > output.pdf
remind -pp [options] file | rem2pdf --svg [options] > output.svg remind -pp [options] file | rem2pdf --svg [options] > output.svg
remind -pp [options] file | rem2pdf --ps [options] > output.ps remind -pp [options] file | rem2pdf --ps [options] > output.ps
remind -pp [options] file | rem2pdf --eps [options] > output.eps
=head1 DESCRIPTION =head1 DESCRIPTION
@@ -343,6 +354,12 @@ output at all.
Output PostScript instead of PDF. Output PostScript instead of PDF.
=item --eps
Output Encapsulated PostScript instead of PDF. In this case, you
should feed C<rem2pdf> only one month's worth of calendar data,
because it cannot create a multi-page encapsulated PostScript file.
=item --svg =item --svg
Output SVG instead of PDF. In this case, you should feed C<rem2pdf> Output SVG instead of PDF. In this case, you should feed C<rem2pdf>