dolibarr 18.0.6
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23/* Inspire de PDF_Label
24 * PDF_Label - PDF label editing
25 * @package PDF_Label
26 * @author Laurent PASSEBECQ <lpasseb@numericable.fr>
27 * @copyright 2003 Laurent PASSEBECQ
28 * disponible ici : http://www.fpdf.org/fr/script/script29.php
29 */
30
31//-------------------------------------------------------------------
32// VERSIONS :
33// 1.0 : Initial release
34// 1.1 : + : Added unit in the constructor
35// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1)
36// + : Added in the description of a label :
37// font-size : defaut char size (can be changed by calling Set_Char_Size(xx);
38// paper-size : Size of the paper for this sheet (thanx to Al Canton)
39// metric : type of unit used in this description
40// You can define your label properties in inches by setting metric to 'in'
41// and printing in millimiter by setting unit to 'mm' in constructor.
42// Added some labels :
43// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com
44// 8600 : thanx to Kunal Walia : kunal@u.washington.edu
45// + : Added 3mm to the position of labels to avoid errors
47
54require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
57
58
63{
67 public $db;
68
69 public $code; // Code of format
70
74 public $page_largeur;
75
79 public $page_hauteur;
80
84 public $format;
85
89 public $marge_gauche;
90
94 public $marge_droite;
95
99 public $marge_haute;
100
104 public $marge_basse;
105
106 // phpcs:disable PEAR.NamingConventions.ValidVariableName.PublicUnderscore
107 // protected
108 // Nom du format de l'etiquette
109 protected $_Avery_Name = '';
110 // Marge de gauche de l'etiquette
111 protected $_Margin_Left = 0;
112 // marge en haut de la page avant la premiere etiquette
113 protected $_Margin_Top = 0;
114 // Espace horizontal entre 2 bandes d'etiquettes
115 protected $_X_Space = 0;
116 // Espace vertical entre 2 bandes d'etiquettes
117 protected $_Y_Space = 0;
118 // NX Nombre d'etiquettes sur la largeur de la page
119 protected $_X_Number = 0;
120 // NY Nombre d'etiquettes sur la hauteur de la page
121 protected $_Y_Number = 0;
122 // Largeur de chaque etiquette
123 protected $_Width = 0;
124 // Hauteur de chaque etiquette
125 protected $_Height = 0;
126 // Hauteur des caracteres
127 protected $_Char_Size = 10;
128 // Hauteur par defaut d'une ligne
129 protected $_Line_Height = 10;
130 // Type of metric.. Will help to calculate good values
131 protected $_Metric = 'mm';
132 // Type of metric for the doc..
133 protected $_Metric_Doc = 'mm';
134 protected $_COUNTX = 1;
135 protected $_COUNTY = 1;
136 protected $_First = 1;
137 public $Tformat;
138
139
140 // phpcs:enable
146 public function __construct($db)
147 {
148 $this->db = $db;
149 }
150
151 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
161 abstract public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '');
162 // phpcs:enable
163
172 abstract public function addSticker(&$pdf, $outputlangs, $param);
173
174 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
183 public function Set_Char_Size(&$pdf, $pt)
184 {
185 // phpcs:enable
186 if ($pt > 3) {
187 $this->_Char_Size = $pt;
188 $this->_Line_Height = $this->_Get_Height_Chars($pt);
189 $pdf->SetFont('', '', $pt);
190 }
191 }
192
193 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
194 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
207 protected function _Pointille(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $nbPointilles = 15)
208 {
209 // phpcs:enable
210 $pdf->SetLineWidth($epaisseur);
211 $length = abs($x1 - $x2);
212 $hauteur = abs($y1 - $y2);
213 if ($length > $hauteur) {
214 $Pointilles = ($length / $nbPointilles) / 2; // taille des pointilles
215 } else {
216 $Pointilles = ($hauteur / $nbPointilles) / 2;
217 }
218 for ($i = $x1; $i <= $x2; $i += $Pointilles + $Pointilles) {
219 for ($j = $i; $j <= ($i + $Pointilles); $j++) {
220 if ($j <= ($x2 - 1)) {
221 $pdf->Line($j, $y1, $j + 1, $y1); // on trace le pointill? du haut, point par point
222 $pdf->Line($j, $y2, $j + 1, $y2); // on trace le pointill? du bas, point par point
223 }
224 }
225 }
226 for ($i = $y1; $i <= $y2; $i += $Pointilles + $Pointilles) {
227 for ($j = $i; $j <= ($i + $Pointilles); $j++) {
228 if ($j <= ($y2 - 1)) {
229 $pdf->Line($x1, $j, $x1, $j + 1); // on trace le pointill? du haut, point par point
230 $pdf->Line($x2, $j, $x2, $j + 1); // on trace le pointill? du bas, point par point
231 }
232 }
233 }
234 }
235
236 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
237 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
250 protected function _Croix(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $taille = 4)
251 {
252 // phpcs:enable
253 $pdf->SetDrawColor(192, 192, 192);
254
255 $pdf->SetLineWidth($epaisseur);
256 $lg = $taille / 2;
257 // croix haut gauche
258 $pdf->Line($x1, $y1 - $lg, $x1, $y1 + $lg);
259 $pdf->Line($x1 - $lg, $y1, $x1 + $lg, $y1);
260 // croix bas gauche
261 $pdf->Line($x1, $y2 - $lg, $x1, $y2 + $lg);
262 $pdf->Line($x1 - $lg, $y2, $x1 + $lg, $y2);
263 // croix haut droit
264 $pdf->Line($x2, $y1 - $lg, $x2, $y1 + $lg);
265 $pdf->Line($x2 - $lg, $y1, $x2 + $lg, $y1);
266 // croix bas droit
267 $pdf->Line($x2, $y2 - $lg, $x2, $y2 + $lg);
268 $pdf->Line($x2 - $lg, $y2, $x2 + $lg, $y2);
269
270 $pdf->SetDrawColor(0, 0, 0);
271 }
272
282 private function convertMetric($value, $src, $dest)
283 {
284 if ($src != $dest) {
285 $tab = array(
286 'in'=>39.37008,
287 'mm'=>1000
288 );
289 return $value * $tab[$dest] / $tab[$src];
290 }
291
292 return $value;
293 }
294
295 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
296 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
303 protected function _Get_Height_Chars($pt)
304 {
305 // phpcs:enable
306 // Array for link between height of characters and space between lines
307 $_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);
308 if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
309 return $_Table_Hauteur_Chars[$pt];
310 } else {
311 return 100; // There is a prob..
312 }
313 }
314
315 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
316 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
324 protected function _Set_Format(&$pdf, $format)
325 {
326 // phpcs:enable
327 $this->_Metric = $format['metric'];
328 $this->_Avery_Name = $format['name'];
329 $this->_Avery_Code = empty($format['code'])?'':$format['code'];
330 $this->_Margin_Left = $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
331 $this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
332 $this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
333 $this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
334 $this->_X_Number = $format['NX'];
335 $this->_Y_Number = $format['NY'];
336 $this->_Width = $this->convertMetric($format['width'], $this->_Metric, $this->_Metric_Doc);
337 $this->_Height = $this->convertMetric($format['height'], $this->_Metric, $this->_Metric_Doc);
338 $this->Set_Char_Size($pdf, $format['font-size']);
339 }
340}
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)
Methode qui permet de modifier la taille des caracteres Cela modiera aussi l'espace entre chaque lign...
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 strem.
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)