You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.4 KiB

11 years ago
9 years ago
11 years ago
10 years ago
11 years ago
9 years ago
11 years ago
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Pdf
  17. * @subpackage Fonts
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Internally used classes */
  23. // require_once 'Zend/Pdf/Element/Name.php';
  24. /** Zend_Pdf_Resource_Font_FontDescriptor */
  25. // require_once 'Zend/Pdf/Resource/Font/FontDescriptor.php';
  26. /** Zend_Pdf_Resource_Font_CidFont */
  27. // require_once 'Zend/Pdf/Resource/Font/CidFont.php';
  28. /**
  29. * Type 2 CIDFonts implementation
  30. *
  31. * For Type 2, the CIDFont program is actually a TrueType font program, which has
  32. * no native notion of CIDs. In a TrueType font program, glyph descriptions are
  33. * identified by glyph index values. Glyph indices are internal to the font and are not
  34. * defined consistently from one font to another. Instead, a TrueType font program
  35. * contains a 'cmap' table that provides mappings directly from character codes to
  36. * glyph indices for one or more predefined encodings.
  37. *
  38. * @package Zend_Pdf
  39. * @subpackage Fonts
  40. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Pdf_Resource_Font_CidFont_TrueType extends Zend_Pdf_Resource_Font_CidFont
  44. {
  45. /**
  46. * Object constructor
  47. *
  48. * @todo Joing this class with Zend_Pdf_Resource_Font_Simple_Parsed_TrueType
  49. *
  50. * @param Zend_Pdf_FileParser_Font_OpenType_TrueType $fontParser Font parser
  51. * object containing parsed TrueType file.
  52. * @param integer $embeddingOptions Options for font embedding.
  53. * @throws Zend_Pdf_Exception
  54. */
  55. public function __construct(Zend_Pdf_FileParser_Font_OpenType_TrueType $fontParser, $embeddingOptions)
  56. {
  57. parent::__construct($fontParser, $embeddingOptions);
  58. $this->_fontType = Zend_Pdf_Font::TYPE_CIDFONT_TYPE_2;
  59. $this->_resource->Subtype = new Zend_Pdf_Element_Name('CIDFontType2');
  60. $fontDescriptor = Zend_Pdf_Resource_Font_FontDescriptor::factory($this, $fontParser, $embeddingOptions);
  61. $this->_resource->FontDescriptor = $this->_objectFactory->newObject($fontDescriptor);
  62. /* Prepare CIDToGIDMap */
  63. // Initialize 128K string of null characters (65536 2 byte integers)
  64. $cidToGidMapData = str_repeat("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 8192);
  65. // Fill the index
  66. $charGlyphs = $this->_cmap->getCoveredCharactersGlyphs();
  67. foreach ($charGlyphs as $charCode => $glyph) {
  68. $cidToGidMapData[$charCode*2 ] = chr($glyph >> 8);
  69. $cidToGidMapData[$charCode*2 + 1] = chr($glyph & 0xFF);
  70. }
  71. // Store CIDToGIDMap within compressed stream object
  72. $cidToGidMap = $this->_objectFactory->newStreamObject($cidToGidMapData);
  73. $cidToGidMap->dictionary->Filter = new Zend_Pdf_Element_Name('FlateDecode');
  74. $this->_resource->CIDToGIDMap = $cidToGidMap;
  75. }
  76. }