| 1 | 2 | simandl | <?php |
| 2 | | | |
| 3 | | | namespace Phem\Libraries\ImportExport\Pdf; |
| 4 | | | /* |
| 5 | | | +ÄĹĄÄĹŞýåĂĂŠ= |
| 6 | | | */ |
| 7 | | | use \FPDI; |
| 8 | | | |
| 9 | | | class PDFCreator extends FPDI |
| 10 | | | { |
| 11 | | | |
| 12 | | | private $widthSpaces; |
| 13 | | | |
| 14 | | | private $angle; |
| 15 | | | |
| 16 | | | function __construct($orientation="P", $unit="mm", $size="A4") |
| 17 | | | { |
| 18 | | | parent::__construct($orientation, $unit, $size); |
| 19 | | | $this->widthSpaces = null; |
| 20 | | | $this->AddFont('Calibri', '', 'calibri.ttf', true); |
| 21 | | | $this->AddFont('times', '', 'times.ttf', true); |
| 22 | | | } |
| 23 | | | |
| 24 | | | public function getWidthSpaces() |
| 25 | | | { |
| 26 | | | return $this->widthSpaces; |
| 27 | | | } |
| 28 | | | |
| 29 | | | public function setWidthSpaces($widthSpaces) |
| 30 | | | { |
| 31 | | | $this->widthSpaces = $widthSpaces; |
| 32 | | | } |
| 33 | | | |
| 34 | | | public function Write($h, $txt, $link = '') |
| 35 | | | { |
| 36 | | | if ($this->widthSpaces != null) |
| 37 | | | { |
| 38 | | | for ($i = 0; $i < mb_strlen($txt); $i++) |
| 39 | | | { |
| 40 | | | $ch = mb_substr($txt, $i, 1); |
| 41 | | | $chWidth = $this->GetStringWidth($ch); |
| 42 | | | parent::Write($h, $ch, $link); |
| 43 | | | $this->x = $this->x + $this->widthSpaces - $chWidth; |
| 44 | | | } |
| 45 | | | |
| 46 | | | } |
| 47 | | | else |
| 48 | | | parent::Write($h, $txt, $link); |
| 49 | | | } |
| 50 | | | |
| 51 | | | public function WriteChecked() |
| 52 | | | { |
| 53 | | | $this->Write(0,'X'); |
| 54 | | | } |
| 55 | | | |
| 56 | | | public function WriteRight($h, $txt, $link = ''){ |
| 57 | | | if ($this->widthSpaces == null){ |
| 58 | | | $this->x = $this->x - $this->GetStringWidth($txt); |
| 59 | | | $this->Write($h, $txt, $link); |
| 60 | | | }else{ |
| 61 | | | $this->x = $this->x - (mb_strlen($txt) * $this->widthSpaces); |
| 62 | | | $this->Write($h, $txt, $link); |
| 63 | | | } |
| 64 | | | } |
| 65 | | | |
| 66 | | | function Rotate($angle,$x=-1,$y=-1) |
| 67 | | | { |
| 68 | | | if($x==-1) |
| 69 | | | $x=$this->x; |
| 70 | | | if($y==-1) |
| 71 | | | $y=$this->y; |
| 72 | | | if($this->angle!=0) |
| 73 | | | $this->_out('Q'); |
| 74 | | | $this->angle=$angle; |
| 75 | | | if($angle!=0) |
| 76 | | | { |
| 77 | | | $angle*=M_PI/180; |
| 78 | | | $c=cos($angle); |
| 79 | | | $s=sin($angle); |
| 80 | | | $cx=$x*$this->k; |
| 81 | | | $cy=($this->h-$y)*$this->k; |
| 82 | | | $this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy)); |
| 83 | | | } |
| 84 | | | } |
| 85 | | | |
| 86 | | | function _endpage() |
| 87 | | | { |
| 88 | | | if($this->angle!=0) |
| 89 | | | { |
| 90 | | | $this->angle=0; |
| 91 | | | $this->_out('Q'); |
| 92 | | | } |
| 93 | | | parent::_endpage(); |
| 94 | | | } |
| 95 | | | |
| 96 | | | |
| 97 | | | /*public function GetStringWidth($s) |
| 98 | | | { |
| 99 | | | // Get width of a string in the current font |
| 100 | | | $s = (string)$s; |
| 101 | | | $cw = &$this->CurrentFont['cw']; |
| 102 | | | $w = 0; |
| 103 | | | $l = mb_strlen($s); |
| 104 | | | for($i=0;$i<$l;$i++) |
| 105 | | | $w += $cw[$s[$i]]; |
| 106 | | | return $w*$this->FontSize/1000; |
| 107 | | | }*/ |
| 108 | | | |
| 109 | | | |
| 110 | | | } |