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

Cpdf::openFont ( font )

open the font file and return a php structure containing it. first check if this one has been done before and saved in a form more suited to php note that if a php serialized version does not exist it will try and make one, but will require write access to the directory to do it... it is MUCH faster to have these serialized files.

private

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

References addMessage().

Referenced by selectFont().

                        {
  // assume that $font contains both the path and perhaps the extension to the file, split them
  $pos=strrpos($font,'/');
  if ($pos===false){
    $dir = './';
    $name = $font;
  } else {
    $dir=substr($font,0,$pos+1);
    $name=substr($font,$pos+1);
  }

  if (substr($name,-4)=='.afm'){
    $name=substr($name,0,strlen($name)-4);
  }
  $this->addMessage('openFont: '.$font.' - '.$name);
  if (file_exists($dir.'php_'.$name.'.afm')){
    $this->addMessage('openFont: php file exists '.$dir.'php_'.$name.'.afm');
    $tmp = file($dir.'php_'.$name.'.afm');
    $this->fonts[$font]=unserialize($tmp[0]);
    if (!isset($this->fonts[$font]['_version_']) || $this->fonts[$font]['_version_']<1){
      // if the font file is old, then clear it out and prepare for re-creation
      $this->addMessage('openFont: clear out, make way for new version.');
      unset($this->fonts[$font]);
    }
  }
  if (!isset($this->fonts[$font]) && file_exists($dir.$name.'.afm')){
    // then rebuild the php_<font>.afm file from the <font>.afm file
    $this->addMessage('openFont: build php file from '.$dir.$name.'.afm');
    $data = array();
    $file = file($dir.$name.'.afm');
    foreach ($file as $rowA){
      $row=trim($rowA);
      $pos=strpos($row,' ');
      if ($pos){
        // then there must be some keyword
        $key = substr($row,0,$pos);
        switch ($key){
          case 'FontName':
          case 'FullName':
          case 'FamilyName':
          case 'Weight':
          case 'ItalicAngle':
          case 'IsFixedPitch':
          case 'CharacterSet':
          case 'UnderlinePosition':
          case 'UnderlineThickness':
          case 'Version':
          case 'EncodingScheme':
          case 'CapHeight':
          case 'XHeight':
          case 'Ascender':
          case 'Descender':
          case 'StdHW':
          case 'StdVW':
          case 'StartCharMetrics':
            $data[$key]=trim(substr($row,$pos));
            break;
          case 'FontBBox':
            $data[$key]=explode(' ',trim(substr($row,$pos)));
            break;
          case 'C':
            //C 39 ; WX 222 ; N quoteright ; B 53 463 157 718 ;
            $bits=explode(';',trim($row));
            $dtmp=array();
            foreach($bits as $bit){
              $bits2 = explode(' ',trim($bit));
              if (strlen($bits2[0])){
                if (count($bits2)>2){
                  $dtmp[$bits2[0]]=array();
                  for ($i=1;$i<count($bits2);$i++){
                    $dtmp[$bits2[0]][]=$bits2[$i];
                  }
                } else if (count($bits2)==2){
                  $dtmp[$bits2[0]]=$bits2[1];
                }
              }
            }
            if ($dtmp['C']>=0){
              $data['C'][$dtmp['C']]=$dtmp;
              $data['C'][$dtmp['N']]=$dtmp;
            } else {
              $data['C'][$dtmp['N']]=$dtmp;
            }
            break;
          case 'KPX':
            //KPX Adieresis yacute -40
            $bits=explode(' ',trim($row));
            $data['KPX'][$bits[1]][$bits[2]]=$bits[3];
            break;
        }
      }
    }
    $data['_version_']=1;
    $this->fonts[$font]=$data;
    $fp = fopen($dir.'php_'.$name.'.afm','w');
    fwrite($fp,serialize($data));
    fclose($fp);
  } else if (!isset($this->fonts[$font])){
    $this->addMessage('openFont: no font file found');
//    echo 'Font not Found '.$font;
  }
}

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