Add --avoid-overfull option to rem2pdf

This commit is contained in:
Dianne Skoll
2026-02-27 16:27:57 -05:00
parent 3431833be2
commit 9c31004b62
2 changed files with 32 additions and 2 deletions

View File

@@ -42,7 +42,7 @@ my $settings = {
media => 'Letter',
width => 0,
height => 0,
avoid_overfull_boxes => 0,
title_font => 'Sans',
header_font => 'Sans',
daynum_font => 'Sans Bold Oblique',
@@ -96,6 +96,7 @@ Options:
--ps Output PostScript instead of PDF
--eps Output encapsulated PostScript instead of PDF
-cN Synonym for --small-calendars=N
--avoid-overfull Shrink font size to avoid over-full boxes. Implies -e
--left-numbers, -x Print day numbers on the left (monthly calendars only)
--fill-page, -e Fill the entire page (monthly calendars only)
--media=MEDIA, -mMEDIA Size for specified media
@@ -139,6 +140,7 @@ my $ret = GetOptions('landscape|l' => \$settings->{landscape},
'svg' => \$settings->{svg},
'ps' => \$settings->{ps},
'eps' => \$settings->{eps},
'avoid-overfull' => \$settings->{avoid_overfull_boxes},
'fill-page|e' => \$settings->{fill_entire_page},
'weeks-per-page|p=i' => \$settings->{weeks_per_page},
'media|m=s' => \$settings->{media},
@@ -186,6 +188,10 @@ if ($version) {
exit(0);
}
if ($settings->{avoid_overfull_boxes}) {
$settings->{fill_entire_page} = 1;
}
my $bad = 0;
foreach my $setting (qw(bg_color line_color title_color header_color daynum_color smallcal_color)) {
my $c = $settings->{$setting};
@@ -481,6 +487,12 @@ the default top-right.
Make the calendar fill the available space on the page.
=item --avoid-overfull
If a calendar box is going to overflow, try to make the entries fit by
decreasing the font size. Using the --avoid-overfull option automatically
enables the --fill-page option.
=item --media=I<media>, -mI<media>
Specify the paper size (Letter, A4, etc.) For a list of valid media sizes,

View File

@@ -608,7 +608,25 @@ sub draw_row
for (my $col=0; $col<7; $col++) {
my $day = $self->{daymap}->[$row]->[$col];
next if ($day < 1);
$self->draw_day($cr, $settings, $so_far, $day, $col, $height);
if ($settings->{avoid_overfull_boxes}) {
my $old_entry_size = $settings->{entry_size};
my $drawn = 0;
while ($settings->{entry_size} >= 2.0) {
my $h = $self->draw_day($cr, $settings, $so_far, $day, $col, 0);
if ($h <= $height) {
$self->draw_day($cr, $settings, $so_far, $day, $col, $height);
$drawn = 1;
last;
}
$settings->{entry_size} -= 0.125;
}
if (!$drawn) {
$self->draw_day($cr, $settings, $so_far, $day, $col, 0);
}
$settings->{entry_size} = $old_entry_size;
} else {
$self->draw_day($cr, $settings, $so_far, $day, $col, $height);
}
}
return $so_far + $height + $settings->{border_size} * 2;