[Koha-cvs] koha/barcodes label-print-pdf.pl [rel_2_2]
Mason James
szrj1m at yahoo.com
Fri Jul 28 01:55:41 CEST 2006
CVSROOT: /sources/koha
Module name: koha
Branch: rel_2_2
Changes by: Mason James <sushi> 06/07/27 23:55:41
Modified files:
barcodes : label-print-pdf.pl
Log message:
the script is now using the clever Text::Wrap module, this does seem to be working a treat. text-wrapping is attempting to wrap on spaces where possible, then a 13 character forced wrap. script now has a regex to remove nl/cr before formatting too.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/barcodes/label-print-pdf.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.1.2.8&r2=1.1.2.9
Patches:
Index: label-print-pdf.pl
===================================================================
RCS file: /sources/koha/koha/barcodes/label-print-pdf.pl,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -b -r1.1.2.8 -r1.1.2.9
--- label-print-pdf.pl 26 Jul 2006 12:16:18 -0000 1.1.2.8
+++ label-print-pdf.pl 27 Jul 2006 23:55:41 -0000 1.1.2.9
@@ -27,6 +27,7 @@
use PDF::Reuse::Barcode;
use PDF::Report;
use POSIX;
+use Text::Wrap;
#use Data::Dumper;
#use Acme::Comment;
@@ -178,6 +179,10 @@
my $spine_label_text_with = 67;
my $y_pos = ( $y_pos_initial_startrow + 90 );
+ # set the column lenght for textwrap, and the seperator.
+ $Text::Wrap::columns = 13;
+ $Text::Wrap::separator = "\n";
+
#warn "Y POS = $y_pos";
foreach $item (@resultsloop) {
@@ -192,24 +197,32 @@
# and the item record has some values for this field, display it.
if ( $conf_data->{"$field"} && $item->{"$field"} ) {
- # chop the string up into 12 char's per line
+ # get the string
$str = $item->{"$field"};
- my $strlen = length($str);
- my $num_lines = ceil( $strlen / 12 );
- my $start_pos = 0;
- my $len = 12;
+
+ # strip out naughty existing nl/cr's
+ $str =~ s/\n//g;
+ $str =~ s/\r//g;
+
+ # chop the string up into _upto_ 12 chunks
+ # and seperate the chunks with newlines
+
+ $str = wrap( "", "", "$str" );
+
+ # split the chunks between newline's, into an array
+ my @strings = split /\n/, $str;
+
+ # warn Dumper @strings;
# then loop for each string line
- for ( 1 .. $num_lines ) {
+ foreach my $str (@strings) {
$pdf->setAddTextPos( $hPos, $vPos - 10 );
- my $chop_str = substr( $str, $start_pos, $len );
my ( $h, $v ) = $pdf->getAddTextPos();
# using '1000' width, so that addText wont use it's
# own internal wordwrap, (as it doesnt work so well)
- $pdf->addText( $chop_str, 10, 1000, 90 );
+ $pdf->addText( $str, 10, 1000, 90 );
- $start_pos = $start_pos + $len;
$vPos = $vPos - 10;
}
} # if field is valid
More information about the Koha-cvs
mailing list