Font_Table_glyf

`glyf` font table.

Defined (1)

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

/lib/dompdf/lib/php-font-lib/classes/Font_Table_glyf.php  
  1. class Font_Table_glyf extends Font_Table { 
  2. protected function _parse() { 
  3. $font = $this->getFont(); 
  4. $offset = $font->pos(); 
  5.  
  6. $loca = $font->getData("loca"); 
  7. $real_loca = array_slice($loca, 0, -1); // Not the last dummy loca entry 
  8.  
  9. $data = array(); 
  10.  
  11. foreach($real_loca as $gid => $location) { 
  12. $_offset = $offset + $loca[$gid]; 
  13. $_size = $loca[$gid+1] - $loca[$gid]; 
  14. $data[$gid] = Font_Glyph_Outline::init($this, $_offset, $_size); 
  15.  
  16. $this->data = $data; 
  17.  
  18. public function getGlyphIDs($gids = array()) { 
  19. $glyphIDs = array(); 
  20.  
  21. foreach ($gids as $_gid) { 
  22. $_glyph = $this->data[$_gid]; 
  23. $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); 
  24.  
  25. return array_unique(array_merge($gids, $glyphIDs)); 
  26.  
  27. public function toHTML() { 
  28. $max = 160; 
  29. $font = $this->getFont(); 
  30.  
  31. $head = $font->getData("head"); 
  32. $head_json = json_encode($head); 
  33.  
  34. $os2 = $font->getData("OS/2"); 
  35. $os2_json = json_encode($os2); 
  36.  
  37. $hmtx = $font->getData("hmtx"); 
  38. $hmtx_json = json_encode($hmtx); 
  39.  
  40. $names = $font->getData("post", "names"); 
  41. $glyphIndexArray = array_flip($font->getUnicodeCharMap()); 
  42.  
  43. $width = (abs($head["xMin"]) + $head["xMax"]); 
  44. $height = (abs($head["yMin"]) + $head["yMax"]); 
  45.  
  46. $ratio = 1; 
  47. if ($width > $max || $height > $max) { 
  48. $ratio = max($width, $height) / $max; 
  49. $width = round($width/$ratio); 
  50. $height = round($height/$ratio); 
  51.  
  52. $n = 500; 
  53.  
  54. $s = "<h3>"."Only the first $n simple glyphs are shown (".count($this->data)." total) 
  55. <div class='glyph-view simple'>Simple glyph</div> 
  56. <div class='glyph-view composite'>Composite glyph</div> 
  57. Zoom: <input type='range' value='100' max='400' onchange='Glyph.resize(this.value)' /> 
  58. </h3> 
  59. <script> 
  60. Glyph.ratio = $ratio; 
  61. Glyph.head = $head_json; 
  62. Glyph.os2 = $os2_json; 
  63. Glyph.hmtx = $hmtx_json; 
  64. Glyph.width = $width; 
  65. Glyph.height = $height; 
  66. </script>"; 
  67.  
  68. foreach($this->data as $g => $glyph) { 
  69. if ($n-- <= 0) { 
  70. break; 
  71.  
  72. $glyph->parseData(); 
  73.  
  74. $shape = array( 
  75. "SVGContours" => $glyph->getSVGContours(),  
  76. "xMin" => $glyph->xMin,  
  77. "yMin" => $glyph->yMin,  
  78. "xMax" => $glyph->xMax,  
  79. "yMax" => $glyph->yMax,  
  80. ); 
  81. $shape_json = json_encode($shape); 
  82.  
  83. $type = ($glyph instanceof Font_Glyph_Outline_Simple ? "simple" : "composite"); 
  84. $char = isset($glyphIndexArray[$g]) ? $glyphIndexArray[$g] : 0; 
  85. $name = isset($names[$g]) ? $names[$g] : sprintf("uni%04x", $char); 
  86. $char = $char ? "&#{$glyphIndexArray[$g]};" : ""; 
  87.  
  88. $s .= "<div class='glyph-view $type' id='glyph-$g'> 
  89. <span class='glyph-id'>$g</span>  
  90. <span class='char'>$char</span> 
  91. <span class='char-name'>$name</span> 
  92. "; 
  93.  
  94. if ($type == "composite") { 
  95. foreach ($glyph->getGlyphIDs() as $_id) { 
  96. $s .= "<a href='#glyph-$_id' class='glyph-component-id'>$_id</a> "; 
  97.  
  98. $s .= "<br /> 
  99. <canvas width='$width' height='$height' id='glyph-canvas-$g'></canvas> 
  100. </div> 
  101. <script>Glyph.glyphs.push([$g, $shape_json]);</script>"; 
  102.  
  103. return $s; 
  104.  
  105.  
  106. protected function _encode() { 
  107. $font = $this->getFont(); 
  108. $subset = $font->getSubset(); 
  109. $data = $this->data; 
  110.  
  111. $loca = array(); 
  112.  
  113. $length = 0; 
  114. foreach($subset as $gid) { 
  115. $loca[] = $length; 
  116. $length += $data[$gid]->encode(); 
  117.  
  118. $loca[] = $length; // dummy loca 
  119. $font->getTableObject("loca")->data = $loca; 
  120.  
  121. return $length;