<?
require_once('bililitePDF_3.php');

class 
bililitePDF_4 extends bililitePDF_3 {
    protected 
$fonts = array();

    public function 
placetext ($string, $font, $size, $x, $y, $theta=0, $r=0, $g=0, $b=0){
        if (!isset(
$this->fonts[$font])) $this->appendFont($font);
        
$string = $this->createString($string);
        
$font = $this->createName($font);
        
$rotation = sprintf('%f %f %f %f', cos($theta), sin($theta), -sin($theta), cos($theta));
        
$r /= 255; // convert from PHP to PDF colors
        
$g /= 255;
        
$b /= 255;
        
$this->currentPage->contents .= "
            q
            1 0 0 1 
$x $y cm
            
$rotation 0 0 cm
            
$r $g $b rg
            BT
            
$font $size Tf
            
$string Tj
            ET
            Q
        "
;
    }
    protected function 
appendFont($font){
        
$n = $this->appendObject($this->createDictionary(array(
            
'Type' => $this->createName('Font'),
            
'Subtype' => $this->createName('Type1'),
            
'BaseFont' => $this->createName($font),
        )));
        
$this->fonts[$font] = $n;
    }
    protected function 
dictResources(){
        
$ret = parent::dictResources();
        
$fonts = array();
        foreach (
$this->fonts as $key => $n) $fonts[$key] = $this->createReference($n);
        
$ret['Font'] = $this->createDictionary($fonts);
        return 
$ret;
    }
}