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.
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
21
/** Zend_Pdf_Resource_Font */
22
require_once 'Zend/Pdf/Resource/Font.php';
24
/** Zend_Pdf_Resource_Font_CidFont */
25
require_once 'Zend/Pdf/Resource/Font/CidFont.php';
27
/** Zend_Pdf_Resource_Font_CidFont_TrueType */
28
require_once 'Zend/Pdf/Resource/Font/CidFont/TrueType.php';
32
* Adobe PDF composite fonts implementation
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
40
* In PDF, a Type 0 font is a CID-keyed font.
42
* CID-keyed fonts provide effective method to operate with multi-byte character encodings.
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.
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.
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.
54
* Font objects should be normally be obtained from the factory methods
55
* {@link Zend_Pdf_Font::fontWithName} and {@link Zend_Pdf_Font::fontWithPath}.
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
62
class Zend_Pdf_Resource_Font_Type0 extends Zend_Pdf_Resource_Font
67
* @var Zend_Pdf_Resource_Font_CidFont
69
private $_descendantFont;
73
* Generate ToUnicode character map data
77
static private function getToUnicodeCMapData()
79
return '/CIDInit /ProcSet findresource begin ' . "\n"
80
. '12 dict begin ' . "\n"
82
. '/CIDSystemInfo ' . "\n"
83
. '<</Registry (Adobe) ' . "\n"
84
. '/Ordering (UCS) ' . "\n"
85
. '/Supplement 0' . "\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"
96
. 'CMapName currentdict /CMap defineresource pop ' . "\n"
105
public function __construct(Zend_Pdf_Resource_Font_CidFont $descendantFont)
107
parent::__construct();
109
$this->_objectFactory->attach($descendantFont->getFactory());
111
$this->_fontType = Zend_Pdf_Font::TYPE_TYPE_0;
112
$this->_descendantFont = $descendantFont;
115
$this->_fontNames = $descendantFont->getFontNames();
117
$this->_isBold = $descendantFont->isBold();
118
$this->_isItalic = $descendantFont->isItalic();
119
$this->_isMonospaced = $descendantFont->isMonospace();
121
$this->_underlinePosition = $descendantFont->getUnderlinePosition();
122
$this->_underlineThickness = $descendantFont->getUnderlineThickness();
123
$this->_strikePosition = $descendantFont->getStrikePosition();
124
$this->_strikeThickness = $descendantFont->getStrikeThickness();
126
$this->_unitsPerEm = $descendantFont->getUnitsPerEm();
128
$this->_ascent = $descendantFont->getAscent();
129
$this->_descent = $descendantFont->getDescent();
130
$this->_lineGap = $descendantFont->getLineGap();
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');
138
$toUnicode = $this->_objectFactory->newStreamObject(self::getToUnicodeCMapData());
139
$this->_resource->ToUnicode = $toUnicode;
144
* Returns an array of glyph numbers corresponding to the Unicode characters.
146
* Zend_Pdf uses 'Identity-H' encoding for Type 0 fonts.
147
* So we don't need to perform any conversion
149
* See also {@link glyphNumberForCharacter()}.
151
* @param array $characterCodes Array of Unicode character codes (code points).
152
* @return array Array of glyph numbers.
154
public function glyphNumbersForCharacters($characterCodes)
156
return $characterCodes;
160
* Returns the glyph number corresponding to the Unicode character.
162
* Zend_Pdf uses 'Identity-H' encoding for Type 0 fonts.
163
* So we don't need to perform any conversion
165
* @param integer $characterCode Unicode character code (code point).
166
* @return integer Glyph number.
168
public function glyphNumberForCharacter($characterCode)
170
return $characterCode;
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.
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.
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.
186
* @param string $string
187
* @param string $charEncoding (optional) Character encoding of source text.
188
* If omitted, uses 'current locale'.
191
public function getCoveredPercentage($string, $charEncoding = '')
193
return $this->_descendantFont->getCoveredPercentage($string, $charEncoding);
197
* Returns the widths of the glyphs.
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()}.
202
* Throws an exception if the glyph number is out of range.
204
* See also {@link widthForGlyph()}.
206
* @param array &$glyphNumbers Array of glyph numbers.
207
* @return array Array of glyph widths (integers).
208
* @throws Zend_Pdf_Exception
210
public function widthsForGlyphs($glyphNumbers)
212
return $this->_descendantFont->widthsForChars($glyphNumbers);
216
* Returns the width of the glyph.
218
* Like {@link widthsForGlyphs()} but used for one glyph at a time.
220
* @param integer $glyphNumber
222
* @throws Zend_Pdf_Exception
224
public function widthForGlyph($glyphNumber)
226
return $this->_descendantFont->widthForChar($glyphNumber);
230
* Convert string to the font encoding.
232
* The method is used to prepare string for text drawing operators
234
* @param string $string
235
* @param string $charEncoding Character encoding of source text.
238
public function encodeString($string, $charEncoding)
240
return iconv($charEncoding, 'UTF-16BE', $string);
244
* Convert string from the font encoding.
246
* The method is used to convert strings retrieved from existing content streams
248
* @param string $string
249
* @param string $charEncoding Character encoding of resulting text.
252
public function decodeString($string, $charEncoding)
254
return iconv('UTF-16BE', $charEncoding, $string);