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 vars
qw($VERSION @EXPORT);
25 # set the version for version checking
28 @EXPORT = qw(&labelsPage &getLabelPosition setPositionsForX setPositionsForY);
33 C4::Barcodes::PrinterConfig - Koha module dealing with labels in a PDF.
37 use C4::Barcodes::PrinterConfig;
41 This package is used to deal with labels in a pdf file. Giving some parameters,
42 this package contains several functions to handle every label considering the
43 environment of the pdf file.
51 my @positionsForX; # Takes all the X positions of the pdf file.
52 my @positionsForY; # Takes all the Y positions of the pdf file.
53 my $firstLabel = 1; # Test if the label passed as a parameter is the first label to be printed into the pdf file.
55 =item setPositionsForX
57 C4::Barcodes::PrinterConfig::setPositionsForX($marginLeft, $labelWidth, $columns, $pageType);
59 Calculate and stores all the X positions across the pdf page.
61 C<$marginLeft> Indicates how much left margin do you want in your page type.
63 C<$labelWidth> Indicates the width of the label that you are going to use.
65 C<$columns> Indicates how many columns do you want in your page type.
67 C<$pageType> Page type to print (eg: a4, legal, etc).
71 sub setPositionsForX
{
72 my ($marginLeft, $labelWidth, $columns, $pageType) = @_;
73 my $defaultDpi = 72/25.4; # By default we know 25.4 mm -> 1 inch -> 72 dots per inch
74 my $whereToStart = ($marginLeft + ($labelWidth/2));
75 my $firstLabel = $whereToStart*$defaultDpi;
76 my $spaceBetweenLabels = $labelWidth*$defaultDpi;
78 for (my $i = 0; $i < $columns ; $i++) {
79 push @positions, ($firstLabel+($spaceBetweenLabels*$i));
81 @positionsForX = @positions;
84 =item setPositionsForY
86 C4::Barcodes::PrinterConfig::setPositionsForY($marginBottom, $labelHeigth, $rows, $pageType);
88 Calculate and stores all tha Y positions across the pdf page.
90 C<$marginBottom> Indicates how much bottom margin do you want in your page type.
92 C<$labelHeigth> Indicates the height of the label that you are going to use.
94 C<$rows> Indicates how many rows do you want in your page type.
96 C<$pageType> Page type to print (eg: a4, legal, etc).
100 sub setPositionsForY
{
101 my ($marginBottom, $labelHeigth, $rows, $pageType) = @_;
102 my $defaultDpi = 72/25.4; # By default we know 25.4 mm -> 1 inch -> 72 dots per inch
103 my $whereToStart = ($marginBottom + ($labelHeigth/2));
104 my $firstLabel = $whereToStart*$defaultDpi;
105 my $spaceBetweenLabels = $labelHeigth*$defaultDpi;
107 for (my $i = 0; $i < $rows; $i++) {
108 unshift @positions, ($firstLabel+($spaceBetweenLabels*$i));
110 @positionsForY = @positions;
113 =item getLabelPosition
115 (my $x, my $y, $pdfObject, $pageObject, $gfxObject, $textObject, $coreObject, $labelPosition) =
116 C4::Barcodes::PrinterConfig::getLabelPosition($labelPosition,
124 Return the (x,y) position of the label that you are going to print considering the environment.
126 C<$labelPosition> Indicates which label positions do you want to place by x and y coordinates.
128 C<$pdfObject> The PDF object in use.
130 C<$page> The page in use.
132 C<$gfx> The gfx resource to handle with barcodes objects.
134 C<$text> The text resource to handle with text.
136 C<$fontObject> The font object
138 C<$pageType> Page type to print (eg: a4, legal, etc).
142 sub getLabelPosition
{
143 my ($labelNum, $pdf, $page, $gfxObject, $textObject, $fontObject, $pageType) = @_;
144 my $indexX = $labelNum % @positionsForX;
145 my $indexY = int($labelNum / @positionsForX);
146 # Calculates the next label position and return that label number
147 my $nextIndexX = $labelNum % @positionsForX;
148 my $nextIndexY = $labelNum % @positionsForY;
151 $page->mediabox($pageType);
152 $gfxObject = $page->gfx;
153 $textObject = $page->text;
154 $textObject->font($fontObject, 7);
156 } elsif (($nextIndexX == 0) && ($nextIndexY == 0)) {
158 $page->mediabox($pageType);
159 $gfxObject = $page->gfx;
160 $textObject = $page->text;
161 $textObject->font($fontObject, 7);
163 $labelNum = $labelNum + 1;
164 if ($labelNum == (@positionsForX*@positionsForY)) {
167 return ($positionsForX[$indexX], $positionsForY[$indexY], $pdf, $page, $gfxObject, $textObject, $fontObject, $labelNum);
172 my @labelTable = C4::Barcodes::PrinterConfig::labelsPage($rows, $columns);
174 This function will help you to build the labels panel, where you can choose
175 wich label position do you want to start the printer process.
177 C<$rows> Indicates how many rows do you want in your page type.
179 C<$columns> Indicates how many rows do you want in your page type.
184 my ($rows, $columns) = @_;
189 for (my $i = 1; $i <= $rows; $i++) {
191 for (my $j = 1; $j <= $columns; $j++) {
198 %cell = (check
=> $check,
200 labelname
=> $labelname);
201 $tagname = $tagname + 1;
202 $labelname = $labelname + 1;
203 push @column, \
%cell;
205 my %columns = (columns
=> \
@column);
206 push @pageType, \
%columns;
219 Koha Physics Library UNLP <matias_veleda@hotmail.com>