From ff7fc93115de3bcb7f6012da7867d7f42922b912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Thu, 4 May 2017 17:36:24 +0200 Subject: [PATCH] Bug 18541 - Patron card creator: Add a grid to support layout design Add a layout grid to patron card creator to figure out the positions of text fields, barcode and images. First draft, not ready to sign off. --- C4/Patroncards/Patroncard.pm | 57 ++++++++++++++++++++++ .../prog/en/modules/patroncards/edit-layout.tt | 10 ++++ patroncards/create-pdf.pl | 1 + patroncards/edit-layout.pl | 2 + 4 files changed, 70 insertions(+) diff --git a/C4/Patroncards/Patroncard.pm b/C4/Patroncards/Patroncard.pm index 7678ac0..10451e4 100644 --- a/C4/Patroncards/Patroncard.pm +++ b/C4/Patroncards/Patroncard.pm @@ -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,62 @@ 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; + + my $obj_stream = "q\n"; # save the graphic state + + my $x = $self->{'llx'}; + my $y = $self->{'lly'}; + + my $cnt = 0; + for ( $x = $self->{'llx'} ; $x <= $self->{'llx'} + $self->{'width'}; $x+=10) { + my $xx = $x; + my $yy = $y + $self->{'height'}; + if ( $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 $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'}; $y <= $self->{'lly'} + $self->{'height'}; $y+=10) { + + my $xx = $x + $self->{'width'}; + my $yy = $y; + + if ( $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 $y m\n"; + $obj_stream .= "$xx $yy l\n"; + $obj_stream .= "s\n"; + } + + $obj_stream .= "Q\n"; # restore the graphic state + + $pdf->Add($obj_stream); +} + + sub draw_text { my ($self, $pdf, %params) = @_; warn sprintf('No pdf object passed in.') and return -1 if !$pdf; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-layout.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-layout.tt index 5b078eb..bd856c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-layout.tt +++ b/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 %] +
  • diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl index e660af6..4a2930f 100755 --- a/patroncards/create-pdf.pl +++ b/patroncards/create-pdf.pl @@ -147,6 +147,7 @@ foreach my $item (@{$items}) { ); $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 diff --git a/patroncards/edit-layout.pl b/patroncards/edit-layout.pl index fb495b1..d244640 100755 --- a/patroncards/edit-layout.pl +++ b/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; -- 2.1.4