noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
pdf_core.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!
23 * \file
24 * \brief API for creating PDF, unicode, based on tfpdf
25 *@see TFPDF
26 */
27/*!
28 * \class Cellule
29 * \brief A Cellule is a cell to print
30 *@see TFPDF
31 */
32require_once NOALYSS_INCLUDE.'/tfpdf/tfpdf.php';
33class Cellule {
34 var $width;
36 var $text;
39 var $align;
40 var $fill;
41 var $link;
42 var $type;
44 {
45 $this->width=$w ;
46 $this->height=$h ;
47 $this->text=$txt;
48 $this->border=$border;
49 $this->new_line=$ln;
50 $this->align=$align;
51 $this->fill=$fill;
52 $this->link=$link;
53 $this->type=$type;
54 return $this;
55 }
56}
57/*!
58 * \class PDF_Core
59 * \brief API for creating PDF, unicode, based on tfpdf
60 *@see TFPDF
61 */
62class PDF_Core extends TFPDF
63{
64
65
66
67 private $cells=array();
68 private $bigger;
69
70 public function __construct ( $orientation = 'P', $unit = 'mm', $format = 'A4')
71 {
72 $this->bigger=0;
73
74 parent::__construct($orientation, $unit, $format);
75 $this->AddFont('DejaVu','','DejaVuSans.ttf',true);
76 $this->AddFont('DejaVu','I','DejaVuSans-Oblique.ttf',true);
77 $this->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true);
78 $this->AddFont('DejaVu','BI','DejaVuSans-BoldOblique.ttf',true);
79 $this->AddFont('DejaVuCond','','DejaVuSansCondensed.ttf',true);
80 $this->AddFont('DejaVuCond','B','DejaVuSansCondensed-Bold.ttf',true);
81 $this->AddFont('DejaVuCond','I','DejaVuSansCondensed-Oblique.ttf',true);
82 $this->AddFont('DejaVuCond','BI','DejaVuSansCondensed-BoldOblique.ttf',true);
83
84
85
86 $this->cells=array();
87 }
88 function get_margin_left()
89 {
90 return $this->lMargin;
91 }
93 {
94 return $this->bMargin;
95
96 }
97 function get_margin_top()
98 {
99 return $this->tMargin;
100 }
102 {
103 return $this->rMargin;
104 }
106 {
107 return $this->DefOrientation;
108 }
109 function get_unit()
110 {
111 return $this->k;
112 }
113 function get_page_size()
114 {
115 return $this->DefPageSize;
116 }
117 /**
118 * Count the number of rows a p_text will take for a multicell
119 * @param $p_text String
120 * @param $p_colSize size of the column in User Unit
121 */
122 private function count_nb_row($p_text,$p_colSize)
123 {
124 // If colSize is bigger than the size of the string then it takes 1 line
125 if ( $this->GetStringWidth($p_text) <= $p_colSize) return 1;
126 $nRow=0;
127 $aWords=explode(' ',$p_text);
128 $nb_words=count($aWords);
129 $string="";
130
131 for ($i=0;$i < $nb_words;$i++){
132 // Concatenate String with current word + a space
133 $string.=$aWords[$i];
134
135 // if there is a word after add a space
136 if ( $i+1 < $nb_words) $string.=" ";
137
138 // Compute new size and compare to the colSize
139 if ( $this->GetStringWidth($string) >= $p_colSize) {
140 // If the size of the string if bigger than we add a row, the current
141 // word is the first word of the next line
142 $nRow++;
143 $string=$aWords[$i];
144 }
145 }
146 $nRow++;
147 return $nRow;
148
149
150
151 }
152 /**
153 * Check if a page must be added due a MultiCell
154 * @return boolean
155 */
156 private function check_page_add()
157 {
158 // break on page
159 $size=count($this->cells);
160 for ($i=0;$i < $size ; $i++)
161 {
162 if ($this->cells[$i]->type == 'M' )
163 {
164 /**
165 * On doit calculer si le texte dépasse la texte et compter le
166 * nombre de lignes que le texte prendrait. Ensuite il faut
167 * faire un saut de page (renvoit true) si dépasse
168 */
169
170 $sizetext=$this->GetStringWidth($this->cells[$i]->text);
171
172 // if text bigger than column width then check
173
174 $y=$this->GetY();
175 $nb_row=$this->count_nb_row($this->cells[$i]->text, $this->cells[$i]->width);
176 $height=$this->cells[$i]->height*$nb_row;
177
178 // If the text is bigger than a sheet of paper then return false
179 if ($height >= $this->h) return false;
180
181 if ( $y + $height > ($this->h - $this->bMargin -7 ))
182 return true;
183
184 }
185 }
186 return false;
187 }
188
189 /**
190 * @brief print the current array of cell and reset it , if different colors are set on the same row
191 * you have to print it before changing
192 *@code
193 * // fill red , text white
194 * $this->SetFillColor(255,0,0);
195 * $this->SetTextColor(255,255,255);
196 * $this->write_cell(15,5,"PRICE",0,0,'R',fill:true);
197 *
198 * // print the cell without a linefeed
199 * $this->print_row();
200 *
201 * // text in black on green
202 *
203 * $this->SetTextColor(0,0,0);
204 * $this->SetFillColor(0,255,0);
205 *
206 * $this->write_cell(15,5,nbm($other['price']),0,0,'R');
207 *@endcode
208 * @see TFPDF::SetTextColor()
209 * @see TFPDF::SetFillColor()
210 * @see TFPDF::SetFontSize()
211 * @return void
212 */
213 protected function print_row()
214 {
215 static $e=0;
216 $e++;
217 if ( $this->check_page_add() == true ) $this->AddPage ();
218 $this->bigger=0;
219 $size=count($this->cells);
220 $cell=$this->cells;
221 if ($size == 0 )return;
222 for ($i=0;$i < $size ; $i++)
223 {
224 $a=$cell[$i];
225 $a->text= noalyss_str_replace("\\", "", $a->text);
226 switch ($a->type)
227 {
228 case "M":
229 $x_m=$this->GetX();
230 $y_m=$this->GetY();
231 parent::MultiCell(
232 $a->width,
233 $a->height,
234 $a->text,
235 $a->border,
236 $a->align,
237 $a->fill
238 );
239 $x_m=$x_m+$a->width;
240 $tmp=$this->GetY()-$y_m;
241 if ( $tmp > $this->bigger) $this->bigger=$tmp;
242 $this->SetXY($x_m,$y_m);
243 break;
244
245 case "C":
246
247 parent::Cell( $a->width,
248 $a->height,
249 $a->text,
250 $a->border,
251 $a->new_line,
252 $a->align,
253 $a->fill,
254 $a->link);
255 break;
256
257 default:
258 break;
259 }
260 }
261 $this->cells=array();
262 }
263 private function add_cell(Cellule $Ce)
264 {
265 $size=count($this->cells);
266 $this->cells[$size]=$Ce;
267
268 }
269 function write_cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
270 {
271 $this->add_cell(new Cellule($w,$h,$txt,$border,$ln,$align,$fill,$link,'C'));
272
273 }
274 function LongLine($w,$h,$txt,$border=0,$align='',$fill=false)
275 {
276 $this->add_cell(new Cellule($w,$h,$txt,$border,0,$align,$fill,'','M'));
277
278 }
279 /**
280 * Print all the cell stored and call Ln (new line)
281 * @param int $p_step
282 */
283
284 function line_new($p_step=null){
285 $this->print_row();
286 if ( $this->bigger==0)
287 parent::Ln($p_step);
288 else
289 parent::Ln($this->bigger);
290 $this->bigger=0;
291 }
292 /**
293 * @brief If the step is even then return 1 and set the backgroup color to blue , otherwise
294 * returns 0, and set the background color to white
295 * It is use to compute alternated colored row , it the parameter fill in write_cell and
296 * cell
297 * @see PDF:write_cell
298 * @see TPDF:cell
299 *
300 */
301 function is_fill($p_step)
302 {
303 if ($p_step % 2 == 0) {
304 $this->SetFillColor(239, 239, 255);
305 $fill = 1;
306 } else {
307 $this->SetFillColor(255, 255, 255);
308 $fill = 0;
309 }
310 return $fill;
311 }
312
313
314
315}
316
noalyss_str_replace($search, $replace, $string)
h( $row[ 'oa_description'])
foreach($array as $idx=> $m) $w
$input_from type
$height
Definition calendar.php:60
A Cellule is a cell to print.
__construct($w, $h, $txt, $border, $ln, $align, $fill, $link, $type)
API for creating PDF, unicode, based on tfpdf.
line_new($p_step=null)
Print all the cell stored and call Ln (new line)
is_fill($p_step)
If the step is even then return 1 and set the backgroup color to blue , otherwise returns 0,...
check_page_add()
Check if a page must be added due a MultiCell.
LongLine($w, $h, $txt, $border=0, $align='', $fill=false)
write_cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
count_nb_row($p_text, $p_colSize)
Count the number of rows a p_text will take for a multicell.
print_row()
print the current array of cell and reset it , if different colors are set on the same row you have t...
__construct( $orientation='P', $unit='mm', $format='A4')
add_cell(Cellule $Ce)
if(count($array)==0) $size
$desc width