Logo Search packages:      
Sourcecode: acidbase version File versions  Download package

Cpdf::addText ( x,
y,
size,
text,
angle = 0,
wordSpaceAdjust = 0 
)

add text to the document, at a specified location, size and angle on the page

Definition at line 2156 of file class.pdf.php.

References $wordSpaceAdjust, PRVTcheckTextDirective(), PRVTcheckTextDirective1(), PRVTgetTextPosition(), selectFont(), and setCurrentFont().

Referenced by addTextWrap().

                                                               {
  if (!$this->numFonts){$this->selectFont('./fonts/Helvetica');}

  // if there are any open callbacks, then they should be called, to show the start of the line
  if ($this->nCallback>0){
    for ($i=$this->nCallback;$i>0;$i--){
      // call each function
      $info = array('x'=>$x,'y'=>$y,'angle'=>$angle,'status'=>'sol','p'=>$this->callback[$i]['p'],'nCallback'=>$this->callback[$i]['nCallback'],'height'=>$this->callback[$i]['height'],'decender'=>$this->callback[$i]['decender']);
      $func = $this->callback[$i]['f'];
      $this->$func($info);
    }
  }
  if ($angle==0){
    $this->objects[$this->currentContents]['c'].="\n".'BT '.sprintf('%.3f',$x).' '.sprintf('%.3f',$y).' Td';
  } else {
    $a = deg2rad((float)$angle);
    $tmp = "\n".'BT ';
    $tmp .= sprintf('%.3f',cos($a)).' '.sprintf('%.3f',(-1.0*sin($a))).' '.sprintf('%.3f',sin($a)).' '.sprintf('%.3f',cos($a)).' ';
    $tmp .= sprintf('%.3f',$x).' '.sprintf('%.3f',$y).' Tm';
    $this->objects[$this->currentContents]['c'] .= $tmp;
  }
  if ($wordSpaceAdjust!=0 || $wordSpaceAdjust != $this->wordSpaceAdjust){
    $this->wordSpaceAdjust=$wordSpaceAdjust;
    $this->objects[$this->currentContents]['c'].=' '.sprintf('%.3f',$wordSpaceAdjust).' Tw';
  }
  $len=strlen($text);
  $start=0;
  for ($i=0;$i<$len;$i++){
    $f=1;
    $directive = $this->PRVTcheckTextDirective($text,$i,$f);
    if ($directive){
      // then we should write what we need to
      if ($i>$start){
        $part = substr($text,$start,$i-$start);
        $this->objects[$this->currentContents]['c'].=' /F'.$this->currentFontNum.' '.sprintf('%.1f',$size).' Tf ';
        $this->objects[$this->currentContents]['c'].=' ('.$this->filterText($part).') Tj';
      }
      if ($f){
        // then there was nothing drastic done here, restore the contents
        $this->setCurrentFont();
      } else {
        $this->objects[$this->currentContents]['c'] .= ' ET';
        $f=1;
        $xp=$x;
        $yp=$y;
        $directive = $this->PRVTcheckTextDirective1($text,$i,$f,1,$xp,$yp,$size,$angle,$wordSpaceAdjust);
        
        // restart the text object
          if ($angle==0){
            $this->objects[$this->currentContents]['c'].="\n".'BT '.sprintf('%.3f',$xp).' '.sprintf('%.3f',$yp).' Td';
          } else {
            $a = deg2rad((float)$angle);
            $tmp = "\n".'BT ';
            $tmp .= sprintf('%.3f',cos($a)).' '.sprintf('%.3f',(-1.0*sin($a))).' '.sprintf('%.3f',sin($a)).' '.sprintf('%.3f',cos($a)).' ';
            $tmp .= sprintf('%.3f',$xp).' '.sprintf('%.3f',$yp).' Tm';
            $this->objects[$this->currentContents]['c'] .= $tmp;
          }
          if ($wordSpaceAdjust!=0 || $wordSpaceAdjust != $this->wordSpaceAdjust){
            $this->wordSpaceAdjust=$wordSpaceAdjust;
            $this->objects[$this->currentContents]['c'].=' '.sprintf('%.3f',$wordSpaceAdjust).' Tw';
          }
      }
      // and move the writing point to the next piece of text
      $i=$i+$directive-1;
      $start=$i+1;
    }
    
  }
  if ($start<$len){
    $part = substr($text,$start);
    $this->objects[$this->currentContents]['c'].=' /F'.$this->currentFontNum.' '.sprintf('%.1f',$size).' Tf ';
    $this->objects[$this->currentContents]['c'].=' ('.$this->filterText($part).') Tj';
  }
  $this->objects[$this->currentContents]['c'].=' ET';

  // if there are any open callbacks, then they should be called, to show the end of the line
  if ($this->nCallback>0){
    for ($i=$this->nCallback;$i>0;$i--){
      // call each function
      $tmp = $this->PRVTgetTextPosition($x,$y,$angle,$size,$wordSpaceAdjust,$text);
      $info = array('x'=>$tmp[0],'y'=>$tmp[1],'angle'=>$angle,'status'=>'eol','p'=>$this->callback[$i]['p'],'nCallback'=>$this->callback[$i]['nCallback'],'height'=>$this->callback[$i]['height'],'decender'=>$this->callback[$i]['decender']);
      $func = $this->callback[$i]['f'];
      $this->$func($info);
    }
  }

}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index