dolibarr 21.0.0-alpha
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
140 abstract public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '');
141 // phpcs:enable
142
151 abstract public function addSticker(&$pdf, $outputlangs, $param);
152
153 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
162 public function Set_Char_Size(&$pdf, $pt)
163 {
164 // phpcs:enable
165 if ($pt > 3) {
166 $this->_Char_Size = $pt;
167 $this->_Line_Height = $this->_Get_Height_Chars($pt);
168 $pdf->SetFont('', '', $pt);
169 }
170 }
171
172 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
173 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
186 protected function _Pointille(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $nbPointilles = 15)
187 {
188 // phpcs:enable
189 $pdf->SetLineWidth($epaisseur);
190 $length = abs($x1 - $x2);
191 $hauteur = abs($y1 - $y2);
192 if ($length > $hauteur) {
193 $Pointilles = ($length / $nbPointilles) / 2; // taille des pointilles
194 } else {
195 $Pointilles = ($hauteur / $nbPointilles) / 2;
196 }
197 for ($i = $x1; $i <= $x2; $i += $Pointilles + $Pointilles) {
198 for ($j = $i; $j <= ($i + $Pointilles); $j++) {
199 if ($j <= ($x2 - 1)) {
200 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
201 $pdf->Line($j, $y1, $j + 1, $y1); // on trace le pointill? du haut, point par point
202 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
203 $pdf->Line($j, $y2, $j + 1, $y2); // on trace le pointill? du bas, point par point
204 }
205 }
206 }
207 for ($i = $y1; $i <= $y2; $i += $Pointilles + $Pointilles) {
208 for ($j = $i; $j <= ($i + $Pointilles); $j++) {
209 if ($j <= ($y2 - 1)) {
210 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
211 $pdf->Line($x1, $j, $x1, $j + 1); // on trace le pointill? du haut, point par point
212 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
213 $pdf->Line($x2, $j, $x2, $j + 1); // on trace le pointill? du bas, point par point
214 }
215 }
216 }
217 }
218
219 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
220 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
235 protected function _Croix(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $taille = 4)
236 {
237 // phpcs:enable
238 $pdf->SetDrawColor(192, 192, 192);
239
240 $pdf->SetLineWidth($epaisseur);
241 $lg = $taille / 2;
242 // croix haut gauche
243 $pdf->Line($x1, $y1 - $lg, $x1, $y1 + $lg);
244 $pdf->Line($x1 - $lg, $y1, $x1 + $lg, $y1);
245 // croix bas gauche
246 $pdf->Line($x1, $y2 - $lg, $x1, $y2 + $lg);
247 $pdf->Line($x1 - $lg, $y2, $x1 + $lg, $y2);
248 // croix haut droit
249 $pdf->Line($x2, $y1 - $lg, $x2, $y1 + $lg);
250 $pdf->Line($x2 - $lg, $y1, $x2 + $lg, $y1);
251 // croix bas droit
252 $pdf->Line($x2, $y2 - $lg, $x2, $y2 + $lg);
253 $pdf->Line($x2 - $lg, $y2, $x2 + $lg, $y2);
254
255 $pdf->SetDrawColor(0, 0, 0);
256 }
257
267 private function convertMetric($value, $src, $dest)
268 {
269 if ($src != $dest) {
270 $tab = array(
271 'in' => 39.37008,
272 'mm' => 1000
273 );
274 return $value * $tab[$dest] / $tab[$src];
275 }
276
277 return $value;
278 }
279
280 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
281 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
288 protected function _Get_Height_Chars($pt)
289 {
290 // phpcs:enable
291 // Array for link between height of characters and space between lines
292 $_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);
293 if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
294 return $_Table_Hauteur_Chars[$pt];
295 } else {
296 return 100; // There is a prob..
297 }
298 }
299
300 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
301 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
309 protected function _Set_Format(&$pdf, $format)
310 {
311 // phpcs:enable
312 $this->_Metric = $format['metric'];
313 $this->_Avery_Name = $format['name'];
314 $this->_Avery_Code = empty($format['code']) ? '' : $format['code'];
315 $this->_Margin_Left = $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
316 $this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
317 $this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
318 $this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
319 $this->_X_Number = $format['NX'];
320 $this->_Y_Number = $format['NY'];
321 $this->_Width = $this->convertMetric($format['width'], $this->_Metric, $this->_Metric_Doc);
322 $this->_Height = $this->convertMetric($format['height'], $this->_Metric, $this->_Metric_Doc);
323 $this->Set_Char_Size($pdf, $format['font-size']);
324 }
325}
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
_Pointille(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $nbPointilles=15)
protected Print dot line
write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir='')
Function to build PDF on disk, then output on HTTP stream.
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)