@@ -, +, @@ design --- C4/Patroncards/Patroncard.pm | 84 +++++++++++++++++++++- .../prog/en/modules/patroncards/edit-layout.tt | 10 +++ patroncards/create-pdf.pl | 5 +- patroncards/edit-layout.pl | 2 + 4 files changed, 98 insertions(+), 3 deletions(-) --- a/C4/Patroncards/Patroncard.pm +++ a/C4/Patroncards/Patroncard.pm @@ -24,7 +24,7 @@ use autouse 'Data::Dumper' => qw(Dumper); use Text::Wrap qw(wrap); #use Font::TTFMetrics; -use C4::Creators::Lib qw(get_font_types); +use C4::Creators::Lib qw(get_font_types get_unit_values); use C4::Creators::PDF qw(StrWidth); use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_attributes); @@ -69,6 +69,7 @@ sub draw_barcode { sub draw_guide_box { my ($self, $pdf) = @_; warn sprintf('No pdf object passed in.') and return -1 if !$pdf; + my $obj_stream = "q\n"; # save the graphic state $obj_stream .= "0.5 w\n"; # border line width $obj_stream .= "1.0 0.0 0.0 RG\n"; # border color red @@ -79,6 +80,87 @@ sub draw_guide_box { $pdf->Add($obj_stream); } +sub draw_guide_grid { + my ($self, $pdf) = @_; + warn sprintf('No pdf object passed in.') and return -1 if !$pdf; + + # Set up the grid in user defied units + my $units = get_unit_values(); + my $unitvalue = 1; + my $unitdesc = ''; + foreach my $un (@$units){ + if ($un->{'type'} eq $self->{'layout'}->{'units'}) { + $unitvalue = $un->{'value'}; + $unitdesc = $un->{'desc'}; + } + } + + my $obj_stream = "q\n"; # save the graphic state + my $x = $self->{'llx'}; + my $y = $self->{'lly'}; + + my $cnt = 0; + for ( $x = $self->{'llx'}/$unitvalue; $x <= ($self->{'llx'} + $self->{'width'})/$unitvalue; $x++) { + my $xx = $x*$unitvalue; + my $yy = $y + $self->{'height'}; + if ( ($cnt % 10) && ! ($cnt % 5) ) { + $obj_stream .= "0.0 1.0 0.0 RG\n"; + $obj_stream .= "0 w\n"; + } elsif ( $cnt % 5 ) { + $obj_stream .= "0.0 1.0 1.0 RG\n"; + $obj_stream .= "0 w\n"; + } else { + $obj_stream .= "0.0 0.0 1.0 RG\n"; + $obj_stream .= "0 w\n"; + } + $cnt ++; + + $obj_stream .= "$xx $y m\n"; + $obj_stream .= "$xx $yy l\n"; + + $obj_stream .= "s\n"; + } + + $x = $self->{'llx'}; + $y = $self->{'lly'}; + $cnt = 0; + for ( $y = $self->{'lly'}/$unitvalue; $y <= ($self->{'lly'} + $self->{'height'})/$unitvalue; $y++) { + + my $xx = $x + $self->{'width'}; + my $yy = $y*$unitvalue; + + if ( ($cnt % 10) && ! ($cnt % 5) ) { + $obj_stream .= "0.0 1.0 0.0 RG\n"; + $obj_stream .= "0 w\n"; + } elsif ( $cnt % 5 ) { + $obj_stream .= "0.0 1.0 1.0 RG\n"; + $obj_stream .= "0 w\n"; + } else { + $obj_stream .= "0.0 0.0 1.0 RG\n"; + $obj_stream .= "0 w\n"; + } + $cnt ++; + + $obj_stream .= "$x $yy m\n"; + $obj_stream .= "$xx $yy l\n"; + $obj_stream .= "s\n"; + } + + $obj_stream .= "Q\n"; # restore the graphic state + $pdf->Add($obj_stream); + + # Add info about units + my $strbottom = "0/0 $unitdesc"; + my $strtop = sprintf('%.2f', $self->{'width'}/$unitvalue) .'/'. sprintf('%.2f', $self->{'height'}/$unitvalue); + my $font_size = 6; + $pdf->Font( 'Courier' ); + $pdf->FontSize( $font_size ); + my $strtop_len = $pdf->StrWidth($strtop) * 1.5; + $pdf->Text( $self->{'llx'} + 2, $self->{'lly'} + 2, "0/0 $unitdesc"); + $pdf->Text( $self->{'llx'} + $self->{'width'} - $strtop_len , $self->{'lly'} + $self->{'height'} - $font_size , $strtop ); +} + + sub draw_text { my ($self, $pdf, %params) = @_; warn sprintf('No pdf object passed in.') and return -1 if !$pdf; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-layout.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-layout.tt @@ -176,6 +176,16 @@ Off [% END %] +
  • + + [% IF ( guide_grid ) %] + On + Off + [% ELSE %] + On + Off + [% END %] +
  • --- a/patroncards/create-pdf.pl +++ a/patroncards/create-pdf.pl @@ -155,8 +155,9 @@ foreach my $item (@{$items}) { text_wrap_cols => 30, #FIXME: hardcoded, ); - $patron_card->draw_guide_box($pdf) if $print_layout_xml->{'guide_box'}; - $patron_card->draw_barcode($pdf) if $print_layout_xml->{'barcode'}; + $patron_card->draw_guide_box($pdf) if $layout_xml->{'guide_box'}; + $patron_card->draw_guide_grid($pdf) if $layout_xml->{'guide_grid'}; + $patron_card->draw_barcode($pdf) if $layout_xml->{'barcode'}; # Do image foo and place binary image data into layout hash my $image_data = {}; --- a/patroncards/edit-layout.pl +++ a/patroncards/edit-layout.pl @@ -156,6 +156,7 @@ if ($op eq 'edit') { layout_name => $layout->get_attr('layout_name'), page_side => ($layout_xml->{'page_side'} eq 'F' ? 0 : 1), guide_box => $layout_xml->{'guide_box'}, + guide_grid => $layout_xml->{'guide_grid'}, units => $units, @barcode, barcode_type => _set_selected($layout_xml->{'barcode'}->[0]->{'type'}, $barcode_types), @@ -218,6 +219,7 @@ elsif ($op eq 'save') { $layout->{'units'} = $cgi->param($parameter) if $parameter eq 'units'; $layout->{'page_side'} = $cgi->param($parameter) if $parameter eq 'page_side'; $layout->{'guide_box'} = $cgi->param($parameter) if $parameter eq 'guide_box'; + $layout->{'guide_grid'} = $cgi->param($parameter) if $parameter eq 'guide_grid'; } } $layout->{'text'} = $text_lines; --