jablonka.czprosek.czf

freenet-router

Subversion Repositories:
[/] [trunk/] [freenet-router/] [var/] [www/] [freenet-router/] [Framework/] [Libraries/] [ImportExport/] [Pdf/] [PDFCreator.php] - Rev 2

Compare with Previous - Blame - Download


<?php

namespace Phem\Libraries\ImportExport\Pdf;
/*
+ěščřžýáíé=
*/
use \FPDI;

class PDFCreator extends FPDI
{

    private $widthSpaces;
    
    private $angle;

    function __construct($orientation="P", $unit="mm", $size="A4")
    {
        parent::__construct($orientation, $unit, $size);
        $this->widthSpaces = null;
        $this->AddFont('Calibri', '', 'calibri.ttf', true);
        $this->AddFont('times', '', 'times.ttf', true);
    }
    
    public function getWidthSpaces()
    {
        return $this->widthSpaces;
    }

    public function setWidthSpaces($widthSpaces)
    {
        $this->widthSpaces = $widthSpaces;
    }
    
    public function Write($h, $txt, $link = '')
    {
        if ($this->widthSpaces != null)
        {
            for ($i = 0; $i < mb_strlen($txt); $i++)
            {
                $ch = mb_substr($txt, $i, 1);
                $chWidth = $this->GetStringWidth($ch);
                parent::Write($h, $ch, $link);
                $this->x = $this->x + $this->widthSpaces - $chWidth;
            }
               
        }
        else
            parent::Write($h, $txt, $link);
    }
    
    public function WriteChecked()
    {
        $this->Write(0,'X');
    }
        
    public function WriteRight($h, $txt, $link = ''){
        if ($this->widthSpaces == null){
            $this->x = $this->x - $this->GetStringWidth($txt);
            $this->Write($h, $txt, $link);
        }else{
            $this->x = $this->x - (mb_strlen($txt) * $this->widthSpaces);
            $this->Write($h, $txt, $link);
        }
    }

    function Rotate($angle,$x=-1,$y=-1)
    {
        if($x==-1)
            $x=$this->x;
        if($y==-1)
            $y=$this->y;
        if($this->angle!=0)
            $this->_out('Q');
        $this->angle=$angle;
        if($angle!=0)
        {
            $angle*=M_PI/180;
            $c=cos($angle);
            $s=sin($angle);
            $cx=$x*$this->k;
            $cy=($this->h-$y)*$this->k;
            $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));
        }
    }
    
    function _endpage()
    {
        if($this->angle!=0)
        {
            $this->angle=0;
            $this->_out('Q');
        }
        parent::_endpage();
    }

    
    /*public function GetStringWidth($s)
    {
        // Get width of a string in the current font
        $s = (string)$s;
        $cw = &$this->CurrentFont['cw'];
        $w = 0;
        $l = mb_strlen($s);
        for($i=0;$i<$l;$i++)
                $w += $cw[$s[$i]];
        return $w*$this->FontSize/1000;
    }*/


}

Powered by WebSVN 2.2.1