Bugzilla – Attachment 63167 Details for
Bug 18550
Patron card creator: Print output does not respect layout units
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18550 - Patron card creator: Print output does not respect layout units
Bug-18550---Patron-card-creator-Print-output-does-.patch (text/plain), 8.08 KB, created by
Marc Véron
on 2017-05-05 13:13:14 UTC
(
hide
)
Description:
Bug 18550 - Patron card creator: Print output does not respect layout units
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2017-05-05 13:13:14 UTC
Size:
8.08 KB
patch
obsolete
>From 478f1f0a579c6e1df5aca51fb84e05b47e95aa85 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Marc=20V=C3=A9ron?= <veron@veron.ch> >Date: Fri, 5 May 2017 15:08:56 +0200 >Subject: [PATCH] Bug 18550 - Patron card creator: Print output does not > respect layout units > >To reproduce: >Text, images and barcode positions are always layed out based on PostScript points, regardless of unit defined in card layout. > >To reproduce: >- Test on top of Bug 18541 (introduces layout grid) >- Create a card layout wir a text field, an image and barcode. Use points > as layout unit >- Activate layout grid >- Create PDF output, save. >- Change layout unit to mm. >- Create PDF output, save. >- Compare PDFs. Verify that the positions are unchanged (still using points). > >- Apply patch >- Create again PDF >- Verify that elements are positionad as expected (using unit, e.g. mm) > >Note: Patch not yet ready to sign-off because of som e c/p, but tests are >welcome. >--- > C4/Patroncards/Patroncard.pm | 56 +++++++++++++++++++++++++++++++++----------- > 1 file changed, 42 insertions(+), 14 deletions(-) > >diff --git a/C4/Patroncards/Patroncard.pm b/C4/Patroncards/Patroncard.pm >index 3fb0f2e..b760704 100644 >--- a/C4/Patroncards/Patroncard.pm >+++ b/C4/Patroncards/Patroncard.pm >@@ -166,6 +166,16 @@ sub draw_text { > warn sprintf('No pdf object passed in.') and return -1 if !$pdf; > my @card_text = (); > return unless (ref($self->{'layout'}->{'text'}) eq 'ARRAY'); # just in case there is not text >+ >+ my $units = get_unit_values(); >+ my $unitvalue = 1; >+ foreach my $un (@$units){ >+ if ($un->{'type'} eq $self->{'layout'}->{'units'}) { >+ $unitvalue = $un->{'value'}; >+ } >+ } >+ >+ > my $text = [@{$self->{'layout'}->{'text'}}]; # make a copy of the arrayref *not* simply a pointer > while (scalar @$text) { > my $line = shift @$text; >@@ -187,8 +197,8 @@ sub draw_text { > $line = join(' ',@orig_line); > } > my $text_attribs = shift @$text; >- my $origin_llx = $self->{'llx'} + $text_attribs->{'llx'}; >- my $origin_lly = $self->{'lly'} + $text_attribs->{'lly'}; >+ my $origin_llx = $self->{'llx'} + $text_attribs->{'llx'} * $unitvalue; >+ my $origin_lly = $self->{'lly'} + $text_attribs->{'lly'} * $unitvalue; > my $Tx = 0; # final text llx > my $Ty = $origin_lly; # final text lly > my $Tw = 0; # final text word spacing. See http://www.adobe.com/devnet/pdf/pdf_reference.html ISO 32000-1 >@@ -226,8 +236,8 @@ sub draw_text { > $string_width = C4::Creators::PDF->StrWidth($line, $text_attribs->{'font'}, $text_attribs->{'font_size'}); > #$font_units_width = $m->string_width($line); > #$string_width = ($font_units_width * $text_attribs->{'font_size'}) / $units_per_em; >- if (($string_width + $text_attribs->{'llx'}) < $self->{'width'}) { >- ($Tx, $Tw) = text_alignment($origin_llx, $self->{'width'}, $text_attribs->{'llx'}, $string_width, $line, $text_attribs->{'text_alignment'}); >+ if ( $string_width + ( $text_attribs->{'llx'} * $unitvalue ) < $self->{'width'}) { >+ ($Tx, $Tw) = text_alignment($origin_llx, $self->{'width'}, $text_attribs->{'llx'} * $unitvalue, $string_width, $line, $text_attribs->{'text_alignment'}); > $line =~ s/^\s+//g; # strip naughty leading spaces > push @lines, {line=> $line, Tx => $Tx, Ty => $Ty, Tw => $Tw}; > last WRAP_LINES; >@@ -236,7 +246,7 @@ sub draw_text { > } > } > else { >- ($Tx, $Tw) = text_alignment($origin_llx, $self->{'width'}, $text_attribs->{'llx'}, $string_width, $line, $text_attribs->{'text_alignment'}); >+ ($Tx, $Tw) = text_alignment($origin_llx, $self->{'width'}, $text_attribs->{'llx'} * $unitvalue, $string_width, $line, $text_attribs->{'text_alignment'}); > $line =~ s/^\s+//g; # strip naughty leading spaces > push @lines, {line=> $line, Tx => $Tx, Ty => $Ty, Tw => $Tw}; > } >@@ -253,7 +263,7 @@ sub draw_text { > else { > $box_height += $text_attribs->{'font_size'}; > } >- box ($origin_llx, $box_lly, $self->{'width'} - $text_attribs->{'llx'}, $box_height, $pdf); >+ box ($origin_llx, $box_lly, $self->{'width'} - ( $text_attribs->{'llx'} * $unitvalue ), $box_height, $pdf); > } > $pdf->Font($text_attribs->{'font'}); > $pdf->FontSize($text_attribs->{'font_size'}); >@@ -267,11 +277,20 @@ sub draw_image { > my ($self, $pdf) = @_; > warn sprintf('No pdf object passed in.') and return -1 if !$pdf; > my $images = $self->{'layout'}->{'images'}; >+ >+ my $units = get_unit_values(); >+ my $unitvalue = 1; >+ foreach my $un (@$units){ >+ if ($un->{'type'} eq $self->{'layout'}->{'units'}) { >+ $unitvalue = $un->{'value'}; >+ } >+ } >+ > PROCESS_IMAGES: > foreach my $image (keys %$images) { > next PROCESS_IMAGES if $images->{$image}->{'data_source'}->[0]->{'image_source'} eq 'none'; >- my $Tx = $self->{'llx'} + $images->{$image}->{'Tx'}; >- my $Ty = $self->{'lly'} + $images->{$image}->{'Ty'}; >+ my $Tx = $self->{'llx'} + $images->{$image}->{'Tx'} * $unitvalue; >+ my $Ty = $self->{'lly'} + $images->{$image}->{'Ty'} * $unitvalue; > warn sprintf('No image passed in.') and next if !$images->{$image}->{'data'}; > my $intName = $pdf->AltJpeg($images->{$image}->{'data'},$images->{$image}->{'Sx'}, $images->{$image}->{'Sy'}, 1, $images->{$image}->{'alt'}->{'data'},$images->{$image}->{'alt'}->{'Sx'}, $images->{$image}->{'alt'}->{'Sy'}, 1); > my $obj_stream = "q\n"; >@@ -286,6 +305,15 @@ sub draw_image { > sub _draw_barcode { # this is cut-and-paste from Label.pm because there is no common place for it atm... > my $self = shift; > my %params = @_; >+ >+ my $units = get_unit_values(); >+ my $unitvalue = 1; >+ foreach my $un (@$units){ >+ if ($un->{'type'} eq $self->{'layout'}->{'units'}) { >+ $unitvalue = $un->{'value'}; >+ } >+ } >+ > my $x_scale_factor = 1; > my $num_of_chars = length($params{'barcode_data'}); > my $tot_bar_length = 0; >@@ -305,8 +333,8 @@ sub _draw_barcode { # this is cut-and-paste from Label.pm because there is no > } > eval { > PDF::Reuse::Barcode::Code39( >- x => $params{'llx'}, >- y => $params{'lly'}, >+ x => $params{'llx'} * $unitvalue, >+ y => $params{'lly'} * $unitvalue, > value => "*$params{barcode_data}*", > xSize => $x_scale_factor, > ySize => $params{'y_scale_factor'}, >@@ -325,8 +353,8 @@ sub _draw_barcode { # this is cut-and-paste from Label.pm because there is no > $x_scale_factor = ($params{'width'} / $tot_bar_length) * 0.9; > eval { > PDF::Reuse::Barcode::COOP2of5( >- x => $params{'llx'}, >- y => $params{'lly'}, >+ x => $params{'llx'}* $unitvalue, >+ y => $params{'lly'}* $unitvalue, > value => "*$params{barcode_data}*", > xSize => $x_scale_factor, > ySize => $params{'y_scale_factor'}, >@@ -343,8 +371,8 @@ sub _draw_barcode { # this is cut-and-paste from Label.pm because there is no > $x_scale_factor = ($params{'width'} / $tot_bar_length) * 0.9; > eval { > PDF::Reuse::Barcode::Industrial2of5( >- x => $params{'llx'}, >- y => $params{'lly'}, >+ x => $params{'llx'}* $unitvalue, >+ y => $params{'lly'}* $unitvalue, > value => "*$params{barcode_data}*", > xSize => $x_scale_factor, > ySize => $params{'y_scale_factor'}, >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18550
:
63167
|
63219
|
63320
|
66932
|
67670
|
67671