~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Pdf/Resource/Font/Type0.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * @package    Zend_Pdf
 
16
 * @subpackage Fonts
 
17
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
18
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
19
 */
 
20
 
 
21
/** Zend_Pdf_Resource_Font */
 
22
require_once 'Zend/Pdf/Resource/Font.php';
 
23
 
 
24
/** Zend_Pdf_Resource_Font_CidFont */
 
25
require_once 'Zend/Pdf/Resource/Font/CidFont.php';
 
26
 
 
27
/** Zend_Pdf_Resource_Font_CidFont_TrueType */
 
28
require_once 'Zend/Pdf/Resource/Font/CidFont/TrueType.php';
 
29
 
 
30
 
 
31
/**
 
32
 * Adobe PDF composite fonts implementation
 
33
 * 
 
34
 * A composite font is one whose glyphs are obtained from other fonts or from fontlike
 
35
 * objects called CIDFonts ({@link Zend_Pdf_Resource_Font_CidFont}), organized hierarchically.
 
36
 * In PDF, a composite font is represented by a font dictionary whose Subtype value is Type0; 
 
37
 * this is also called a Type 0 font (the Type 0 font at the top level of the hierarchy is the 
 
38
 * root font).
 
39
 * 
 
40
 * In PDF, a Type 0 font is a CID-keyed font.
 
41
 *
 
42
 * CID-keyed fonts provide effective method to operate with multi-byte character encodings.
 
43
 *  
 
44
 * The CID-keyed font architecture specifies the external representation of certain font programs, 
 
45
 * called CMap and CIDFont files, along with some conventions for combining and using those files.
 
46
 *  
 
47
 * A CID-keyed font is the combination of a CMap with one or more CIDFonts, simple fonts, 
 
48
 * or composite fonts containing glyph descriptions.
 
49
 * 
 
50
 * The term 'CID-keyed font' reflects the fact that CID (character identifier) numbers
 
51
 * are used to index and access the glyph descriptions in the font.
 
52
 * 
 
53
 *  
 
54
 * Font objects should be normally be obtained from the factory methods
 
55
 * {@link Zend_Pdf_Font::fontWithName} and {@link Zend_Pdf_Font::fontWithPath}.
 
56
 *
 
57
 * @package    Zend_Pdf
 
58
 * @subpackage Fonts
 
59
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
60
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
61
 */
 
62
class Zend_Pdf_Resource_Font_Type0 extends Zend_Pdf_Resource_Font
 
63
{
 
64
    /**
 
65
     * Descendant CIDFont
 
66
     * 
 
67
     * @var Zend_Pdf_Resource_Font_CidFont
 
68
     */
 
69
    private $_descendantFont;
 
70
 
 
71
 
 
72
    /**
 
73
     * Generate ToUnicode character map data
 
74
     * 
 
75
     * @return string
 
76
     */
 
77
    static private function getToUnicodeCMapData()
 
78
    {
 
79
        return '/CIDInit /ProcSet findresource begin '              . "\n"
 
80
             . '12 dict begin '                                     . "\n"
 
81
             . 'begincmap '                                         . "\n"
 
82
             . '/CIDSystemInfo '                                    . "\n"
 
83
             . '<</Registry (Adobe) '                               . "\n"
 
84
             . '/Ordering (UCS) '                                   . "\n"
 
85
             . '/Supplement 0'                                      . "\n"
 
86
             . '>> def'                                             . "\n"
 
87
             . '/CMapName /Adobe-Identity-UCS def '                 . "\n"
 
88
             . '/CMapType 2 def '                                   . "\n"
 
89
             . '1 begincodespacerange'                              . "\n"
 
90
             . '<0000> <FFFF> '                                     . "\n"
 
91
             . 'endcodespacerange '                                 . "\n"
 
92
             . '1 beginbfrange '                                    . "\n"
 
93
             . '<0000> <FFFF> <0000> '                              . "\n"
 
94
             . 'endbfrange '                                        . "\n"
 
95
             . 'endcmap '                                           . "\n"
 
96
             . 'CMapName currentdict /CMap defineresource pop '     . "\n"
 
97
             . 'end '
 
98
             . 'end ';
 
99
            }
 
100
 
 
101
    /**
 
102
     * Object constructor
 
103
     *
 
104
     */
 
105
    public function __construct(Zend_Pdf_Resource_Font_CidFont $descendantFont)
 
106
    {
 
107
        parent::__construct();
 
108
        
 
109
        $this->_objectFactory->attach($descendantFont->getFactory());
 
110
        
 
111
        $this->_fontType       = Zend_Pdf_Font::TYPE_TYPE_0;
 
112
        $this->_descendantFont = $descendantFont;
 
113
 
 
114
 
 
115
        $this->_fontNames    = $descendantFont->getFontNames();
 
116
 
 
117
        $this->_isBold       = $descendantFont->isBold();
 
118
        $this->_isItalic     = $descendantFont->isItalic();
 
119
        $this->_isMonospaced = $descendantFont->isMonospace();
 
120
 
 
121
        $this->_underlinePosition  = $descendantFont->getUnderlinePosition();
 
122
        $this->_underlineThickness = $descendantFont->getUnderlineThickness();
 
123
        $this->_strikePosition     = $descendantFont->getStrikePosition();
 
124
        $this->_strikeThickness    = $descendantFont->getStrikeThickness();
 
125
 
 
126
        $this->_unitsPerEm = $descendantFont->getUnitsPerEm();
 
127
 
 
128
        $this->_ascent  = $descendantFont->getAscent();
 
129
        $this->_descent = $descendantFont->getDescent();
 
130
        $this->_lineGap = $descendantFont->getLineGap();
 
131
        
 
132
        
 
133
        $this->_resource->Subtype         = new Zend_Pdf_Element_Name('Type0');
 
134
        $this->_resource->BaseFont        = new Zend_Pdf_Element_Name($descendantFont->getResource()->BaseFont->value);
 
135
        $this->_resource->DescendantFonts = new Zend_Pdf_Element_Array(array( $descendantFont->getResource() ));
 
136
        $this->_resource->Encoding        = new Zend_Pdf_Element_Name('Identity-H');
 
137
        
 
138
        $toUnicode = $this->_objectFactory->newStreamObject(self::getToUnicodeCMapData());
 
139
        $this->_resource->ToUnicode = $toUnicode;
 
140
        
 
141
    }
 
142
 
 
143
    /**
 
144
     * Returns an array of glyph numbers corresponding to the Unicode characters.
 
145
     *
 
146
     * Zend_Pdf uses 'Identity-H' encoding for Type 0 fonts.
 
147
     * So we don't need to perform any conversion 
 
148
     *
 
149
     * See also {@link glyphNumberForCharacter()}.
 
150
     *
 
151
     * @param array $characterCodes Array of Unicode character codes (code points).
 
152
     * @return array Array of glyph numbers.
 
153
     */
 
154
    public function glyphNumbersForCharacters($characterCodes)
 
155
    {
 
156
        return $characterCodes;
 
157
    }
 
158
 
 
159
    /**
 
160
     * Returns the glyph number corresponding to the Unicode character.
 
161
     *
 
162
     * Zend_Pdf uses 'Identity-H' encoding for Type 0 fonts.
 
163
     * So we don't need to perform any conversion 
 
164
     *
 
165
     * @param integer $characterCode Unicode character code (code point).
 
166
     * @return integer Glyph number.
 
167
     */
 
168
    public function glyphNumberForCharacter($characterCode)
 
169
    {
 
170
        return $characterCode;
 
171
    }
 
172
    
 
173
    /**
 
174
     * Returns a number between 0 and 1 inclusive that indicates the percentage
 
175
     * of characters in the string which are covered by glyphs in this font.
 
176
     *
 
177
     * Since no one font will contain glyphs for the entire Unicode character
 
178
     * range, this method can be used to help locate a suitable font when the
 
179
     * actual contents of the string are not known.
 
180
     *
 
181
     * Note that some fonts lie about the characters they support. Additionally,
 
182
     * fonts don't usually contain glyphs for control characters such as tabs
 
183
     * and line breaks, so it is rare that you will get back a full 1.0 score.
 
184
     * The resulting value should be considered informational only.
 
185
     *
 
186
     * @param string $string
 
187
     * @param string $charEncoding (optional) Character encoding of source text.
 
188
     *   If omitted, uses 'current locale'.
 
189
     * @return float
 
190
     */
 
191
    public function getCoveredPercentage($string, $charEncoding = '')
 
192
    {
 
193
        return $this->_descendantFont->getCoveredPercentage($string, $charEncoding);
 
194
    }
 
195
 
 
196
    /**
 
197
     * Returns the widths of the glyphs.
 
198
     *
 
199
     * The widths are expressed in the font's glyph space. You are responsible
 
200
     * for converting to user space as necessary. See {@link unitsPerEm()}.
 
201
     *
 
202
     * Throws an exception if the glyph number is out of range.
 
203
     *
 
204
     * See also {@link widthForGlyph()}.
 
205
     *
 
206
     * @param array &$glyphNumbers Array of glyph numbers.
 
207
     * @return array Array of glyph widths (integers).
 
208
     * @throws Zend_Pdf_Exception
 
209
     */
 
210
    public function widthsForGlyphs($glyphNumbers)
 
211
    {
 
212
        return $this->_descendantFont->widthsForChars($glyphNumbers);
 
213
    }
 
214
 
 
215
    /**
 
216
     * Returns the width of the glyph.
 
217
     *
 
218
     * Like {@link widthsForGlyphs()} but used for one glyph at a time.
 
219
     *
 
220
     * @param integer $glyphNumber
 
221
     * @return integer
 
222
     * @throws Zend_Pdf_Exception
 
223
     */
 
224
    public function widthForGlyph($glyphNumber)
 
225
    {
 
226
        return $this->_descendantFont->widthForChar($glyphNumber);
 
227
    }
 
228
 
 
229
    /**
 
230
     * Convert string to the font encoding.
 
231
     * 
 
232
     * The method is used to prepare string for text drawing operators 
 
233
     *
 
234
     * @param string $string
 
235
     * @param string $charEncoding Character encoding of source text.
 
236
     * @return string
 
237
     */
 
238
    public function encodeString($string, $charEncoding)
 
239
    {
 
240
        return iconv($charEncoding, 'UTF-16BE', $string);
 
241
    }
 
242
 
 
243
    /**
 
244
     * Convert string from the font encoding.
 
245
     *
 
246
     * The method is used to convert strings retrieved from existing content streams
 
247
     *
 
248
     * @param string $string
 
249
     * @param string $charEncoding Character encoding of resulting text.
 
250
     * @return string
 
251
     */
 
252
        public function decodeString($string, $charEncoding)
 
253
    {
 
254
        return iconv('UTF-16BE', $charEncoding, $string);
 
255
    }
 
256
}