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

Cpdf::PRVTcheckTextDirective1 ( &$  text,
i,
&$  f,
final,
&$  x,
&$  y,
size = 0,
angle = 0,
wordSpaceAdjust = 0 
)

checks if the text stream contains a control directive if so then makes some changes and returns the number of characters involved in the directive this has been re-worked to include everything neccesary to fins the current writing point, so that the location can be sent to the callback function if required if the directive does not require a font change, then $f should be set to 0

private

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

References $wordSpaceAdjust, getFontDecender(), getFontHeight(), and PRVTgetTextPosition().

Referenced by addText(), and PRVTcheckTextDirective().

                                                                                                  {
  $directive = 0;
  $j=$i;
  if ($text[$j]=='<'){
    $j++;
    switch($text[$j]){
      case '/':
        $j++;
        if (strlen($text) <= $j){
          return $directive;
        }
        switch($text[$j]){
          case 'b':
          case 'i':
            $j++;
            if ($text[$j]=='>'){
              $p = strrpos($this->currentTextState,$text[$j-1]);
              if ($p !== false){
                // then there is one to remove
                $this->currentTextState = substr($this->currentTextState,0,$p).substr($this->currentTextState,$p+1);
              }
              $directive=$j-$i+1;
            }
            break;
          case 'c':
            // this this might be a callback function
            $j++;
            $k = strpos($text,'>',$j);
            if ($k!==false && $text[$j]==':'){
              // then this will be treated as a callback directive
              $directive = $k-$i+1;
              $f=0;
              // split the remainder on colons to get the function name and the paramater
              $tmp = substr($text,$j+1,$k-$j-1);
              $b1 = strpos($tmp,':');
              if ($b1!==false){
                $func = substr($tmp,0,$b1);
                $parm = substr($tmp,$b1+1);
              } else {
                $func=$tmp;
                $parm='';
              }
              if (!isset($func) || !strlen(trim($func))){
                $directive=0;
              } else {
                // only call the function if this is the final call
                if ($final){
                  // need to assess the text position, calculate the text width to this point
                  // can use getTextWidth to find the text width I think
                  $tmp = $this->PRVTgetTextPosition($x,$y,$angle,$size,$wordSpaceAdjust,substr($text,0,$i));
                  $info = array('x'=>$tmp[0],'y'=>$tmp[1],'angle'=>$angle,'status'=>'end','p'=>$parm,'nCallback'=>$this->nCallback);
                  $x=$tmp[0];
                  $y=$tmp[1];
                  $ret = $this->$func($info);
                  if (is_array($ret)){
                    // then the return from the callback function could set the position, to start with, later will do font colour, and font
                    foreach($ret as $rk=>$rv){
                      switch($rk){
                        case 'x':
                        case 'y':
                          $$rk=$rv;
                          break;
                      }
                    }
                  }
                  // also remove from to the stack
                  // for simplicity, just take from the end, fix this another day
                  $this->nCallback--;
                  if ($this->nCallback<0){
                    $this->nCallBack=0;
                  }
                }
              }
            }
            break;
        }
        break;
      case 'b':
      case 'i':
        $j++;
        if ($text[$j]=='>'){
          $this->currentTextState.=$text[$j-1];
          $directive=$j-$i+1;
        }
        break;
      case 'C':
        $noClose=1;
      case 'c':
        // this this might be a callback function
        $j++;
        $k = strpos($text,'>',$j);
        if ($k!==false && $text[$j]==':'){
          // then this will be treated as a callback directive
          $directive = $k-$i+1;
          $f=0;
          // split the remainder on colons to get the function name and the paramater
//          $bits = explode(':',substr($text,$j+1,$k-$j-1));
          $tmp = substr($text,$j+1,$k-$j-1);
          $b1 = strpos($tmp,':');
          if ($b1!==false){
            $func = substr($tmp,0,$b1);
            $parm = substr($tmp,$b1+1);
          } else {
            $func=$tmp;
            $parm='';
          }
          if (!isset($func) || !strlen(trim($func))){
            $directive=0;
          } else {
            // only call the function if this is the final call, ie, the one actually doing printing, not measurement
            if ($final){
              // need to assess the text position, calculate the text width to this point
              // can use getTextWidth to find the text width I think
              // also add the text height and decender
              $tmp = $this->PRVTgetTextPosition($x,$y,$angle,$size,$wordSpaceAdjust,substr($text,0,$i));
              $info = array('x'=>$tmp[0],'y'=>$tmp[1],'angle'=>$angle,'status'=>'start','p'=>$parm,'f'=>$func,'height'=>$this->getFontHeight($size),'decender'=>$this->getFontDecender($size));
              $x=$tmp[0];
              $y=$tmp[1];
              if (!isset($noClose) || !$noClose){
                // only add to the stack if this is a small 'c', therefore is a start-stop pair
                $this->nCallback++;
                $info['nCallback']=$this->nCallback;
                $this->callback[$this->nCallback]=$info;
              }
              $ret = $this->$func($info);
              if (is_array($ret)){
                // then the return from the callback function could set the position, to start with, later will do font colour, and font
                foreach($ret as $rk=>$rv){
                  switch($rk){
                    case 'x':
                    case 'y':
                      $$rk=$rv;
                      break;
                  }
                }
              }
            }
          }
        }
        break;
    }
  } 
  return $directive;
}

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