Annotation of /com_supacart/trunk/admin_files/classes/pdf/fpdf.php
Parent Directory
|
Revision Log
Revision 4 - (view) (download)
| 1 : | andphe | 4 | <?php |
| 2 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 3 : | /** | ||
| 4 : | * @version $Id: fpdf.php 617 2007-01-04 19:43:08Z soeren_nb $ | ||
| 5 : | * @package SupaCart | ||
| 6 : | * @subpackage HMTL2PDF | ||
| 7 : | * @author Olivier PLATHEY | ||
| 8 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 9 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 10 : | * SupaCart is free software, originally derived from Virtuemart. This version may have been modified pursuant | ||
| 11 : | * to the GNU General Public License, and as distributed it includes or | ||
| 12 : | * is derivative of works licensed under the GNU General Public License or | ||
| 13 : | * other free or open source software licenses. | ||
| 14 : | * See /administrator/components/com_supacart/COPYRIGHT.php for copyright notices and details. | ||
| 15 : | * | ||
| 16 : | * http://www.supacart.com | ||
| 17 : | */ | ||
| 18 : | /******************************************************************************* | ||
| 19 : | * Software: FPDF * | ||
| 20 : | * Version: 1.52(modified) * | ||
| 21 : | * Date: 2003-12-30 * | ||
| 22 : | * Author: Olivier PLATHEY * | ||
| 23 : | * License: Freeware * | ||
| 24 : | * * | ||
| 25 : | * You may use, modify and redistribute this software as you wish. * | ||
| 26 : | *******************************************************************************/ | ||
| 27 : | |||
| 28 : | // Modified by Renato A.C. [html2fpdf.sf.net] | ||
| 29 : | // (look for 'EDITEI' in the code) | ||
| 30 : | |||
| 31 : | if(!class_exists('FPDF')) | ||
| 32 : | { | ||
| 33 : | define('FPDF_VERSION','1.52'); | ||
| 34 : | |||
| 35 : | class FPDF | ||
| 36 : | { | ||
| 37 : | //Private properties | ||
| 38 : | var $DisplayPreferences=''; //EDITEI - added | ||
| 39 : | var $outlines=array(); //EDITEI - added | ||
| 40 : | var $OutlineRoot; //EDITEI - added | ||
| 41 : | var $flowingBlockAttr; //EDITEI - added | ||
| 42 : | var $page; //current page number | ||
| 43 : | var $n; //current object number | ||
| 44 : | var $offsets; //array of object offsets | ||
| 45 : | var $buffer; //buffer holding in-memory PDF | ||
| 46 : | var $pages; //array containing pages | ||
| 47 : | var $state; //current document state | ||
| 48 : | var $compress; //compression flag | ||
| 49 : | var $DefOrientation; //default orientation | ||
| 50 : | var $CurOrientation; //current orientation | ||
| 51 : | var $OrientationChanges; //array indicating orientation changes | ||
| 52 : | var $k; //scale factor (number of points in user unit) | ||
| 53 : | var $fwPt,$fhPt; //dimensions of page format in points | ||
| 54 : | var $fw,$fh; //dimensions of page format in user unit | ||
| 55 : | var $wPt,$hPt; //current dimensions of page in points | ||
| 56 : | var $w,$h; //current dimensions of page in user unit | ||
| 57 : | var $lMargin; //left margin | ||
| 58 : | var $tMargin; //top margin | ||
| 59 : | var $rMargin; //right margin | ||
| 60 : | var $bMargin; //page break margin | ||
| 61 : | var $cMargin; //cell margin | ||
| 62 : | var $x,$y; //current position in user unit for cell positioning | ||
| 63 : | var $lasth; //height of last cell printed | ||
| 64 : | var $LineWidth; //line width in user unit | ||
| 65 : | var $CoreFonts; //array of standard font names | ||
| 66 : | var $fonts; //array of used fonts | ||
| 67 : | var $FontFiles; //array of font files | ||
| 68 : | var $diffs; //array of encoding differences | ||
| 69 : | var $images; //array of used images | ||
| 70 : | var $PageLinks; //array of links in pages | ||
| 71 : | var $links; //array of internal links | ||
| 72 : | var $FontFamily; //current font family | ||
| 73 : | var $FontStyle; //current font style | ||
| 74 : | var $underline; //underlining flag | ||
| 75 : | var $CurrentFont; //current font info | ||
| 76 : | var $FontSizePt; //current font size in points | ||
| 77 : | var $FontSize; //current font size in user unit | ||
| 78 : | var $DrawColor; //commands for drawing color | ||
| 79 : | var $FillColor; //commands for filling color | ||
| 80 : | var $TextColor; //commands for text color | ||
| 81 : | var $ColorFlag; //indicates whether fill and text colors are different | ||
| 82 : | var $ws; //word spacing | ||
| 83 : | var $AutoPageBreak; //automatic page breaking | ||
| 84 : | var $PageBreakTrigger; //threshold used to trigger page breaks | ||
| 85 : | var $InFooter; //flag set when processing footer | ||
| 86 : | var $ZoomMode; //zoom display mode | ||
| 87 : | var $LayoutMode; //layout display mode | ||
| 88 : | var $title; //title | ||
| 89 : | var $subject; //subject | ||
| 90 : | var $author; //author | ||
| 91 : | var $keywords; //keywords | ||
| 92 : | var $creator; //creator | ||
| 93 : | var $AliasNbPages; //alias for total number of pages | ||
| 94 : | |||
| 95 : | /******************************************************************************* | ||
| 96 : | * * | ||
| 97 : | * Public methods * | ||
| 98 : | * * | ||
| 99 : | *******************************************************************************/ | ||
| 100 : | function FPDF($orientation='P',$unit='mm',$format='A4') | ||
| 101 : | { | ||
| 102 : | //Some checks | ||
| 103 : | $this->_dochecks(); | ||
| 104 : | //Initialization of properties | ||
| 105 : | $this->page=0; | ||
| 106 : | $this->n=2; | ||
| 107 : | $this->buffer=''; | ||
| 108 : | $this->pages=array(); | ||
| 109 : | $this->OrientationChanges=array(); | ||
| 110 : | $this->state=0; | ||
| 111 : | $this->fonts=array(); | ||
| 112 : | $this->FontFiles=array(); | ||
| 113 : | $this->diffs=array(); | ||
| 114 : | $this->images=array(); | ||
| 115 : | $this->links=array(); | ||
| 116 : | $this->InFooter=false; | ||
| 117 : | $this->lasth=0; | ||
| 118 : | $this->FontFamily=''; | ||
| 119 : | $this->FontStyle=''; | ||
| 120 : | $this->FontSizePt=12; | ||
| 121 : | $this->underline=false; | ||
| 122 : | $this->DrawColor='0 G'; | ||
| 123 : | $this->FillColor='0 g'; | ||
| 124 : | $this->TextColor='0 g'; | ||
| 125 : | $this->ColorFlag=false; | ||
| 126 : | $this->ws=0; | ||
| 127 : | //Standard fonts | ||
| 128 : | $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', | ||
| 129 : | 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', | ||
| 130 : | 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', | ||
| 131 : | 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats'); | ||
| 132 : | //Scale factor | ||
| 133 : | if($unit=='pt') $this->k=1; | ||
| 134 : | elseif($unit=='mm') $this->k=72/25.4; | ||
| 135 : | elseif($unit=='cm') $this->k=72/2.54; | ||
| 136 : | elseif($unit=='in') $this->k=72; | ||
| 137 : | else $this->Error('Incorrect unit: '.$unit); | ||
| 138 : | //Page format | ||
| 139 : | if(is_string($format)) | ||
| 140 : | { | ||
| 141 : | $format=strtolower($format); | ||
| 142 : | if($format=='a3') $format=array(841.89,1190.55); | ||
| 143 : | elseif($format=='a4') $format=array(595.28,841.89); | ||
| 144 : | elseif($format=='a5') $format=array(420.94,595.28); | ||
| 145 : | elseif($format=='letter') $format=array(612,792); | ||
| 146 : | elseif($format=='legal') $format=array(612,1008); | ||
| 147 : | else $this->Error('Unknown page format: '.$format); | ||
| 148 : | $this->fwPt=$format[0]; | ||
| 149 : | $this->fhPt=$format[1]; | ||
| 150 : | } | ||
| 151 : | else | ||
| 152 : | { | ||
| 153 : | $this->fwPt=$format[0]*$this->k; | ||
| 154 : | $this->fhPt=$format[1]*$this->k; | ||
| 155 : | } | ||
| 156 : | $this->fw=$this->fwPt/$this->k; | ||
| 157 : | $this->fh=$this->fhPt/$this->k; | ||
| 158 : | //Page orientation | ||
| 159 : | $orientation=strtolower($orientation); | ||
| 160 : | if($orientation=='p' or $orientation=='portrait') | ||
| 161 : | { | ||
| 162 : | $this->DefOrientation='P'; | ||
| 163 : | $this->wPt=$this->fwPt; | ||
| 164 : | $this->hPt=$this->fhPt; | ||
| 165 : | } | ||
| 166 : | elseif($orientation=='l' or $orientation=='landscape') | ||
| 167 : | { | ||
| 168 : | $this->DefOrientation='L'; | ||
| 169 : | $this->wPt=$this->fhPt; | ||
| 170 : | $this->hPt=$this->fwPt; | ||
| 171 : | } | ||
| 172 : | else $this->Error('Incorrect orientation: '.$orientation); | ||
| 173 : | $this->CurOrientation=$this->DefOrientation; | ||
| 174 : | $this->w=$this->wPt/$this->k; | ||
| 175 : | $this->h=$this->hPt/$this->k; | ||
| 176 : | //Page margins (1 cm) | ||
| 177 : | $margin=28.35/$this->k; | ||
| 178 : | $this->SetMargins($margin,$margin); | ||
| 179 : | //Interior cell margin (1 mm) | ||
| 180 : | $this->cMargin=$margin/10; | ||
| 181 : | //Line width (0.2 mm) | ||
| 182 : | $this->LineWidth=.567/$this->k; | ||
| 183 : | //Automatic page break | ||
| 184 : | $this->SetAutoPageBreak(true,2*$margin); | ||
| 185 : | //Full width display mode | ||
| 186 : | $this->SetDisplayMode('fullwidth'); | ||
| 187 : | //Compression | ||
| 188 : | $this->SetCompression(true); | ||
| 189 : | } | ||
| 190 : | |||
| 191 : | function SetMargins($left,$top,$right=-1) | ||
| 192 : | { | ||
| 193 : | //Set left, top and right margins | ||
| 194 : | $this->lMargin=$left; | ||
| 195 : | $this->tMargin=$top; | ||
| 196 : | if($right==-1) $right=$left; | ||
| 197 : | $this->rMargin=$right; | ||
| 198 : | } | ||
| 199 : | |||
| 200 : | function SetLeftMargin($margin) | ||
| 201 : | { | ||
| 202 : | //Set left margin | ||
| 203 : | $this->lMargin=$margin; | ||
| 204 : | if($this->page>0 and $this->x<$margin) $this->x=$margin; | ||
| 205 : | } | ||
| 206 : | |||
| 207 : | function SetTopMargin($margin) | ||
| 208 : | { | ||
| 209 : | //Set top margin | ||
| 210 : | $this->tMargin=$margin; | ||
| 211 : | } | ||
| 212 : | |||
| 213 : | function SetRightMargin($margin) | ||
| 214 : | { | ||
| 215 : | //Set right margin | ||
| 216 : | $this->rMargin=$margin; | ||
| 217 : | } | ||
| 218 : | |||
| 219 : | function SetAutoPageBreak($auto,$margin=0) | ||
| 220 : | { | ||
| 221 : | //Set auto page break mode and triggering margin | ||
| 222 : | $this->AutoPageBreak=$auto; | ||
| 223 : | $this->bMargin=$margin; | ||
| 224 : | $this->PageBreakTrigger=$this->h-$margin; | ||
| 225 : | } | ||
| 226 : | |||
| 227 : | function SetDisplayMode($zoom,$layout='continuous') | ||
| 228 : | { | ||
| 229 : | //Set display mode in viewer | ||
| 230 : | if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) | ||
| 231 : | $this->ZoomMode=$zoom; | ||
| 232 : | else | ||
| 233 : | $this->Error('Incorrect zoom display mode: '.$zoom); | ||
| 234 : | if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') | ||
| 235 : | $this->LayoutMode=$layout; | ||
| 236 : | else | ||
| 237 : | $this->Error('Incorrect layout display mode: '.$layout); | ||
| 238 : | } | ||
| 239 : | |||
| 240 : | function SetCompression($compress) | ||
| 241 : | { | ||
| 242 : | //Set page compression | ||
| 243 : | if(function_exists('gzcompress')) $this->compress=$compress; | ||
| 244 : | else $this->compress=false; | ||
| 245 : | } | ||
| 246 : | |||
| 247 : | function SetTitle($title) | ||
| 248 : | { | ||
| 249 : | //Title of document | ||
| 250 : | $this->title=$title; | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | function SetSubject($subject) | ||
| 254 : | { | ||
| 255 : | //Subject of document | ||
| 256 : | $this->subject=$subject; | ||
| 257 : | } | ||
| 258 : | |||
| 259 : | function SetAuthor($author) | ||
| 260 : | { | ||
| 261 : | //Author of document | ||
| 262 : | $this->author=$author; | ||
| 263 : | } | ||
| 264 : | |||
| 265 : | function SetKeywords($keywords) | ||
| 266 : | { | ||
| 267 : | //Keywords of document | ||
| 268 : | $this->keywords=$keywords; | ||
| 269 : | } | ||
| 270 : | |||
| 271 : | function SetCreator($creator) | ||
| 272 : | { | ||
| 273 : | //Creator of document | ||
| 274 : | $this->creator=$creator; | ||
| 275 : | } | ||
| 276 : | |||
| 277 : | function AliasNbPages($alias='{nb}') | ||
| 278 : | { | ||
| 279 : | //Define an alias for total number of pages | ||
| 280 : | $this->AliasNbPages=$alias; | ||
| 281 : | } | ||
| 282 : | |||
| 283 : | function Error($msg) | ||
| 284 : | { | ||
| 285 : | //Fatal error | ||
| 286 : | die('<B>FPDF error: </B>'.$msg); | ||
| 287 : | } | ||
| 288 : | |||
| 289 : | function Open() | ||
| 290 : | { | ||
| 291 : | //Begin document | ||
| 292 : | if($this->state==0) $this->_begindoc(); | ||
| 293 : | } | ||
| 294 : | |||
| 295 : | function Close() | ||
| 296 : | { | ||
| 297 : | //Terminate document | ||
| 298 : | if($this->state==3) return; | ||
| 299 : | if($this->page==0) $this->AddPage(); | ||
| 300 : | //Page footer | ||
| 301 : | $this->InFooter=true; | ||
| 302 : | $this->Footer(); | ||
| 303 : | $this->InFooter=false; | ||
| 304 : | //Close page | ||
| 305 : | $this->_endpage(); | ||
| 306 : | //Close document | ||
| 307 : | $this->_enddoc(); | ||
| 308 : | } | ||
| 309 : | |||
| 310 : | function AddPage($orientation='') | ||
| 311 : | { | ||
| 312 : | //Start a new page | ||
| 313 : | if($this->state==0) $this->Open(); | ||
| 314 : | $family=$this->FontFamily; | ||
| 315 : | $style=$this->FontStyle.($this->underline ? 'U' : ''); | ||
| 316 : | $size=$this->FontSizePt; | ||
| 317 : | $lw=$this->LineWidth; | ||
| 318 : | $dc=$this->DrawColor; | ||
| 319 : | $fc=$this->FillColor; | ||
| 320 : | $tc=$this->TextColor; | ||
| 321 : | $cf=$this->ColorFlag; | ||
| 322 : | if($this->page>0) | ||
| 323 : | { | ||
| 324 : | //Page footer | ||
| 325 : | $this->InFooter=true; | ||
| 326 : | $this->Footer(); | ||
| 327 : | $this->InFooter=false; | ||
| 328 : | //Close page | ||
| 329 : | $this->_endpage(); | ||
| 330 : | } | ||
| 331 : | //Start new page | ||
| 332 : | $this->_beginpage($orientation); | ||
| 333 : | //Set line cap style to square | ||
| 334 : | $this->_out('2 J'); | ||
| 335 : | //Set line width | ||
| 336 : | $this->LineWidth=$lw; | ||
| 337 : | $this->_out(sprintf('%.2f w',$lw*$this->k)); | ||
| 338 : | //Set font | ||
| 339 : | if($family) $this->SetFont($family,$style,$size); | ||
| 340 : | //Set colors | ||
| 341 : | $this->DrawColor=$dc; | ||
| 342 : | if($dc!='0 G') $this->_out($dc); | ||
| 343 : | $this->FillColor=$fc; | ||
| 344 : | if($fc!='0 g') $this->_out($fc); | ||
| 345 : | $this->TextColor=$tc; | ||
| 346 : | $this->ColorFlag=$cf; | ||
| 347 : | //Page header | ||
| 348 : | $this->Header(); | ||
| 349 : | //Restore line width | ||
| 350 : | if($this->LineWidth!=$lw) | ||
| 351 : | { | ||
| 352 : | $this->LineWidth=$lw; | ||
| 353 : | $this->_out(sprintf('%.2f w',$lw*$this->k)); | ||
| 354 : | } | ||
| 355 : | //Restore font | ||
| 356 : | if($family) $this->SetFont($family,$style,$size); | ||
| 357 : | //Restore colors | ||
| 358 : | if($this->DrawColor!=$dc) | ||
| 359 : | { | ||
| 360 : | $this->DrawColor=$dc; | ||
| 361 : | $this->_out($dc); | ||
| 362 : | } | ||
| 363 : | if($this->FillColor!=$fc) | ||
| 364 : | { | ||
| 365 : | $this->FillColor=$fc; | ||
| 366 : | $this->_out($fc); | ||
| 367 : | } | ||
| 368 : | $this->TextColor=$tc; | ||
| 369 : | $this->ColorFlag=$cf; | ||
| 370 : | } | ||
| 371 : | |||
| 372 : | function Header() | ||
| 373 : | { | ||
| 374 : | //To be implemented in your own inherited class | ||
| 375 : | } | ||
| 376 : | |||
| 377 : | function Footer() | ||
| 378 : | { | ||
| 379 : | //To be implemented in your own inherited class | ||
| 380 : | } | ||
| 381 : | |||
| 382 : | function PageNo() | ||
| 383 : | { | ||
| 384 : | //Get current page number | ||
| 385 : | return $this->page; | ||
| 386 : | } | ||
| 387 : | |||
| 388 : | function SetDrawColor($r,$g=-1,$b=-1) | ||
| 389 : | { | ||
| 390 : | //Set color for all stroking operations | ||
| 391 : | if(($r==0 and $g==0 and $b==0) or $g==-1) $this->DrawColor=sprintf('%.3f G',$r/255); | ||
| 392 : | else $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255); | ||
| 393 : | if($this->page>0) $this->_out($this->DrawColor); | ||
| 394 : | } | ||
| 395 : | |||
| 396 : | function SetFillColor($r,$g=-1,$b=-1) | ||
| 397 : | { | ||
| 398 : | //Set color for all filling operations | ||
| 399 : | if(($r==0 and $g==0 and $b==0) or $g==-1) $this->FillColor=sprintf('%.3f g',$r/255); | ||
| 400 : | else$this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); | ||
| 401 : | $this->ColorFlag = ($this->FillColor != $this->TextColor); | ||
| 402 : | if($this->page>0) $this->_out($this->FillColor); | ||
| 403 : | } | ||
| 404 : | |||
| 405 : | function SetTextColor($r,$g=-1,$b=-1) | ||
| 406 : | { | ||
| 407 : | //Set color for text | ||
| 408 : | if(($r==0 and $g==0 and $b==0) or $g==-1) $this->TextColor=sprintf('%.3f g',$r/255); | ||
| 409 : | else $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); | ||
| 410 : | $this->ColorFlag = ($this->FillColor != $this->TextColor); | ||
| 411 : | } | ||
| 412 : | |||
| 413 : | function GetStringWidth($s) | ||
| 414 : | { | ||
| 415 : | //Get width of a string in the current font | ||
| 416 : | $s=(string)$s; | ||
| 417 : | $cw=&$this->CurrentFont['cw']; | ||
| 418 : | $w=0; | ||
| 419 : | $l=strlen($s); | ||
| 420 : | for($i=0;$i<$l;$i++) $w+=$cw[$s{$i}]; | ||
| 421 : | return $w*$this->FontSize/1000; | ||
| 422 : | } | ||
| 423 : | |||
| 424 : | function SetLineWidth($width) | ||
| 425 : | { | ||
| 426 : | //Set line width | ||
| 427 : | $this->LineWidth=$width; | ||
| 428 : | if($this->page>0) $this->_out(sprintf('%.2f w',$width*$this->k)); | ||
| 429 : | } | ||
| 430 : | |||
| 431 : | function Line($x1,$y1,$x2,$y2) | ||
| 432 : | { | ||
| 433 : | //Draw a line | ||
| 434 : | $this->_out(sprintf('%.2f %.2f m %.2f %.2f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); | ||
| 435 : | } | ||
| 436 : | |||
| 437 : | function Rect($x,$y,$w,$h,$style='') | ||
| 438 : | { | ||
| 439 : | //Draw a rectangle | ||
| 440 : | if($style=='F') $op='f'; | ||
| 441 : | elseif($style=='FD' or $style=='DF') $op='B'; | ||
| 442 : | else $op='S'; | ||
| 443 : | $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); | ||
| 444 : | } | ||
| 445 : | |||
| 446 : | function AddFont($family,$style='',$file='') | ||
| 447 : | { | ||
| 448 : | //Add a TrueType or Type1 font | ||
| 449 : | $family=strtolower($family); | ||
| 450 : | if($family=='arial') $family='helvetica'; | ||
| 451 : | $style=strtoupper($style); | ||
| 452 : | if($style=='IB') $style='BI'; | ||
| 453 : | if(isset($this->fonts[$family.$style])) $this->Error('Font already added: '.$family.' '.$style); | ||
| 454 : | if($file=='') $file=str_replace(' ','',$family).strtolower($style).'.php'; | ||
| 455 : | if(defined('FPDF_FONTPATH')) $file=FPDF_FONTPATH.$file; | ||
| 456 : | include($file); | ||
| 457 : | if(!isset($name)) $this->Error('Could not include font definition file'); | ||
| 458 : | $i=count($this->fonts)+1; | ||
| 459 : | $this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file); | ||
| 460 : | if($diff) | ||
| 461 : | { | ||
| 462 : | //Search existing encodings | ||
| 463 : | $d=0; | ||
| 464 : | $nb=count($this->diffs); | ||
| 465 : | for($i=1;$i<=$nb;$i++) | ||
| 466 : | if($this->diffs[$i]==$diff) | ||
| 467 : | { | ||
| 468 : | $d=$i; | ||
| 469 : | break; | ||
| 470 : | } | ||
| 471 : | if($d==0) | ||
| 472 : | { | ||
| 473 : | $d=$nb+1; | ||
| 474 : | $this->diffs[$d]=$diff; | ||
| 475 : | } | ||
| 476 : | $this->fonts[$family.$style]['diff']=$d; | ||
| 477 : | } | ||
| 478 : | if($file) | ||
| 479 : | { | ||
| 480 : | if($type=='TrueType') $this->FontFiles[$file]=array('length1'=>$originalsize); | ||
| 481 : | else $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); | ||
| 482 : | } | ||
| 483 : | } | ||
| 484 : | |||
| 485 : | function SetFont($family,$style='',$size=0) | ||
| 486 : | { | ||
| 487 : | //Select a font; size given in points | ||
| 488 : | global $fpdf_charwidths; | ||
| 489 : | |||
| 490 : | $family=strtolower($family); | ||
| 491 : | if($family=='') $family=$this->FontFamily; | ||
| 492 : | //EDITEI - now understands: monospace,serif,sans [serif] | ||
| 493 : | if($family=='monospace') $family='courier'; | ||
| 494 : | if($family=='serif') $family='times'; | ||
| 495 : | if($family=='sans') $family='arial'; | ||
| 496 : | if($family=='arial') $family='helvetica'; | ||
| 497 : | elseif($family=='symbol' or $family=='zapfdingbats') $style=''; | ||
| 498 : | $style=strtoupper($style); | ||
| 499 : | if(is_int(strpos($style,'U'))) | ||
| 500 : | { | ||
| 501 : | $this->underline=true; | ||
| 502 : | $style=str_replace('U','',$style); | ||
| 503 : | } | ||
| 504 : | else $this->underline=false; | ||
| 505 : | if ($style=='IB') $style='BI'; | ||
| 506 : | if ($size==0) $size=$this->FontSizePt; | ||
| 507 : | //Test if font is already selected | ||
| 508 : | if($this->FontFamily==$family and $this->FontStyle==$style and $this->FontSizePt==$size) return; | ||
| 509 : | //Test if used for the first time | ||
| 510 : | $fontkey=$family.$style; | ||
| 511 : | if(!isset($this->fonts[$fontkey])) | ||
| 512 : | { | ||
| 513 : | //Check if one of the standard fonts | ||
| 514 : | if(isset($this->CoreFonts[$fontkey])) | ||
| 515 : | { | ||
| 516 : | if(!isset($fpdf_charwidths[$fontkey])) | ||
| 517 : | { | ||
| 518 : | //Load metric file | ||
| 519 : | $file=$family; | ||
| 520 : | if($family=='times' or $family=='helvetica') $file.=strtolower($style); | ||
| 521 : | $file.='.php'; | ||
| 522 : | if(defined('FPDF_FONTPATH')) $file=FPDF_FONTPATH.$file; | ||
| 523 : | include($file); | ||
| 524 : | if(!isset($fpdf_charwidths[$fontkey])) $this->Error('Could not include font metric file'); | ||
| 525 : | } | ||
| 526 : | $i=count($this->fonts)+1; | ||
| 527 : | $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]); | ||
| 528 : | } | ||
| 529 : | else $this->Error('Undefined font: '.$family.' '.$style); | ||
| 530 : | } | ||
| 531 : | //Select it | ||
| 532 : | $this->FontFamily=$family; | ||
| 533 : | $this->FontStyle=$style; | ||
| 534 : | $this->FontSizePt=$size; | ||
| 535 : | $this->FontSize=$size/$this->k; | ||
| 536 : | $this->CurrentFont=&$this->fonts[$fontkey]; | ||
| 537 : | if($this->page>0) | ||
| 538 : | $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); | ||
| 539 : | } | ||
| 540 : | |||
| 541 : | function SetFontSize($size) | ||
| 542 : | { | ||
| 543 : | //Set font size in points | ||
| 544 : | if($this->FontSizePt==$size) return; | ||
| 545 : | $this->FontSizePt=$size; | ||
| 546 : | $this->FontSize=$size/$this->k; | ||
| 547 : | if($this->page>0) | ||
| 548 : | $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); | ||
| 549 : | } | ||
| 550 : | |||
| 551 : | function AddLink() | ||
| 552 : | { | ||
| 553 : | //Create a new internal link | ||
| 554 : | $n=count($this->links)+1; | ||
| 555 : | $this->links[$n]=array(0,0); | ||
| 556 : | return $n; | ||
| 557 : | } | ||
| 558 : | |||
| 559 : | function SetLink($link,$y=0,$page=-1) | ||
| 560 : | { | ||
| 561 : | //Set destination of internal link | ||
| 562 : | if($y==-1) $y=$this->y; | ||
| 563 : | if($page==-1) $page=$this->page; | ||
| 564 : | $this->links[$link]=array($page,$y); | ||
| 565 : | } | ||
| 566 : | |||
| 567 : | function Link($x,$y,$w,$h,$link) | ||
| 568 : | { | ||
| 569 : | //Put a link on the page | ||
| 570 : | $this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link); | ||
| 571 : | } | ||
| 572 : | |||
| 573 : | function Text($x,$y,$txt) | ||
| 574 : | { | ||
| 575 : | //Output a string | ||
| 576 : | $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); | ||
| 577 : | if($this->underline and $txt!='') $s.=' '.$this->_dounderline($x,$y,$txt); | ||
| 578 : | if($this->ColorFlag) $s='q '.$this->TextColor.' '.$s.' Q'; | ||
| 579 : | $this->_out($s); | ||
| 580 : | } | ||
| 581 : | |||
| 582 : | function AcceptPageBreak() | ||
| 583 : | { | ||
| 584 : | //Accept automatic page break or not | ||
| 585 : | return $this->AutoPageBreak; | ||
| 586 : | } | ||
| 587 : | |||
| 588 : | function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='',$currentx=0) //EDITEI | ||
| 589 : | { | ||
| 590 : | //Output a cell | ||
| 591 : | $k=$this->k; | ||
| 592 : | if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) | ||
| 593 : | { | ||
| 594 : | //Automatic page break | ||
| 595 : | $x=$this->x;//Current X position | ||
| 596 : | $ws=$this->ws;//Word Spacing | ||
| 597 : | if($ws>0) | ||
| 598 : | { | ||
| 599 : | $this->ws=0; | ||
| 600 : | $this->_out('0 Tw'); | ||
| 601 : | } | ||
| 602 : | $this->AddPage($this->CurOrientation); | ||
| 603 : | $this->x=$x; | ||
| 604 : | if($ws>0) | ||
| 605 : | { | ||
| 606 : | $this->ws=$ws; | ||
| 607 : | $this->_out(sprintf('%.3f Tw',$ws*$k)); | ||
| 608 : | } | ||
| 609 : | } | ||
| 610 : | if($w==0) $w = $this->w-$this->rMargin-$this->x; | ||
| 611 : | $s=''; | ||
| 612 : | if($fill==1 or $border==1) | ||
| 613 : | { | ||
| 614 : | if ($fill==1) $op=($border==1) ? 'B' : 'f'; | ||
| 615 : | else $op='S'; | ||
| 616 : | //$op='S';//DEBUG | ||
| 617 : | $s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); | ||
| 618 : | } | ||
| 619 : | if(is_string($border)) | ||
| 620 : | { | ||
| 621 : | $x=$this->x; | ||
| 622 : | $y=$this->y; | ||
| 623 : | if(is_int(strpos($border,'L'))) | ||
| 624 : | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); | ||
| 625 : | if(is_int(strpos($border,'T'))) | ||
| 626 : | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); | ||
| 627 : | if(is_int(strpos($border,'R'))) | ||
| 628 : | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); | ||
| 629 : | if(is_int(strpos($border,'B'))) | ||
| 630 : | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); | ||
| 631 : | } | ||
| 632 : | if($txt!='') | ||
| 633 : | { | ||
| 634 : | if($align=='R') $dx=$w-$this->cMargin-$this->GetStringWidth($txt); | ||
| 635 : | elseif($align=='C') $dx=($w-$this->GetStringWidth($txt))/2; | ||
| 636 : | elseif($align=='L' or $align=='J') $dx=$this->cMargin; | ||
| 637 : | else $dx = 0; | ||
| 638 : | if($this->ColorFlag) $s.='q '.$this->TextColor.' '; | ||
| 639 : | $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); | ||
| 640 : | //Check whether we are going to outline text or not | ||
| 641 : | if($this->outline_on) | ||
| 642 : | { | ||
| 643 : | $s.=' '.sprintf('%.2f w',$this->LineWidth*$this->k).' '; | ||
| 644 : | $s.=" $this->DrawColor "; | ||
| 645 : | $s.=" 2 Tr "; | ||
| 646 : | } | ||
| 647 : | //Superscript and Subscript Y coordinate adjustment | ||
| 648 : | $adjusty = 0; | ||
| 649 : | if($this->SUB) $adjusty = 1; | ||
| 650 : | if($this->SUP) $adjusty = -1; | ||
| 651 : | //End of coordinate adjustment | ||
| 652 : | $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-(($this->y+$adjusty)+.5*$h+.3*$this->FontSize))*$k,$txt2); //EDITEI | ||
| 653 : | if($this->underline) | ||
| 654 : | $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize+$adjusty,$txt2); | ||
| 655 : | //Superscript and Subscript Y coordinate adjustment (now for striked-through texts) | ||
| 656 : | $adjusty = 1.6; | ||
| 657 : | if($this->SUB) $adjusty = 3.05; | ||
| 658 : | if($this->SUP) $adjusty = 1.1; | ||
| 659 : | //End of coordinate adjustment | ||
| 660 : | if($this->strike) //EDITEI | ||
| 661 : | $s.=' '.$this->_dounderline($this->x+$dx,$this->y+$adjusty,$txt); | ||
| 662 : | if($this->ColorFlag) $s.=' Q'; | ||
| 663 : | if($link!='') $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); | ||
| 664 : | } | ||
| 665 : | if($s) $this->_out($s); | ||
| 666 : | $this->lasth=$h; | ||
| 667 : | if( strpos($txt,"\n") !== false) $ln=1; //EDITEI - cell now recognizes \n! << comes from <BR> tag | ||
| 668 : | if($ln>0) | ||
| 669 : | { | ||
| 670 : | //Go to next line | ||
| 671 : | $this->y += $h; | ||
| 672 : | if($ln==1) //EDITEI | ||
| 673 : | { | ||
| 674 : | //Move to next line | ||
| 675 : | if ($currentx != 0) $this->x=$currentx; | ||
| 676 : | else $this->x=$this->lMargin; | ||
| 677 : | } | ||
| 678 : | } | ||
| 679 : | else $this->x+=$w; | ||
| 680 : | } | ||
| 681 : | |||
| 682 : | //EDITEI | ||
| 683 : | function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0,$link='') | ||
| 684 : | { | ||
| 685 : | //Output text with automatic or explicit line breaks | ||
| 686 : | $cw=&$this->CurrentFont['cw']; | ||
| 687 : | if($w==0) $w=$this->w-$this->rMargin-$this->x; | ||
| 688 : | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; | ||
| 689 : | $s=str_replace("\r",'',$txt); | ||
| 690 : | $nb=strlen($s); | ||
| 691 : | if($nb>0 and $s[$nb-1]=="\n") $nb--; | ||
| 692 : | $b=0; | ||
| 693 : | if($border) | ||
| 694 : | { | ||
| 695 : | if($border==1) | ||
| 696 : | { | ||
| 697 : | $border='LTRB'; | ||
| 698 : | $b='LRT'; | ||
| 699 : | $b2='LR'; | ||
| 700 : | } | ||
| 701 : | else | ||
| 702 : | { | ||
| 703 : | $b2=''; | ||
| 704 : | if(is_int(strpos($border,'L'))) $b2.='L'; | ||
| 705 : | if(is_int(strpos($border,'R'))) $b2.='R'; | ||
| 706 : | $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; | ||
| 707 : | } | ||
| 708 : | } | ||
| 709 : | $sep=-1; | ||
| 710 : | $i=0; | ||
| 711 : | $j=0; | ||
| 712 : | $l=0; | ||
| 713 : | $ns=0; | ||
| 714 : | $nl=1; | ||
| 715 : | while($i<$nb) | ||
| 716 : | { | ||
| 717 : | //Get next character | ||
| 718 : | $c=$s{$i}; | ||
| 719 : | if($c=="\n") | ||
| 720 : | { | ||
| 721 : | //Explicit line break | ||
| 722 : | if($this->ws>0) | ||
| 723 : | { | ||
| 724 : | $this->ws=0; | ||
| 725 : | $this->_out('0 Tw'); | ||
| 726 : | } | ||
| 727 : | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); | ||
| 728 : | $i++; | ||
| 729 : | $sep=-1; | ||
| 730 : | $j=$i; | ||
| 731 : | $l=0; | ||
| 732 : | $ns=0; | ||
| 733 : | $nl++; | ||
| 734 : | if($border and $nl==2) $b=$b2; | ||
| 735 : | continue; | ||
| 736 : | } | ||
| 737 : | if($c==' ') | ||
| 738 : | { | ||
| 739 : | $sep=$i; | ||
| 740 : | $ls=$l; | ||
| 741 : | $ns++; | ||
| 742 : | } | ||
| 743 : | $l+=$cw[$c]; | ||
| 744 : | if($l>$wmax) | ||
| 745 : | { | ||
| 746 : | //Automatic line break | ||
| 747 : | if($sep==-1) | ||
| 748 : | { | ||
| 749 : | if($i==$j) $i++; | ||
| 750 : | if($this->ws>0) | ||
| 751 : | { | ||
| 752 : | $this->ws=0; | ||
| 753 : | $this->_out('0 Tw'); | ||
| 754 : | } | ||
| 755 : | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); | ||
| 756 : | } | ||
| 757 : | else | ||
| 758 : | { | ||
| 759 : | if($align=='J') | ||
| 760 : | { | ||
| 761 : | $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; | ||
| 762 : | $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); | ||
| 763 : | } | ||
| 764 : | $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link); | ||
| 765 : | $i=$sep+1; | ||
| 766 : | } | ||
| 767 : | $sep=-1; | ||
| 768 : | $j=$i; | ||
| 769 : | $l=0; | ||
| 770 : | $ns=0; | ||
| 771 : | $nl++; | ||
| 772 : | if($border and $nl==2) $b=$b2; | ||
| 773 : | } | ||
| 774 : | else $i++; | ||
| 775 : | } | ||
| 776 : | //Last chunk | ||
| 777 : | if($this->ws>0) | ||
| 778 : | { | ||
| 779 : | $this->ws=0; | ||
| 780 : | $this->_out('0 Tw'); | ||
| 781 : | } | ||
| 782 : | if($border and is_int(strpos($border,'B'))) $b.='B'; | ||
| 783 : | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); | ||
| 784 : | $this->x=$this->lMargin; | ||
| 785 : | } | ||
| 786 : | |||
| 787 : | function Write($h,$txt,$currentx=0,$link='') //EDITEI | ||
| 788 : | { | ||
| 789 : | //Output text in flowing mode | ||
| 790 : | $cw=&$this->CurrentFont['cw']; | ||
| 791 : | $w=$this->w-$this->rMargin-$this->x; | ||
| 792 : | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; | ||
| 793 : | $s=str_replace("\r",'',$txt); | ||
| 794 : | $nb=strlen($s); | ||
| 795 : | $sep=-1; | ||
| 796 : | $i=0; | ||
| 797 : | $j=0; | ||
| 798 : | $l=0; | ||
| 799 : | $nl=1; | ||
| 800 : | while($i<$nb) | ||
| 801 : | { | ||
| 802 : | //Get next character | ||
| 803 : | $c=$s{$i}; | ||
| 804 : | if($c=="\n") | ||
| 805 : | { | ||
| 806 : | //Explicit line break | ||
| 807 : | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); | ||
| 808 : | $i++; | ||
| 809 : | $sep=-1; | ||
| 810 : | $j=$i; | ||
| 811 : | $l=0; | ||
| 812 : | if($nl==1) | ||
| 813 : | { | ||
| 814 : | if ($currentx != 0) $this->x=$currentx;//EDITEI | ||
| 815 : | else $this->x=$this->lMargin; | ||
| 816 : | $w=$this->w-$this->rMargin-$this->x; | ||
| 817 : | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; | ||
| 818 : | } | ||
| 819 : | $nl++; | ||
| 820 : | continue; | ||
| 821 : | } | ||
| 822 : | if($c == ' ') $sep=$i; | ||
| 823 : | $l += $cw[$c]; | ||
| 824 : | if($l > $wmax) | ||
| 825 : | { | ||
| 826 : | //Automatic line break | ||
| 827 : | if($sep==-1) | ||
| 828 : | { | ||
| 829 : | if($this->x > $this->lMargin) | ||
| 830 : | { | ||
| 831 : | //Move to next line | ||
| 832 : | if ($currentx != 0) $this->x=$currentx;//EDITEI | ||
| 833 : | else $this->x=$this->lMargin; | ||
| 834 : | $this->y+=$h; | ||
| 835 : | $w=$this->w-$this->rMargin-$this->x; | ||
| 836 : | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; | ||
| 837 : | $i++; | ||
| 838 : | $nl++; | ||
| 839 : | continue; | ||
| 840 : | } | ||
| 841 : | if($i==$j) $i++; | ||
| 842 : | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); | ||
| 843 : | } | ||
| 844 : | else | ||
| 845 : | { | ||
| 846 : | $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); | ||
| 847 : | $i=$sep+1; | ||
| 848 : | } | ||
| 849 : | $sep=-1; | ||
| 850 : | $j=$i; | ||
| 851 : | $l=0; | ||
| 852 : | if($nl==1) | ||
| 853 : | { | ||
| 854 : | if ($currentx != 0) $this->x=$currentx;//EDITEI | ||
| 855 : | else $this->x=$this->lMargin; | ||
| 856 : | $w=$this->w-$this->rMargin-$this->x; | ||
| 857 : | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; | ||
| 858 : | } | ||
| 859 : | $nl++; | ||
| 860 : | } | ||
| 861 : | else $i++; | ||
| 862 : | } | ||
| 863 : | //Last chunk | ||
| 864 : | if($i!=$j) $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link); | ||
| 865 : | } | ||
| 866 : | |||
| 867 : | //-------------------------FLOWING BLOCK------------------------------------// | ||
| 868 : | //EDITEI some things (added/changed) // | ||
| 869 : | //The following functions were originally written by Damon Kohler // | ||
| 870 : | //--------------------------------------------------------------------------// | ||
| 871 : | |||
| 872 : | function saveFont() | ||
| 873 : | { | ||
| 874 : | $saved = array(); | ||
| 875 : | $saved[ 'family' ] = $this->FontFamily; | ||
| 876 : | $saved[ 'style' ] = $this->FontStyle; | ||
| 877 : | $saved[ 'sizePt' ] = $this->FontSizePt; | ||
| 878 : | $saved[ 'size' ] = $this->FontSize; | ||
| 879 : | $saved[ 'curr' ] =& $this->CurrentFont; | ||
| 880 : | $saved[ 'color' ] = $this->TextColor; //EDITEI | ||
| 881 : | $saved[ 'bgcolor' ] = $this->FillColor; //EDITEI | ||
| 882 : | $saved[ 'HREF' ] = $this->HREF; //EDITEI | ||
| 883 : | $saved[ 'underline' ] = $this->underline; //EDITEI | ||
| 884 : | $saved[ 'strike' ] = $this->strike; //EDITEI | ||
| 885 : | $saved[ 'SUP' ] = $this->SUP; //EDITEI | ||
| 886 : | $saved[ 'SUB' ] = $this->SUB; //EDITEI | ||
| 887 : | $saved[ 'linewidth' ] = $this->LineWidth; //EDITEI | ||
| 888 : | $saved[ 'drawcolor' ] = $this->DrawColor; //EDITEI | ||
| 889 : | $saved[ 'is_outline' ] = $this->outline_on; //EDITEI | ||
| 890 : | |||
| 891 : | return $saved; | ||
| 892 : | } | ||
| 893 : | |||
| 894 : | function restoreFont( $saved ) | ||
| 895 : | { | ||
| 896 : | $this->FontFamily = $saved[ 'family' ]; | ||
| 897 : | $this->FontStyle = $saved[ 'style' ]; | ||
| 898 : | $this->FontSizePt = $saved[ 'sizePt' ]; | ||
| 899 : | $this->FontSize = $saved[ 'size' ]; | ||
| 900 : | $this->CurrentFont =& $saved[ 'curr' ]; | ||
| 901 : | $this->TextColor = $saved[ 'color' ]; //EDITEI | ||
| 902 : | $this->FillColor = $saved[ 'bgcolor' ]; //EDITEI | ||
| 903 : | $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well | ||
| 904 : | $this->HREF = $saved[ 'HREF' ]; //EDITEI | ||
| 905 : | $this->underline = $saved[ 'underline' ]; //EDITEI | ||
| 906 : | $this->strike = $saved[ 'strike' ]; //EDITEI | ||
| 907 : | $this->SUP = $saved[ 'SUP' ]; //EDITEI | ||
| 908 : | $this->SUB = $saved[ 'SUB' ]; //EDITEI | ||
| 909 : | $this->LineWidth = $saved[ 'linewidth' ]; //EDITEI | ||
| 910 : | $this->DrawColor = $saved[ 'drawcolor' ]; //EDITEI | ||
| 911 : | $this->outline_on = $saved[ 'is_outline' ]; //EDITEI | ||
| 912 : | |||
| 913 : | if( $this->page > 0) | ||
| 914 : | $this->_out( sprintf( 'BT /F%d %.2f Tf ET', $this->CurrentFont[ 'i' ], $this->FontSizePt ) ); | ||
| 915 : | } | ||
| 916 : | |||
| 917 : | function newFlowingBlock( $w, $h, $b = 0, $a = 'J', $f = 0 , $is_table = false ) | ||
| 918 : | { | ||
| 919 : | // cell width in points | ||
| 920 : | if ($is_table) $this->flowingBlockAttr[ 'width' ] = ($w * $this->k); | ||
| 921 : | else $this->flowingBlockAttr[ 'width' ] = ($w * $this->k) - (2*$this->cMargin*$this->k); | ||
| 922 : | // line height in user units | ||
| 923 : | $this->flowingBlockAttr[ 'is_table' ] = $is_table; | ||
| 924 : | $this->flowingBlockAttr[ 'height' ] = $h; | ||
| 925 : | $this->flowingBlockAttr[ 'lineCount' ] = 0; | ||
| 926 : | $this->flowingBlockAttr[ 'border' ] = $b; | ||
| 927 : | $this->flowingBlockAttr[ 'align' ] = $a; | ||
| 928 : | $this->flowingBlockAttr[ 'fill' ] = $f; | ||
| 929 : | $this->flowingBlockAttr[ 'font' ] = array(); | ||
| 930 : | $this->flowingBlockAttr[ 'content' ] = array(); | ||
| 931 : | $this->flowingBlockAttr[ 'contentWidth' ] = 0; | ||
| 932 : | } | ||
| 933 : | |||
| 934 : | function finishFlowingBlock($outofblock=false) | ||
| 935 : | { | ||
| 936 : | if (!$outofblock) $currentx = $this->x; //EDITEI - in order to make the Cell method work better | ||
| 937 : | //prints out the last chunk | ||
| 938 : | $is_table = $this->flowingBlockAttr[ 'is_table' ]; | ||
| 939 : | $maxWidth =& $this->flowingBlockAttr[ 'width' ]; | ||
| 940 : | $lineHeight =& $this->flowingBlockAttr[ 'height' ]; | ||
| 941 : | $border =& $this->flowingBlockAttr[ 'border' ]; | ||
| 942 : | $align =& $this->flowingBlockAttr[ 'align' ]; | ||
| 943 : | $fill =& $this->flowingBlockAttr[ 'fill' ]; | ||
| 944 : | $content =& $this->flowingBlockAttr[ 'content' ]; | ||
| 945 : | $font =& $this->flowingBlockAttr[ 'font' ]; | ||
| 946 : | $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ]; | ||
| 947 : | $lineCount =& $this->flowingBlockAttr[ 'lineCount' ]; | ||
| 948 : | |||
| 949 : | // set normal spacing | ||
| 950 : | $this->_out( sprintf( '%.3f Tw', 0 ) ); | ||
| 951 : | $this->ws = 0; | ||
| 952 : | |||
| 953 : | // the amount of space taken up so far in user units | ||
| 954 : | $usedWidth = 0; | ||
| 955 : | |||
| 956 : | // Print out each chunk | ||
| 957 : | //EDITEI - Print content according to alignment | ||
| 958 : | $empty = $maxWidth - $contentWidth; | ||
| 959 : | $empty /= $this->k; | ||
| 960 : | $b = ''; //do not use borders | ||
| 961 : | $arraysize = count($content); | ||
| 962 : | $margins = (2*$this->cMargin); | ||
| 963 : | if ($outofblock) | ||
| 964 : | { | ||
| 965 : | $align = 'C'; | ||
| 966 : | $empty = 0; | ||
| 967 : | $margins = $this->cMargin; | ||
| 968 : | } | ||
| 969 : | switch($align) | ||
| 970 : | { | ||
| 971 : | case 'R': | ||
| 972 : | foreach ( $content as $k => $chunk ) | ||
| 973 : | { | ||
| 974 : | $this->restoreFont( $font[ $k ] ); | ||
| 975 : | $stringWidth = $this->GetStringWidth( $chunk ) + ( $this->ws * substr_count( $chunk, ' ' ) / $this->k ); | ||
| 976 : | // determine which borders should be used | ||
| 977 : | $b = ''; | ||
| 978 : | if ( $lineCount == 1 && is_int( strpos( $border, 'T' ) ) ) $b .= 'T'; | ||
| 979 : | if ( $k == count( $content ) - 1 && is_int( strpos( $border, 'R' ) ) ) $b .= 'R'; | ||
| 980 : | |||
| 981 : | if ($k == $arraysize-1 and !$outofblock) $skipln = 1; | ||
| 982 : | else $skipln = 0; | ||
| 983 : | |||
| 984 : | if ($arraysize == 1) $this->Cell( $stringWidth + $margins + $empty, $lineHeight, $chunk, $b, $skipln, $align, $fill, $this->HREF , $currentx ); //mono-style line | ||
| 985 : | elseif ($k == 0) $this->Cell( $stringWidth + ($margins/2) + $empty, $lineHeight, $chunk, $b, 0, 'R', $fill, $this->HREF );//first part | ||
| 986 : | elseif ($k == $arraysize-1 ) $this->Cell( $stringWidth + ($margins/2), $lineHeight, $chunk, $b, $skipln, '', $fill, $this->HREF, $currentx );//last part | ||
| 987 : | else $this->Cell( $stringWidth , $lineHeight, $chunk, $b, 0, '', $fill, $this->HREF );//middle part | ||
| 988 : | } | ||
| 989 : | break; | ||
| 990 : | case 'L': | ||
| 991 : | case 'J': | ||
| 992 : | foreach ( $content as $k => $chunk ) | ||
| 993 : | { | ||
| 994 : | $this->restoreFont( $font[ $k ] ); | ||
| 995 : | $stringWidth = $this->GetStringWidth( $chunk ) + ( $this->ws * substr_count( $chunk, ' ' ) / $this->k ); | ||
| 996 : | // determine which borders should be used | ||
| 997 : | $b = ''; | ||
| 998 : | if ( $lineCount == 1 && is_int( strpos( $border, 'T' ) ) ) $b .= 'T'; | ||
| 999 : | if ( $k == 0 && is_int( strpos( $border, 'L' ) ) ) $b .= 'L'; | ||
| 1000 : | |||
| 1001 : | if ($k == $arraysize-1 and !$outofblock) $skipln = 1; | ||
| 1002 : | else $skipln = 0; | ||
| 1003 : | |||
| 1004 : | if (!$is_table and !$outofblock and !$fill and $align=='L' and $k == 0) {$align='';$margins=0;} //Remove margins in this special (though often) case | ||
| 1005 : | |||
| 1006 : | if ($arraysize == 1) $this->Cell( $stringWidth + $margins + $empty, $lineHeight, $chunk, $b, $skipln, $align, $fill, $this->HREF , $currentx ); //mono-style line | ||
| 1007 : | elseif ($k == 0) $this->Cell( $stringWidth + ($margins/2), $lineHeight, $chunk, $b, $skipln, $align, $fill, $this->HREF );//first part | ||
| 1008 : | elseif ($k == $arraysize-1 ) $this->Cell( $stringWidth + ($margins/2) + $empty, $lineHeight, $chunk, $b, $skipln, '', $fill, $this->HREF, $currentx );//last part | ||
| 1009 : | else $this->Cell( $stringWidth , $lineHeight, $chunk, $b, $skipln, '', $fill, $this->HREF );//middle part | ||
| 1010 : | } | ||
| 1011 : | break; | ||
| 1012 : | case 'C': | ||
| 1013 : | foreach ( $content as $k => $chunk ) | ||
| 1014 : | { | ||
| 1015 : | $this->restoreFont( $font[ $k ] ); | ||
| 1016 : | $stringWidth = $this->GetStringWidth( $chunk ) + ( $this->ws * substr_count( $chunk, ' ' ) / $this->k ); | ||
| 1017 : | // determine which borders should be used | ||
| 1018 : | $b = ''; | ||
| 1019 : | if ( $lineCount == 1 && is_int( strpos( $border, 'T' ) ) ) $b .= 'T'; | ||
| 1020 : | |||
| 1021 : | if ($k == $arraysize-1 and !$outofblock) $skipln = 1; | ||
| 1022 : | else $skipln = 0; | ||
| 1023 : | |||
| 1024 : | if ($arraysize == 1) $this->Cell( $stringWidth + $margins + $empty, $lineHeight, $chunk, $b, $skipln, $align, $fill, $this->HREF , $currentx ); //mono-style line | ||
| 1025 : | elseif ($k == 0) $this->Cell( $stringWidth + ($margins/2) + ($empty/2), $lineHeight, $chunk, $b, 0, 'R', $fill, $this->HREF );//first part | ||
| 1026 : | elseif ($k == $arraysize-1 ) $this->Cell( $stringWidth + ($margins/2) + ($empty/2), $lineHeight, $chunk, $b, $skipln, 'L', $fill, $this->HREF, $currentx );//last part | ||
| 1027 : | else $this->Cell( $stringWidth , $lineHeight, $chunk, $b, 0, '', $fill, $this->HREF );//middle part | ||
| 1028 : | } | ||
| 1029 : | break; | ||
| 1030 : | default: break; | ||
| 1031 : | } | ||
| 1032 : | } | ||
| 1033 : | |||
| 1034 : | function WriteFlowingBlock( $s , $outofblock = false ) | ||
| 1035 : | { | ||
| 1036 : | if (!$outofblock) $currentx = $this->x; //EDITEI - in order to make the Cell method work better | ||
| 1037 : | $is_table = $this->flowingBlockAttr[ 'is_table' ]; | ||
| 1038 : | // width of all the content so far in points | ||
| 1039 : | $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ]; | ||
| 1040 : | // cell width in points | ||
| 1041 : | $maxWidth =& $this->flowingBlockAttr[ 'width' ]; | ||
| 1042 : | $lineCount =& $this->flowingBlockAttr[ 'lineCount' ]; | ||
| 1043 : | // line height in user units | ||
| 1044 : | $lineHeight =& $this->flowingBlockAttr[ 'height' ]; | ||
| 1045 : | $border =& $this->flowingBlockAttr[ 'border' ]; | ||
| 1046 : | $align =& $this->flowingBlockAttr[ 'align' ]; | ||
| 1047 : | $fill =& $this->flowingBlockAttr[ 'fill' ]; | ||
| 1048 : | $content =& $this->flowingBlockAttr[ 'content' ]; | ||
| 1049 : | $font =& $this->flowingBlockAttr[ 'font' ]; | ||
| 1050 : | |||
| 1051 : | $font[] = $this->saveFont(); | ||
| 1052 : | $content[] = ''; | ||
| 1053 : | |||
| 1054 : | $currContent =& $content[ count( $content ) - 1 ]; | ||
| 1055 : | |||
| 1056 : | // where the line should be cutoff if it is to be justified | ||
| 1057 : | $cutoffWidth = $contentWidth; | ||
| 1058 : | |||
| 1059 : | // for every character in the string | ||
| 1060 : | for ( $i = 0; $i < strlen( $s ); $i++ ) | ||
| 1061 : | { | ||
| 1062 : | // extract the current character | ||
| 1063 : | $c = $s{$i}; | ||
| 1064 : | // get the width of the character in points | ||
| 1065 : | $cw = $this->CurrentFont[ 'cw' ][ $c ] * ( $this->FontSizePt / 1000 ); | ||
| 1066 : | |||
| 1067 : | if ( $c == ' ' ) | ||
| 1068 : | { | ||
| 1069 : | $currContent .= ' '; | ||
| 1070 : | $cutoffWidth = $contentWidth; | ||
| 1071 : | $contentWidth += $cw; | ||
| 1072 : | continue; | ||
| 1073 : | } | ||
| 1074 : | // try adding another char | ||
| 1075 : | if ( $contentWidth + $cw > $maxWidth ) | ||
| 1076 : | { | ||
| 1077 : | // it won't fit, output what we already have | ||
| 1078 : | $lineCount++; | ||
| 1079 : | //Readjust MaxSize in order to use the whole page width | ||
| 1080 : | if ($outofblock and ($lineCount == 1) ) $maxWidth = $this->pgwidth * $this->k; | ||
| 1081 : | // contains any content that didn't make it into this print | ||
| 1082 : | $savedContent = ''; | ||
| 1083 : | $savedFont = array(); | ||
| 1084 : | // first, cut off and save any partial words at the end of the string | ||
| 1085 : | $words = explode( ' ', $currContent ); | ||
| 1086 : | |||
| 1087 : | // if it looks like we didn't finish any words for this chunk | ||
| 1088 : | if ( count( $words ) == 1 ) | ||
| 1089 : | { | ||
| 1090 : | // save and crop off the content currently on the stack | ||
| 1091 : | $savedContent = array_pop( $content ); | ||
| 1092 : | $savedFont = array_pop( $font ); | ||
| 1093 : | |||
| 1094 : | // trim any trailing spaces off the last bit of content | ||
| 1095 : | $currContent =& $content[ count( $content ) - 1 ]; | ||
| 1096 : | $currContent = rtrim( $currContent ); | ||
| 1097 : | } | ||
| 1098 : | else // otherwise, we need to find which bit to cut off | ||
| 1099 : | { | ||
| 1100 : | $lastContent = ''; | ||
| 1101 : | for ( $w = 0; $w < count( $words ) - 1; $w++) $lastContent .= "{$words[ $w ]} "; | ||
| 1102 : | |||
| 1103 : | $savedContent = $words[ count( $words ) - 1 ]; | ||
| 1104 : | $savedFont = $this->saveFont(); | ||
| 1105 : | // replace the current content with the cropped version | ||
| 1106 : | $currContent = rtrim( $lastContent ); | ||
| 1107 : | } | ||
| 1108 : | // update $contentWidth and $cutoffWidth since they changed with cropping | ||
| 1109 : | $contentWidth = 0; | ||
| 1110 : | foreach ( $content as $k => $chunk ) | ||
| 1111 : | { | ||
| 1112 : | $this->restoreFont( $font[ $k ] ); | ||
| 1113 : | $contentWidth += $this->GetStringWidth( $chunk ) * $this->k; | ||
| 1114 : | } | ||
| 1115 : | $cutoffWidth = $contentWidth; | ||
| 1116 : | // if it's justified, we need to find the char spacing | ||
| 1117 : | if( $align == 'J' ) | ||
| 1118 : | { | ||
| 1119 : | // count how many spaces there are in the entire content string | ||
| 1120 : | $numSpaces = 0; | ||
| 1121 : | foreach ( $content as $chunk ) $numSpaces += substr_count( $chunk, ' ' ); | ||
| 1122 : | // if there's more than one space, find word spacing in points | ||
| 1123 : | if ( $numSpaces > 0 ) $this->ws = ( $maxWidth - $cutoffWidth ) / $numSpaces; | ||
| 1124 : | else $this->ws = 0; | ||
| 1125 : | $this->_out( sprintf( '%.3f Tw', $this->ws ) ); | ||
| 1126 : | } | ||
| 1127 : | // otherwise, we want normal spacing | ||
| 1128 : | else $this->_out( sprintf( '%.3f Tw', 0 ) ); | ||
| 1129 : | |||
| 1130 : | //EDITEI - Print content according to alignment | ||
| 1131 : | if (!isset($numSpaces)) $numSpaces = 0; | ||
| 1132 : | $contentWidth -= ($this->ws*$numSpaces); | ||
| 1133 : | $empty = $maxWidth - $contentWidth - 2*($this->ws*$numSpaces); | ||
| 1134 : | $empty /= $this->k; | ||
| 1135 : | $b = ''; //do not use borders | ||
| 1136 : | /*'If' below used in order to fix "first-line of other page with justify on" bug*/ | ||
| 1137 : | if($this->y+$this->divheight>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) | ||
| 1138 : | { | ||
| 1139 : | $bak_x=$this->x;//Current X position | ||
| 1140 : | $ws=$this->ws;//Word Spacing | ||
| 1141 : | if($ws>0) | ||
| 1142 : | { | ||
| 1143 : | $this->ws=0; | ||
| 1144 : | $this->_out('0 Tw'); | ||
| 1145 : | } | ||
| 1146 : | $this->AddPage($this->CurOrientation); | ||
| 1147 : | $this->x=$bak_x; | ||
| 1148 : | if($ws>0) | ||
| 1149 : | { | ||
| 1150 : | $this->ws=$ws; | ||
| 1151 : | $this->_out(sprintf('%.3f Tw',$ws)); | ||
| 1152 : | } | ||
| 1153 : | } | ||
| 1154 : | $arraysize = count($content); | ||
| 1155 : | $margins = (2*$this->cMargin); | ||
| 1156 : | if ($outofblock) | ||
| 1157 : | { | ||
| 1158 : | $align = 'C'; | ||
| 1159 : | $empty = 0; | ||
| 1160 : | $margins = $this->cMargin; | ||
| 1161 : | } | ||
| 1162 : | switch($align) | ||
| 1163 : | { | ||
| 1164 : | case 'R': | ||
| 1165 : | foreach ( $content as $k => $chunk ) | ||
| 1166 : | { | ||
| 1167 : | $this->restoreFont( $font[ $k ] ); | ||
| 1168 : | $stringWidth = $this->GetStringWidth( $chunk ) + ( $this->ws * substr_count( $chunk, ' ' ) / $this->k ); | ||
| 1169 : | // determine which borders should be used | ||
| 1170 : | $b = ''; | ||
| 1171 : | if ( $lineCount == 1 && is_int( strpos( $border, 'T' ) ) ) $b .= 'T'; | ||
| 1172 : | if ( $k == count( $content ) - 1 && is_int( strpos( $border, 'R' ) ) ) $b .= 'R'; | ||
| 1173 : | |||
| 1174 : | if ($arraysize == 1) $this->Cell( $stringWidth + $margins + $empty, $lineHeight, $chunk, $b, 1, $align, $fill, $this->HREF , $currentx ); //mono-style line | ||
| 1175 : | elseif ($k == 0) $this->Cell( $stringWidth + ($margins/2) + $empty, $lineHeight, $chunk, $b, 0, 'R', $fill, $this->HREF );//first part | ||
| 1176 : | elseif ($k == $arraysize-1 ) $this->Cell( $stringWidth + ($margins/2), $lineHeight, $chunk, $b, 1, '', $fill, $this->HREF, $currentx );//last part | ||
| 1177 : | else $this->Cell( $stringWidth , $lineHeight, $chunk, $b, 0, '', $fill, $this->HREF );//middle part | ||
| 1178 : | } | ||
| 1179 : | break; | ||
| 1180 : | case 'L': | ||
| 1181 : | case 'J': | ||
| 1182 : | foreach ( $content as $k => $chunk ) | ||
| 1183 : | { | ||
| 1184 : | $this->restoreFont( $font[ $k ] ); | ||
| 1185 : | $stringWidth = $this->GetStringWidth( $chunk ) + ( $this->ws * substr_count( $chunk, ' ' ) / $this->k ); | ||
| 1186 : | // determine which borders should be used | ||
| 1187 : | $b = ''; | ||
| 1188 : | if ( $lineCount == 1 && is_int( strpos( $border, 'T' ) ) ) $b .= 'T'; | ||
| 1189 : | if ( $k == 0 && is_int( strpos( $border, 'L' ) ) ) $b .= 'L'; | ||
| 1190 : | |||
| 1191 : | if (!$is_table and !$outofblock and !$fill and $align=='L' and $k == 0) | ||
| 1192 : | { | ||
| 1193 : | //Remove margins in this special (though often) case | ||
| 1194 : | $align=''; | ||
| 1195 : | $margins=0; | ||
| 1196 : | } | ||
| 1197 : | |||
| 1198 : | if ($arraysize == 1) $this->Cell( $stringWidth + $margins + $empty, $lineHeight, $chunk, $b, 1, $align, $fill, $this->HREF , $currentx ); //mono-style line | ||
| 1199 : | elseif ($k == 0) $this->Cell( $stringWidth + ($margins/2), $lineHeight, $chunk, $b, 0, $align, $fill, $this->HREF );//first part | ||
| 1200 : | elseif ($k == $arraysize-1 ) $this->Cell( $stringWidth + ($margins/2) + $empty, $lineHeight, $chunk, $b, 1, '', $fill, $this->HREF, $currentx );//last part | ||
| 1201 : | else $this->Cell( $stringWidth , $lineHeight, $chunk, $b, 0, '', $fill, $this->HREF );//middle part | ||
| 1202 : | |||
| 1203 : | if (!$is_table and !$outofblock and !$fill and $align=='' and $k == 0) | ||
| 1204 : | { | ||
| 1205 : | $align = 'L'; | ||
| 1206 : | $margins = (2*$this->cMargin); | ||
| 1207 : | } | ||
| 1208 : | } | ||
| 1209 : | break; | ||
| 1210 : | case 'C': | ||
| 1211 : | foreach ( $content as $k => $chunk ) | ||
| 1212 : | { | ||
| 1213 : | $this->restoreFont( $font[ $k ] ); | ||
| 1214 : | $stringWidth = $this->GetStringWidth( $chunk ) + ( $this->ws * substr_count( $chunk, ' ' ) / $this->k ); | ||
| 1215 : | // determine which borders should be used | ||
| 1216 : | $b = ''; | ||
| 1217 : | if ( $lineCount == 1 && is_int( strpos( $border, 'T' ) ) ) $b .= 'T'; | ||
| 1218 : | |||
| 1219 : | if ($arraysize == 1) $this->Cell( $stringWidth + $margins + $empty, $lineHeight, $chunk, $b, 1, $align, $fill, $this->HREF , $currentx ); //mono-style line | ||
| 1220 : | elseif ($k == 0) $this->Cell( $stringWidth + ($margins/2) + ($empty/2), $lineHeight, $chunk, $b, 0, 'R', $fill, $this->HREF );//first part | ||
| 1221 : | elseif ($k == $arraysize-1 ) $this->Cell( $stringWidth + ($margins/2) + ($empty/2), $lineHeight, $chunk, $b, 1, 'L', $fill, $this->HREF, $currentx );//last part | ||
| 1222 : | else $this->Cell( $stringWidth , $lineHeight, $chunk, $b, 0, '', $fill, $this->HREF );//middle part | ||
| 1223 : | } | ||
| 1224 : | break; | ||
| 1225 : | default: break; | ||
| 1226 : | } | ||
| 1227 : | // move on to the next line, reset variables, tack on saved content and current char | ||
| 1228 : | $this->restoreFont( $savedFont ); | ||
| 1229 : | $font = array( $savedFont ); | ||
| 1230 : | $content = array( $savedContent . $s{ $i } ); | ||
| 1231 : | |||
| 1232 : | $currContent =& $content[ 0 ]; | ||
| 1233 : | $contentWidth = $this->GetStringWidth( $currContent ) * $this->k; | ||
| 1234 : | $cutoffWidth = $contentWidth; | ||
| 1235 : | } | ||
| 1236 : | // another character will fit, so add it on | ||
| 1237 : | else | ||
| 1238 : | { | ||
| 1239 : | $contentWidth += $cw; | ||
| 1240 : | $currContent .= $s{ $i }; | ||
| 1241 : | } | ||
| 1242 : | } | ||
| 1243 : | } | ||
| 1244 : | //----------------------END OF FLOWING BLOCK------------------------------------// | ||
| 1245 : | |||
| 1246 : | //EDITEI | ||
| 1247 : | //Thanks to Ron Korving for the WordWrap() function | ||
| 1248 : | function WordWrap(&$text, $maxwidth) | ||
| 1249 : | { | ||
| 1250 : | $biggestword=0;//EDITEI | ||
| 1251 : | $toonarrow=false;//EDITEI | ||
| 1252 : | |||
| 1253 : | $text = trim($text); | ||
| 1254 : | if ($text==='') return 0; | ||
| 1255 : | $space = $this->GetStringWidth(' '); | ||
| 1256 : | $lines = explode("\n", $text); | ||
| 1257 : | $text = ''; | ||
| 1258 : | $count = 0; | ||
| 1259 : | |||
| 1260 : | foreach ($lines as $line) | ||
| 1261 : | { | ||
| 1262 : | $words = preg_split('/ +/', $line); | ||
| 1263 : | $width = 0; | ||
| 1264 : | |||
| 1265 : | foreach ($words as $word) | ||
| 1266 : | { | ||
| 1267 : | $wordwidth = $this->GetStringWidth($word); | ||
| 1268 : | |||
| 1269 : | //EDITEI | ||
| 1270 : | //Warn user that maxwidth is insufficient | ||
| 1271 : | if ($wordwidth > $maxwidth) | ||
| 1272 : | { | ||
| 1273 : | if ($wordwidth > $biggestword) $biggestword = $wordwidth; | ||
| 1274 : | $toonarrow=true;//EDITEI | ||
| 1275 : | } | ||
| 1276 : | if ($width + $wordwidth <= $maxwidth) | ||
| 1277 : | { | ||
| 1278 : | $width += $wordwidth + $space; | ||
| 1279 : | $text .= $word.' '; | ||
| 1280 : | } | ||
| 1281 : | else | ||
| 1282 : | { | ||
| 1283 : | $width = $wordwidth + $space; | ||
| 1284 : | $text = rtrim($text)."\n".$word.' '; | ||
| 1285 : | $count++; | ||
| 1286 : | } | ||
| 1287 : | } | ||
| 1288 : | $text = rtrim($text)."\n"; | ||
| 1289 : | $count++; | ||
| 1290 : | } | ||
| 1291 : | $text = rtrim($text); | ||
| 1292 : | |||
| 1293 : | //Return -(wordsize) if word is bigger than maxwidth | ||
| 1294 : | if ($toonarrow) return -$biggestword; | ||
| 1295 : | else return $count; | ||
| 1296 : | } | ||
| 1297 : | |||
| 1298 : | //EDITEI | ||
| 1299 : | //Thanks to Seb(captainseb@wanadoo.fr) for the _SetTextRendering() and SetTextOutline() functions | ||
| 1300 : | /** | ||
| 1301 : | * Set Text Rendering Mode | ||
| 1302 : | * @param int $mode Set the rendering mode.<ul><li>0 : Fill text (default)</li><li>1 : Stroke</li><li>2 : Fill & stroke</li></ul> | ||
| 1303 : | * @see SetTextOutline() | ||
| 1304 : | */ | ||
| 1305 : | //This function is not being currently used | ||
| 1306 : | function _SetTextRendering($mode) { | ||
| 1307 : | if (!(($mode == 0) || ($mode == 1) || ($mode == 2))) | ||
| 1308 : | $this->Error("Text rendering mode should be 0, 1 or 2 (value : $mode)"); | ||
| 1309 : | $this->_out($mode.' Tr'); | ||
| 1310 : | } | ||
| 1311 : | |||
| 1312 : | /** | ||
| 1313 : | * Set Text Ouline On/Off | ||
| 1314 : | * @param mixed $width If set to false the text rending mode is set to fill, else it's the width of the outline | ||
| 1315 : | * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255 | ||
| 1316 : | * @param int $g Green component (between 0 and 255) | ||
| 1317 : | * @param int $b Blue component (between 0 and 255) | ||
| 1318 : | * @see _SetTextRendering() | ||
| 1319 : | */ | ||
| 1320 : | function SetTextOutline($width, $r=0, $g=-1, $b=-1) //EDITEI | ||
| 1321 : | { | ||
| 1322 : | if ($width == false) //Now resets all values | ||
| 1323 : | { | ||
| 1324 : | $this->outline_on = false; | ||
| 1325 : | $this->SetLineWidth(0.2); | ||
| 1326 : | $this->SetDrawColor(0); | ||
| 1327 : | $this->_setTextRendering(0); | ||
| 1328 : | $this->_out('0 Tr'); | ||
| 1329 : | } | ||
| 1330 : | else | ||
| 1331 : | { | ||
| 1332 : | $this->SetLineWidth($width); | ||
| 1333 : | $this->SetDrawColor($r, $g , $b); | ||
| 1334 : | $this->_out('2 Tr'); //Fixed | ||
| 1335 : | } | ||
| 1336 : | } | ||
| 1337 : | |||
| 1338 : | //function Circle() thanks to Olivier PLATHEY | ||
| 1339 : | //EDITEI | ||
| 1340 : | function Circle($x,$y,$r,$style='') | ||
| 1341 : | { | ||
| 1342 : | $this->Ellipse($x,$y,$r,$r,$style); | ||
| 1343 : | } | ||
| 1344 : | |||
| 1345 : | //function Ellipse() thanks to Olivier PLATHEY | ||
| 1346 : | //EDITEI | ||
| 1347 : | function Ellipse($x,$y,$rx,$ry,$style='D') | ||
| 1348 : | { | ||
| 1349 : | if($style=='F') $op='f'; | ||
| 1350 : | elseif($style=='FD' or $style=='DF') $op='B'; | ||
| 1351 : | else $op='S'; | ||
| 1352 : | $lx=4/3*(M_SQRT2-1)*$rx; | ||
| 1353 : | $ly=4/3*(M_SQRT2-1)*$ry; | ||
| 1354 : | $k=$this->k; | ||
| 1355 : | $h=$this->h; | ||
| 1356 : | $this->_out(sprintf('%.2f %.2f m %.2f %.2f %.2f %.2f %.2f %.2f c', | ||
| 1357 : | ($x+$rx)*$k,($h-$y)*$k, | ||
| 1358 : | ($x+$rx)*$k,($h-($y-$ly))*$k, | ||
| 1359 : | ($x+$lx)*$k,($h-($y-$ry))*$k, | ||
| 1360 : | $x*$k,($h-($y-$ry))*$k)); | ||
| 1361 : | $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c', | ||
| 1362 : | ($x-$lx)*$k,($h-($y-$ry))*$k, | ||
| 1363 : | ($x-$rx)*$k,($h-($y-$ly))*$k, | ||
| 1364 : | ($x-$rx)*$k,($h-$y)*$k)); | ||
| 1365 : | $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c', | ||
| 1366 : | ($x-$rx)*$k,($h-($y+$ly))*$k, | ||
| 1367 : | ($x-$lx)*$k,($h-($y+$ry))*$k, | ||
| 1368 : | $x*$k,($h-($y+$ry))*$k)); | ||
| 1369 : | $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c %s', | ||
| 1370 : | ($x+$lx)*$k,($h-($y+$ry))*$k, | ||
| 1371 : | ($x+$rx)*$k,($h-($y+$ly))*$k, | ||
| 1372 : | ($x+$rx)*$k,($h-$y)*$k, | ||
| 1373 : | $op)); | ||
| 1374 : | } | ||
| 1375 : | |||
| 1376 : | function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$paint=true) | ||
| 1377 : | { | ||
| 1378 : | //Put an image on the page | ||
| 1379 : | if(!isset($this->images[$file])) | ||
| 1380 : | { | ||
| 1381 : | //First use of image, get info | ||
| 1382 : | if($type=='') | ||
| 1383 : | { | ||
| 1384 : | $pos=strrpos($file,'.'); | ||
| 1385 : | if(!$pos) $this->Error('Image file has no extension and no type was specified: '.$file); | ||
| 1386 : | $type=substr($file,$pos+1); | ||
| 1387 : | } | ||
| 1388 : | $type=strtolower($type); | ||
| 1389 : | $mqr=get_magic_quotes_runtime(); | ||
| 1390 : | set_magic_quotes_runtime(0); | ||
| 1391 : | if($type=='jpg' or $type=='jpeg') $info=$this->_parsejpg($file); | ||
| 1392 : | elseif($type=='png') $info=$this->_parsepng($file); | ||
| 1393 : | elseif($type=='gif') $info=$this->_parsegif($file); //EDITEI - GIF format included | ||
| 1394 : | else | ||
| 1395 : | { | ||
| 1396 : | //Allow for additional formats | ||
| 1397 : | $mtd='_parse'.$type; | ||
| 1398 : | if(!method_exists($this,$mtd)) $this->Error('Unsupported image type: '.$type); | ||
| 1399 : | $info=$this->$mtd($file); | ||
| 1400 : | } | ||
| 1401 : | set_magic_quotes_runtime($mqr); | ||
| 1402 : | $info['i']=count($this->images)+1; | ||
| 1403 : | $this->images[$file]=$info; | ||
| 1404 : | } | ||
| 1405 : | else $info=$this->images[$file]; | ||
| 1406 : | //Automatic width and height calculation if needed | ||
| 1407 : | if($w==0 and $h==0) | ||
| 1408 : | { | ||
| 1409 : | //Put image at 72 dpi | ||
| 1410 : | $w=$info['w']/$this->k; | ||
| 1411 : | $h=$info['h']/$this->k; | ||
| 1412 : | } | ||
| 1413 : | if($w==0) $w=$h*$info['w']/$info['h']; | ||
| 1414 : | if($h==0) $h=$w*$info['h']/$info['w']; | ||
| 1415 : | |||
| 1416 : | $changedpage = false; //EDITEI | ||
| 1417 : | |||
| 1418 : | //Avoid drawing out of the paper(exceeding width limits). //EDITEI | ||
| 1419 : | if ( ($x + $w) > $this->fw ) | ||
| 1420 : | { | ||
| 1421 : | $x = $this->lMargin; | ||
| 1422 : | $y += 5; | ||
| 1423 : | } | ||
| 1424 : | //Avoid drawing out of the page. //EDITEI | ||
| 1425 : | if ( ($y + $h) > $this->fh ) | ||
| 1426 : | { | ||
| 1427 : | $this->AddPage(); | ||
| 1428 : | $y = $tMargin + 10; // +10 to avoid drawing too close to border of page | ||
| 1429 : | $changedpage = true; | ||
| 1430 : | } | ||
| 1431 : | |||
| 1432 : | $outstring = sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']); | ||
| 1433 : | |||
| 1434 : | if($paint) //EDITEI | ||
| 1435 : | { | ||
| 1436 : | $this->_out($outstring); | ||
| 1437 : | if($link) $this->Link($x,$y,$w,$h,$link); | ||
| 1438 : | } | ||
| 1439 : | |||
| 1440 : | //Avoid writing text on top of the image. //EDITEI | ||
| 1441 : | if ($changedpage) $this->y = $y + $h; | ||
| 1442 : | else $this->y = $y + $h; | ||
| 1443 : | |||
| 1444 : | //Return width-height array //EDITEI | ||
| 1445 : | $sizesarray['WIDTH'] = $w; | ||
| 1446 : | $sizesarray['HEIGHT'] = $h; | ||
| 1447 : | $sizesarray['X'] = $x; //Position before painting image | ||
| 1448 : | $sizesarray['Y'] = $y; //Position before painting image | ||
| 1449 : | $sizesarray['OUTPUT'] = $outstring; | ||
| 1450 : | return $sizesarray; | ||
| 1451 : | } | ||
| 1452 : | |||
| 1453 : | //EDITEI - Done after reading a little about PDF reference guide | ||
| 1454 : | function DottedRect($x=100,$y=150,$w=50,$h=50) | ||
| 1455 : | { | ||
| 1456 : | $x *= $this->k ; | ||
| 1457 : | $y = ($this->h-$y)*$this->k; | ||
| 1458 : | $w *= $this->k ; | ||
| 1459 : | $h *= $this->k ;// - h? | ||
| 1460 : | |||
| 1461 : | $herex = $x; | ||
| 1462 : | $herey = $y; | ||
| 1463 : | |||
| 1464 : | //Make fillcolor == drawcolor | ||
| 1465 : | $bak_fill = $this->FillColor; | ||
| 1466 : | $this->FillColor = $this->DrawColor; | ||
| 1467 : | $this->FillColor = str_replace('RG','rg',$this->FillColor); | ||
| 1468 : | $this->_out($this->FillColor); | ||
| 1469 : | |||
| 1470 : | while ($herex < ($x + $w)) //draw from upper left to upper right | ||
| 1471 : | { | ||
| 1472 : | $this->DrawDot($herex,$herey); | ||
| 1473 : | $herex += (3*$this->k); | ||
| 1474 : | } | ||
| 1475 : | $herex = $x + $w; | ||
| 1476 : | while ($herey > ($y - $h)) //draw from upper right to lower right | ||
| 1477 : | { | ||
| 1478 : | $this->DrawDot($herex,$herey); | ||
| 1479 : | $herey -= (3*$this->k); | ||
| 1480 : | } | ||
| 1481 : | $herey = $y - $h; | ||
| 1482 : | while ($herex > $x) //draw from lower right to lower left | ||
| 1483 : | { | ||
| 1484 : | $this->DrawDot($herex,$herey); | ||
| 1485 : | $herex -= (3*$this->k); | ||
| 1486 : | } | ||
| 1487 : | $herex = $x; | ||
| 1488 : | while ($herey < $y) //draw from lower left to upper left | ||
| 1489 : | { | ||
| 1490 : | $this->DrawDot($herex,$herey); | ||
| 1491 : | $herey += (3*$this->k); | ||
| 1492 : | } | ||
| 1493 : | $herey = $y; | ||
| 1494 : | |||
| 1495 : | $this->FillColor = $bak_fill; | ||
| 1496 : | $this->_out($this->FillColor); //return fillcolor back to normal | ||
| 1497 : | } | ||
| 1498 : | |||
| 1499 : | //EDITEI - Done after reading a little about PDF reference guide | ||
| 1500 : | function DrawDot($x,$y) //center x y | ||
| 1501 : | { | ||
| 1502 : | $op = 'B'; // draw Filled Dots | ||
| 1503 : | //F == fill //S == stroke //B == stroke and fill | ||
| 1504 : | $r = 0.5 * $this->k; //raio | ||
| 1505 : | |||
| 1506 : | //Start Point | ||
| 1507 : | $x1 = $x - $r; | ||
| 1508 : | $y1 = $y; | ||
| 1509 : | //End Point | ||
| 1510 : | $x2 = $x + $r; | ||
| 1511 : | $y2 = $y; | ||
| 1512 : | //Auxiliar Point | ||
| 1513 : | $x3 = $x; | ||
| 1514 : | $y3 = $y + (2*$r);// 2*raio to make a round (not oval) shape | ||
| 1515 : | |||
| 1516 : | //Round join and cap | ||
| 1517 : | $s="\n".'1 J'."\n"; | ||
| 1518 : | $s.='1 j'."\n"; | ||
| 1519 : | |||
| 1520 : | //Upper circle | ||
| 1521 : | $s.=sprintf('%.3f %.3f m'."\n",$x1,$y1); //x y start drawing | ||
| 1522 : | $s.=sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c'."\n",$x1,$y1,$x3,$y3,$x2,$y2);//Bezier curve | ||
| 1523 : | //Lower circle | ||
| 1524 : | $y3 = $y - (2*$r); | ||
| 1525 : | $s.=sprintf("\n".'%.3f %.3f m'."\n",$x1,$y1); //x y start drawing | ||
| 1526 : | $s.=sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c'."\n",$x1,$y1,$x3,$y3,$x2,$y2); | ||
| 1527 : | $s.=$op."\n"; //stroke and fill | ||
| 1528 : | |||
| 1529 : | //Draw in PDF file | ||
| 1530 : | $this->_out($s); | ||
| 1531 : | } | ||
| 1532 : | |||
| 1533 : | function SetDash($black=false,$white=false) | ||
| 1534 : | { | ||
| 1535 : | if($black and $white) $s=sprintf('[%.3f %.3f] 0 d',$black*$this->k,$white*$this->k); | ||
| 1536 : | else $s='[] 0 d'; | ||
| 1537 : | $this->_out($s); | ||
| 1538 : | } | ||
| 1539 : | |||
| 1540 : | function Bookmark($txt,$level=0,$y=0) | ||
| 1541 : | { | ||
| 1542 : | if($y == -1) $y = $this->GetY(); | ||
| 1543 : | $this->outlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->PageNo()); | ||
| 1544 : | } | ||
| 1545 : | |||
| 1546 : | function DisplayPreferences($preferences) | ||
| 1547 : | { | ||
| 1548 : | $this->DisplayPreferences .= $preferences; | ||
| 1549 : | } | ||
| 1550 : | |||
| 1551 : | function _putbookmarks() | ||
| 1552 : | { | ||
| 1553 : | $nb=count($this->outlines); | ||
| 1554 : | if($nb==0) return; | ||
| 1555 : | $lru=array(); | ||
| 1556 : | $level=0; | ||
| 1557 : | foreach($this->outlines as $i=>$o) | ||
| 1558 : | { | ||
| 1559 : | if($o['l']>0) | ||
| 1560 : | { | ||
| 1561 : | $parent=$lru[$o['l']-1]; | ||
| 1562 : | //Set parent and last pointers | ||
| 1563 : | $this->outlines[$i]['parent']=$parent; | ||
| 1564 : | $this->outlines[$parent]['last']=$i; | ||
| 1565 : | if($o['l']>$level) | ||
| 1566 : | { | ||
| 1567 : | //Level increasing: set first pointer | ||
| 1568 : | $this->outlines[$parent]['first']=$i; | ||
| 1569 : | } | ||
| 1570 : | } | ||
| 1571 : | else | ||
| 1572 : | $this->outlines[$i]['parent']=$nb; | ||
| 1573 : | if($o['l']<=$level and $i>0) | ||
| 1574 : | { | ||
| 1575 : | //Set prev and next pointers | ||
| 1576 : | $prev=$lru[$o['l']]; | ||
| 1577 : | $this->outlines[$prev]['next']=$i; | ||
| 1578 : | $this->outlines[$i]['prev']=$prev; | ||
| 1579 : | } | ||
| 1580 : | $lru[$o['l']]=$i; | ||
| 1581 : | $level=$o['l']; | ||
| 1582 : | } | ||
| 1583 : | //Outline items | ||
| 1584 : | $n=$this->n+1; | ||
| 1585 : | foreach($this->outlines as $i=>$o) | ||
| 1586 : | { | ||
| 1587 : | $this->_newobj(); | ||
| 1588 : | $this->_out('<</Title '.$this->_textstring($o['t'])); | ||
| 1589 : | $this->_out('/Parent '.($n+$o['parent']).' 0 R'); | ||
| 1590 : | if(isset($o['prev'])) | ||
| 1591 : | $this->_out('/Prev '.($n+$o['prev']).' 0 R'); | ||
| 1592 : | if(isset($o['next'])) | ||
| 1593 : | $this->_out('/Next '.($n+$o['next']).' 0 R'); | ||
| 1594 : | if(isset($o['first'])) | ||
| 1595 : | $this->_out('/First '.($n+$o['first']).' 0 R'); | ||
| 1596 : | if(isset($o['last'])) | ||
| 1597 : | $this->_out('/Last '.($n+$o['last']).' 0 R'); | ||
| 1598 : | $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]',1+2*$o['p'],($this->h-$o['y'])*$this->k)); | ||
| 1599 : | $this->_out('/Count 0>>'); | ||
| 1600 : | $this->_out('endobj'); | ||
| 1601 : | } | ||
| 1602 : | //Outline root | ||
| 1603 : | $this->_newobj(); | ||
| 1604 : | $this->OutlineRoot=$this->n; | ||
| 1605 : | $this->_out('<</Type /Outlines /First '.$n.' 0 R'); | ||
| 1606 : | $this->_out('/Last '.($n+$lru[0]).' 0 R>>'); | ||
| 1607 : | $this->_out('endobj'); | ||
| 1608 : | } | ||
| 1609 : | |||
| 1610 : | function Ln($h='') | ||
| 1611 : | { | ||
| 1612 : | //Line feed; default value is last cell height | ||
| 1613 : | $this->x=$this->lMargin; | ||
| 1614 : | if(is_string($h)) $this->y+=$this->lasth; | ||
| 1615 : | else $this->y+=$h; | ||
| 1616 : | } | ||
| 1617 : | |||
| 1618 : | function GetX() | ||
| 1619 : | { | ||
| 1620 : | //Get x position | ||
| 1621 : | return $this->x; | ||
| 1622 : | } | ||
| 1623 : | |||
| 1624 : | function SetX($x) | ||
| 1625 : | { | ||
| 1626 : | //Set x position | ||
| 1627 : | if($x >= 0) $this->x=$x; | ||
| 1628 : | else $this->x = $this->w + $x; | ||
| 1629 : | } | ||
| 1630 : | |||
| 1631 : | function GetY() | ||
| 1632 : | { | ||
| 1633 : | //Get y position | ||
| 1634 : | return $this->y; | ||
| 1635 : | } | ||
| 1636 : | |||
| 1637 : | function SetY($y) | ||
| 1638 : | { | ||
| 1639 : | //Set y position and reset x | ||
| 1640 : | $this->x=$this->lMargin; | ||
| 1641 : | if($y>=0) | ||
| 1642 : | $this->y=$y; | ||
| 1643 : | else | ||
| 1644 : | $this->y=$this->h+$y; | ||
| 1645 : | } | ||
| 1646 : | |||
| 1647 : | function SetXY($x,$y) | ||
| 1648 : | { | ||
| 1649 : | //Set x and y positions | ||
| 1650 : | $this->SetY($y); | ||
| 1651 : | $this->SetX($x); | ||
| 1652 : | } | ||
| 1653 : | |||
| 1654 : | function Output($name='',$dest='') | ||
| 1655 : | { | ||
| 1656 : | //Output PDF to some destination | ||
| 1657 : | global $_SERVER; | ||
| 1658 : | |||
| 1659 : | //Finish document if necessary | ||
| 1660 : | if($this->state < 3) $this->Close(); | ||
| 1661 : | //Normalize parameters | ||
| 1662 : | if(is_bool($dest)) $dest=$dest ? 'D' : 'F'; | ||
| 1663 : | $dest=strtoupper($dest); | ||
| 1664 : | if($dest=='') | ||
| 1665 : | { | ||
| 1666 : | if($name=='') | ||
| 1667 : | { | ||
| 1668 : | $name='doc.pdf'; | ||
| 1669 : | $dest='I'; | ||
| 1670 : | } | ||
| 1671 : | else | ||
| 1672 : | $dest='F'; | ||
| 1673 : | } | ||
| 1674 : | switch($dest) | ||
| 1675 : | { | ||
| 1676 : | case 'I': | ||
| 1677 : | //Send to standard output | ||
| 1678 : | if(isset($_SERVER['SERVER_NAME'])) | ||
| 1679 : | { | ||
| 1680 : | //We send to a browser | ||
| 1681 : | Header('Content-Type: application/pdf'); | ||
| 1682 : | if(headers_sent()) | ||
| 1683 : | $this->Error('Some data has already been output to browser, can\'t send PDF file'); | ||
| 1684 : | Header('Content-Length: '.strlen($this->buffer)); | ||
| 1685 : | Header('Content-disposition: inline; filename='.$name); | ||
| 1686 : | } | ||
| 1687 : | echo $this->buffer; | ||
| 1688 : | break; | ||
| 1689 : | case 'D': | ||
| 1690 : | //Download file | ||
| 1691 : | if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) | ||
| 1692 : | Header('Content-Type: application/force-download'); | ||
| 1693 : | else | ||
| 1694 : | Header('Content-Type: application/octet-stream'); | ||
| 1695 : | if(headers_sent()) | ||
| 1696 : | $this->Error('Some data has already been output to browser, can\'t send PDF file'); | ||
| 1697 : | Header('Content-Length: '.strlen($this->buffer)); | ||
| 1698 : | Header('Content-disposition: attachment; filename='.$name); | ||
| 1699 : | echo $this->buffer; | ||
| 1700 : | break; | ||
| 1701 : | case 'F': | ||
| 1702 : | //Save to local file | ||
| 1703 : | $f=fopen($name,'wb'); | ||
| 1704 : | if(!$f) $this->Error('Unable to create output file: '.$name); | ||
| 1705 : | fwrite($f,$this->buffer,strlen($this->buffer)); | ||
| 1706 : | fclose($f); | ||
| 1707 : | break; | ||
| 1708 : | case 'S': | ||
| 1709 : | //Return as a string | ||
| 1710 : | return $this->buffer; | ||
| 1711 : | default: | ||
| 1712 : | $this->Error('Incorrect output destination: '.$dest); | ||
| 1713 : | } | ||
| 1714 : | return ''; | ||
| 1715 : | } | ||
| 1716 : | |||
| 1717 : | /******************************************************************************* | ||
| 1718 : | * * | ||
| 1719 : | * Protected methods * | ||
| 1720 : | * * | ||
| 1721 : | *******************************************************************************/ | ||
| 1722 : | function _dochecks() | ||
| 1723 : | { | ||
| 1724 : | //Check for locale-related bug | ||
| 1725 : | if(1.1==1) | ||
| 1726 : | $this->Error('Don\'t alter the locale before including class file'); | ||
| 1727 : | //Check for decimal separator | ||
| 1728 : | if(sprintf('%.1f',1.0)!='1.0') | ||
| 1729 : | setlocale(LC_NUMERIC,'C'); | ||
| 1730 : | } | ||
| 1731 : | |||
| 1732 : | function _begindoc() | ||
| 1733 : | { | ||
| 1734 : | //Start document | ||
| 1735 : | $this->state=1; | ||
| 1736 : | $this->_out('%PDF-1.3'); | ||
| 1737 : | } | ||
| 1738 : | |||
| 1739 : | function _putpages() | ||
| 1740 : | { | ||
| 1741 : | $nb=$this->page; | ||
| 1742 : | if(!empty($this->AliasNbPages)) | ||
| 1743 : | { | ||
| 1744 : | //Replace number of pages | ||
| 1745 : | for($n=1;$n<=$nb;$n++) | ||
| 1746 : | $this->pages[$n]=str_replace($this->AliasNbPages,$nb,$this->pages[$n]); | ||
| 1747 : | } | ||
| 1748 : | if($this->DefOrientation=='P') | ||
| 1749 : | { | ||
| 1750 : | $wPt=$this->fwPt; | ||
| 1751 : | $hPt=$this->fhPt; | ||
| 1752 : | } | ||
| 1753 : | else | ||
| 1754 : | { | ||
| 1755 : | $wPt=$this->fhPt; | ||
| 1756 : | $hPt=$this->fwPt; | ||
| 1757 : | } | ||
| 1758 : | $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; | ||
| 1759 : | for($n=1;$n<=$nb;$n++) | ||
| 1760 : | { | ||
| 1761 : | //Page | ||
| 1762 : | $this->_newobj(); | ||
| 1763 : | $this->_out('<</Type /Page'); | ||
| 1764 : | $this->_out('/Parent 1 0 R'); | ||
| 1765 : | if(isset($this->OrientationChanges[$n])) | ||
| 1766 : | $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt)); | ||
| 1767 : | $this->_out('/Resources 2 0 R'); | ||
| 1768 : | if(isset($this->PageLinks[$n])) | ||
| 1769 : | { | ||
| 1770 : | //Links | ||
| 1771 : | $annots='/Annots ['; | ||
| 1772 : | foreach($this->PageLinks[$n] as $pl) | ||
| 1773 : | { | ||
| 1774 : | $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); | ||
| 1775 : | $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; | ||
| 1776 : | if(is_string($pl[4])) | ||
| 1777 : | $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; | ||
| 1778 : | else | ||
| 1779 : | { | ||
| 1780 : | $l=$this->links[$pl[4]]; | ||
| 1781 : | $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; | ||
| 1782 : | $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k); | ||
| 1783 : | } | ||
| 1784 : | } | ||
| 1785 : | $this->_out($annots.']'); | ||
| 1786 : | } | ||
| 1787 : | $this->_out('/Contents '.($this->n+1).' 0 R>>'); | ||
| 1788 : | $this->_out('endobj'); | ||
| 1789 : | //Page content | ||
| 1790 : | $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; | ||
| 1791 : | $this->_newobj(); | ||
| 1792 : | $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); | ||
| 1793 : | $this->_putstream($p); | ||
| 1794 : | $this->_out('endobj'); | ||
| 1795 : | } | ||
| 1796 : | //Pages root | ||
| 1797 : | $this->offsets[1]=strlen($this->buffer); | ||
| 1798 : | $this->_out('1 0 obj'); | ||
| 1799 : | $this->_out('<</Type /Pages'); | ||
| 1800 : | $kids='/Kids ['; | ||
| 1801 : | for($i=0;$i<$nb;$i++) | ||
| 1802 : | $kids.=(3+2*$i).' 0 R '; | ||
| 1803 : | $this->_out($kids.']'); | ||
| 1804 : | $this->_out('/Count '.$nb); | ||
| 1805 : | $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt)); | ||
| 1806 : | $this->_out('>>'); | ||
| 1807 : | $this->_out('endobj'); | ||
| 1808 : | } | ||
| 1809 : | |||
| 1810 : | function _putfonts() | ||
| 1811 : | { | ||
| 1812 : | $nf=$this->n; | ||
| 1813 : | foreach($this->diffs as $diff) | ||
| 1814 : | { | ||
| 1815 : | //Encodings | ||
| 1816 : | $this->_newobj(); | ||
| 1817 : | $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); | ||
| 1818 : | $this->_out('endobj'); | ||
| 1819 : | } | ||
| 1820 : | $mqr=get_magic_quotes_runtime(); | ||
| 1821 : | set_magic_quotes_runtime(0); | ||
| 1822 : | foreach($this->FontFiles as $file=>$info) | ||
| 1823 : | { | ||
| 1824 : | //Font file embedding | ||
| 1825 : | $this->_newobj(); | ||
| 1826 : | $this->FontFiles[$file]['n']=$this->n; | ||
| 1827 : | if(defined('FPDF_FONTPATH')) | ||
| 1828 : | $file=FPDF_FONTPATH.$file; | ||
| 1829 : | $size=filesize($file); | ||
| 1830 : | if(!$size) | ||
| 1831 : | $this->Error('Font file not found'); | ||
| 1832 : | $this->_out('<</Length '.$size); | ||
| 1833 : | if(substr($file,-2)=='.z') | ||
| 1834 : | $this->_out('/Filter /FlateDecode'); | ||
| 1835 : | $this->_out('/Length1 '.$info['length1']); | ||
| 1836 : | if(isset($info['length2'])) | ||
| 1837 : | $this->_out('/Length2 '.$info['length2'].' /Length3 0'); | ||
| 1838 : | $this->_out('>>'); | ||
| 1839 : | $f=fopen($file,'rb'); | ||
| 1840 : | $this->_putstream(fread($f,$size)); | ||
| 1841 : | fclose($f); | ||
| 1842 : | $this->_out('endobj'); | ||
| 1843 : | } | ||
| 1844 : | set_magic_quotes_runtime($mqr); | ||
| 1845 : | foreach($this->fonts as $k=>$font) | ||
| 1846 : | { | ||
| 1847 : | //Font objects | ||
| 1848 : | $this->fonts[$k]['n']=$this->n+1; | ||
| 1849 : | $type=$font['type']; | ||
| 1850 : | $name=$font['name']; | ||
| 1851 : | if($type=='core') | ||
| 1852 : | { | ||
| 1853 : | //Standard font | ||
| 1854 : | $this->_newobj(); | ||
| 1855 : | $this->_out('<</Type /Font'); | ||
| 1856 : | $this->_out('/BaseFont /'.$name); | ||
| 1857 : | $this->_out('/Subtype /Type1'); | ||
| 1858 : | if($name!='Symbol' and $name!='ZapfDingbats') | ||
| 1859 : | $this->_out('/Encoding /WinAnsiEncoding'); | ||
| 1860 : | $this->_out('>>'); | ||
| 1861 : | $this->_out('endobj'); | ||
| 1862 : | } | ||
| 1863 : | elseif($type=='Type1' or $type=='TrueType') | ||
| 1864 : | { | ||
| 1865 : | //Additional Type1 or TrueType font | ||
| 1866 : | $this->_newobj(); | ||
| 1867 : | $this->_out('<</Type /Font'); | ||
| 1868 : | $this->_out('/BaseFont /'.$name); | ||
| 1869 : | $this->_out('/Subtype /'.$type); | ||
| 1870 : | $this->_out('/FirstChar 32 /LastChar 255'); | ||
| 1871 : | $this->_out('/Widths '.($this->n+1).' 0 R'); | ||
| 1872 : | $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); | ||
| 1873 : | if($font['enc']) | ||
| 1874 : | { | ||
| 1875 : | if(isset($font['diff'])) | ||
| 1876 : | $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); | ||
| 1877 : | else | ||
| 1878 : | $this->_out('/Encoding /WinAnsiEncoding'); | ||
| 1879 : | } | ||
| 1880 : | $this->_out('>>'); | ||
| 1881 : | $this->_out('endobj'); | ||
| 1882 : | //Widths | ||
| 1883 : | $this->_newobj(); | ||
| 1884 : | $cw=&$font['cw']; | ||
| 1885 : | $s='['; | ||
| 1886 : | for($i=32;$i<=255;$i++) | ||
| 1887 : | $s.=$cw[chr($i)].' '; | ||
| 1888 : | $this->_out($s.']'); | ||
| 1889 : | $this->_out('endobj'); | ||
| 1890 : | //Descriptor | ||
| 1891 : | $this->_newobj(); | ||
| 1892 : | $s='<</Type /FontDescriptor /FontName /'.$name; | ||
| 1893 : | foreach($font['desc'] as $k=>$v) | ||
| 1894 : | $s.=' /'.$k.' '.$v; | ||
| 1895 : | $file=$font['file']; | ||
| 1896 : | if($file) | ||
| 1897 : | $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; | ||
| 1898 : | $this->_out($s.'>>'); | ||
| 1899 : | $this->_out('endobj'); | ||
| 1900 : | } | ||
| 1901 : | else | ||
| 1902 : | { | ||
| 1903 : | //Allow for additional types | ||
| 1904 : | $mtd='_put'.strtolower($type); | ||
| 1905 : | if(!method_exists($this,$mtd)) | ||
| 1906 : | $this->Error('Unsupported font type: '.$type); | ||
| 1907 : | $this->$mtd($font); | ||
| 1908 : | } | ||
| 1909 : | } | ||
| 1910 : | } | ||
| 1911 : | |||
| 1912 : | function _putimages() | ||
| 1913 : | { | ||
| 1914 : | $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; | ||
| 1915 : | reset($this->images); | ||
| 1916 : | while(list($file,$info)=each($this->images)) | ||
| 1917 : | { | ||
| 1918 : | $this->_newobj(); | ||
| 1919 : | $this->images[$file]['n']=$this->n; | ||
| 1920 : | $this->_out('<</Type /XObject'); | ||
| 1921 : | $this->_out('/Subtype /Image'); | ||
| 1922 : | $this->_out('/Width '.$info['w']); | ||
| 1923 : | $this->_out('/Height '.$info['h']); | ||
| 1924 : | if($info['cs']=='Indexed') | ||
| 1925 : | $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); | ||
| 1926 : | else | ||
| 1927 : | { | ||
| 1928 : | $this->_out('/ColorSpace /'.$info['cs']); | ||
| 1929 : | if($info['cs']=='DeviceCMYK') | ||
| 1930 : | $this->_out('/Decode [1 0 1 0 1 0 1 0]'); | ||
| 1931 : | } | ||
| 1932 : | $this->_out('/BitsPerComponent '.$info['bpc']); | ||
| 1933 : | $this->_out('/Filter /'.$info['f']); | ||
| 1934 : | if(isset($info['parms'])) | ||
| 1935 : | $this->_out($info['parms']); | ||
| 1936 : | if(isset($info['trns']) and is_array($info['trns'])) | ||
| 1937 : | { | ||
| 1938 : | $trns=''; | ||
| 1939 : | for($i=0;$i<count($info['trns']);$i++) | ||
| 1940 : | $trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; | ||
| 1941 : | $this->_out('/Mask ['.$trns.']'); | ||
| 1942 : | } | ||
| 1943 : | $this->_out('/Length '.strlen($info['data']).'>>'); | ||
| 1944 : | $this->_putstream($info['data']); | ||
| 1945 : | unset($this->images[$file]['data']); | ||
| 1946 : | $this->_out('endobj'); | ||
| 1947 : | //Palette | ||
| 1948 : | if($info['cs']=='Indexed') | ||
| 1949 : | { | ||
| 1950 : | $this->_newobj(); | ||
| 1951 : | $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal']; | ||
| 1952 : | $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); | ||
| 1953 : | $this->_putstream($pal); | ||
| 1954 : | $this->_out('endobj'); | ||
| 1955 : | } | ||
| 1956 : | } | ||
| 1957 : | } | ||
| 1958 : | |||
| 1959 : | function _putresources() | ||
| 1960 : | { | ||
| 1961 : | $this->_putfonts(); | ||
| 1962 : | $this->_putimages(); | ||
| 1963 : | //Resource dictionary | ||
| 1964 : | $this->offsets[2]=strlen($this->buffer); | ||
| 1965 : | $this->_out('2 0 obj'); | ||
| 1966 : | $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); | ||
| 1967 : | $this->_out('/Font <<'); | ||
| 1968 : | foreach($this->fonts as $font) | ||
| 1969 : | $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); | ||
| 1970 : | $this->_out('>>'); | ||
| 1971 : | if(count($this->images)) | ||
| 1972 : | { | ||
| 1973 : | $this->_out('/XObject <<'); | ||
| 1974 : | foreach($this->images as $image) | ||
| 1975 : | $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); | ||
| 1976 : | $this->_out('>>'); | ||
| 1977 : | } | ||
| 1978 : | $this->_out('>>'); | ||
| 1979 : | $this->_out('endobj'); | ||
| 1980 : | $this->_putbookmarks(); //EDITEI | ||
| 1981 : | } | ||
| 1982 : | |||
| 1983 : | function _putinfo() | ||
| 1984 : | { | ||
| 1985 : | $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); | ||
| 1986 : | if(!empty($this->title)) | ||
| 1987 : | $this->_out('/Title '.$this->_textstring($this->title)); | ||
| 1988 : | if(!empty($this->subject)) | ||
| 1989 : | $this->_out('/Subject '.$this->_textstring($this->subject)); | ||
| 1990 : | if(!empty($this->author)) | ||
| 1991 : | $this->_out('/Author '.$this->_textstring($this->author)); | ||
| 1992 : | if(!empty($this->keywords)) | ||
| 1993 : | $this->_out('/Keywords '.$this->_textstring($this->keywords)); | ||
| 1994 : | if(!empty($this->creator)) | ||
| 1995 : | $this->_out('/Creator '.$this->_textstring($this->creator)); | ||
| 1996 : | $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); | ||
| 1997 : | } | ||
| 1998 : | |||
| 1999 : | function _putcatalog() | ||
| 2000 : | { | ||
| 2001 : | $this->_out('/Type /Catalog'); | ||
| 2002 : | $this->_out('/Pages 1 0 R'); | ||
| 2003 : | if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]'); | ||
| 2004 : | elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]'); | ||
| 2005 : | elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); | ||
| 2006 : | elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); | ||
| 2007 : | if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage'); | ||
| 2008 : | elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn'); | ||
| 2009 : | elseif($this->LayoutMode=='two') $this->_out('/PageLayout /TwoColumnLeft'); | ||
| 2010 : | //EDITEI - added lines below | ||
| 2011 : | if(count($this->outlines)>0) | ||
| 2012 : | { | ||
| 2013 : | $this->_out('/Outlines '.$this->OutlineRoot.' 0 R'); | ||
| 2014 : | $this->_out('/PageMode /UseOutlines'); | ||
| 2015 : | } | ||
| 2016 : | if(is_int(strpos($this->DisplayPreferences,'FullScreen'))) $this->_out('/PageMode /FullScreen'); | ||
| 2017 : | if($this->DisplayPreferences) | ||
| 2018 : | { | ||
| 2019 : | $this->_out('/ViewerPreferences<<'); | ||
| 2020 : | if(is_int(strpos($this->DisplayPreferences,'HideMenubar'))) $this->_out('/HideMenubar true'); | ||
| 2021 : | if(is_int(strpos($this->DisplayPreferences,'HideToolbar'))) $this->_out('/HideToolbar true'); | ||
| 2022 : | if(is_int(strpos($this->DisplayPreferences,'HideWindowUI'))) $this->_out('/HideWindowUI true'); | ||
| 2023 : | if(is_int(strpos($this->DisplayPreferences,'DisplayDocTitle'))) $this->_out('/DisplayDocTitle true'); | ||
| 2024 : | if(is_int(strpos($this->DisplayPreferences,'CenterWindow'))) $this->_out('/CenterWindow true'); | ||
| 2025 : | if(is_int(strpos($this->DisplayPreferences,'FitWindow'))) $this->_out('/FitWindow true'); | ||
| 2026 : | $this->_out('>>'); | ||
| 2027 : | } | ||
| 2028 : | } | ||
| 2029 : | |||
| 2030 : | function _puttrailer() | ||
| 2031 : | { | ||
| 2032 : | $this->_out('/Size '.($this->n+1)); | ||
| 2033 : | $this->_out('/Root '.$this->n.' 0 R'); | ||
| 2034 : | $this->_out('/Info '.($this->n-1).' 0 R'); | ||
| 2035 : | } | ||
| 2036 : | |||
| 2037 : | function _enddoc() | ||
| 2038 : | { | ||
| 2039 : | $this->_putpages(); | ||
| 2040 : | $this->_putresources(); | ||
| 2041 : | //Info | ||
| 2042 : | $this->_newobj(); | ||
| 2043 : | $this->_out('<<'); | ||
| 2044 : | $this->_putinfo(); | ||
| 2045 : | $this->_out('>>'); | ||
| 2046 : | $this->_out('endobj'); | ||
| 2047 : | //Catalog | ||
| 2048 : | $this->_newobj(); | ||
| 2049 : | $this->_out('<<'); | ||
| 2050 : | $this->_putcatalog(); | ||
| 2051 : | $this->_out('>>'); | ||
| 2052 : | $this->_out('endobj'); | ||
| 2053 : | //Cross-ref | ||
| 2054 : | $o=strlen($this->buffer); | ||
| 2055 : | $this->_out('xref'); | ||
| 2056 : | $this->_out('0 '.($this->n+1)); | ||
| 2057 : | $this->_out('0000000000 65535 f '); | ||
| 2058 : | for($i=1; $i <= $this->n ; $i++) | ||
| 2059 : | $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); | ||
| 2060 : | //Trailer | ||
| 2061 : | $this->_out('trailer'); | ||
| 2062 : | $this->_out('<<'); | ||
| 2063 : | $this->_puttrailer(); | ||
| 2064 : | $this->_out('>>'); | ||
| 2065 : | $this->_out('startxref'); | ||
| 2066 : | $this->_out($o); | ||
| 2067 : | $this->_out('%%EOF'); | ||
| 2068 : | $this->state=3; | ||
| 2069 : | } | ||
| 2070 : | |||
| 2071 : | function _beginpage($orientation) | ||
| 2072 : | { | ||
| 2073 : | $this->page++; | ||
| 2074 : | $this->pages[$this->page]=''; | ||
| 2075 : | $this->state=2; | ||
| 2076 : | $this->x=$this->lMargin; | ||
| 2077 : | $this->y=$this->tMargin; | ||
| 2078 : | $this->FontFamily=''; | ||
| 2079 : | //Page orientation | ||
| 2080 : | if(!$orientation) | ||
| 2081 : | $orientation=$this->DefOrientation; | ||
| 2082 : | else | ||
| 2083 : | { | ||
| 2084 : | $orientation=strtoupper($orientation{0}); | ||
| 2085 : | if($orientation!=$this->DefOrientation) | ||
| 2086 : | $this->OrientationChanges[$this->page]=true; | ||
| 2087 : | } | ||
| 2088 : | if($orientation!=$this->CurOrientation) | ||
| 2089 : | { | ||
| 2090 : | //Change orientation | ||
| 2091 : | if($orientation=='P') | ||
| 2092 : | { | ||
| 2093 : | $this->wPt=$this->fwPt; | ||
| 2094 : | $this->hPt=$this->fhPt; | ||
| 2095 : | $this->w=$this->fw; | ||
| 2096 : | $this->h=$this->fh; | ||
| 2097 : | } | ||
| 2098 : | else | ||
| 2099 : | { | ||
| 2100 : | $this->wPt=$this->fhPt; | ||
| 2101 : | $this->hPt=$this->fwPt; | ||
| 2102 : | $this->w=$this->fh; | ||
| 2103 : | $this->h=$this->fw; | ||
| 2104 : | } | ||
| 2105 : | $this->PageBreakTrigger=$this->h-$this->bMargin; | ||
| 2106 : | $this->CurOrientation=$orientation; | ||
| 2107 : | } | ||
| 2108 : | } | ||
| 2109 : | |||
| 2110 : | function _endpage() | ||
| 2111 : | { | ||
| 2112 : | //End of page contents | ||
| 2113 : | $this->state=1; | ||
| 2114 : | } | ||
| 2115 : | |||
| 2116 : | function _newobj() | ||
| 2117 : | { | ||
| 2118 : | //Begin a new object | ||
| 2119 : | $this->n++; | ||
| 2120 : | $this->offsets[$this->n]=strlen($this->buffer); | ||
| 2121 : | $this->_out($this->n.' 0 obj'); | ||
| 2122 : | } | ||
| 2123 : | |||
| 2124 : | function _dounderline($x,$y,$txt) | ||
| 2125 : | { | ||
| 2126 : | //Underline text | ||
| 2127 : | $up=$this->CurrentFont['up']; | ||
| 2128 : | $ut=$this->CurrentFont['ut']; | ||
| 2129 : | $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); | ||
| 2130 : | return sprintf('%.2f %.2f %.2f %.2f re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); | ||
| 2131 : | } | ||
| 2132 : | |||
| 2133 : | function _parsejpg($file) | ||
| 2134 : | { | ||
| 2135 : | //Extract info from a JPEG file | ||
| 2136 : | $a=GetImageSize($file); | ||
| 2137 : | if(!$a) | ||
| 2138 : | $this->Error('Missing or incorrect image file: '.$file); | ||
| 2139 : | if($a[2]!=2) | ||
| 2140 : | $this->Error('Not a JPEG file: '.$file); | ||
| 2141 : | if(!isset($a['channels']) or $a['channels']==3) | ||
| 2142 : | $colspace='DeviceRGB'; | ||
| 2143 : | elseif($a['channels']==4) | ||
| 2144 : | $colspace='DeviceCMYK'; | ||
| 2145 : | else | ||
| 2146 : | $colspace='DeviceGray'; | ||
| 2147 : | $bpc=isset($a['bits']) ? $a['bits'] : 8; | ||
| 2148 : | //Read whole file | ||
| 2149 : | $f=fopen($file,'rb'); | ||
| 2150 : | $data=''; | ||
| 2151 : | while(!feof($f)) | ||
| 2152 : | $data.=fread($f,4096); | ||
| 2153 : | fclose($f); | ||
| 2154 : | return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); | ||
| 2155 : | } | ||
| 2156 : | |||
| 2157 : | function _parsepng($file) | ||
| 2158 : | { | ||
| 2159 : | //Extract info from a PNG file | ||
| 2160 : | $f=fopen($file,'rb'); | ||
| 2161 : | //Extract info from a PNG file | ||
| 2162 : | if(!$f) $this->Error('Can\'t open image file: '.$file); | ||
| 2163 : | //Check signature | ||
| 2164 : | if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) | ||
| 2165 : | $this->Error('Not a PNG file: '.$file); | ||
| 2166 : | //Read header chunk | ||
| 2167 : | fread($f,4); | ||
| 2168 : | if(fread($f,4)!='IHDR') $this->Error('Incorrect PNG file: '.$file); | ||
| 2169 : | $w=$this->_freadint($f); | ||
| 2170 : | $h=$this->_freadint($f); | ||
| 2171 : | $bpc=ord(fread($f,1)); | ||
| 2172 : | if($bpc>8) $this->Error('16-bit depth not supported: '.$file); | ||
| 2173 : | $ct=ord(fread($f,1)); | ||
| 2174 : | if($ct==0) $colspace='DeviceGray'; | ||
| 2175 : | elseif($ct==2) $colspace='DeviceRGB'; | ||
| 2176 : | elseif($ct==3) $colspace='Indexed'; | ||
| 2177 : | else $this->Error('Alpha channel not supported: '.$file); | ||
| 2178 : | if(ord(fread($f,1))!=0) $this->Error('Unknown compression method: '.$file); | ||
| 2179 : | if(ord(fread($f,1))!=0) $this->Error('Unknown filter method: '.$file); | ||
| 2180 : | if(ord(fread($f,1))!=0) $this->Error('Interlacing not supported: '.$file); | ||
| 2181 : | fread($f,4); | ||
| 2182 : | $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; | ||
| 2183 : | //Scan chunks looking for palette, transparency and image data | ||
| 2184 : | $pal=''; | ||
| 2185 : | $trns=''; | ||
| 2186 : | $data=''; | ||
| 2187 : | do | ||
| 2188 : | { | ||
| 2189 : | $n=$this->_freadint($f); | ||
| 2190 : | $type=fread($f,4); | ||
| 2191 : | if($type=='PLTE') | ||
| 2192 : | { | ||
| 2193 : | //Read palette | ||
| 2194 : | $pal=fread($f,$n); | ||
| 2195 : | fread($f,4); | ||
| 2196 : | } | ||
| 2197 : | elseif($type=='tRNS') | ||
| 2198 : | { | ||
| 2199 : | //Read transparency info | ||
| 2200 : | $t=fread($f,$n); | ||
| 2201 : | if($ct==0) $trns=array(ord(substr($t,1,1))); | ||
| 2202 : | elseif($ct==2) $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); | ||
| 2203 : | else | ||
| 2204 : | { | ||
| 2205 : | $pos=strpos($t,chr(0)); | ||
| 2206 : | if(is_int($pos)) $trns=array($pos); | ||
| 2207 : | } | ||
| 2208 : | fread($f,4); | ||
| 2209 : | } | ||
| 2210 : | elseif($type=='IDAT') | ||
| 2211 : | { | ||
| 2212 : | //Read image data block | ||
| 2213 : | $data.=fread($f,$n); | ||
| 2214 : | fread($f,4); | ||
| 2215 : | } | ||
| 2216 : | elseif($type=='IEND') break; | ||
| 2217 : | else fread($f,$n+4); | ||
| 2218 : | } | ||
| 2219 : | while($n); | ||
| 2220 : | if($colspace=='Indexed' and empty($pal)) $this->Error('Missing palette in '.$file); | ||
| 2221 : | fclose($f); | ||
| 2222 : | return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); | ||
| 2223 : | } | ||
| 2224 : | |||
| 2225 : | function _parsegif($file) //EDITEI - GIF support is now included | ||
| 2226 : | { | ||
| 2227 : | //Function by J�r�me Fenal | ||
| 2228 : | require_once(RELATIVE_PATH.'gif.php'); //GIF class in pure PHP from Yamasoft (http://www.yamasoft.com/php-gif.zip) | ||
| 2229 : | |||
| 2230 : | $h=0; | ||
| 2231 : | $w=0; | ||
| 2232 : | $gif=new CGIF(); | ||
| 2233 : | |||
| 2234 : | if (!$gif->loadFile($file, 0)) | ||
| 2235 : | $this->Error("GIF parser: unable to open file $file"); | ||
| 2236 : | |||
| 2237 : | if($gif->m_img->m_gih->m_bLocalClr) { | ||
| 2238 : | $nColors = $gif->m_img->m_gih->m_nTableSize; | ||
| 2239 : | $pal = $gif->m_img->m_gih->m_colorTable->toString(); | ||
| 2240 : | if($bgColor != -1) { | ||
| 2241 : | $bgColor = $this->m_img->m_gih->m_colorTable->colorIndex($bgColor); | ||
| 2242 : | } | ||
| 2243 : | $colspace='Indexed'; | ||
| 2244 : | } elseif($gif->m_gfh->m_bGlobalClr) { | ||
| 2245 : | $nColors = $gif->m_gfh->m_nTableSize; | ||
| 2246 : | $pal = $gif->m_gfh->m_colorTable->toString(); | ||
| 2247 : | if((isset($bgColor)) and $bgColor != -1) { | ||
| 2248 : | $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor); | ||
| 2249 : | } | ||
| 2250 : | $colspace='Indexed'; | ||
| 2251 : | } else { | ||
| 2252 : | $nColors = 0; | ||
| 2253 : | $bgColor = -1; | ||
| 2254 : | $colspace='DeviceGray'; | ||
| 2255 : | $pal=''; | ||
| 2256 : | } | ||
| 2257 : | |||
| 2258 : | $trns=''; | ||
| 2259 : | if($gif->m_img->m_bTrans && ($nColors > 0)) { | ||
| 2260 : | $trns=array($gif->m_img->m_nTrans); | ||
| 2261 : | } | ||
| 2262 : | |||
| 2263 : | $data=$gif->m_img->m_data; | ||
| 2264 : | $w=$gif->m_gfh->m_nWidth; | ||
| 2265 : | $h=$gif->m_gfh->m_nHeight; | ||
| 2266 : | |||
| 2267 : | if($colspace=='Indexed' and empty($pal)) | ||
| 2268 : | $this->Error('Missing palette in '.$file); | ||
| 2269 : | |||
| 2270 : | if ($this->compress) { | ||
| 2271 : | $data=gzcompress($data); | ||
| 2272 : | return array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data); | ||
| 2273 : | } else { | ||
| 2274 : | return array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data); | ||
| 2275 : | } | ||
| 2276 : | } | ||
| 2277 : | |||
| 2278 : | function _freadint($f) | ||
| 2279 : | { | ||
| 2280 : | //Read a 4-byte integer from file | ||
| 2281 : | $i=ord(fread($f,1))<<24; | ||
| 2282 : | $i+=ord(fread($f,1))<<16; | ||
| 2283 : | $i+=ord(fread($f,1))<<8; | ||
| 2284 : | $i+=ord(fread($f,1)); | ||
| 2285 : | return $i; | ||
| 2286 : | } | ||
| 2287 : | |||
| 2288 : | function _textstring($s) | ||
| 2289 : | { | ||
| 2290 : | //Format a text string | ||
| 2291 : | return '('.$this->_escape($s).')'; | ||
| 2292 : | } | ||
| 2293 : | |||
| 2294 : | function _escape($s) | ||
| 2295 : | { | ||
| 2296 : | //Add \ before \, ( and ) | ||
| 2297 : | return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); | ||
| 2298 : | } | ||
| 2299 : | |||
| 2300 : | function _putstream($s) | ||
| 2301 : | { | ||
| 2302 : | $this->_out('stream'); | ||
| 2303 : | $this->_out($s); | ||
| 2304 : | $this->_out('endstream'); | ||
| 2305 : | } | ||
| 2306 : | |||
| 2307 : | function _out($s) | ||
| 2308 : | { | ||
| 2309 : | //Add a line to the document | ||
| 2310 : | if($this->state==2) $this->pages[$this->page] .= $s."\n"; | ||
| 2311 : | else $this->buffer .= $s."\n"; | ||
| 2312 : | } | ||
| 2313 : | |||
| 2314 : | |||
| 2315 : | }//End of class | ||
| 2316 : | |||
| 2317 : | //Handle special IE contype request | ||
| 2318 : | if(isset($_SERVER['HTTP_USER_AGENT']) and $_SERVER['HTTP_USER_AGENT']=='contype') | ||
| 2319 : | { | ||
| 2320 : | Header('Content-Type: application/pdf'); | ||
| 2321 : | exit; | ||
| 2322 : | } | ||
| 2323 : | |||
| 2324 : | } //end of 'if(!class_exists('FPDF'))'' | ||
| 2325 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

