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,
svg => 0,
ps => 0,
eps => 0,
verbose => 0,
};
@@ -83,6 +84,7 @@ Options:
--small-calendars=N Choose location for small calendars
--svg Output SVG instead of PDF
--ps Output PostScript instead of PDF
--eps Output encapsulated PostScript instead of PDF
-cN Synonym for --small-calendars=N
--left-numbers, -x Print day numbers on the left
--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},
'svg' => \$settings->{svg},
'ps' => \$settings->{ps},
'eps' => \$settings->{eps},
'fill-page|e' => \$settings->{fill_entire_page},
'media|m=s' => \$settings->{media},
'width|w=i' => \$settings->{width},
@@ -181,8 +184,10 @@ if ($settings->{landscape}) {
$settings->{height} = $tmp;
}
if ($settings->{svg} && $settings->{ps}) {
print STDERR "Only one of --ps or --svg may be used.\n";
if ($settings->{svg} && $settings->{ps} ||
$settings->{svg} && $settings->{eps} ||
$settings->{eps} && $settings->{ps}) {
print STDERR "Only one of --eps, --ps or --svg may be used.\n";
exit(1);
}
@@ -201,9 +206,13 @@ my $surface;
if ($settings->{svg}) {
$surface = Cairo::SvgSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef,
$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,
$settings->{width}, $settings->{height});
if ($settings->{eps}) {
$surface->set_eps(1);
$settings->{ps} = 1;
}
} else {
$surface = Cairo::PdfSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef,
$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'); };
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_begin_setup();
}
@@ -245,9 +255,9 @@ while(1) {
}
last;
}
if ($settings->{svg} && $done_one) {
if (($settings->{eps} || $settings->{svg}) && $done_one) {
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;
}
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 --svg [options] > output.svg
remind -pp [options] file | rem2pdf --ps [options] > output.ps
remind -pp [options] file | rem2pdf --eps [options] > output.eps
=head1 DESCRIPTION
@@ -343,6 +354,12 @@ output at all.
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
Output SVG instead of PDF. In this case, you should feed C<rem2pdf>