暂无描述

File.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * @package php-font-lib
  4. * @link https://github.com/PhenX/php-font-lib
  5. * @author Fabien Ménager <fabien.menager@gmail.com>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. */
  8. namespace FontLib\EOT;
  9. /**
  10. * EOT font file.
  11. *
  12. * @package php-font-lib
  13. */
  14. class File extends \FontLib\TrueType\File {
  15. const TTEMBED_SUBSET = 0x00000001;
  16. const TTEMBED_TTCOMPRESSED = 0x00000004;
  17. const TTEMBED_FAILIFVARIATIONSIMULATED = 0x00000010;
  18. const TTMBED_EMBEDEUDC = 0x00000020;
  19. const TTEMBED_VALIDATIONTESTS = 0x00000040; // Deprecated
  20. const TTEMBED_WEBOBJECT = 0x00000080;
  21. const TTEMBED_XORENCRYPTDATA = 0x10000000;
  22. /**
  23. * @var Header
  24. */
  25. public $header;
  26. function parseHeader() {
  27. if (!empty($this->header)) {
  28. return;
  29. }
  30. $this->header = new Header($this);
  31. $this->header->parse();
  32. }
  33. function parse() {
  34. $this->parseHeader();
  35. $flags = $this->header->data["Flags"];
  36. if ($flags & self::TTEMBED_TTCOMPRESSED) {
  37. $mtx_version = $this->readUInt8();
  38. $mtx_copy_limit = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8();
  39. $mtx_offset_1 = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8();
  40. $mtx_offset_2 = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8();
  41. /*
  42. var_dump("$mtx_version $mtx_copy_limit $mtx_offset_1 $mtx_offset_2");
  43. $pos = $this->pos();
  44. $size = $mtx_offset_1 - $pos;
  45. var_dump("pos: $pos");
  46. var_dump("size: $size");*/
  47. }
  48. if ($flags & self::TTEMBED_XORENCRYPTDATA) {
  49. // Process XOR
  50. }
  51. // TODO Read font data ...
  52. }
  53. /**
  54. * Little endian version of the read method
  55. *
  56. * @param int $n The number of bytes to read
  57. *
  58. * @return string
  59. */
  60. public function read($n) {
  61. if ($n < 1) {
  62. return "";
  63. }
  64. $string = (string) fread($this->f, $n);
  65. $chunks = mb_str_split($string, 2, '8bit');
  66. $chunks = array_map("strrev", $chunks);
  67. return implode("", $chunks);
  68. }
  69. public function readUInt32() {
  70. $uint32 = parent::readUInt32();
  71. return $uint32 >> 16 & 0x0000FFFF | $uint32 << 16 & 0xFFFF0000;
  72. }
  73. /**
  74. * Get font copyright
  75. *
  76. * @return string|null
  77. */
  78. function getFontCopyright() {
  79. return null;
  80. }
  81. /**
  82. * Get font name
  83. *
  84. * @return string|null
  85. */
  86. function getFontName() {
  87. return $this->header->data["FamilyName"];
  88. }
  89. /**
  90. * Get font subfamily
  91. *
  92. * @return string|null
  93. */
  94. function getFontSubfamily() {
  95. return $this->header->data["StyleName"];
  96. }
  97. /**
  98. * Get font subfamily ID
  99. *
  100. * @return string|null
  101. */
  102. function getFontSubfamilyID() {
  103. return $this->header->data["StyleName"];
  104. }
  105. /**
  106. * Get font full name
  107. *
  108. * @return string|null
  109. */
  110. function getFontFullName() {
  111. return $this->header->data["FullName"];
  112. }
  113. /**
  114. * Get font version
  115. *
  116. * @return string|null
  117. */
  118. function getFontVersion() {
  119. return $this->header->data["VersionName"];
  120. }
  121. /**
  122. * Get font weight
  123. *
  124. * @return string|null
  125. */
  126. function getFontWeight() {
  127. return $this->header->data["Weight"];
  128. }
  129. /**
  130. * Get font Postscript name
  131. *
  132. * @return string|null
  133. */
  134. function getFontPostscriptName() {
  135. return null;
  136. }
  137. }