diff --git a/rem2pdf/bin/rem2pdf b/rem2pdf/bin/rem2pdf index 414acf6f..73f03fdd 100755 --- a/rem2pdf/bin/rem2pdf +++ b/rem2pdf/bin/rem2pdf @@ -42,10 +42,10 @@ my $settings = { entry_font => 'Helvetica', small_cal_font => 'Helvetica', - title_size => '14px', - header_size => '14px', - daynum_size => '14px', - entry_size => '8px', + title_size => 14, + header_size => 14, + daynum_size => 14, + entry_size => 8, border_size => 6, line_thickness => 1, diff --git a/rem2pdf/lib/Remind/PDF/Entry.pm b/rem2pdf/lib/Remind/PDF/Entry.pm index 71672a8a..db7fc619 100644 --- a/rem2pdf/lib/Remind/PDF/Entry.pm +++ b/rem2pdf/lib/Remind/PDF/Entry.pm @@ -41,8 +41,8 @@ sub render $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_text($self->{body}); + my $desc = Pango::FontDescription->from_string($settings->{entry_font} . ' ' . $settings->{entry_size} . 'px'); $layout->set_font_description($desc); my ($wid, $h) = $layout->get_pixel_size(); @@ -81,9 +81,80 @@ sub adjust { } sub render { - my ($self) = @_; - return 0; + my ($self, $month, $cr, $settings, $so_far, $day, $col, $height) = @_; + + # Do nothing in pre-render mode + return 0 unless $height; + + my ($x1, $y1, $x2, $y2) = $month->col_box_coordinates($so_far, $col, $height, $settings); + + my $layout; + my $bodywidth = 0; + if ($self->{fontsize} <= 0) { + $self->{fontsize} = $settings->{entry_size}; + } + if ($self->{size} <= 0) { + $self->{size} = $settings->{daynum_size}; + } + + if ($self->{phase} !~ /^[0123]$/) { + # Invalid phase + return 0; + } + + if ($self->{body} ne '') { + $layout = Pango::Cairo::create_layout($cr); + $layout->set_text($self->{body}); + my $desc = Pango::FontDescription->from_string($settings->{entry_font} . ' ' . $self->{fontsize} . 'px'); + $layout->set_font_description($desc); + ($bodywidth, undef) = $layout->get_pixel_size(); + } + my ($xc, $yc); + if ($settings->{numbers_on_left}) { + $yc = $so_far + $settings->{border_size} + ($self->{size} / 2); + $xc = $x2 - $settings->{border_size} - ($self->{size} / 2); + if ($bodywidth) { + $xc -= ($bodywidth + $settings->{border_size}); + } + } else { + $xc = $x1 + $settings->{border_size} + ($self->{size} / 2); + $yc = $so_far + $settings->{border_size} + ($self->{size} / 2); + } + $self->draw_moon($xc, $yc, $cr); + if ($layout) { + $cr->save(); + $cr->move_to ($xc + ($self->{size}/2) + $settings->{border_size}, + $yc + ($self->{size}/2) - $self->{fontsize} ); + Pango::Cairo::show_layout($cr, $layout); + $cr->restore(); + } } + +sub draw_moon +{ + my ($self, $xc, $yc, $cr) = @_; + $cr->save(); + $cr->new_path(); + $cr->arc($xc, $yc, $self->{size}/2, 0, 2*3.1415926535); + if ($self->{phase} == 0) { + $cr->stroke_preserve(); + $cr->fill(); + } elsif ($self->{phase} == 1) { + $cr->stroke(); + $cr->arc($xc, $yc, $self->{size}/2, 3.1415926535/2, 3 * 3.1415926535/2); + $cr->stroke_preserve(); + $cr->fill(); + } elsif ($self->{phase} == 2) { + $cr->stroke(); + } elsif ($self->{phase} == 3) { + $cr->stroke(); + $cr->arc($xc, $yc, $self->{size}/2, 3 * 3.1415926535/2, 3.1415926535/2); + $cr->stroke_preserve(); + $cr->fill(); + } + $cr->restore(); +} + package Remind::PDF::Entry::shade; use base 'Remind::PDF::Entry'; sub adjust diff --git a/rem2pdf/lib/Remind/PDF/Month.pm b/rem2pdf/lib/Remind/PDF/Month.pm index a690f450..8354cab4 100644 --- a/rem2pdf/lib/Remind/PDF/Month.pm +++ b/rem2pdf/lib/Remind/PDF/Month.pm @@ -272,6 +272,8 @@ sub draw_day { my ($self, $cr, $settings, $so_far, $day, $col, $height) = @_; + my $top = $so_far; + my ($x1, $y1, $x2, $y2) = $self->col_box_coordinates($so_far, $col, $height, $settings); # Do shading if we're in "for real" mode @@ -290,7 +292,7 @@ sub draw_day # Draw the day number my $layout = Pango::Cairo::create_layout($cr); $layout->set_text($day); - my $desc = Pango::FontDescription->from_string($settings->{daynum_font} . ' ' . $settings->{daynum_size}); + my $desc = Pango::FontDescription->from_string($settings->{daynum_font} . ' ' . $settings->{daynum_size} . 'px'); $layout->set_font_description($desc); my ($wid, $h) = $layout->get_pixel_size(); @@ -314,7 +316,7 @@ sub draw_day 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); + $entry->render($self, $cr, $settings, $top, $day, $col, $height); next; } if ($done) { @@ -347,7 +349,7 @@ sub draw_daynames } my $layout = Pango::Cairo::create_layout($cr); $layout->set_text(Encode::decode('UTF-8', $self->{daynames}->[$j])); - my $desc = Pango::FontDescription->from_string($settings->{header_font} . ' ' . $settings->{header_size}); + my $desc = Pango::FontDescription->from_string($settings->{header_font} . ' ' . $settings->{header_size} . 'px'); $layout->set_font_description($desc); @@ -370,7 +372,7 @@ sub draw_title my $layout = Pango::Cairo::create_layout($cr); $layout->set_text(Encode::decode('UTF-8', $title)); - my $desc = Pango::FontDescription->from_string($settings->{title_font} . ' ' . $settings->{title_size}); + my $desc = Pango::FontDescription->from_string($settings->{title_font} . ' ' . $settings->{title_size} . 'px'); $layout->set_font_description($desc); diff --git a/tests/scripts.rem b/tests/scripts.rem new file mode 100644 index 00000000..c67fc82b --- /dev/null +++ b/tests/scripts.rem @@ -0,0 +1,16 @@ +REM 1 MSG Përkujtues +REM 2 MSG تذكير +REM 3 MSG 提醒 +REM 4 MSG રીમાઇન્ડર +REM 5 MSG Emlékeztető +REM 6 MSG Áminning +REM 7 MSG תִזכּוֹרֶת +REM 8 MSG अनुस्मारक +REM 9 MSG Эскертүү +REM 10 MSG Напоминание +REM 11 MSG Υπενθύμιση + +REM [moondate(0)] SPECIAL MOON 0 +REM [moondate(1)] SPECIAL MOON 1 +REM [moondate(2)] SPECIAL MOON 2 -1 -1 [moontime(2)] +REM [moondate(3)] SPECIAL MOON 3 -1 -1 [moontime(3)]