PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/include/PHPExcel/Writer/PDF/lib/php-font-lib/classes/font_table_directory_entry.cls.php

https://bitbucket.org/ite/on-track-code-base
PHP | 121 lines | 68 code | 28 blank | 25 comment | 2 complexity | 7d0c854f636ebead27d047c7b6d6ecc1 MD5 | raw file
  1. <?php
  2. /**
  3. * @package php-font-lib
  4. * @link http://php-font-lib.googlecode.com/
  5. * @author Fabien Ménager <fabien.menager@gmail.com>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. * @version $Id: font_table_directory_entry.cls.php 38 2011-11-07 17:09:59Z fabien.menager $
  8. */
  9. /**
  10. * Generic Font table directory entry.
  11. *
  12. * @package php-font-lib
  13. */
  14. class Font_Table_Directory_Entry extends Font_Binary_Stream {
  15. /**
  16. * @var Font_TrueType
  17. */
  18. protected $font;
  19. /**
  20. * @var Font_Table
  21. */
  22. protected $font_table;
  23. public $entryLength = 4;
  24. var $tag;
  25. var $checksum;
  26. var $offset;
  27. var $length;
  28. protected $origF;
  29. static function computeChecksum($data){
  30. $len = strlen($data);
  31. $mod = $len % 4;
  32. if ($mod) {
  33. $data = str_pad($data, $len + (4 - $mod), "\0");
  34. }
  35. $len = strlen($data);
  36. $hi = 0x0000;
  37. $lo = 0x0000;
  38. for ($i = 0; $i < $len; $i += 4) {
  39. $hi += (ord($data[$i] ) << 8) + ord($data[$i+1]);
  40. $lo += (ord($data[$i+2]) << 8) + ord($data[$i+3]);
  41. $hi += $lo >> 16;
  42. $lo = $lo & 0xFFFF;
  43. $hi = $hi & 0xFFFF;
  44. }
  45. return ($hi << 8) + $lo;
  46. }
  47. function __construct(Font_TrueType $font) {
  48. $this->font = $font;
  49. $this->f = $font->f;
  50. $this->tag = $this->read(4);
  51. }
  52. function open($filename, $mode = self::modeRead) {
  53. // void
  54. }
  55. function setTable(Font_Table $font_table) {
  56. $this->font_table = $font_table;
  57. }
  58. function encode($entry_offset){
  59. Font::d("\n==== $this->tag ====");
  60. //Font::d("Entry offset = $entry_offset");
  61. $data = $this->font_table;
  62. $font = $this->font;
  63. $table_offset = $font->pos();
  64. $table_length = $data->encode();
  65. $font->seek($table_offset);
  66. $table_data = $font->read($table_length);
  67. $font->seek($entry_offset);
  68. $font->write($this->tag, 4);
  69. $font->writeUInt32(self::computeChecksum($table_data));
  70. $font->writeUInt32($table_offset);
  71. $font->writeUInt32($table_length);
  72. Font::d("Bytes written = $table_length");
  73. $font->seek($table_offset + $table_length);
  74. }
  75. /**
  76. * @return Font_TrueType
  77. */
  78. function getFont() {
  79. return $this->font;
  80. }
  81. function startRead() {
  82. $this->seek($this->offset);
  83. }
  84. function endRead() {
  85. //
  86. }
  87. function startWrite() {
  88. $this->seek($this->offset);
  89. }
  90. function endWrite() {
  91. //
  92. }
  93. }