From 2739a41651d4dc1ee32095cfdabd06193caacfab Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Wed, 25 Dec 2024 10:37:18 -0500 Subject: [PATCH] If we ask for multiple weekly calendars, render then two weeks to a page. --- rem2pdf/bin/rem2pdf.in | 10 +++++++- rem2pdf/lib/Remind/PDF.pm | 53 ++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/rem2pdf/bin/rem2pdf.in b/rem2pdf/bin/rem2pdf.in index c68fe258..eb7d3434 100644 --- a/rem2pdf/bin/rem2pdf.in +++ b/rem2pdf/bin/rem2pdf.in @@ -392,7 +392,7 @@ month. Possible values for I are: =item Z<>0 -Do not draw any small calendares +Do not draw any small calendars =item Z<>1 @@ -563,6 +563,14 @@ it is syntactically correct. If you use invalid Pango markup, the Pango library will print a warning and B will not render any output for the invalid reminder. +=head1 WEEKLY CALENDARS + +B will produce weekly calendars if you invoke B with the +B<-p+> option. If you ask for a single weekly calendar, B will +make it fill the entire page. If you ask for more than one week's worth +of data (for example, B then B will put +two week's worth of reminders on a single page. + =head1 ABSOLUTELY-POSITIONED TEXT If your B special reminder starts with C<@I,I> where I diff --git a/rem2pdf/lib/Remind/PDF.pm b/rem2pdf/lib/Remind/PDF.pm index c633f20c..1c253d2b 100644 --- a/rem2pdf/lib/Remind/PDF.pm +++ b/rem2pdf/lib/Remind/PDF.pm @@ -1043,12 +1043,37 @@ sub render { my ($self, $cr, $settings, $index, $total) = @_; $settings->{numbers_on_left} = 1; + # Set up bounding box + if ($total == 1) { + $self->{bounding_box} = [ + $settings->{margin_left}, + $settings->{margin_top}, + $settings->{width} - $settings->{margin_right}, + $settings->{height} - $settings->{margin_bottom}] + } else { + if ($index % 2) { + $self->{bounding_box} = [ + $settings->{margin_left}, + $settings->{margin_top}, + $settings->{width} - $settings->{margin_right}, + ($settings->{height} - $settings->{margin_bottom})/2] + } else { + $self->{bounding_box} = [ + $settings->{margin_left}, + ($settings->{height} + $settings->{margin_bottom})/2, + $settings->{width} - $settings->{margin_right}, + $settings->{height} - $settings->{margin_bottom}]; + } + } $self->draw_headings($cr, $settings); for (my $i=0; $i<7; $i++) { $self->draw_entries($cr, $settings, $i); } $self->draw_lines($cr, $settings); - $cr->show_page(); + if ($index == $total || ($index %2) == 0) { + $cr->show_page(); + } + if ($settings->{verbose}) { print STDERR "rem2pdf: Rendered " . $self->{dates}->[0]->{date} . " to " . $self->{dates}->[6]->{date} . "\n"; } @@ -1075,7 +1100,7 @@ sub draw_headings my ($wid, $h) = $layout->get_pixel_size(); $cr->save; - $cr->move_to($settings->{margin_left} + $i * $cell + $cell/2 - $wid/2, $settings->{margin_top}); + $cr->move_to($settings->{margin_left} + $i * $cell + $cell/2 - $wid/2, $self->{bounding_box}[1]); Pango::Cairo::show_layout($cr, $layout); $cr->restore(); @@ -1090,7 +1115,7 @@ sub draw_headings my ($wid2, $h2) = $layout->get_pixel_size(); $cr->save; - $cr->move_to($settings->{margin_left} + $i * $cell + $cell/2 - $wid2/2, $settings->{margin_top} + $h); + $cr->move_to($settings->{margin_left} + $i * $cell + $cell/2 - $wid2/2, $self->{bounding_box}[1] + $h); Pango::Cairo::show_layout($cr, $layout); $cr->restore(); @@ -1098,7 +1123,7 @@ sub draw_headings $ymax = $h + $h2; } } - $self->{heading_bottom_y} = $ymax+ $settings->{border_size}; + $self->{heading_bottom_y} = $ymax + $self->{bounding_box}[1]; } sub draw_entries @@ -1109,9 +1134,9 @@ sub draw_entries # Coordinates of box from line-to-line my $l2l_box = [$i * $cell + $settings->{margin_left}, - $self->{heading_bottom_y} + $settings->{margin_top}, + $self->{heading_bottom_y}, ($i+1) * $cell + $settings->{margin_left}, - $settings->{height} - $settings->{margin_bottom}]; + $self->{bounding_box}[3]]; # Coordinates of drawing-space box my $box = [$l2l_box->[0] + $settings->{border_size}, @@ -1191,26 +1216,26 @@ sub draw_lines my ($self, $cr, $settings) = @_; # Top horizonal line - $cr->move_to($settings->{margin_left}, $settings->{margin_top}); - $cr->line_to($settings->{width} - $settings->{margin_right}, $settings->{margin_top}); + $cr->move_to($self->{bounding_box}[0], $self->{bounding_box}[1]); + $cr->line_to($self->{bounding_box}[2], $self->{bounding_box}[1]); $cr->stroke(); # Horizontal line below headings - $cr->move_to($settings->{margin_left}, $self->{heading_bottom_y} + $settings->{margin_top}); - $cr->line_to($settings->{width} - $settings->{margin_right}, $self->{heading_bottom_y} + $settings->{margin_top}); + $cr->move_to($self->{bounding_box}[0], $self->{heading_bottom_y}); + $cr->line_to($self->{bounding_box}[2], $self->{heading_bottom_y}); $cr->stroke(); # Bottom horizontal line - $cr->move_to($settings->{margin_left}, $settings->{height} - $settings->{margin_bottom}); - $cr->line_to($settings->{width} - $settings->{margin_right}, $settings->{height} - $settings->{margin_bottom}); + $cr->move_to($self->{bounding_box}[0], $self->{bounding_box}[3]); + $cr->line_to($self->{bounding_box}[2], $self->{bounding_box}[3]); $cr->stroke(); # Vertical lines my $w = ($settings->{width} - $settings->{margin_left} - $settings->{margin_right})/7; for (my $i=0; $i<=7; $i++) { my $x = $settings->{margin_left} + ($i * $w); - $cr->move_to($x, $settings->{margin_top}); - $cr->line_to($x, $settings->{height} - $settings->{margin_bottom}); + $cr->move_to($x, $self->{bounding_box}[1]); + $cr->line_to($x, $self->{bounding_box}[3]); $cr->stroke(); } }