encoding_map.cls.php 846 B

123456789101112131415161718192021222324252627282930313233343536
  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$
  8. */
  9. /**
  10. * Encoding map used to map a code point to a Unicode char.
  11. *
  12. * @package php-font-lib
  13. */
  14. class Encoding_Map {
  15. private $f;
  16. function __construct($file) {
  17. $this->f = fopen($file, "r");
  18. }
  19. function parse(){
  20. $map = array();
  21. while($line = fgets($this->f)) {
  22. if (preg_match("/^[\!\=]([0-9A-F]{2,})\s+U\+([0-9A-F]{2})([0-9A-F]{2})\s+([^\s]+)/", $line, $matches)) {
  23. $unicode = (hexdec($matches[2]) << 8) + hexdec($matches[3]);
  24. $map[hexdec($matches[1])] = array($unicode, $matches[4]);
  25. }
  26. }
  27. ksort($map);
  28. return $map;
  29. }
  30. }