diff --git a/rem2pdf/bin/rem2pdf.in b/rem2pdf/bin/rem2pdf.in index eb7d3434..9d2b04dd 100644 --- a/rem2pdf/bin/rem2pdf.in +++ b/rem2pdf/bin/rem2pdf.in @@ -64,6 +64,8 @@ my $settings = { ps => 0, eps => 0, verbose => 0, + + weeks_per_page => 1, }; my $me = $0; @@ -92,6 +94,7 @@ Options: --width=W, -wW Specify media width in 1/72nds of an inch --height=H, -hH Specify media height in 1/72nds of an inch --wrap, -y Make calendar fit in 5 rows (monthly calendars only) +--weeks-per-page=N, -pN Number of weeks per page (weekly calendars only) --title-font=FONT Specify font for calendar title --header-font=FONT Specify font for weekday names --daynum-font=FONT Specify font for day numbers @@ -121,6 +124,7 @@ my $ret = GetOptions('landscape|l' => \$settings->{landscape}, 'ps' => \$settings->{ps}, 'eps' => \$settings->{eps}, 'fill-page|e' => \$settings->{fill_entire_page}, + 'weeks-per-page|p=i' => \$settings->{weeks_per_page}, 'media|m=s' => \$settings->{media}, 'width|w=i' => \$settings->{width}, 'wrap|y' => \$settings->{wrap_calendar}, @@ -153,6 +157,12 @@ if ($help) { exit(0); } +if ($settings->{weeks_per_page} < 1) { + $settings->{weeks_per_page} = 1;} +elsif ($settings->{weeks_per_page} > 4) { + $settings->{weeks_per_page} = 4; +} + if ($settings->{width} <= 0 || $settings->{height} <= 0) { my $size = $media_to_size->{ucfirst($settings->{media})}; @@ -521,6 +531,11 @@ first row of the calendar, and adjust the small calendar positions as needed. This results in a calendar that only requires 5 rows, but with the last day or two appearing in the I row. +=item --weeks-per-page=I, -pI. + +This option is only used for weekly calendars. I is the number of weeks +to print per page; it is an integer that can range from 1 to 4. + =item --verbose, -v Print (on STDERR) the name of the month and year for each month that @@ -566,10 +581,8 @@ 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. +B<-p+> option. the B<--weeks-per-page> option specifies how many +weeks' worth of reminders to print per page, and can range from 1 to 4. =head1 ABSOLUTELY-POSITIONED TEXT diff --git a/rem2pdf/lib/Remind/PDF.pm b/rem2pdf/lib/Remind/PDF.pm index 1c253d2b..9b83733e 100644 --- a/rem2pdf/lib/Remind/PDF.pm +++ b/rem2pdf/lib/Remind/PDF.pm @@ -1044,25 +1044,28 @@ sub render my ($self, $cr, $settings, $index, $total) = @_; $settings->{numbers_on_left} = 1; # Set up bounding box - if ($total == 1) { + if ($settings->{weeks_per_page} == 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}]; + my $total_height = $settings->{height} - $settings->{margin_top} - $settings->{margin_bottom}; + my $week_height = $total_height / $settings->{weeks_per_page}; + my $top_offset = (($index-1) % $settings->{weeks_per_page}) * $week_height; + my $bot_offset = $top_offset + $week_height; + $self->{bounding_box} = + $self->{bounding_box} = [ + $settings->{margin_left}, + $settings->{margin_top} + $top_offset, + $settings->{width} - $settings->{margin_right}, + $settings->{margin_top} + $bot_offset]; + if ($index != 1) { + $self->{bounding_box}[1] += 0.25 * $settings->{margin_top}; + } + if ($index != $settings->{weeks_per_page}) { + $self->{bounding_box}[3] -= 0.25 * $settings->{margin_top}; } } $self->draw_headings($cr, $settings); @@ -1070,7 +1073,7 @@ sub render $self->draw_entries($cr, $settings, $i); } $self->draw_lines($cr, $settings); - if ($index == $total || ($index %2) == 0) { + if ($index == $total || ($index % $settings->{weeks_per_page}) == 0) { $cr->show_page(); }