mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-21 00:32:54 +02:00
216 lines
7.1 KiB
Plaintext
216 lines
7.1 KiB
Plaintext
#!@PERL@
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Encode;
|
|
use Cairo;
|
|
use Pango;
|
|
use Getopt::Long;
|
|
|
|
my $VERSION = '@VERSION@';
|
|
|
|
use Remind::PDF;
|
|
|
|
my $media_to_size = {
|
|
"Letter" => [ 612, 792],
|
|
"Tabloid" => [ 792, 1224],
|
|
"Ledger" => [1224, 792],
|
|
"Legal" => [ 612, 1008],
|
|
"Statement" => [ 396, 612],
|
|
"Executive" => [ 540, 720],
|
|
"A3" => [ 842, 1190],
|
|
"A4" => [ 595, 842],
|
|
"A5" => [ 420, 595],
|
|
"B4" => [ 729, 1032],
|
|
"B5" => [ 519, 729],
|
|
"Folio" => [ 612, 936],
|
|
"Quarto" => [ 612, 780],
|
|
"10x14" => [ 720, 1008],
|
|
};
|
|
|
|
my $help = 0;
|
|
|
|
my $settings = {
|
|
landscape => 0,
|
|
numbers_on_left => 0,
|
|
small_calendars => 0,
|
|
fill_entire_page => 0,
|
|
|
|
media => 'Letter',
|
|
width => 0,
|
|
height => 0,
|
|
|
|
title_font => 'Helvetica',
|
|
header_font => 'Helvetica',
|
|
daynum_font => 'Helvetica Bold Oblique',
|
|
entry_font => 'Helvetica',
|
|
small_cal_font => 'Helvetica',
|
|
|
|
title_size => 14,
|
|
header_size => 14,
|
|
daynum_size => 14,
|
|
entry_size => 8,
|
|
|
|
border_size => 4,
|
|
line_thickness => 1,
|
|
|
|
margin_top => 36,
|
|
margin_bottom => 36,
|
|
margin_left => 36,
|
|
margin_right => 36,
|
|
};
|
|
|
|
my $me = $0;
|
|
$me =~ s/^.*\///;
|
|
|
|
sub usage
|
|
{
|
|
print <<"EOF";
|
|
$me (version $VERSION): Convert Remind -pp output to a PDF calendar.
|
|
|
|
Usage: remind -pp [options] filename | $me [options] > out.pdf
|
|
|
|
Options:
|
|
|
|
--landscape, -l Print in landscape orientation
|
|
--small-calendars=N Choose location for small calendars
|
|
-c=N Synonym for --small-calendars=N
|
|
--left-numbers, -x Print day numbers on the left
|
|
--fill-page, -e Fill the entire page
|
|
--media=MEDIA, -m=MEDIA Size for specified media
|
|
--witdh=W, -w=W Specify media width in 1/72nds of an inch
|
|
--height=H, -h=H Specify media height in 1/72nds of an inch
|
|
--title-font=FONT Specify font for calendar title
|
|
--header-font=FONT Specify font for weekday names
|
|
--daynum-font=FONT Specify font for day numbers
|
|
--entry-font=FONT Specify font for calendar entries
|
|
--small-cal-font=FONT Specify font for small calendars
|
|
--title-size=S Specify size of font for calendar title in points
|
|
--header-size=S Specify size of font for weekday names
|
|
--daynum-size=S Specify size of font for day numbers
|
|
--entry-size=S Specify size of font for calendar entries
|
|
--border-size=S Specify size of gaps between items in 1/72nds of an inch
|
|
--line-thickness=S Specify line thickness in 1/72nds of an inch
|
|
--margin-top=S Specify top margin size in 1/72nds of an inch
|
|
--margin-bottom=S Specify bottom margin size in 1/72nds of an inch
|
|
--margin-left=S Specify left margin size in 1/72nds of an inch
|
|
--margin-right=S Specify right margin size in 1/72nds of an inch
|
|
--help Display this help
|
|
EOF
|
|
}
|
|
|
|
my $ret = GetOptions('landscape|l' => \$settings->{landscape},
|
|
'small-calendars|c=i' => \$settings->{small_calendars},
|
|
'left-numbers|x' => \$settings->{numbers_on_left},
|
|
'fill-page|e' => \$settings->{fill_entire_page},
|
|
'media|m=s' => \$settings->{media},
|
|
'width|w=i' => \$settings->{width},
|
|
'height|h=i' => \$settings->{height},
|
|
'title-font=s' => \$settings->{title_font},
|
|
'header-font=s' => \$settings->{header_font},
|
|
'daynum-font=s' => \$settings->{daynum_font},
|
|
'entry-font=s' => \$settings->{entry_font},
|
|
'small-cal-font=s' => \$settings->{small_cal_font},
|
|
'title-size=f' => \$settings->{title_size},
|
|
'header-size=f' => \$settings->{header_size},
|
|
'daynum-size=f' => \$settings->{daynum_size},
|
|
'entry-size=f' => \$settings->{entry_size},
|
|
'border-size=f' => \$settings->{border_size},
|
|
'line-thickness=f' => \$settings->{line_thickness},
|
|
'margin-top=f' => \$settings->{margin_top},
|
|
'margin-bottom=f' => \$settings->{margin_bottom},
|
|
'margin-left=f' => \$settings->{margin_left},
|
|
'margin-right=f' => \$settings->{margin_right},
|
|
'help' => \$help
|
|
);
|
|
if (!$ret) {
|
|
usage();
|
|
exit(1);
|
|
}
|
|
|
|
if ($help) {
|
|
usage();
|
|
exit(0);
|
|
}
|
|
|
|
if ($settings->{width} <= 0 ||
|
|
$settings->{height} <= 0) {
|
|
my $size = $media_to_size->{ucfirst($settings->{media})};
|
|
if (!$size) {
|
|
print STDERR "Unknown media " . $settings->{media} . "\n";
|
|
exit(1);
|
|
}
|
|
$settings->{width} = $size->[0];
|
|
$settings->{height} = $size->[1];
|
|
}
|
|
|
|
if ($settings->{landscape}) {
|
|
my $tmp = $settings->{width};
|
|
$settings->{width} = $settings->{height};
|
|
$settings->{height} = $tmp;
|
|
}
|
|
|
|
# Don't read from a terminal
|
|
if (-t STDIN) {
|
|
print STDERR "I can't read data from a terminal. Please run like this:\n";
|
|
print STDERR " remind -pp [options] filename | $me [options] > out.pdf\n";
|
|
exit(1);
|
|
}
|
|
|
|
my $done_one = 0;
|
|
|
|
my $errored_out = 0;
|
|
|
|
my $surface = Cairo::PdfSurface->create_for_stream(sub { print $_[1] unless $errored_out; }, undef,
|
|
$settings->{width}, $settings->{height});
|
|
|
|
$surface->set_metadata('title', 'Calendar');
|
|
$surface->set_metadata('author', 'Remind (https://dianne.skoll.ca/projects/remind/)');
|
|
$surface->set_metadata('creator', 'rem2pdf (https://dianne.skoll.ca/projects/remind/)');
|
|
$surface->set_metadata('subject', 'Calendar');
|
|
|
|
my $cr = Cairo::Context->create($surface);
|
|
$cr->set_line_width($settings->{line_thickness});
|
|
|
|
while(1) {
|
|
my ($obj, $err) = Remind::PDF->create_from_stream(*STDIN,
|
|
{color => 1,
|
|
shade => 1,
|
|
moon => 1,
|
|
pango => 1,
|
|
week => 1,});
|
|
|
|
if (!$obj) {
|
|
if (!$done_one) {
|
|
$errored_out = 1;
|
|
print STDERR "$me: $err\n";
|
|
exit(1);
|
|
}
|
|
last;
|
|
}
|
|
$done_one = 1;
|
|
$obj->render($cr, $settings);
|
|
}
|
|
|
|
$surface->finish();
|
|
|
|
|
|
__END__
|
|
|
|
|
|
for (my $x=36; $x < 612-36; $x += 72) {
|
|
$cr->move_to($x, 0);
|
|
$cr->line_to($x, 792);
|
|
$cr->stroke;
|
|
}
|
|
|
|
$cr->set_source_rgb(0,0.5,0);
|
|
$cr->arc(612/2, 792/2, 36, 0, 2*3.1415926535);
|
|
$cr->stroke_preserve;
|
|
$cr->fill;
|
|
$cr->move_to(612/2, 792/2);
|
|
$cr->set_source_rgb(0,0,0);
|
|
$cr->set_font_size(36);
|
|
$cr->show_text(Encode::decode('UTF-8', "מֵם סוֹפִיתçédo"));
|
|
|