1 package C4::Barcodes::PrinterConfig;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
19 #use warnings; FIXME - Bug 2505
20 use vars qw($VERSION @EXPORT);
26 # set the version for version checking
27 $VERSION = 3.07.00.049;
29 @EXPORT = qw(&labelsPage &getLabelPosition setPositionsForX setPositionsForY);
34 C4::Barcodes::PrinterConfig - Koha module dealing with labels in a PDF.
38 use C4::Barcodes::PrinterConfig;
42 This package is used to deal with labels in a pdf file. Giving some parameters,
43 this package contains several functions to handle every label considering the
44 environment of the pdf file.
48 =head2 my @positionsForX;
50 Takes all the X positions of the pdf file.
52 =head2 my @positionsForY;
54 Takes all the Y positions of the pdf file.
56 =head2 my $firstLabel = 1;
58 Test if the label passed as a parameter is the first label to be printed into the pdf file.
60 =head2 setPositionsForX
62 C4::Barcodes::PrinterConfig::setPositionsForX($marginLeft, $labelWidth, $columns, $pageType);
64 Calculate and stores all the X positions across the pdf page.
66 C<$marginLeft> Indicates how much left margin do you want in your page type.
68 C<$labelWidth> Indicates the width of the label that you are going to use.
70 C<$columns> Indicates how many columns do you want in your page type.
72 C<$pageType> Page type to print (eg: a4, legal, etc).
76 # Globals used by the functions
81 sub setPositionsForX {
82 my ($marginLeft, $labelWidth, $columns, $pageType) = @_;
83 my $defaultDpi = 72/25.4; # By default we know 25.4 mm -> 1 inch -> 72 dots per inch
84 my $whereToStart = ($marginLeft + ($labelWidth/2));
85 my $firstLabel = $whereToStart*$defaultDpi;
86 my $spaceBetweenLabels = $labelWidth*$defaultDpi;
88 for (my $i = 0; $i < $columns ; $i++) {
89 push @positions, ($firstLabel+($spaceBetweenLabels*$i));
91 @positionsForX = @positions;
94 =head2 setPositionsForY
96 C4::Barcodes::PrinterConfig::setPositionsForY($marginBottom, $labelHeigth, $rows, $pageType);
98 Calculate and stores all tha Y positions across the pdf page.
100 C<$marginBottom> Indicates how much bottom margin do you want in your page type.
102 C<$labelHeigth> Indicates the height of the label that you are going to use.
104 C<$rows> Indicates how many rows do you want in your page type.
106 C<$pageType> Page type to print (eg: a4, legal, etc).
110 sub setPositionsForY {
111 my ($marginBottom, $labelHeigth, $rows, $pageType) = @_;
112 my $defaultDpi = 72/25.4; # By default we know 25.4 mm -> 1 inch -> 72 dots per inch
113 my $whereToStart = ($marginBottom + ($labelHeigth/2));
114 my $firstLabel = $whereToStart*$defaultDpi;
115 my $spaceBetweenLabels = $labelHeigth*$defaultDpi;
117 for (my $i = 0; $i < $rows; $i++) {
118 unshift @positions, ($firstLabel+($spaceBetweenLabels*$i));
120 @positionsForY = @positions;
123 =head2 getLabelPosition
125 (my $x, my $y, $pdfObject, $pageObject, $gfxObject, $textObject, $coreObject, $labelPosition) =
126 C4::Barcodes::PrinterConfig::getLabelPosition($labelPosition, $pdfObject, $page, $gfx, $text, $fontObject, $pageType);
128 Return the (x,y) position of the label that you are going to print considering the environment.
130 C<$labelPosition> Indicates which label positions do you want to place by x and y coordinates.
132 C<$pdfObject> The PDF object in use.
134 C<$page> The page in use.
136 C<$gfx> The gfx resource to handle with barcodes objects.
138 C<$text> The text resource to handle with text.
140 C<$fontObject> The font object
142 C<$pageType> Page type to print (eg: a4, legal, etc).
146 sub getLabelPosition {
147 my ($labelNum, $pdf, $page, $gfxObject, $textObject, $fontObject, $pageType) = @_;
148 my $indexX = $labelNum % @positionsForX;
149 my $indexY = int($labelNum / @positionsForX);
150 # Calculates the next label position and return that label number
151 my $nextIndexX = $labelNum % @positionsForX;
152 my $nextIndexY = $labelNum % @positionsForY;
155 $page->mediabox($pageType);
156 $gfxObject = $page->gfx;
157 $textObject = $page->text;
158 $textObject->font($fontObject, 7);
160 } elsif (($nextIndexX == 0) && ($nextIndexY == 0)) {
162 $page->mediabox($pageType);
163 $gfxObject = $page->gfx;
164 $textObject = $page->text;
165 $textObject->font($fontObject, 7);
167 $labelNum = $labelNum + 1;
168 if ($labelNum == (@positionsForX*@positionsForY)) {
171 return ($positionsForX[$indexX], $positionsForY[$indexY], $pdf, $page, $gfxObject, $textObject, $fontObject, $labelNum);
176 my @labelTable = C4::Barcodes::PrinterConfig::labelsPage($rows, $columns);
178 This function will help you to build the labels panel, where you can choose
179 wich label position do you want to start the printer process.
181 C<$rows> Indicates how many rows do you want in your page type.
183 C<$columns> Indicates how many rows do you want in your page type.
188 my ($rows, $columns) = @_;
193 for (my $i = 1; $i <= $rows; $i++) {
195 for (my $j = 1; $j <= $columns; $j++) {
202 %cell = (check => $check,
204 labelname => $labelname);
205 $tagname = $tagname + 1;
206 $labelname = $labelname + 1;
207 push @column, \%cell;
209 my %columns = (columns => \@column);
210 push @pageType, \%columns;
221 Koha Physics Library UNLP <matias_veleda@hotmail.com>