dolibarr 21.0.0-beta
commonstickergenerator.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Steve Dillon
3 * Copyright (C) 2003 Laurent Passebecq
4 * Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
5 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
6 * Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
7 * Copyright (C) 2015 Francis Appels <francis.appels@yahoo.com>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24/* Inspire de PDF_Label
25 * PDF_Label - PDF label editing
26 * @package PDF_Label
27 * @author Laurent PASSEBECQ <lpasseb@numericable.fr>
28 * @copyright 2003 Laurent PASSEBECQ
29 * disponible ici : http://www.fpdf.org/fr/script/script29.php
30 */
31
32//-------------------------------------------------------------------
33// VERSIONS :
34// 1.0 : Initial release
35// 1.1 : + : Added unit in the constructor
36// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1)
37// + : Added in the description of a label :
38// font-size : default char size (can be changed by calling Set_Char_Size(xx);
39// paper-size : Size of the paper for this sheet (thanx to Al Canton)
40// metric : type of unit used in this description
41// You can define your label properties in inches by setting metric to 'in'
42// and printing in millimeter by setting unit to 'mm' in constructor.
43// Added some labels :
44// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com
45// 8600 : thanx to Kunal Walia : kunal@u.washington.edu
46// + : Added 3mm to the position of labels to avoid errors
48
55require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
57require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
58require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
59
60
65{
69 public $db;
70
74 public $code; // Code of format
75
76 // phpcs:disable PEAR.NamingConventions.ValidVariableName.PublicUnderscore
77 // protected
78 // Name of stick
79 protected $_Avery_Name = '';
80 // Code of stick
81 protected $_Avery_Code = '';
82 // Marge de gauche de l'etiquette
83 protected $_Margin_Left = 0;
84 // marge en haut de la page avant la premiere etiquette
85 protected $_Margin_Top = 0;
86 // Espace horizontal entre 2 bandes d'etiquettes
87 protected $_X_Space = 0;
88 // Espace vertical entre 2 bandes d'etiquettes
89 protected $_Y_Space = 0;
90 // NX Nombre d'etiquettes sur la largeur de la page
91 protected $_X_Number = 0;
92 // NY Number of labels on the height of a page
93 protected $_Y_Number = 0;
94 // width of label
95 protected $_Width = 0;
96 // Height of label
97 protected $_Height = 0;
98 // Height of characters
99 protected $_Char_Size = 10;
100 // Height by default of a line
101 protected $_Line_Height = 10;
102 // Type of metric.. Will help to calculate good values
103 protected $_Metric = 'mm';
104 // Type of metric for the doc..
105 protected $_Metric_Doc = 'mm';
106 protected $_COUNTX = 1;
107 protected $_COUNTY = 1;
108 protected $_First = 1;
112 public $Tformat;
113
117 public $_Avery_Labels;
118 // phpcs:enable
119
125 public function __construct($db)
126 {
127 $this->db = $db;
128 }
129
130 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
141 abstract public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = '');
142 // phpcs:enable
143
152 abstract public function addSticker(&$pdf, $outputlangs, $param);
153
154 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
163 public function Set_Char_Size(&$pdf, $pt)
164 {
165 // phpcs:enable
166 if ($pt > 3) {
167 $this->_Char_Size = $pt;
168 $this->_Line_Height = $this->_Get_Height_Chars($pt);
169 $pdf->SetFont('', '', $pt);
170 }
171 }
172
173 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
174 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
187 protected function _Pointille(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $nbPointilles = 15)
188 {
189 // phpcs:enable
190 $pdf->SetLineWidth($epaisseur);
191 $length = abs($x1 - $x2);
192 $hauteur = abs($y1 - $y2);
193 if ($length > $hauteur) {
194 $Pointilles = ($length / $nbPointilles) / 2; // taille des pointilles
195 } else {
196 $Pointilles = ($hauteur / $nbPointilles) / 2;
197 }
198 for ($i = $x1; $i <= $x2; $i += $Pointilles + $Pointilles) {
199 for ($j = $i; $j <= ($i + $Pointilles); $j++) {
200 if ($j <= ($x2 - 1)) {
201 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
202 $pdf->Line($j, $y1, $j + 1, $y1); // on trace le pointill? du haut, point par point
203 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
204 $pdf->Line($j, $y2, $j + 1, $y2); // on trace le pointill? du bas, point par point
205 }
206 }
207 }
208 for ($i = $y1; $i <= $y2; $i += $Pointilles + $Pointilles) {
209 for ($j = $i; $j <= ($i + $Pointilles); $j++) {
210 if ($j <= ($y2 - 1)) {
211 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
212 $pdf->Line($x1, $j, $x1, $j + 1); // on trace le pointill? du haut, point par point
213 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
214 $pdf->Line($x2, $j, $x2, $j + 1); // on trace le pointill? du bas, point par point
215 }
216 }
217 }
218 }
219
220 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
221 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
236 protected function _Croix(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $taille = 4)
237 {
238 // phpcs:enable
239 $pdf->SetDrawColor(192, 192, 192);
240
241 $pdf->SetLineWidth($epaisseur);
242 $lg = $taille / 2;
243 // croix haut gauche
244 $pdf->Line($x1, $y1 - $lg, $x1, $y1 + $lg);
245 $pdf->Line($x1 - $lg, $y1, $x1 + $lg, $y1);
246 // croix bas gauche
247 $pdf->Line($x1, $y2 - $lg, $x1, $y2 + $lg);
248 $pdf->Line($x1 - $lg, $y2, $x1 + $lg, $y2);
249 // croix haut droit
250 $pdf->Line($x2, $y1 - $lg, $x2, $y1 + $lg);
251 $pdf->Line($x2 - $lg, $y1, $x2 + $lg, $y1);
252 // croix bas droit
253 $pdf->Line($x2, $y2 - $lg, $x2, $y2 + $lg);
254 $pdf->Line($x2 - $lg, $y2, $x2 + $lg, $y2);
255
256 $pdf->SetDrawColor(0, 0, 0);
257 }
258
268 private function convertMetric($value, $src, $dest)
269 {
270 if ($src != $dest) {
271 $tab = array(
272 'in' => 39.37008,
273 'mm' => 1000
274 );
275 return $value * $tab[$dest] / $tab[$src];
276 }
277
278 return $value;
279 }
280
281 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
282 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
289 protected function _Get_Height_Chars($pt)
290 {
291 // phpcs:enable
292 // Array for link between height of characters and space between lines
293 $_Table_Hauteur_Chars = array(6 => 2, 7 => 2.5, 8 => 3, 9 => 3.5, 10 => 4, 11 => 6, 12 => 7, 13 => 8, 14 => 9, 15 => 10);
294 if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
295 return $_Table_Hauteur_Chars[$pt];
296 } else {
297 return 100; // There is a prob..
298 }
299 }
300
301 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
302 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
310 protected function _Set_Format(&$pdf, $format)
311 {
312 // phpcs:enable
313 $this->_Metric = $format['metric'];
314 $this->_Avery_Name = $format['name'];
315 $this->_Avery_Code = empty($format['code']) ? '' : $format['code'];
316 $this->_Margin_Left = $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
317 $this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
318 $this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
319 $this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
320 $this->_X_Number = $format['NX'];
321 $this->_Y_Number = $format['NY'];
322 $this->_Width = $this->convertMetric($format['width'], $this->_Metric, $this->_Metric_Doc);
323 $this->_Height = $this->convertMetric($format['height'], $this->_Metric, $this->_Metric_Doc);
324 $this->Set_Char_Size($pdf, $format['font-size']);
325 }
326}
Parent class for documents (PDF, ODT, ...) generators.
Class to generate stick sheet with format Avery or other personalised.
_Get_Height_Chars($pt)
protected Give the height for a char size given.
_Croix(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $taille=4)
protected Function realisant une croix aux 4 coins des cartes
Set_Char_Size(&$pdf, $pt)
Method to modify the size of characters This will also modify the space between lines.
convertMetric($value, $src, $dest)
Convert units (in to mm, mm to in) $src and $dest must be 'in' or 'mm'.
_Set_Format(&$pdf, $format)
protected Set format
write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir='', $filename='')
Function to build PDF on disk, then output on HTTP stream.
_Pointille(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $nbPointilles=15)
protected Print dot line
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)