[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/PDF/ -> TCPDF.php (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10  require_once  'libraries/tcpdf/config/lang/eng.php';
  11  require_once  'libraries/tcpdf/tcpdf.php';
  12  
  13  class Vtiger_PDF_TCPDF extends TCPDF {
  14  
  15      protected $FontFamily;
  16  
  17  	public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') {
  18          parent::__construct($orientation, $unit, $format, $unicode, $encoding);
  19          $this->SetFont('','',10);
  20          $this->setFontFamily('times');
  21      }
  22  
  23  	function getFontSize() {
  24          return $this->FontSizePt;
  25      }
  26  
  27  	function setFontFamily($family) {
  28          $this->FontFamily = $family;
  29      }
  30  
  31  	function GetStringHeight($sa,$w) {
  32          if(empty($sa)) return 0;
  33          
  34          $sa = str_replace("\r","",$sa);
  35          // remove the last newline
  36          if (substr($sa,-1) == "\n")
  37          $sa = substr($sa,0,-1);
  38  
  39          $blocks = explode("\n",$sa);
  40          $wmax = $w - (2 * $this->cMargin);
  41  
  42          $lines = 0;
  43          $spacesize = $this->GetCharWidth(32);
  44          foreach ($blocks as $block) {
  45              if (!empty($block)) {
  46                  $words = explode(" ",$block);
  47  
  48                  $cw = 0;
  49                  for ($i = 0;$i < count($words);$i++) {
  50                      if ($i != 0) $cw += $spacesize;
  51  
  52                      $wordwidth = $this->GetStringWidth($words[$i]);
  53                      $cw += $wordwidth;
  54  
  55                      if ($cw > $wmax) { // linebreak
  56                          $cw = $wordwidth;
  57                          $lines++;
  58                      }
  59                  }
  60              }
  61  
  62              $lines++;
  63          }
  64  
  65          return ($lines * ($this->FontSize * $this->cell_height_ratio)) + 2;
  66      }
  67  
  68  	function SetFont($family, $style='', $size='') {
  69          if($family == '') {
  70              $family = $this->FontFamily;
  71          }
  72          //Select a font; size given in points
  73          if ($size == 0) {
  74              $size = $this->FontSizePt;
  75          }
  76          // try to add font (if not already added)
  77          $fontdata =  $this->AddFont($family, $style);
  78          $this->FontFamily = $fontdata['family'];
  79          $this->FontStyle = $fontdata['style'];
  80          $this->CurrentFont = &$this->fonts[$fontdata['fontkey']];
  81          $this->SetFontSize($size);
  82      }
  83  }
  84  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1