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

Cpdf::selectFont ( fontName,
encoding = '',
set = 1 

if the font is not loaded then load it and make the required object else just make it the current font the encoding array can contain 'encoding'=> 'none','WinAnsiEncoding','MacRomanEncoding' or 'MacExpertEncoding' note that encoding='none' will need to be used for symbolic fonts and 'differences' => an array of mappings between numbers 0->255 and character names.

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

References $options, addMessage(), o_contents(), o_font(), o_fontDescriptor(), openFont(), and setCurrentFont().

Referenced by addText(), addTextWrap(), getFontDecender(), getFontHeight(), getTextWidth(), and setCurrentFont().

  if (!isset($this->fonts[$fontName])){
    // load the file
    if (isset($this->fonts[$fontName])){
//      $dir=substr($fontName,0,$pos+1);
      if (substr($name,-4)=='.afm'){
      if (is_array($encoding)){
        // then encoding and differences might be set
        if (isset($encoding['encoding'])){
        if (isset($encoding['differences'])){
      } else if (strlen($encoding)){
        // then perhaps only the encoding has been set
      $fontObj = $this->numObj;
      // if this is a '.afm' font, and there is a '.pfa' file to go with it ( as there
      // should be for all non-basic fonts), then load it into an object and put the
      // references into the font object
      $basefile = substr($fontName,0,strlen($fontName)-4);
      if (file_exists($basefile.'.pfb')){
        $fbtype = 'pfb';
      } else if (file_exists($basefile.'.ttf')){
        $fbtype = 'ttf';
      } else {
      $fbfile = $basefile.'.'.$fbtype;
//      $pfbfile = substr($fontName,0,strlen($fontName)-4).'.pfb';
//      $ttffile = substr($fontName,0,strlen($fontName)-4).'.ttf';
      $this->addMessage('selectFont: checking for - '.$fbfile);
      if (substr($fontName,-4)=='.afm' && strlen($fbtype) ){
        $adobeFontName = $this->fonts[$fontName]['FontName'];
//        $fontObj = $this->numObj;
        $this->addMessage('selectFont: adding font file - '.$fbfile.' - '.$adobeFontName);
        // find the array of fond widths, and put that into an object.
        $firstChar = -1;
        $lastChar = 0;
        $widths = array();
        foreach ($this->fonts[$fontName]['C'] as $num=>$d){
          if (intval($num)>0 || $num=='0'){
            if ($lastChar>0 && $num>$lastChar+1){
                $widths[] = 0;
            $widths[] = $d['WX'];
            if ($firstChar==-1){
              $firstChar = $num;
            $lastChar = $num;
        // also need to adjust the widths for the differences array
        if (isset($options['differences'])){
          foreach($options['differences'] as $charNum=>$charName){
            if ($charNum>$lastChar){
            if (isset($this->fonts[$fontName]['C'][$charName])){
        $this->addMessage('selectFont: FirstChar='.$firstChar);
        $this->addMessage('selectFont: LastChar='.$lastChar);
        foreach($widths as $width){
          $this->objects[$this->numObj]['c'].=' '.$width;
        $this->objects[$this->numObj]['c'].=' ]';
        $widthid = $this->numObj;

        // load the pfb file, and put that into an object too.
        // note that pdf supports only binary format type 1 font files, though there is a 
        // simple utility to convert them from pfa to pfb.
        $fp = fopen($fbfile,'rb');
        $tmp = get_magic_quotes_runtime();
        $data = fread($fp,filesize($fbfile));

        // create the font descriptor
        $fontDescriptorId = $this->numObj;
        $pfbid = $this->numObj;
        // determine flags (more than a little flakey, hopefully will not matter much)
        if ($this->fonts[$fontName]['ItalicAngle']!=0){ $flags+=pow(2,6); }
        if ($this->fonts[$fontName]['IsFixedPitch']=='true'){ $flags+=1; }
        $flags+=pow(2,5); // assume non-sybolic

        $list = array('Ascent'=>'Ascender','CapHeight'=>'CapHeight','Descent'=>'Descender','FontBBox'=>'FontBBox','ItalicAngle'=>'ItalicAngle');
        $fdopt = array(
         ,'StemV'=>100  // don't know what the value for this should be!
        foreach($list as $k=>$v){
          if (isset($this->fonts[$fontName][$v])){

        if ($fbtype=='pfb'){
        } else if ($fbtype=='ttf'){

        // embed the font program
        // determine the cruicial lengths within this file
        if ($fbtype=='pfb'){
          $l1 = strpos($data,'eexec')+6;
          $l2 = strpos($data,'00000000')-$l1;
          $l3 = strlen($data)-$l2-$l1;
        } else if ($fbtype=='ttf'){
          $l1 = strlen($data);

        // tell the font object about all this new stuff
        $tmp = array('BaseFont'=>$adobeFontName,'Widths'=>$widthid
        if ($fbtype=='ttf'){
        $this->addMessage('adding extra info to font.('.$fontObj.')');
        foreach($tmp as $fk=>$fv){
          $this->addMessage($fk." : ".$fv);

      } else {
        $this->addMessage('selectFont: pfb or ttf file not found, ok if this is one of the 14 standard fonts');

      // also set the differences here, note that this means that these will take effect only the 
      //first time that a font is selected, else they are ignored
      if (isset($options['differences'])){
  if ($set && isset($this->fonts[$fontName])){
    // so if for some reason the font was not set in the last one then it will not be selected
    // the next line means that if a new font is selected, then the current text state will be
    // applied to it as well.
  return $this->currentFontNum;

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