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

Cpdf::getTextWidth ( size,
text 
)

calculate how wide a given text string will be on a page, at a given size. this can be called externally, but is alse used by the other class functions

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

References PRVTcheckTextDirective(), selectFont(), and setCurrentFont().

Referenced by PRVTgetTextPosition().

                                  {
  // this function should not change any of the settings, though it will need to
  // track any directives which change during calculation, so copy them at the start
  // and put them back at the end.
  $store_currentTextState = $this->currentTextState;

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

  // converts a number or a float to a string so it can get the width
  $text = "$text";

  // hmm, this is where it all starts to get tricky - use the font information to
  // calculate the width of each character, add them up and convert to user units
  $w=0;
  $len=strlen($text);
  $cf = $this->currentFont;
  for ($i=0;$i<$len;$i++){
    $f=1;
    $directive = $this->PRVTcheckTextDirective($text,$i,$f);
    if ($directive){
      if ($f){
        $this->setCurrentFont();
        $cf = $this->currentFont;
      }
      $i=$i+$directive-1;
    } else {
      $char=ord($text[$i]);
      if (isset($this->fonts[$cf]['differences'][$char])){
        // then this character is being replaced by another
        $name = $this->fonts[$cf]['differences'][$char];
        if (isset($this->fonts[$cf]['C'][$name]['WX'])){
          $w+=$this->fonts[$cf]['C'][$name]['WX'];
        }
      } else if (isset($this->fonts[$cf]['C'][$char]['WX'])){
        $w+=$this->fonts[$cf]['C'][$char]['WX'];
      }
    }
  }
  
  $this->currentTextState = $store_currentTextState;
  $this->setCurrentFont();

  return $w*$size/1000;
}

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