dolibarr  7.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  *
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 <http://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 
54 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
55 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
56 require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
57 
58 
62 abstract class CommonStickerGenerator
63 {
64 
65  public $code; // Code of format
66  public $format; // Array with informations
67 
68  // protected
69  var $_Avery_Name = ''; // Nom du format de l'etiquette
70  var $_Margin_Left = 0; // Marge de gauche de l'etiquette
71  var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette
72  var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes
73  var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes
74  var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page
75  var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page
76  var $_Width = 0; // Largeur de chaque etiquette
77  var $_Height = 0; // Hauteur de chaque etiquette
78  var $_Char_Size = 10; // Hauteur des caracteres
79  var $_Line_Height = 10; // Hauteur par defaut d'une ligne
80  var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values
81  var $_Metric_Doc = 'mm'; // Type of metric for the doc..
82  var $_COUNTX = 1;
83  var $_COUNTY = 1;
84  var $_First = 1;
85  var $Tformat;
86 
92  function __construct($db)
93  {
94  $this->db = $db;
95  }
96 
106  abstract function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='');
107 
116  abstract function addSticker(&$pdf,$outputlangs,$param);
117 
126  function Set_Char_Size(&$pdf,$pt)
127  {
128  if ($pt > 3) {
129  $this->_Char_Size = $pt;
130  $this->_Line_Height = $this->_Get_Height_Chars($pt);
131  $pdf->SetFont('','',$pt);
132  }
133  }
134 
147  function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15)
148  {
149  $pdf->SetLineWidth($epaisseur);
150  $length=abs($x1-$x2);
151  $hauteur=abs($y1-$y2);
152  if($length>$hauteur) {
153  $Pointilles=($length/$nbPointilles)/2; // taille des pointilles
154  }
155  else {
156  $Pointilles=($hauteur/$nbPointilles)/2;
157  }
158  for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
159  for($j=$i;$j<=($i+$Pointilles);$j++) {
160  if($j<=($x2-1)) {
161  $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point
162  $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point
163  }
164  }
165  }
166  for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) {
167  for($j=$i;$j<=($i+$Pointilles);$j++) {
168  if($j<=($y2-1)) {
169  $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point
170  $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point
171  }
172  }
173  }
174  }
175 
188  function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4)
189  {
190  $pdf->SetDrawColor(192,192,192);
191 
192  $pdf->SetLineWidth($epaisseur);
193  $lg=$taille/2;
194  // croix haut gauche
195  $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg);
196  $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1);
197  // croix bas gauche
198  $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg);
199  $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2);
200  // croix haut droit
201  $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg);
202  $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1);
203  // croix bas droit
204  $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg);
205  $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2);
206 
207  $pdf->SetDrawColor(0,0,0);
208  }
209 
219  function _Convert_Metric ($value, $src, $dest)
220  {
221  if ($src != $dest) {
222  $tab['in'] = 39.37008;
223  $tab['mm'] = 1000;
224  return $value * $tab[$dest] / $tab[$src];
225  } else {
226  return $value;
227  }
228  }
229 
236  function _Get_Height_Chars($pt)
237  {
238  // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes
239  $_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);
240  if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
241  return $_Table_Hauteur_Chars[$pt];
242  } else {
243  return 100; // There is a prob..
244  }
245  }
246 
254  function _Set_Format(&$pdf, $format)
255  {
256  $this->_Metric = $format['metric'];
257  $this->_Avery_Name = $format['name'];
258  $this->_Avery_Code = $format['code'];
259  $this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
260  $this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
261  $this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
262  $this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
263  $this->_X_Number = $format['NX'];
264  $this->_Y_Number = $format['NY'];
265  $this->_Width = $this->_Convert_Metric($format['width'], $this->_Metric, $this->_Metric_Doc);
266  $this->_Height = $this->_Convert_Metric($format['height'], $this->_Metric, $this->_Metric_Doc);
267  $this->Set_Char_Size($pdf, $format['font-size']);
268  }
269 
270 }
_Croix(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $taille=4)
protected Function realisant une croix aux 4 coins des cartes
write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir='')
Function to build PDF on disk, then output on HTTP strem.
Class to generate stick sheet with format Avery or other personalised.
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) ...
_Convert_Metric($value, $src, $dest)
protected Convert units (in to mm, mm to in) $src and $dest must be 'in' or 'mm'
_Pointille(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $nbPointilles=15)
protected Print dot line
Set_Char_Size(&$pdf, $pt)
Methode qui permet de modifier la taille des caracteres Cela modiera aussi l'espace entre chaque lign...
_Set_Format(&$pdf, $format)
protected Set format
_Get_Height_Chars($pt)
protected Give the height for a char size given.