ReadAFM

The WooCommerce PDF & Print ReadAFM function.

Description

ReadAFM( $file, &$map ); 

Parameters (2)

0. $file
The file.
1. $map
The map.

Usage

  1. if ( !function_exists( 'ReadAFM' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-pdf-print/pdf/font/makefont/makefont.php'; 
  3.  
  4. // The file. 
  5. $file = null; 
  6.  
  7. // The map. 
  8. $map = &$map; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ReadAFM($file, $map); 
  12.  

Defined (1)

The function is defined in the following location(s).

/pdf/font/makefont/makefont.php  
  1. function ReadAFM($file, &$map) 
  2. //Read a font metric file 
  3. $a=file($file); 
  4. if(empty($a)) 
  5. die('File not found'); 
  6. $widths=array(); 
  7. $fm=array(); 
  8. $fix=array('Edot'=>'Edotaccent', 'edot'=>'edotaccent', 'Idot'=>'Idotaccent', 'Zdot'=>'Zdotaccent', 'zdot'=>'zdotaccent',  
  9. 'Odblacute'=>'Ohungarumlaut', 'odblacute'=>'ohungarumlaut', 'Udblacute'=>'Uhungarumlaut', 'udblacute'=>'uhungarumlaut',  
  10. 'Gcedilla'=>'Gcommaaccent', 'gcedilla'=>'gcommaaccent', 'Kcedilla'=>'Kcommaaccent', 'kcedilla'=>'kcommaaccent',  
  11. 'Lcedilla'=>'Lcommaaccent', 'lcedilla'=>'lcommaaccent', 'Ncedilla'=>'Ncommaaccent', 'ncedilla'=>'ncommaaccent',  
  12. 'Rcedilla'=>'Rcommaaccent', 'rcedilla'=>'rcommaaccent', 'Scedilla'=>'Scommaaccent', 'scedilla'=>'scommaaccent',  
  13. 'Tcedilla'=>'Tcommaaccent', 'tcedilla'=>'tcommaaccent', 'Dslash'=>'Dcroat', 'dslash'=>'dcroat', 'Dmacron'=>'Dcroat', 'dmacron'=>'dcroat',  
  14. 'combininggraveaccent'=>'gravecomb', 'combininghookabove'=>'hookabovecomb', 'combiningtildeaccent'=>'tildecomb',  
  15. 'combiningacuteaccent'=>'acutecomb', 'combiningdotbelow'=>'dotbelowcomb', 'dongsign'=>'dong'); 
  16. foreach($a as $l) 
  17. $e=explode(' ', rtrim($l)); 
  18. if(count($e)<2) 
  19. continue; 
  20. $code=$e[0]; 
  21. $param=$e[1]; 
  22. if($code=='C') 
  23. //Character metrics 
  24. $cc=(int)$e[1]; 
  25. $w=$e[4]; 
  26. $gn=$e[7]; 
  27. if(substr($gn, -4)=='20AC') 
  28. $gn='Euro'; 
  29. if(isset($fix[$gn])) 
  30. //Fix incorrect glyph name 
  31. foreach($map as $c=>$n) 
  32. if($n==$fix[$gn]) 
  33. $map[$c]=$gn; 
  34. if(empty($map)) 
  35. //Symbolic font: use built-in encoding 
  36. $widths[$cc]=$w; 
  37. else 
  38. $widths[$gn]=$w; 
  39. if($gn=='X') 
  40. $fm['CapXHeight']=$e[13]; 
  41. if($gn=='.notdef') 
  42. $fm['MissingWidth']=$w; 
  43. elseif($code=='FontName') 
  44. $fm['FontName']=$param; 
  45. elseif($code=='Weight') 
  46. $fm['Weight']=$param; 
  47. elseif($code=='ItalicAngle') 
  48. $fm['ItalicAngle']=(double)$param; 
  49. elseif($code=='Ascender') 
  50. $fm['Ascender']=(int)$param; 
  51. elseif($code=='Descender') 
  52. $fm['Descender']=(int)$param; 
  53. elseif($code=='UnderlineThickness') 
  54. $fm['UnderlineThickness']=(int)$param; 
  55. elseif($code=='UnderlinePosition') 
  56. $fm['UnderlinePosition']=(int)$param; 
  57. elseif($code=='IsFixedPitch') 
  58. $fm['IsFixedPitch']=($param=='true'); 
  59. elseif($code=='FontBBox') 
  60. $fm['FontBBox']=array($e[1], $e[2], $e[3], $e[4]); 
  61. elseif($code=='CapHeight') 
  62. $fm['CapHeight']=(int)$param; 
  63. elseif($code=='StdVW') 
  64. $fm['StdVW']=(int)$param; 
  65. if(!isset($fm['FontName'])) 
  66. die('FontName not found'); 
  67. if(!empty($map)) 
  68. if(!isset($widths['.notdef'])) 
  69. $widths['.notdef']=600; 
  70. if(!isset($widths['Delta']) && isset($widths['increment'])) 
  71. $widths['Delta']=$widths['increment']; 
  72. //Order widths according to map 
  73. for($i=0;$i<=255;$i++) 
  74. if(!isset($widths[$map[$i]])) 
  75. echo '<b>Warning:</b> character '.$map[$i].' is missing<br>'; 
  76. $widths[$i]=$widths['.notdef']; 
  77. else 
  78. $widths[$i]=$widths[$map[$i]]; 
  79. $fm['Widths']=$widths; 
  80. return $fm;