More work

This commit is contained in:
Dianne Skoll
2022-01-27 10:23:30 -05:00
parent 2f8eaeacf0
commit 9d9bdabf79
2 changed files with 67 additions and 17 deletions

View File

@@ -2,6 +2,10 @@ package Remind::PDF::Entry;
use strict;
use warnings;
use Cairo;
use Pango;
use Encode;
sub new_from_hash
{
my ($class, $hash) = @_;
@@ -14,7 +18,7 @@ sub new_from_hash
$class = 'Remind::PDF::Entry::UNKNOWN';
}
}
bless($hash, $class);
bless $hash, $class;
$hash->adjust();
return $hash;
}
@@ -28,6 +32,32 @@ sub adjust
$self->{b} = 0;
}
sub render
{
my ($self, $month, $cr, $settings, $so_far, $day, $col, $height) = @_;
my ($x1, $y1, $x2, $y2) = $month->col_box_coordinates($so_far, $col, $height, $settings);
my $layout = Pango::Cairo::create_layout($cr);
$layout->set_width(1024 * ($x2 - $x1 - 2 * $settings->{border_size}));
$layout->set_wrap('word-char');
$layout->set_text(Encode::decode('UTF-8', $self->{body}));
my $desc = Pango::FontDescription->from_string($settings->{entry_font} . ' ' . $settings->{entry_size});
$layout->set_font_description($desc);
my ($wid, $h) = $layout->get_pixel_size();
if ($height) {
$cr->save();
$cr->set_source_rgb($self->{r} / 255,
$self->{g} / 255,
$self->{b} / 255);
$cr->move_to($x1 + $settings->{border_size}, $so_far);
Pango::Cairo::show_layout($cr, $layout);
$cr->restore();
}
return $h;
}
package Remind::PDF::Entry::html;
use base 'Remind::PDF::Entry';
package Remind::PDF::Entry::htmlclass;
@@ -36,6 +66,24 @@ package Remind::PDF::Entry::week;
use base 'Remind::PDF::Entry';
package Remind::PDF::Entry::moon;
use base 'Remind::PDF::Entry';
sub adjust {
my ($self) = @_;
my ($phase, $size, $fontsize, $msg) = split(/\s+/, $self->{body}, 4);
$phase = '' unless defined($phase);
$size = -1 unless defined($size);
$fontsize = -1 unless defined($fontsize);
$msg = '' unless defined($msg);
$self->{phase} = $phase;
$self->{size} = $size;
$self->{fontsize} = $fontsize;
$self->{body} = $msg;
}
sub render
{
my ($self) = @_;
return 0;
}
package Remind::PDF::Entry::shade;
use base 'Remind::PDF::Entry';
sub adjust

View File

@@ -308,23 +308,25 @@ sub draw_day
$cr->restore();
}
$layout = Pango::Cairo::create_layout($cr);
$layout->set_width(($x2 - $x1 - 2 * $settings->{border_size}) * 1024);
$layout->set_wrap('word');
$layout->set_text("Bobby snorkle flump chump twinkle");
$desc = Pango::FontDescription->from_string($settings->{entry_font} . ' ' . $settings->{entry_size});
$layout->set_font_description($desc);
my ($wid2, $h2) = $layout->get_pixel_size();
if ($height) {
$cr->save;
$cr->move_to($x1 + $settings->{border_size}, $so_far + 2* $settings->{border_size} + $h);
Pango::Cairo::show_layout($cr, $layout);
$cr->restore();
$so_far += $h + 2 * $settings->{border_size};
my $entry_height = 0;
my $done = 0;
foreach my $entry (@{$self->{entries}->[$day]}) {
# Moon should not adjust height
if ($entry->isa('Remind::PDF::Entry::moon')) {
$entry->render($self, $cr, $settings, $so_far, $day, $col, $height);
next;
}
if ($done) {
$so_far += $settings->{border_size};
$entry_height += $settings->{border_size};
}
$done = 1;
my $h2 = $entry->render($self, $cr, $settings, $so_far, $day, $col, $height);
$entry_height += $h2;
$so_far += $h2;
}
return $h + $h2 + 2 * $settings->{border_size};
return $h + $entry_height + 2 * $settings->{border_size};
}
sub draw_daynames