/library/Zend/Pdf/Resource/Font/CidFont/TrueType.php
PHP | 88 lines | 24 code | 12 blank | 52 comment | 0 complexity | 8199c70f964c41a66eba805ac2a79f0c MD5 | raw file
Possible License(s): AGPL-1.0
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-2012 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: TrueType.php 24594 2012-01-05 21:27:01Z matthew $
21 */
22
23
24/** Internally used classes */
25
26require_once 'Zend/Pdf/Element/Name.php';
27
28/** Zend_Pdf_Resource_Font_FontDescriptor */
29require_once 'Zend/Pdf/Resource/Font/FontDescriptor.php';
30
31
32/** Zend_Pdf_Resource_Font_CidFont */
33require_once 'Zend/Pdf/Resource/Font/CidFont.php';
34
35/**
36 * Type 2 CIDFonts implementation
37 *
38 * For Type 2, the CIDFont program is actually a TrueType font program, which has
39 * no native notion of CIDs. In a TrueType font program, glyph descriptions are
40 * identified by glyph index values. Glyph indices are internal to the font and are not
41 * defined consistently from one font to another. Instead, a TrueType font program
42 * contains a 'cmap' table that provides mappings directly from character codes to
43 * glyph indices for one or more predefined encodings.
44 *
45 * @package Zend_Pdf
46 * @subpackage Fonts
47 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
48 * @license http://framework.zend.com/license/new-bsd New BSD License
49 */
50class Zend_Pdf_Resource_Font_CidFont_TrueType extends Zend_Pdf_Resource_Font_CidFont
51{
52 /**
53 * Object constructor
54 *
55 * @todo Joing this class with Zend_Pdf_Resource_Font_Simple_Parsed_TrueType
56 *
57 * @param Zend_Pdf_FileParser_Font_OpenType_TrueType $fontParser Font parser
58 * object containing parsed TrueType file.
59 * @param integer $embeddingOptions Options for font embedding.
60 * @throws Zend_Pdf_Exception
61 */
62 public function __construct(Zend_Pdf_FileParser_Font_OpenType_TrueType $fontParser, $embeddingOptions)
63 {
64 parent::__construct($fontParser, $embeddingOptions);
65
66 $this->_fontType = Zend_Pdf_Font::TYPE_CIDFONT_TYPE_2;
67
68 $this->_resource->Subtype = new Zend_Pdf_Element_Name('CIDFontType2');
69
70 $fontDescriptor = Zend_Pdf_Resource_Font_FontDescriptor::factory($this, $fontParser, $embeddingOptions);
71 $this->_resource->FontDescriptor = $this->_objectFactory->newObject($fontDescriptor);
72
73 /* Prepare CIDToGIDMap */
74 // Initialize 128K string of null characters (65536 2 byte integers)
75 $cidToGidMapData = str_repeat("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 8192);
76 // Fill the index
77 $charGlyphs = $this->_cmap->getCoveredCharactersGlyphs();
78 foreach ($charGlyphs as $charCode => $glyph) {
79 $cidToGidMapData[$charCode*2 ] = chr($glyph >> 8);
80 $cidToGidMapData[$charCode*2 + 1] = chr($glyph & 0xFF);
81 }
82 // Store CIDToGIDMap within compressed stream object
83 $cidToGidMap = $this->_objectFactory->newStreamObject($cidToGidMapData);
84 $cidToGidMap->dictionary->Filter = new Zend_Pdf_Element_Name('FlateDecode');
85 $this->_resource->CIDToGIDMap = $cidToGidMap;
86 }
87
88}