| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 //============================================================+ 3 // File name : tcpdf.php 4 // Begin : 2002-08-03 5 // Last Update : 2006-08-05 6 // Author : Nicola Asuni 7 // Version : 1.53.0.TC023_PHP4 8 // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html) 9 // 10 // Description : This is a PHP4 class for generating PDF files 11 // on-the-fly without requiring external 12 // extensions. 13 // 14 // IMPORTANT: 15 // This class is an extension and improvement of the public Domain 16 // FPDF class by Olivier Plathey (http://www.fpdf.org). 17 // 18 // Main changes by Nicola Asuni: 19 // PHP4 porting; 20 // UTF-8 Unicode support; 21 // code refactoring; 22 // source code clean up; 23 // code style and formatting; 24 // source code documentation using phpDocumentor (www.phpdoc.org); 25 // All ISO page formats were included; 26 // image scale factor; 27 // includes methods to parse and printsome XHTML code, supporting the following elements: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small; 28 // includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (http://www.mribti.com/barcode/) (require GD library: http://www.boutell.com/gd/); 29 // defines standard Header() and Footer() methods. 30 //============================================================+ 31 32 /** 33 * include configuration file 34 */ 35 require_once(dirname(__FILE__).'/config/tcpdf_config.php'); 36 37 38 /** 39 * TCPDF Class. 40 * @package com.tecnick.tcpdf 41 */ 42 43 /** 44 * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br> 45 * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br> 46 * <h3>TCPDF main changes from FPDF are:</h3><ul> 47 * <li>PHP4 porting</li> 48 * <li>UTF-8 Unicode support</li> 49 * <li>source code clean up</li> 50 * <li>code style and formatting</li> 51 * <li>source code documentation using phpDocumentor (www.phpdoc.org)</li> 52 * <li>All ISO page formats were included</li> 53 * <li>image scale factor</li> 54 * <li>includes methods to parse and printsome XHTML code, supporting the following elements: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small;</li> 55 * <li>includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (http://www.mribti.com/barcode/) (require GD library: http://www.boutell.com/gd/)</li> 56 * <li>defines standard Header() and Footer() methods.</li> 57 * </ul> 58 * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p> 59 * @name TCPDF 60 * @package com.tecnick.tcpdf 61 * @abstract Class for generating PDF files on-the-fly without requiring external extensions. 62 * @author Nicola Asuni 63 * @copyright 2004-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com 64 * @link http://tcpdf.sourceforge.net 65 * @license http://www.gnu.org/copyleft/lesser.html LGPL 66 @version 1.53.0.TC023_PHP4 67 */ 68 69 if(!class_exists('TCPDF')) { 70 /** 71 * define default PDF document producer 72 */ 73 define('PDF_PRODUCER','TCPDF 1.53.0.TC023_PHP4 (http://tcpdf.sourceforge.net)'); 74 75 /** 76 * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br> 77 * This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br> 78 * This version contains some changes: [porting to PHP4, support for UTF-8 Unicode, code style and formatting, php documentation (www.phpdoc.org), ISO page formats, minor improvements, image scale factor]<br> 79 * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br> 80 * To add your own TTF fonts please read /fonts/README.TXT 81 * @name TCPDF 82 * @package com.tecnick.tcpdf 83 * @version 1.53.0.TC023 84 * @author Nicola Asuni 85 * @link http://tcpdf.sourceforge.net 86 * @license http://www.gnu.org/copyleft/lesser.html LGPL 87 */ 88 class TCPDF { 89 //var properties 90 91 /** 92 * @var current page number 93 * @access protected 94 */ 95 var $page; 96 97 /** 98 * @var current object number 99 * @access protected 100 */ 101 var $n; 102 103 /** 104 * @var array of object offsets 105 * @access protected 106 */ 107 var $offsets; 108 109 /** 110 * @var buffer holding in-memory PDF 111 * @access protected 112 */ 113 var $buffer; 114 115 /** 116 * @var array containing pages 117 * @access protected 118 */ 119 var $pages; 120 121 /** 122 * @var current document state 123 * @access protected 124 */ 125 var $state; 126 127 /** 128 * @var compression flag 129 * @access protected 130 */ 131 var $compress; 132 133 /** 134 * @var default orientation 135 * @access protected 136 */ 137 var $DefOrientation; 138 139 /** 140 * @var current orientation 141 * @access protected 142 */ 143 var $CurOrientation; 144 145 /** 146 * @var array indicating orientation changes 147 * @access protected 148 */ 149 var $OrientationChanges; 150 151 /** 152 * @var scale factor (number of points in user unit) 153 * @access protected 154 */ 155 var $k; 156 157 /** 158 * @var width of page format in points 159 * @access protected 160 */ 161 var $fwPt; 162 163 /** 164 * @var height of page format in points 165 * @access protected 166 */ 167 var $fhPt; 168 169 /** 170 * @var width of page format in user unit 171 * @access protected 172 */ 173 var $fw; 174 175 /** 176 * @var height of page format in user unit 177 * @access protected 178 */ 179 var $fh; 180 181 /** 182 * @var current width of page in points 183 * @access protected 184 */ 185 var $wPt; 186 187 /** 188 * @var current height of page in points 189 * @access protected 190 */ 191 var $hPt; 192 193 /** 194 * @var current width of page in user unit 195 * @access protected 196 */ 197 var $w; 198 199 /** 200 * @var current height of page in user unit 201 * @access protected 202 */ 203 var $h; 204 205 /** 206 * @var left margin 207 * @access protected 208 */ 209 var $lMargin; 210 211 /** 212 * @var top margin 213 * @access protected 214 */ 215 var $tMargin; 216 217 /** 218 * @var right margin 219 * @access protected 220 */ 221 var $rMargin; 222 223 /** 224 * @var page break margin 225 * @access protected 226 */ 227 var $bMargin; 228 229 /** 230 * @var cell margin 231 * @access protected 232 */ 233 var $cMargin; 234 235 /** 236 * @var current horizontal position in user unit for cell positioning 237 * @access protected 238 */ 239 var $x; 240 241 /** 242 * @var current vertical position in user unit for cell positioning 243 * @access protected 244 */ 245 var $y; 246 247 /** 248 * @var height of last cell printed 249 * @access protected 250 */ 251 var $lasth; 252 253 /** 254 * @var line width in user unit 255 * @access protected 256 */ 257 var $LineWidth; 258 259 /** 260 * @var array of standard font names 261 * @access protected 262 */ 263 var $CoreFonts; 264 265 /** 266 * @var array of used fonts 267 * @access protected 268 */ 269 var $fonts; 270 271 /** 272 * @var array of font files 273 * @access protected 274 */ 275 var $FontFiles; 276 277 /** 278 * @var array of encoding differences 279 * @access protected 280 */ 281 var $diffs; 282 283 /** 284 * @var array of used images 285 * @access protected 286 */ 287 var $images; 288 289 /** 290 * @var array of links in pages 291 * @access protected 292 */ 293 var $PageLinks; 294 295 /** 296 * @var array of internal links 297 * @access protected 298 */ 299 var $links; 300 301 /** 302 * @var current font family 303 * @access protected 304 */ 305 var $FontFamily; 306 307 /** 308 * @var current font style 309 * @access protected 310 */ 311 var $FontStyle; 312 313 /** 314 * @var underlining flag 315 * @access protected 316 */ 317 var $underline; 318 319 /** 320 * @var current font info 321 * @access protected 322 */ 323 var $CurrentFont; 324 325 /** 326 * @var current font size in points 327 * @access protected 328 */ 329 var $FontSizePt; 330 331 /** 332 * @var current font size in user unit 333 * @access protected 334 */ 335 var $FontSize; 336 337 /** 338 * @var commands for drawing color 339 * @access protected 340 */ 341 var $DrawColor; 342 343 /** 344 * @var commands for filling color 345 * @access protected 346 */ 347 var $FillColor; 348 349 /** 350 * @var commands for text color 351 * @access protected 352 */ 353 var $TextColor; 354 355 /** 356 * @var indicates whether fill and text colors are different 357 * @access protected 358 */ 359 var $ColorFlag; 360 361 /** 362 * @var word spacing 363 * @access protected 364 */ 365 var $ws; 366 367 /** 368 * @var automatic page breaking 369 * @access protected 370 */ 371 var $AutoPageBreak; 372 373 /** 374 * @var threshold used to trigger page breaks 375 * @access protected 376 */ 377 var $PageBreakTrigger; 378 379 /** 380 * @var flag set when processing footer 381 * @access protected 382 */ 383 var $InFooter; 384 385 /** 386 * @var zoom display mode 387 * @access protected 388 */ 389 var $ZoomMode; 390 391 /** 392 * @var layout display mode 393 * @access protected 394 */ 395 var $LayoutMode; 396 397 /** 398 * @var title 399 * @access protected 400 */ 401 var $title; 402 403 /** 404 * @var subject 405 * @access protected 406 */ 407 var $subject; 408 409 /** 410 * @var author 411 * @access protected 412 */ 413 var $author; 414 415 /** 416 * @var keywords 417 * @access protected 418 */ 419 var $keywords; 420 421 /** 422 * @var creator 423 * @access protected 424 */ 425 var $creator; 426 427 /** 428 * @var alias for total number of pages 429 * @access protected 430 */ 431 var $AliasNbPages; 432 433 /** 434 * @var right-bottom corner X coordinate of inserted image 435 * @since 2002-07-31 436 * @author Nicola Asuni 437 * @access protected 438 */ 439 var $img_rb_x; 440 441 /** 442 * @var right-bottom corner Y coordinate of inserted image 443 * @since 2002-07-31 444 * @author Nicola Asuni 445 * @access protected 446 */ 447 var $img_rb_y; 448 449 /** 450 * @var image scale factor 451 * @since 2004-06-14 452 * @author Nicola Asuni 453 * @access protected 454 */ 455 var $imgscale = 1; 456 457 /** 458 * @var boolean set to true when the input text is unicode (require unicode fonts) 459 * @since 2005-01-02 460 * @author Nicola Asuni 461 * @access protected 462 */ 463 var $isunicode = false; 464 465 /** 466 * @var PDF version 467 * @since 1.5.3 468 * @access protected 469 */ 470 var $PDFVersion = "1.3"; 471 472 473 // ---------------------- 474 475 /** 476 * @var Minimum distance between header and top page margin. 477 * @access private 478 */ 479 var $header_margin; 480 481 /** 482 * @var Minimum distance between footer and bottom page margin. 483 * @access private 484 */ 485 var $footer_margin; 486 487 /** 488 * @var original left margin value 489 * @access private 490 * @since 1.53.0.TC013 491 */ 492 var $original_lMargin; 493 494 /** 495 * @var original right margin value 496 * @access private 497 * @since 1.53.0.TC013 498 */ 499 var $original_rMargin; 500 501 /** 502 * @var Header font. 503 * @access private 504 */ 505 var $header_font; 506 507 /** 508 * @var Footer font. 509 * @access private 510 */ 511 var $footer_font; 512 513 /** 514 * @var Language templates. 515 * @access private 516 */ 517 var $l; 518 519 /** 520 * @var Barcode to print on page footer (only if set). 521 * @access private 522 */ 523 var $barcode = false; 524 525 /** 526 * @var If true prints header 527 * @access private 528 */ 529 var $print_header = true; 530 531 /** 532 * @var If true prints footer. 533 * @access private 534 */ 535 var $print_footer = true; 536 537 /** 538 * @var Header width (0 = full page width). 539 * @access private 540 */ 541 var $header_width = 0; 542 543 /** 544 * @var Header image logo. 545 * @access private 546 */ 547 var $header_logo = ""; 548 549 /** 550 * @var Header image logo width in mm. 551 * @access private 552 */ 553 var $header_logo_width = 30; 554 555 /** 556 * @var String to print as title on document header. 557 * @access private 558 */ 559 var $header_title = ""; 560 561 /** 562 * @var String to print on document header. 563 * @access private 564 */ 565 var $header_string = ""; 566 567 /** 568 * @var Default number of columns for html table. 569 * @access private 570 */ 571 var $default_table_columns = 4; 572 573 574 // variables for html parser 575 576 /** 577 * @var HTML PARSER: store current link. 578 * @access private 579 */ 580 var $HREF; 581 582 /** 583 * @var HTML PARSER: store font list. 584 * @access private 585 */ 586 var $fontList; 587 588 /** 589 * @var HTML PARSER: true when font attribute is set. 590 * @access private 591 */ 592 var $issetfont; 593 594 /** 595 * @var HTML PARSER: true when color attribute is set. 596 * @access private 597 */ 598 var $issetcolor; 599 600 /** 601 * @var HTML PARSER: true in case of ordered list (OL), false otherwise. 602 * @access private 603 */ 604 var $listordered = false; 605 606 /** 607 * @var HTML PARSER: count list items. 608 * @access private 609 */ 610 var $listcount = 0; 611 612 /** 613 * @var HTML PARSER: size of table border. 614 * @access private 615 */ 616 var $tableborder = 0; 617 618 /** 619 * @var HTML PARSER: true at the beginning of table. 620 * @access private 621 */ 622 var $tdbegin = false; 623 624 /** 625 * @var HTML PARSER: table width. 626 * @access private 627 */ 628 var $tdwidth = 0; 629 630 /** 631 * @var HTML PARSER: table height. 632 * @access private 633 */ 634 var $tdheight = 0; 635 636 /** 637 * @var HTML PARSER: table align. 638 * @access private 639 */ 640 var $tdalign = "L"; 641 642 /** 643 * @var HTML PARSER: table background color. 644 * @access private 645 */ 646 var $tdbgcolor = false; 647 648 /** 649 * @var Store temporary font size in points. 650 * @access private 651 */ 652 var $tempfontsize = 10; 653 654 /** 655 * @var Bold font style status. 656 * @access private 657 */ 658 var $b; 659 660 /** 661 * @var Underlined font style status. 662 * @access private 663 */ 664 var $u; 665 666 /** 667 * @var Italic font style status. 668 * @access private 669 */ 670 var $i; 671 672 /** 673 * @var spacer for LI tags. 674 * @access private 675 */ 676 var $lispacer = ""; 677 678 /** 679 * @var default encoding 680 * @access private 681 * @since 1.53.0.TC010 682 */ 683 var $encoding = "UTF-8"; 684 685 /** 686 * @var PHP internal encoding 687 * @access private 688 * @since 1.53.0.TC016 689 */ 690 var $internal_encoding; 691 692 /** 693 * @var store previous fill color as RGB array 694 * @access private 695 * @since 1.53.0.TC017 696 */ 697 var $prevFillColor = array(255,255,255); 698 699 /** 700 * @var store previous text color as RGB array 701 * @access private 702 * @since 1.53.0.TC017 703 */ 704 var $prevTextColor = array(0,0,0); 705 706 /** 707 * @var store previous font family 708 * @access private 709 * @since 1.53.0.TC017 710 */ 711 var $prevFontFamily; 712 713 /** 714 * @var store previous font style 715 * @access private 716 * @since 1.53.0.TC017 717 */ 718 var $prevFontStyle; 719 720 //------------------------------------------------------------ 721 // var methods 722 //------------------------------------------------------------ 723 724 /** 725 * This is the class constructor. 726 * It allows to set up the page format, the orientation and 727 * the measure unit used in all the methods (except for the font sizes). 728 * @since 1.0 729 * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul> 730 * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit. 731 * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul> 732 * @param boolean $unicode TRUE means that the input text is unicode (default = true) 733 * @param String $encoding charset encoding; default is UTF-8 734 */ 735 function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") { 736 737 /* Set internal character encoding to ASCII */ 738 if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) { 739 $this->internal_encoding = mb_internal_encoding(); 740 mb_internal_encoding("ASCII"); 741 } 742 743 //Some checks 744 $this->_dochecks(); 745 //Initialization of properties 746 $this->isunicode=$unicode; 747 $this->page=0; 748 $this->n=2; 749 $this->buffer=''; 750 $this->pages=array(); 751 $this->OrientationChanges=array(); 752 $this->state=0; 753 $this->fonts=array(); 754 $this->FontFiles=array(); 755 $this->diffs=array(); 756 $this->images=array(); 757 $this->links=array(); 758 $this->InFooter=false; 759 $this->lasth=0; 760 $this->FontFamily=''; 761 $this->FontStyle=''; 762 $this->FontSizePt=12; 763 $this->underline=false; 764 $this->DrawColor='0 G'; 765 $this->FillColor='0 g'; 766 $this->TextColor='0 g'; 767 $this->ColorFlag=false; 768 $this->ws=0; 769 //Standard Unicode fonts 770 $this->CoreFonts=array( 771 'courier'=>'Courier', 772 'courierB'=>'Courier-Bold', 773 'courierI'=>'Courier-Oblique', 774 'courierBI'=>'Courier-BoldOblique', 775 'helvetica'=>'Helvetica', 776 'helveticaB'=>'Helvetica-Bold', 777 'helveticaI'=>'Helvetica-Oblique', 778 'helveticaBI'=>'Helvetica-BoldOblique', 779 'times'=>'Times-Roman', 780 'timesB'=>'Times-Bold', 781 'timesI'=>'Times-Italic', 782 'timesBI'=>'Times-BoldItalic', 783 'symbol'=>'Symbol', 784 'zapfdingbats'=>'ZapfDingbats' 785 ); 786 787 //Scale factor 788 // 2003-06-11 - Nicola Asuni : changed if/else with switch statement 789 switch (strtolower($unit)){ 790 case 'pt': {$this->k=1; break;} 791 case 'mm': {$this->k=72/25.4; break;} 792 case 'cm': {$this->k=72/2.54; break;} 793 case 'in': {$this->k=72; break;} 794 default : {$this->Error('Incorrect unit: '.$unit); break;} 795 } 796 797 //Page format 798 if(is_string($format)) { 799 // 2002-07-24 - Nicola Asuni (info@tecnick.com) 800 // Added new page formats (45 standard ISO paper formats and 4 american common formats). 801 // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm) 802 switch (strtoupper($format)){ 803 case '4A0': {$format = array(4767.87,6740.79); break;} 804 case '2A0': {$format = array(3370.39,4767.87); break;} 805 case 'A0': {$format = array(2383.94,3370.39); break;} 806 case 'A1': {$format = array(1683.78,2383.94); break;} 807 case 'A2': {$format = array(1190.55,1683.78); break;} 808 case 'A3': {$format = array(841.89,1190.55); break;} 809 case 'A4': default: {$format = array(595.28,841.89); break;} 810 case 'A5': {$format = array(419.53,595.28); break;} 811 case 'A6': {$format = array(297.64,419.53); break;} 812 case 'A7': {$format = array(209.76,297.64); break;} 813 case 'A8': {$format = array(147.40,209.76); break;} 814 case 'A9': {$format = array(104.88,147.40); break;} 815 case 'A10': {$format = array(73.70,104.88); break;} 816 case 'B0': {$format = array(2834.65,4008.19); break;} 817 case 'B1': {$format = array(2004.09,2834.65); break;} 818 case 'B2': {$format = array(1417.32,2004.09); break;} 819 case 'B3': {$format = array(1000.63,1417.32); break;} 820 case 'B4': {$format = array(708.66,1000.63); break;} 821 case 'B5': {$format = array(498.90,708.66); break;} 822 case 'B6': {$format = array(354.33,498.90); break;} 823 case 'B7': {$format = array(249.45,354.33); break;} 824 case 'B8': {$format = array(175.75,249.45); break;} 825 case 'B9': {$format = array(124.72,175.75); break;} 826 case 'B10': {$format = array(87.87,124.72); break;} 827 case 'C0': {$format = array(2599.37,3676.54); break;} 828 case 'C1': {$format = array(1836.85,2599.37); break;} 829 case 'C2': {$format = array(1298.27,1836.85); break;} 830 case 'C3': {$format = array(918.43,1298.27); break;} 831 case 'C4': {$format = array(649.13,918.43); break;} 832 case 'C5': {$format = array(459.21,649.13); break;} 833 case 'C6': {$format = array(323.15,459.21); break;} 834 case 'C7': {$format = array(229.61,323.15); break;} 835 case 'C8': {$format = array(161.57,229.61); break;} 836 case 'C9': {$format = array(113.39,161.57); break;} 837 case 'C10': {$format = array(79.37,113.39); break;} 838 case 'RA0': {$format = array(2437.80,3458.27); break;} 839 case 'RA1': {$format = array(1729.13,2437.80); break;} 840 case 'RA2': {$format = array(1218.90,1729.13); break;} 841 case 'RA3': {$format = array(864.57,1218.90); break;} 842 case 'RA4': {$format = array(609.45,864.57); break;} 843 case 'SRA0': {$format = array(2551.18,3628.35); break;} 844 case 'SRA1': {$format = array(1814.17,2551.18); break;} 845 case 'SRA2': {$format = array(1275.59,1814.17); break;} 846 case 'SRA3': {$format = array(907.09,1275.59); break;} 847 case 'SRA4': {$format = array(637.80,907.09); break;} 848 case 'LETTER': {$format = array(612.00,792.00); break;} 849 case 'LEGAL': {$format = array(612.00,1008.00); break;} 850 case 'EXECUTIVE': {$format = array(521.86,756.00); break;} 851 case 'FOLIO': {$format = array(612.00,936.00); break;} 852 // default: {$this->Error('Unknown page format: '.$format); break;} 853 // END CHANGES Nicola Asuni 854 } 855 $this->fwPt=$format[0]; 856 $this->fhPt=$format[1]; 857 } 858 else { 859 $this->fwPt=$format[0]*$this->k; 860 $this->fhPt=$format[1]*$this->k; 861 } 862 863 $this->fw=$this->fwPt/$this->k; 864 $this->fh=$this->fhPt/$this->k; 865 866 //Page orientation 867 $orientation=strtolower($orientation); 868 if($orientation=='p' or $orientation=='portrait') { 869 $this->DefOrientation='P'; 870 $this->wPt=$this->fwPt; 871 $this->hPt=$this->fhPt; 872 } 873 elseif($orientation=='l' or $orientation=='landscape') { 874 $this->DefOrientation='L'; 875 $this->wPt=$this->fhPt; 876 $this->hPt=$this->fwPt; 877 } 878 else { 879 $this->Error('Incorrect orientation: '.$orientation); 880 } 881 882 $this->CurOrientation=$this->DefOrientation; 883 $this->w=$this->wPt/$this->k; 884 $this->h=$this->hPt/$this->k; 885 //Page margins (1 cm) 886 $margin=28.35/$this->k; 887 $this->SetMargins($margin,$margin); 888 //Interior cell margin (1 mm) 889 $this->cMargin=$margin/10; 890 //Line width (0.2 mm) 891 $this->LineWidth=.567/$this->k; 892 //Automatic page break 893 $this->SetAutoPageBreak(true,2*$margin); 894 //Full width display mode 895 $this->SetDisplayMode('fullwidth'); 896 //Compression 897 $this->SetCompression(true); 898 //Set default PDF version number 899 $this->PDFVersion = "1.3"; 900 901 $this->encoding = $encoding; 902 $this->b = 0; 903 $this->i = 0; 904 $this->u = 0; 905 $this->HREF = ''; 906 $this->fontlist = array("arial", "times", "courier", "helvetica", "symbol"); 907 $this->issetfont = false; 908 $this->issetcolor = false; 909 $this->tableborder = 0; 910 $this->tdbegin = false; 911 $this->tdwidth= 0; 912 $this->tdheight = 0; 913 $this->tdalign = "L"; 914 $this->tdbgcolor = false; 915 916 $this->SetFillColor(200, 200, 200, true); 917 $this->SetTextColor(0, 0, 0, true); 918 } 919 920 /** 921 * Set the image scale. 922 * @param float $scale image scale. 923 * @author Nicola Asuni 924 * @since 1.5.2 925 */ 926 function setImageScale($scale) { 927 $this->imgscale=$scale; 928 } 929 930 /** 931 * Returns the image scale. 932 * @return float image scale. 933 * @author Nicola Asuni 934 * @since 1.5.2 935 */ 936 function getImageScale() { 937 return $this->imgscale; 938 } 939 940 /** 941 * Returns the page width in units. 942 * @return int page width. 943 * @author Nicola Asuni 944 * @since 1.5.2 945 */ 946 function getPageWidth() { 947 return $this->w; 948 } 949 950 /** 951 * Returns the page height in units. 952 * @return int page height. 953 * @author Nicola Asuni 954 * @since 1.5.2 955 */ 956 function getPageHeight() { 957 return $this->fh; 958 } 959 960 /** 961 * Returns the page break margin. 962 * @return int page break margin. 963 * @author Nicola Asuni 964 * @since 1.5.2 965 */ 966 function getBreakMargin() { 967 return $this->bMargin; 968 } 969 970 /** 971 * Returns the scale factor (number of points in user unit). 972 * @return int scale factor. 973 * @author Nicola Asuni 974 * @since 1.5.2 975 */ 976 function getScaleFactor() { 977 return $this->k; 978 } 979 980 /** 981 * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them. 982 * @param float $left Left margin. 983 * @param float $top Top margin. 984 * @param float $right Right margin. Default value is the left one. 985 * @since 1.0 986 * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak() 987 */ 988 function SetMargins($left, $top, $right=-1) { 989 //Set left, top and right margins 990 $this->lMargin=$left; 991 $this->tMargin=$top; 992 if($right==-1) { 993 $right=$left; 994 } 995 $this->rMargin=$right; 996 } 997 998 /** 999 * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin. 1000 * @param float $margin The margin. 1001 * @since 1.4 1002 * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins() 1003 */ 1004 function SetLeftMargin($margin) { 1005 //Set left margin 1006 $this->lMargin=$margin; 1007 if(($this->page>0) and ($this->x<$margin)) { 1008 $this->x=$margin; 1009 } 1010 } 1011 1012 /** 1013 * Defines the top margin. The method can be called before creating the first page. 1014 * @param float $margin The margin. 1015 * @since 1.5 1016 * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins() 1017 */ 1018 function SetTopMargin($margin) { 1019 //Set top margin 1020 $this->tMargin=$margin; 1021 } 1022 1023 /** 1024 * Defines the right margin. The method can be called before creating the first page. 1025 * @param float $margin The margin. 1026 * @since 1.5 1027 * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins() 1028 */ 1029 function SetRightMargin($margin) { 1030 //Set right margin 1031 $this->rMargin=$margin; 1032 } 1033 1034 /** 1035 * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm. 1036 * @param boolean $auto Boolean indicating if mode should be on or off. 1037 * @param float $margin Distance from the bottom of the page. 1038 * @since 1.0 1039 * @see Cell(), MultiCell(), AcceptPageBreak() 1040 */ 1041 function SetAutoPageBreak($auto, $margin=0) { 1042 //Set auto page break mode and triggering margin 1043 $this->AutoPageBreak=$auto; 1044 $this->bMargin=$margin; 1045 $this->PageBreakTrigger=$this->h-$margin; 1046 } 1047 1048 /** 1049 * Defines the way the document is to be displayed by the viewer. The zoom level can be set: pages can be displayed entirely on screen, occupy the full width of the window, use real size, be scaled by a specific zooming factor or use viewer default (configured in the Preferences menu of Acrobat). The page layout can be specified too: single at once, continuous display, two columns or viewer default. By default, documents use the full width mode with continuous display. 1050 * @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul> 1051 * @param string $layout The page layout. Possible values are:<ul><li>single: displays one page at once</li><li>continuous: displays pages continuously (default)</li><li>two: displays two pages on two columns</li><li>default: uses viewer default mode</li></ul> 1052 * @since 1.2 1053 */ 1054 function SetDisplayMode($zoom, $layout='continuous') { 1055 //Set display mode in viewer 1056 if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) { 1057 $this->ZoomMode=$zoom; 1058 } 1059 else { 1060 $this->Error('Incorrect zoom display mode: '.$zoom); 1061 } 1062 if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') { 1063 $this->LayoutMode=$layout; 1064 } 1065 else { 1066 $this->Error('Incorrect layout display mode: '.$layout); 1067 } 1068 } 1069 1070 /** 1071 * Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default. 1072 * Note: the Zlib extension is required for this feature. If not present, compression will be turned off. 1073 * @param boolean $compress Boolean indicating if compression must be enabled. 1074 * @since 1.4 1075 */ 1076 function SetCompression($compress) { 1077 //Set page compression 1078 if(function_exists('gzcompress')) { 1079 $this->compress=$compress; 1080 } 1081 else { 1082 $this->compress=false; 1083 } 1084 } 1085 1086 /** 1087 * Defines the title of the document. 1088 * @param string $title The title. 1089 * @since 1.2 1090 * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject() 1091 */ 1092 function SetTitle($title) { 1093 //Title of document 1094 $this->title=$title; 1095 } 1096 1097 /** 1098 * Defines the subject of the document. 1099 * @param string $subject The subject. 1100 * @since 1.2 1101 * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle() 1102 */ 1103 function SetSubject($subject) { 1104 //Subject of document 1105 $this->subject=$subject; 1106 } 1107 1108 /** 1109 * Defines the author of the document. 1110 * @param string $author The name of the author. 1111 * @since 1.2 1112 * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle() 1113 */ 1114 function SetAuthor($author) { 1115 //Author of document 1116 $this->author=$author; 1117 } 1118 1119 /** 1120 * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'. 1121 * @param string $keywords The list of keywords. 1122 * @since 1.2 1123 * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle() 1124 */ 1125 function SetKeywords($keywords) { 1126 //Keywords of document 1127 $this->keywords=$keywords; 1128 } 1129 1130 /** 1131 * Defines the creator of the document. This is typically the name of the application that generates the PDF. 1132 * @param string $creator The name of the creator. 1133 * @since 1.2 1134 * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle() 1135 */ 1136 function SetCreator($creator) { 1137 //Creator of document 1138 $this->creator=$creator; 1139 } 1140 1141 /** 1142 * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br /> 1143 * <b>Example:</b><br /> 1144 * <pre> 1145 * class PDF extends TCPDF { 1146 * function Footer() { 1147 * //Go to 1.5 cm from bottom 1148 * $this->SetY(-15); 1149 * //Select Arial italic 8 1150 * $this->SetFont('Arial','I',8); 1151 * //Print current and total page numbers 1152 * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 1153 * } 1154 * } 1155 * $pdf=new PDF(); 1156 * $pdf->AliasNbPages(); 1157 * </pre> 1158 * @param string $alias The alias. Default value: {nb}. 1159 * @since 1.4 1160 * @see PageNo(), Footer() 1161 */ 1162 function AliasNbPages($alias='{nb}') { 1163 //Define an alias for total number of pages 1164 $this->AliasNbPages = $this->_escapetext($alias); 1165 } 1166 1167 /** 1168 * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid. 1169 * 2004-06-11 :: Nicola Asuni : changed bold tag with strong 1170 * @param string $msg The error message 1171 * @since 1.0 1172 */ 1173 function Error($msg) { 1174 //Fatal error 1175 die('<strong>TCPDF error: </strong>'.$msg); 1176 } 1177 1178 /** 1179 * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically. 1180 * Note: no page is created by this method 1181 * @since 1.0 1182 * @see AddPage(), Close() 1183 */ 1184 function Open() { 1185 //Begin document 1186 $this->state=1; 1187 } 1188 1189 /** 1190 * Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document. 1191 * @since 1.0 1192 * @see Open(), Output() 1193 */ 1194 function Close() { 1195 //Terminate document 1196 if($this->state==3) { 1197 return; 1198 } 1199 if($this->page==0) { 1200 $this->AddPage(); 1201 } 1202 //Page footer 1203 $this->InFooter=true; 1204 $this->Footer(); 1205 $this->InFooter=false; 1206 //Close page 1207 $this->_endpage(); 1208 //Close document 1209 $this->_enddoc(); 1210 } 1211 1212 /** 1213 * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header. 1214 * The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width. 1215 * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards. 1216 * @param string $orientation Page orientation. Possible values are (case insensitive):<ul><li>P or Portrait</li><li>L or Landscape</li></ul> The default value is the one passed to the constructor. 1217 * @since 1.0 1218 * @see TCPDF(), Header(), Footer(), SetMargins() 1219 */ 1220 function AddPage($orientation='') { 1221 //Start a new page 1222 if($this->state==0) { 1223 $this->Open(); 1224 } 1225 $family=$this->FontFamily; 1226 $style=$this->FontStyle.($this->underline ? 'U' : ''); 1227 $size=$this->FontSizePt; 1228 $lw=$this->LineWidth; 1229 $dc=$this->DrawColor; 1230 $fc=$this->FillColor; 1231 $tc=$this->TextColor; 1232 $cf=$this->ColorFlag; 1233 if($this->page>0) { 1234 //Page footer 1235 $this->InFooter=true; 1236 $this->Footer(); 1237 $this->InFooter=false; 1238 //Close page 1239 $this->_endpage(); 1240 } 1241 //Start new page 1242 $this->_beginpage($orientation); 1243 //Set line cap style to square 1244 $this->_out('2 J'); 1245 //Set line width 1246 $this->LineWidth=$lw; 1247 $this->_out(sprintf('%.2f w',$lw*$this->k)); 1248 //Set font 1249 if($family) { 1250 $this->SetFont($family,$style,$size); 1251 } 1252 //Set colors 1253 $this->DrawColor=$dc; 1254 if($dc!='0 G') { 1255 $this->_out($dc); 1256 } 1257 $this->FillColor=$fc; 1258 if($fc!='0 g') { 1259 $this->_out($fc); 1260 } 1261 $this->TextColor=$tc; 1262 $this->ColorFlag=$cf; 1263 //Page header 1264 $this->Header(); 1265 //Restore line width 1266 if($this->LineWidth!=$lw) { 1267 $this->LineWidth=$lw; 1268 $this->_out(sprintf('%.2f w',$lw*$this->k)); 1269 } 1270 //Restore font 1271 if($family) { 1272 $this->SetFont($family,$style,$size); 1273 } 1274 //Restore colors 1275 if($this->DrawColor!=$dc) { 1276 $this->DrawColor=$dc; 1277 $this->_out($dc); 1278 } 1279 if($this->FillColor!=$fc) { 1280 $this->FillColor=$fc; 1281 $this->_out($fc); 1282 } 1283 $this->TextColor=$tc; 1284 $this->ColorFlag=$cf; 1285 } 1286 1287 1288 1289 /** 1290 * Set header data. 1291 * @param string $ln header image logo 1292 * @param string $lw header image logo width in mm 1293 * @param string $ht string to print as title on document header 1294 * @param string $hs string to print on document header 1295 */ 1296 function setHeaderData($ln="", $lw=0, $ht="", $hs="") { 1297 $this->header_logo = $ln; 1298 $this->header_logo_width = $lw; 1299 $this->header_title = $ht; 1300 $this->header_string = $hs; 1301 } 1302 1303 /** 1304 * Set header margin. 1305 * (minimum distance between header and top page margin) 1306 * @param int $hm distance in millimeters 1307 */ 1308 function setHeaderMargin($hm=10) { 1309 $this->header_margin = $hm; 1310 } 1311 1312 /** 1313 * Set footer margin. 1314 * (minimum distance between footer and bottom page margin) 1315 * @param int $fm distance in millimeters 1316 */ 1317 function setFooterMargin($fm=10) { 1318 $this->footer_margin = $fm; 1319 } 1320 1321 /** 1322 * This method is used to render the page header. 1323 * It is automatically called by AddPage() and could be overwritten in your own inherited class. 1324 */ 1325 function Header() { 1326 if ($this->print_header) { 1327 1328 if (!isset($this->original_lMargin)) { 1329 $this->original_lMargin = $this->lMargin; 1330 } 1331 if (!isset($this->original_rMargin)) { 1332 $this->original_rMargin = $this->rMargin; 1333 } 1334 1335 //set current position 1336 $this->SetXY($this->original_lMargin, $this->header_margin); 1337 1338 if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) { 1339 $this->Image(K_PATH_IMAGES.$this->header_logo, $this->original_lMargin, $this->header_margin, $this->header_logo_width); 1340 } 1341 else { 1342 $this->img_rb_y = $this->GetY(); 1343 } 1344 1345 $cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2); 1346 1347 $header_x = $this->original_lMargin + ($this->header_logo_width * 1.05); //set left margin for text data cell 1348 1349 // header title 1350 $this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1); 1351 $this->SetX($header_x); 1352 $this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, 'L'); 1353 1354 // header string 1355 $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]); 1356 $this->SetX($header_x); 1357 $this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, 'L', 0); 1358 1359 // print an ending header line 1360 if (empty($this->header_width)) { 1361 //set style for cell border 1362 $this->SetLineWidth(0.3); 1363 $this->SetDrawColor(0, 0, 0); 1364 $this->SetY(1 + max($this->img_rb_y, $this->GetY())); 1365 $this->SetX($this->original_lMargin); 1366 $this->Cell(0, 0, '', 'T', 0, 'C'); 1367 } 1368 1369 //restore position 1370 $this->SetXY($this->original_lMargin, $this->tMargin); 1371 } 1372 } 1373 1374 /** 1375 * This method is used to render the page footer. 1376 * It is automatically called by AddPage() and could be overwritten in your own inherited class. 1377 */ 1378 function Footer() { 1379 if ($this->print_footer) { 1380 1381 if (!isset($this->original_lMargin)) { 1382 $this->original_lMargin = $this->lMargin; 1383 } 1384 if (!isset($this->original_rMargin)) { 1385 $this->original_rMargin = $this->rMargin; 1386 } 1387 1388 //set font 1389 $this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]); 1390 //set style for cell border 1391 $line_width = 0.3; 1392 $this->SetLineWidth($line_width); 1393 $this->SetDrawColor(0, 0, 0); 1394 1395 $footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height 1396 //get footer y position 1397 $footer_y = $this->h - $this->footer_margin - $footer_height; 1398 //set current position 1399 $this->SetXY($this->original_lMargin, $footer_y); 1400 1401 //print document barcode 1402 if ($this->barcode) { 1403 $this->Ln(); 1404 $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)); //max width 1405 $this->writeBarcode($this->original_lMargin, $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode); 1406 } 1407 1408 $this->SetXY($this->original_lMargin, $footer_y); 1409 1410 //Print page number 1411 $this->Cell(0, $footer_height, $this->l['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R'); 1412 } 1413 } 1414 1415 /** 1416 * Returns the current page number. 1417 * @return int page number 1418 * @since 1.0 1419 * @see AliasNbPages() 1420 */ 1421 function PageNo() { 1422 //Get current page number 1423 return $this->page; 1424 } 1425 1426 /** 1427 * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page. 1428 * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255 1429 * @param int $g Green component (between 0 and 255) 1430 * @param int $b Blue component (between 0 and 255) 1431 * @since 1.3 1432 * @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell() 1433 */ 1434 function SetDrawColor($r, $g=-1, $b=-1) { 1435 //Set color for all stroking operations 1436 if(($r==0 and $g==0 and $b==0) or $g==-1) { 1437 $this->DrawColor=sprintf('%.3f G',$r/255); 1438 } 1439 else { 1440 $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255); 1441 } 1442 if($this->page>0) { 1443 $this->_out($this->DrawColor); 1444 } 1445 } 1446 1447 /** 1448 * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page. 1449 * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255 1450 * @param int $g Green component (between 0 and 255) 1451 * @param int $b Blue component (between 0 and 255) 1452 * @param boolean $storeprev if true stores the RGB array on $prevFillColor variable. 1453 * @since 1.3 1454 * @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell() 1455 */ 1456 function SetFillColor($r, $g=-1, $b=-1, $storeprev=false) { 1457 //Set color for all filling operations 1458 if(($r==0 and $g==0 and $b==0) or $g==-1) { 1459 $this->FillColor=sprintf('%.3f g',$r/255); 1460 } 1461 else { 1462 $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); 1463 } 1464 $this->ColorFlag=($this->FillColor!=$this->TextColor); 1465 if($this->page>0) { 1466 $this->_out($this->FillColor); 1467 } 1468 if ($storeprev) { 1469 // store color as previous value 1470 $this->prevFillColor = array($r, $g, $b); 1471 } 1472 } 1473 1474 /** 1475 * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page. 1476 * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255 1477 * @param int $g Green component (between 0 and 255) 1478 * @param int $b Blue component (between 0 and 255) 1479 * @param boolean $storeprev if true stores the RGB array on $prevTextColor variable. 1480 * @since 1.3 1481 * @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell() 1482 */ 1483 function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) { 1484 //Set color for text 1485 if(($r==0 and $g==0 and $b==0) or $g==-1) { 1486 $this->TextColor=sprintf('%.3f g',$r/255); 1487 } 1488 else { 1489 $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); 1490 } 1491 $this->ColorFlag=($this->FillColor!=$this->TextColor); 1492 if ($storeprev) { 1493 // store color as previous value 1494 $this->prevTextColor = array($r, $g, $b); 1495 } 1496 } 1497 1498 /** 1499 * Returns the length of a string in user unit. A font must be selected.<br> 1500 * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02] 1501 * @param string $s The string whose length is to be computed 1502 * @return int 1503 * @since 1.2 1504 */ 1505 function GetStringWidth($s) { 1506 //Get width of a string in the current font 1507 $s = (string)$s; 1508 $cw = &$this->CurrentFont['cw']; 1509 $w = 0; 1510 if($this->isunicode) { 1511 $unicode = $this->UTF8StringToArray($s); 1512 foreach($unicode as $char) { 1513 if (isset($cw[$char])) { 1514 $w+=$cw[$char]; 1515 } elseif(isset($cw[ord($char)])) { 1516 $w+=$cw[ord($char)]; 1517 } elseif(isset($cw[chr($char)])) { 1518 $w+=$cw[chr($char)]; 1519 } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { 1520 $w += $this->CurrentFont['desc']['MissingWidth']; // set default size 1521 } else { 1522 $w += 500; 1523 } 1524 } 1525 } else { 1526 $l = strlen($s); 1527 for($i=0; $i<$l; $i++) { 1528 if (isset($cw[$s{$i}])) { 1529 $w += $cw[$s{$i}]; 1530 } else if (isset($cw[ord($s{$i})])) { 1531 $w += $cw[ord($s{$i})]; 1532 } 1533 } 1534 } 1535 return ($w * $this->FontSize / 1000); 1536 } 1537 1538 /** 1539 * Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page. 1540 * @param float $width The width. 1541 * @since 1.0 1542 * @see Line(), Rect(), Cell(), MultiCell() 1543 */ 1544 function SetLineWidth($width) { 1545 //Set line width 1546 $this->LineWidth=$width; 1547 if($this->page>0) { 1548 $this->_out(sprintf('%.2f w',$width*$this->k)); 1549 } 1550 } 1551 1552 /** 1553 * Draws a line between two points. 1554 * @param float $x1 Abscissa of first point 1555 * @param float $y1 Ordinate of first point 1556 * @param float $x2 Abscissa of second point 1557 * @param float $y2 Ordinate of second point 1558 * @since 1.0 1559 * @see SetLineWidth(), SetDrawColor() 1560 */ 1561 function Line($x1, $y1, $x2, $y2) { 1562 //Draw a line 1563 $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)); 1564 } 1565 1566 /** 1567 * Outputs a rectangle. It can be drawn (border only), filled (with no border) or both. 1568 * @param float $x Abscissa of upper-left corner 1569 * @param float $y Ordinate of upper-left corner 1570 * @param float $w Width 1571 * @param float $h Height 1572 * @param string $style Style of rendering. Possible values are:<ul><li>D or empty string: draw (default)</li><li>F: fill</li><li>DF or FD: draw and fill</li></ul> 1573 * @since 1.0 1574 * @see SetLineWidth(), SetDrawColor(), SetFillColor() 1575 */ 1576 function Rect($x, $y, $w, $h, $style='') { 1577 //Draw a rectangle 1578 if($style=='F') { 1579 $op='f'; 1580 } 1581 elseif($style=='FD' or $style=='DF') { 1582 $op='B'; 1583 } 1584 else { 1585 $op='S'; 1586 } 1587 $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); 1588 } 1589 1590 /** 1591 * Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by FPDF_FONTPATH if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated. 1592 * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]. 1593 * <b>Example</b>:<br /> 1594 * <pre> 1595 * $pdf->AddFont('Comic','I'); 1596 * // is equivalent to: 1597 * $pdf->AddFont('Comic','I','comici.php'); 1598 * </pre> 1599 * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font. 1600 * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul> 1601 * @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space. 1602 * @since 1.5 1603 * @see SetFont() 1604 */ 1605 function AddFont($family, $style='', $file='') { 1606 if(empty($family)) { 1607 return; 1608 } 1609 1610 //Add a TrueType or Type1 font 1611 $family = strtolower($family); 1612 if((!$this->isunicode) AND ($family == 'arial')) { 1613 $family = 'helvetica'; 1614 } 1615 1616 $style=strtoupper($style); 1617 $style=str_replace('U','',$style); 1618 if($style == 'IB') { 1619 $style = 'BI'; 1620 } 1621 1622 $fontkey = $family.$style; 1623 // check if the font has been already added 1624 if(isset($this->fonts[$fontkey])) { 1625 return; 1626 } 1627 1628 if($file=='') { 1629 $file = str_replace(' ', '', $family).strtolower($style).'.php'; 1630 } 1631 if(!file_exists($this->_getfontpath().$file)) { 1632 // try to load the basic file without styles 1633 $file = str_replace(' ', '', $family).'.php'; 1634 } 1635 1636 include($this->_getfontpath().$file); 1637 1638 if(!isset($name) AND !isset($fpdf_charwidths)) { 1639 $this->Error('Could not include font definition file'); 1640 } 1641 1642 $i = count($this->fonts)+1; 1643 1644 if($this->isunicode) { 1645 $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg); 1646 $fpdf_charwidths[$fontkey] = $cw; 1647 } else { 1648 $this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]); 1649 } 1650 1651 if(isset($diff) AND (!empty($diff))) { 1652 //Search existing encodings 1653 $d=0; 1654 $nb=count($this->diffs); 1655 for($i=1;$i<=$nb;$i++) { 1656 if($this->diffs[$i]==$diff) { 1657 $d=$i; 1658 break; 1659 } 1660 } 1661 if($d==0) { 1662 $d=$nb+1; 1663 $this->diffs[$d]=$diff; 1664 } 1665 $this->fonts[$fontkey]['diff']=$d; 1666 } 1667 if(!empty($file)) { 1668 if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) { 1669 $this->FontFiles[$file]=array('length1'=>$originalsize); 1670 } 1671 else { 1672 $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); 1673 } 1674 } 1675 } 1676 1677 /** 1678 * Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid. 1679 * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe). 1680 * The method can be called before the first page is created and the font is retained from page to page. 1681 If you just wish to change the current font size, it is simpler to call SetFontSize(). 1682 * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the FPDF_FONTPATH constant</li></ul><br /> 1683 * Example for the last case (note the trailing slash):<br /> 1684 * <pre> 1685 * define('FPDF_FONTPATH','/home/www/font/'); 1686 * require('tcpdf.php'); 1687 * 1688 * //Times regular 12 1689 * $pdf->SetFont('Times'); 1690 * //Arial bold 14 1691 * $pdf->SetFont('Arial','B',14); 1692 * //Removes bold 1693 * $pdf->SetFont(''); 1694 * //Times bold, italic and underlined 14 1695 * $pdf->SetFont('Times','BIU'); 1696 * </pre><br /> 1697 * If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated. 1698 * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained. 1699 * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li></ul>or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats 1700 * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12 1701 * @since 1.0 1702 * @see AddFont(), SetFontSize(), Cell(), MultiCell(), Write() 1703 */ 1704 function SetFont($family, $style='', $size=0) { 1705 // save previous values 1706 $this->prevFontFamily = $this->FontFamily; 1707 $this->prevFontStyle = $this->FontStyle; 1708 1709 //Select a font; size given in points 1710 global $fpdf_charwidths; 1711 1712 $family=strtolower($family); 1713 if($family=='') { 1714 $family=$this->FontFamily; 1715 } 1716 if((!$this->isunicode) AND ($family == 'arial')) { 1717 $family = 'helvetica'; 1718 } 1719 elseif(($family=="symbol") OR ($family=="zapfdingbats")) { 1720 $style=''; 1721 } 1722 $style=strtoupper($style); 1723 1724 if(strpos($style,'U')!==false) { 1725 $this->underline=true; 1726 $style=str_replace('U','',$style); 1727 } 1728 else { 1729 $this->underline=false; 1730 } 1731 if($style=='IB') { 1732 $style='BI'; 1733 } 1734 if($size==0) { 1735 $size=$this->FontSizePt; 1736 } 1737 1738 // try to add font (if not already added) 1739 if($this->isunicode) { 1740 $this->AddFont($family, $style); 1741 } 1742 1743 //Test if font is already selected 1744 if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size)) { 1745 return; 1746 } 1747 1748 $fontkey = $family.$style; 1749 //if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) { 1750 // $style=''; 1751 //} 1752 1753 //Test if used for the first time 1754 if(!isset($this->fonts[$fontkey])) { 1755 //Check if one of the standard fonts 1756 if(isset($this->CoreFonts[$fontkey])) { 1757 if(!isset($fpdf_charwidths[$fontkey])) { 1758 //Load metric file 1759 $file = $family; 1760 if(($family!='symbol') AND ($family!='zapfdingbats')) { 1761 $file .= strtolower($style); 1762 } 1763 if(!file_exists($this->_getfontpath().$file.'.php')) { 1764 // try to load the basic file without styles 1765 $file = $family; 1766 $fontkey = $family; 1767 } 1768 include($this->_getfontpath().$file.'.php'); 1769 if (($this->isunicode AND !isset($ctg)) OR ((!$this->isunicode) AND (!isset($fpdf_charwidths[$fontkey]))) ) { 1770 $this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php"); 1771 } 1772 } 1773 $i = count($this->fonts) + 1; 1774 1775 if($this->isunicode) { 1776 $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg); 1777 $fpdf_charwidths[$fontkey] = $cw; 1778 } else { 1779 $this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]); 1780 } 1781 } 1782 else { 1783 $this->Error('Undefined font: '.$family.' '.$style); 1784 } 1785 } 1786 //Select it 1787 $this->FontFamily = $family; 1788 $this->FontStyle = $style; 1789 $this->FontSizePt = $size; 1790 $this->FontSize = $size / $this->k; 1791 $this->CurrentFont = &$this->fonts[$fontkey]; 1792 if($this->page>0) { 1793 $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); 1794 } 1795 } 1796 1797 /** 1798 * Defines the size of the current font. 1799 * @param float $size The size (in points) 1800 * @since 1.0 1801 * @see SetFont() 1802 */ 1803 function SetFontSize($size) { 1804 //Set font size in points 1805 if($this->FontSizePt==$size) { 1806 return; 1807 } 1808 $this->FontSizePt = $size; 1809 $this->FontSize = $size / $this->k; 1810 if($this->page > 0) { 1811 $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); 1812 } 1813 } 1814 1815 /** 1816 * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br /> 1817 * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink(). 1818 * @since 1.5 1819 * @see Cell(), Write(), Image(), Link(), SetLink() 1820 */ 1821 function AddLink() { 1822 //Create a new internal link 1823 $n=count($this->links)+1; 1824 $this->links[$n]=array(0,0); 1825 return $n; 1826 } 1827 1828 /** 1829 * Defines the page and position a link points to 1830 * @param int $link The link identifier returned by AddLink() 1831 * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page) 1832 * @param int $page Number of target page; -1 indicates the current page. This is the default value 1833 * @since 1.5 1834 * @see AddLink() 1835 */ 1836 function SetLink($link, $y=0, $page=-1) { 1837 //Set destination of internal link 1838 if($y==-1) { 1839 $y=$this->y; 1840 } 1841 if($page==-1) { 1842 $page=$this->page; 1843 } 1844 $this->links[$link]=array($page,$y); 1845 } 1846 1847 /** 1848 * Puts a link on a rectangular area of the page. Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image. 1849 * @param float $x Abscissa of the upper-left corner of the rectangle 1850 * @param float $y Ordinate of the upper-left corner of the rectangle 1851 * @param float $w Width of the rectangle 1852 * @param float $h Height of the rectangle 1853 * @param mixed $link URL or identifier returned by AddLink() 1854 * @since 1.5 1855 * @see AddLink(), Cell(), Write(), Image() 1856 */ 1857 function Link($x, $y, $w, $h, $link) { 1858 //Put a link on the page 1859 $this->PageLinks[$this->page][] = array($x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h*$this->k, $link); 1860 } 1861 1862 /** 1863 * Prints a character string. The origin is on the left of the first charcter, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text. 1864 * @param float $x Abscissa of the origin 1865 * @param float $y Ordinate of the origin 1866 * @param string $txt String to print 1867 * @since 1.0 1868 * @see SetFont(), SetTextColor(), Cell(), MultiCell(), Write() 1869 */ 1870 function Text($x, $y, $txt) { 1871 //Output a string 1872 $s=sprintf('BT %.2f %.2f Td (%s) Tj ET', $x * $this->k, ($this->h-$y) * $this->k, $this->_escapetext($txt)); 1873 if($this->underline AND ($txt!='')) { 1874 $s .= ' '.$this->_dounderline($x,$y,$txt); 1875 } 1876 if($this->ColorFlag) { 1877 $s='q '.$this->TextColor.' '.$s.' Q'; 1878 } 1879 $this->_out($s); 1880 } 1881 1882 /** 1883 * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br /> 1884 * This method is called automatically and should not be called directly by the application.<br /> 1885 * <b>Example:</b><br /> 1886 * The method is overriden in an inherited class in order to obtain a 3 column layout:<br /> 1887 * <pre> 1888 * class PDF extends TCPDF { 1889 * var $col=0; 1890 * 1891 * function SetCol($col) { 1892 * //Move position to a column 1893 * $this->col=$col; 1894 * $x=10+$col*65; 1895 * $this->SetLeftMargin($x); 1896 * $this->SetX($x); 1897 * } 1898 * 1899 * function AcceptPageBreak() { 1900 * if($this->col<2) { 1901 * //Go to next column 1902 * $this->SetCol($this->col+1); 1903 * $this->SetY(10); 1904 * return false; 1905 * } 1906 * else { 1907 * //Go back to first column and issue page break 1908 * $this->SetCol(0); 1909 * return true; 1910 * } 1911 * } 1912 * } 1913 * 1914 * $pdf=new PDF(); 1915 * $pdf->Open(); 1916 * $pdf->AddPage(); 1917 * $pdf->SetFont('Arial','',12); 1918 * for($i=1;$i<=300;$i++) { 1919 * $pdf->Cell(0,5,"Line $i",0,1); 1920 * } 1921 * $pdf->Output(); 1922 * </pre> 1923 * @return boolean 1924 * @since 1.4 1925 * @see SetAutoPageBreak() 1926 */ 1927 function AcceptPageBreak() { 1928 //Accept automatic page break or not 1929 return $this->AutoPageBreak; 1930 } 1931 1932 /** 1933 * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br /> 1934 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting. 1935 * @param float $w Cell width. If 0, the cell extends up to the right margin. 1936 * @param float $h Cell height. Default value: 0. 1937 * @param string $txt String to print. Default value: empty string. 1938 * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> 1939 * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> 1940 Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0. 1941 * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li></ul> 1942 * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. 1943 * @param mixed $link URL or identifier returned by AddLink(). 1944 * @since 1.0 1945 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak() 1946 */ 1947 function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='') { 1948 //Output a cell 1949 $k=$this->k; 1950 if(($this->y + $h) > $this->PageBreakTrigger AND empty($this->InFooter) AND $this->AcceptPageBreak()) { 1951 //Automatic page break 1952 $x = $this->x; 1953 $ws = $this->ws; 1954 if($ws > 0) { 1955 $this->ws = 0; 1956 $this->_out('0 Tw'); 1957 } 1958 $this->AddPage($this->CurOrientation); 1959 $this->x = $x; 1960 if($ws > 0) { 1961 $this->ws = $ws; 1962 $this->_out(sprintf('%.3f Tw',$ws * $k)); 1963 } 1964 } 1965 if($w == 0) { 1966 $w = $this->w - $this->rMargin - $this->x; 1967 } 1968 $s = ''; 1969 if(($fill == 1) OR ($border == 1)) { 1970 if($fill == 1) { 1971 $op = ($border == 1) ? 'B' : 'f'; 1972 } 1973 else { 1974 $op = 'S'; 1975 } 1976 $s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op); 1977 } 1978 if(is_string($border)) { 1979 $x=$this->x; 1980 $y=$this->y; 1981 if(strpos($border,'L')!==false) { 1982 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); 1983 } 1984 if(strpos($border,'T')!==false) { 1985 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); 1986 } 1987 if(strpos($border,'R')!==false) { 1988 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 1989 } 1990 if(strpos($border,'B')!==false) { 1991 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 1992 } 1993 } 1994 if($txt != '') { 1995 $width = $this->GetStringWidth($txt); 1996 if($align == 'R') { 1997 $dx = $w - $this->cMargin - $width; 1998 } 1999 elseif($align=='C') { 2000 $dx = ($w - $width)/2; 2001 } 2002 else { 2003 $dx = $this->cMargin; 2004 } 2005 if($this->ColorFlag) { 2006 $s .= 'q '.$this->TextColor.' '; 2007 } 2008 $txt2 = $this->_escapetext($txt); 2009 $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + 0.5 * $h + 0.3 * $this->FontSize)) * $k, $txt2); 2010 if($this->underline) { 2011 $s.=' '.$this->_dounderline($this->x + $dx, $this->y + 0.5 * $h + 0.3 * $this->FontSize, $txt); 2012 } 2013 if($this->ColorFlag) { 2014 $s.=' Q'; 2015 } 2016 if($link) { 2017 $this->Link($this->x + $dx, $this->y + 0.5 * $h - 0.5 * $this->FontSize, $width, $this->FontSize, $link); 2018 } 2019 } 2020 if($s) { 2021 $this->_out($s); 2022 } 2023 $this->lasth = $h; 2024 if($ln>0) { 2025 //Go to next line 2026 $this->y += $h; 2027 if($ln == 1) { 2028 $this->x = $this->lMargin; 2029 } 2030 } 2031 else { 2032 $this->x += $w; 2033 } 2034 } 2035 2036 /** 2037 * This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br /> 2038 * Text can be aligned, centered or justified. The cell block can be framed and the background painted. 2039 * @param float $w Width of cells. If 0, they extend up to the right margin of the page. 2040 * @param float $h Height of cells. 2041 * @param string $txt String to print 2042 * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> 2043 * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> 2044 Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0. 2045 * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value)</li></ul> 2046 * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. 2047 * @since 1.3 2048 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak() 2049 */ 2050 function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0) { 2051 //Output text with automatic or explicit line breaks 2052 $cw = &$this->CurrentFont['cw']; 2053 2054 if($w == 0) { 2055 $w = $this->w - $this->rMargin - $this->x; 2056 } 2057 2058 $wmax = ($w - 2 * $this->cMargin); 2059 2060 $s = str_replace("\r", '', $txt); // remove carriage returns 2061 $nb = strlen($s); 2062 2063 $b=0; 2064 if($border) { 2065 if($border==1) { 2066 $border='LTRB'; 2067 $b='LRT'; 2068 $b2='LR'; 2069 } 2070 else { 2071 $b2=''; 2072 if(strpos($border,'L')!==false) { 2073 $b2.='L'; 2074 } 2075 if(strpos($border,'R')!==false) { 2076 $b2.='R'; 2077 } 2078 $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2; 2079 } 2080 } 2081 $sep=-1; 2082 $i=0; 2083 $j=0; 2084 $l=0; 2085 $ns=0; 2086 $nl=1; 2087 while($i<$nb) { 2088 //Get next character 2089 $c = $s{$i}; 2090 if(preg_match("/[\n]/u", $c)) { 2091 //Explicit line break 2092 if($this->ws > 0) { 2093 $this->ws = 0; 2094 $this->_out('0 Tw'); 2095 } 2096 $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill); 2097 $i++; 2098 $sep=-1; 2099 $j=$i; 2100 $l=0; 2101 $ns=0; 2102 $nl++; 2103 if($border and $nl==2) { 2104 $b = $b2; 2105 } 2106 continue; 2107 } 2108 if(preg_match("/[ ]/u", $c)) { 2109 $sep = $i; 2110 $ls = $l; 2111 $ns++; 2112 } 2113 2114 $l = $this->GetStringWidth(substr($s, $j, $i-$j)); 2115 2116 if($l > $wmax) { 2117 //Automatic line break 2118 if($sep == -1) { 2119 if($i == $j) { 2120 $i++; 2121 } 2122 if($this->ws > 0) { 2123 $this->ws = 0; 2124 $this->_out('0 Tw'); 2125 } 2126 $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill); 2127 } 2128 else { 2129 if($align=='J') { 2130 $this->ws = ($ns>1) ? ($wmax-$ls)/($ns-1) : 0; 2131 $this->_out(sprintf('%.3f Tw', $this->ws * $this->k)); 2132 } 2133 $this->Cell($w, $h, substr($s, $j, $sep-$j), $b, 2, $align, $fill); 2134 $i = $sep + 1; 2135 } 2136 $sep=-1; 2137 $j=$i; 2138 $l=0; 2139 $ns=0; 2140 $nl++; 2141 if($border AND ($nl==2)) { 2142 $b=$b2; 2143 } 2144 } 2145 else { 2146 $i++; 2147 } 2148 } 2149 //Last chunk 2150 if($this->ws>0) { 2151 $this->ws=0; 2152 $this->_out('0 Tw'); 2153 } 2154 if($border and is_int(strpos($border,'B'))) { 2155 $b.='B'; 2156 } 2157 $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill); 2158 $this->x=$this->lMargin; 2159 } 2160 2161 /** 2162 * This method prints text from the current position. When the right margin is reached (or the \n character is met) a line break occurs and text continues from the left margin. Upon method exit, the current position is left just at the end of the text. It is possible to put a link on the text.<br /> 2163 * <b>Example:</b><br /> 2164 * <pre> 2165 * //Begin with regular font 2166 * $pdf->SetFont('Arial','',14); 2167 * $pdf->Write(5,'Visit '); 2168 * //Then put a blue underlined link 2169 * $pdf->SetTextColor(0,0,255); 2170 * $pdf->SetFont('','U'); 2171 * $pdf->Write(5,'www.tecnick.com','http://www.tecnick.com'); 2172 * </pre> 2173 * @param float $h Line height 2174 * @param string $txt String to print 2175 * @param mixed $link URL or identifier returned by AddLink() 2176 * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0. 2177 * @since 1.5 2178 * @see SetFont(), SetTextColor(), AddLink(), MultiCell(), SetAutoPageBreak() 2179 */ 2180 function Write($h, $txt, $link='', $fill=0) { 2181 2182 //Output text in flowing mode 2183 $cw = &$this->CurrentFont['cw']; 2184 $w = $this->w - $this->rMargin - $this->x; 2185 $wmax = ($w - 2 * $this->cMargin); 2186 2187 $s = str_replace("\r", '', $txt); 2188 $nb = strlen($s); 2189 2190 // handle single space character 2191 if(($nb==1) AND preg_match("/[ ]/u", $s)) { 2192 $this->x += $this->GetStringWidth($s); 2193 return; 2194 } 2195 2196 $sep=-1; 2197 $i=0; 2198 $j=0; 2199 $l=0; 2200 $nl=1; 2201 while($i<$nb) { 2202 //Get next character 2203 $c=$s{$i}; 2204 if(preg_match("/[\n]/u", $c)) { 2205 //Explicit line break 2206 $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link); 2207 $i++; 2208 $sep = -1; 2209 $j = $i; 2210 $l = 0; 2211 if($nl == 1) { 2212 $this->x = $this->lMargin; 2213 $w = $this->w - $this->rMargin - $this->x; 2214 $wmax = ($w - 2 * $this->cMargin); 2215 } 2216 $nl++; 2217 continue; 2218 } 2219 if(preg_match("/[ ]/u", $c)) { 2220 $sep= $i; 2221 } 2222 2223 $l = $this->GetStringWidth(substr($s, $j, $i-$j)); 2224 2225 if($l >