Font_Glyph_Outline_Composite

Composite glyph outline.

Defined (1)

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

/lib/dompdf/lib/php-font-lib/classes/Font_Glyph_Outline_Composite.php  
  1. class Font_Glyph_Outline_Composite extends Font_Glyph_Outline { 
  2. const ARG_1_AND_2_ARE_WORDS = 0x0001; 
  3. const ARGS_ARE_XY_VALUES = 0x0002; 
  4. const ROUND_XY_TO_GRID = 0x0004; 
  5. const WE_HAVE_A_SCALE = 0x0008; 
  6. const MORE_COMPONENTS = 0x0020; 
  7. const WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; 
  8. const WE_HAVE_A_TWO_BY_TWO = 0x0080; 
  9. const WE_HAVE_INSTRUCTIONS = 0x0100; 
  10. const USE_MY_METRICS = 0x0200; 
  11. const OVERLAP_COMPOUND = 0x0400; 
  12.  
  13. /** 
  14. * @var Font_Glyph_Outline_Component[] 
  15. */ 
  16. public $components = array(); 
  17.  
  18. function getGlyphIDs() { 
  19. if (empty($this->components)) { 
  20. $this->parseData(); 
  21.  
  22. $glyphIDs = array(); 
  23. foreach ($this->components as $_component) { 
  24. $glyphIDs[] = $_component->glyphIndex; 
  25.  
  26. $_glyph = $this->table->data[$_component->glyphIndex]; 
  27. $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); 
  28.  
  29. return $glyphIDs; 
  30.  
  31. /**function parse() { 
  32. //$this->parseData(); 
  33. }*/ 
  34.  
  35. function parseData() { 
  36. parent::parseData(); 
  37.  
  38. $font = $this->getFont(); 
  39.  
  40. do { 
  41. $flags = $font->readUInt16(); 
  42. $glyphIndex = $font->readUInt16(); 
  43.  
  44. $a = 1.0; $b = 0.0; 
  45. $c = 0.0; $d = 1.0; 
  46. $e = 0.0; $f = 0.0; 
  47.  
  48. $point_compound = null; 
  49. $point_component = null; 
  50.  
  51. $instructions = null; 
  52.  
  53. if ($flags & self::ARG_1_AND_2_ARE_WORDS) { 
  54. if ($flags & self::ARGS_ARE_XY_VALUES) { 
  55. $e = $font->readInt16(); 
  56. $f = $font->readInt16(); 
  57. else { 
  58. $point_compound = $font->readUInt16(); 
  59. $point_component = $font->readUInt16(); 
  60. else { 
  61. if ($flags & self::ARGS_ARE_XY_VALUES) { 
  62. $e = $font->readInt8(); 
  63. $f = $font->readInt8(); 
  64. else { 
  65. $point_compound = $font->readUInt8(); 
  66. $point_component = $font->readUInt8(); 
  67.  
  68. if ($flags & self::WE_HAVE_A_SCALE) { 
  69. $a = $d = $font->readInt16(); 
  70. elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { 
  71. $a = $font->readInt16(); 
  72. $d = $font->readInt16(); 
  73. elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { 
  74. $a = $font->readInt16(); 
  75. $b = $font->readInt16(); 
  76. $c = $font->readInt16(); 
  77. $d = $font->readInt16(); 
  78.  
  79. //if ($flags & self::WE_HAVE_INSTRUCTIONS) { 
  80. // 
  81. //} 
  82.  
  83. $component = new Font_Glyph_Outline_Component(); 
  84. $component->flags = $flags; 
  85. $component->glyphIndex = $glyphIndex; 
  86. $component->a = $a; 
  87. $component->b = $b; 
  88. $component->c = $c; 
  89. $component->d = $d; 
  90. $component->e = $e; 
  91. $component->f = $f; 
  92. $component->point_compound = $point_compound; 
  93. $component->point_component = $point_component; 
  94. $component->instructions = $instructions; 
  95.  
  96. $this->components[] = $component; 
  97.  
  98. } while ($flags & self::MORE_COMPONENTS); 
  99.  
  100. function encode() { 
  101. $font = $this->getFont(); 
  102.  
  103. $gids = $font->getSubset(); 
  104.  
  105. $size = $font->writeInt16(-1); 
  106. $size += $font->writeFWord($this->xMin); 
  107. $size += $font->writeFWord($this->yMin); 
  108. $size += $font->writeFWord($this->xMax); 
  109. $size += $font->writeFWord($this->yMax); 
  110.  
  111. foreach ($this->components as $_i => $_component) { 
  112. $flags = 0; 
  113. if ($_component->point_component === null && $_component->point_compound === null) { 
  114. $flags |= self::ARGS_ARE_XY_VALUES; 
  115.  
  116. if (abs($_component->e) > 0x7F || abs($_component->f) > 0x7F) { 
  117. $flags |= self::ARG_1_AND_2_ARE_WORDS; 
  118. elseif ($_component->point_component > 0xFF || $_component->point_compound > 0xFF) { 
  119. $flags |= self::ARG_1_AND_2_ARE_WORDS; 
  120.  
  121. if ($_component->b == 0 && $_component->c == 0) { 
  122. if ($_component->a == $_component->d) { 
  123. if ($_component->a != 1.0) { 
  124. $flags |= self::WE_HAVE_A_SCALE; 
  125. else { 
  126. $flags |= self::WE_HAVE_AN_X_AND_Y_SCALE; 
  127. else { 
  128. $flags |= self::WE_HAVE_A_TWO_BY_TWO; 
  129.  
  130. if ($_i < count($this->components)-1) { 
  131. $flags |= self::MORE_COMPONENTS; 
  132.  
  133. $size += $font->writeUInt16($flags); 
  134.  
  135. $new_gid = array_search($_component->glyphIndex, $gids); 
  136. $size += $font->writeUInt16($new_gid); 
  137.  
  138. if ($flags & self::ARG_1_AND_2_ARE_WORDS) { 
  139. if ($flags & self::ARGS_ARE_XY_VALUES) { 
  140. $size += $font->writeInt16($_component->e); 
  141. $size += $font->writeInt16($_component->f); 
  142. else { 
  143. $size += $font->writeUInt16($_component->point_compound); 
  144. $size += $font->writeUInt16($_component->point_component); 
  145. else { 
  146. if ($flags & self::ARGS_ARE_XY_VALUES) { 
  147. $size += $font->writeInt8($_component->e); 
  148. $size += $font->writeInt8($_component->f); 
  149. else { 
  150. $size += $font->writeUInt8($_component->point_compound); 
  151. $size += $font->writeUInt8($_component->point_component); 
  152.  
  153. if ($flags & self::WE_HAVE_A_SCALE) { 
  154. $size += $font->writeInt16($_component->a); 
  155. elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { 
  156. $size += $font->writeInt16($_component->a); 
  157. $size += $font->writeInt16($_component->d); 
  158. elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { 
  159. $size += $font->writeInt16($_component->a); 
  160. $size += $font->writeInt16($_component->b); 
  161. $size += $font->writeInt16($_component->c); 
  162. $size += $font->writeInt16($_component->d); 
  163.  
  164. return $size; 
  165.  
  166. public function getSVGContours() { 
  167. $contours = array(); 
  168.  
  169. /** @var Font_Table_glyf $glyph_data */ 
  170. $glyph_data = $this->getFont()->getTableObject("glyf"); 
  171.  
  172. /** @var Font_Glyph_Outline[] $glyphs */ 
  173. $glyphs = $glyph_data->data; 
  174.  
  175. foreach ($this->components as $component) { 
  176. $contours[] = array( 
  177. "contours" => $glyphs[$component->glyphIndex]->getSVGContours(),  
  178. "transform" => $component->getMatrix(),  
  179. ); 
  180.  
  181. return $contours;