24 #require_once 'Zend/Pdf/Element/Array.php'; 25 #require_once 'Zend/Pdf/Element/Dictionary.php'; 26 #require_once 'Zend/Pdf/Element/Name.php'; 27 #require_once 'Zend/Pdf/Element/Numeric.php'; 28 #require_once 'Zend/Pdf/Element/String.php'; 32 #require_once 'Zend/Pdf/Resource/Font.php'; 90 parent::__construct();
97 $this->_fontNames = $fontParser->names;
99 $this->_isBold = $fontParser->isBold;
100 $this->_isItalic = $fontParser->isItalic;
101 $this->_isMonospaced = $fontParser->isMonospaced;
103 $this->_underlinePosition = $fontParser->underlinePosition;
104 $this->_underlineThickness = $fontParser->underlineThickness;
105 $this->_strikePosition = $fontParser->strikePosition;
106 $this->_strikeThickness = $fontParser->strikeThickness;
108 $this->_unitsPerEm = $fontParser->unitsPerEm;
110 $this->_ascent = $fontParser->ascent;
111 $this->_descent = $fontParser->descent;
112 $this->_lineGap = $fontParser->lineGap;
115 $this->_cmap = $fontParser->cmap;
128 $glyphWidths = $fontParser->glyphWidths;
129 $charGlyphs = $this->_cmap->getCoveredCharactersGlyphs();
130 $charWidths = array();
131 foreach ($charGlyphs as $charCode => $glyph) {
132 if(isset($glyphWidths[$glyph]) && !is_null($glyphWidths[$glyph])) {
133 $charWidths[$charCode] = $glyphWidths[$glyph];
136 $this->_charWidths = $charWidths;
137 $this->_missingCharWidth = $glyphWidths[0];
140 $widthFrequencies = array_count_values($charWidths);
141 $defaultWidth =
null;
142 $defaultWidthFrequency = -1;
143 foreach ($widthFrequencies as $width => $frequency) {
144 if ($frequency > $defaultWidthFrequency) {
145 $defaultWidth = $width;
146 $defaultWidthFrequency = $frequency;
154 $defWidthChars = array_keys($charWidths, $defaultWidth);
155 foreach ($defWidthChars as $charCode) {
156 unset($charWidths[$charCode]);
160 ksort($charWidths, SORT_NUMERIC);
164 $widthsSequences = array();
165 foreach ($charWidths as $charCode => $width) {
166 if ($lastCharCode == -1) {
167 $charCodesSequense = array();
168 $sequenceStartCode = $charCode;
169 }
else if ($charCode != $lastCharCode + 1) {
171 $widthsSequences[$sequenceStartCode] = $charCodesSequense;
172 $charCodesSequense = array();
173 $sequenceStartCode = $charCode;
175 $charCodesSequense[] = $width;
176 $lastCharCode = $charCode;
179 if (count($charWidths) != 0) {
180 $widthsSequences[$sequenceStartCode] = $charCodesSequense;
183 $pdfCharsWidths = array();
184 foreach ($widthsSequences as $startCode => $widthsSequence) {
186 $pdfWidths = array();
188 $widthsInSequence = 0;
189 foreach ($widthsSequence as $width) {
190 if ($lastWidth != $width) {
192 if ($widthsInSequence != 0) {
199 $startCode = $startCode + $widthsInSequence;
200 $widthsInSequence = 0;
209 if (count($pdfWidths) != 0) {
214 array_pop($pdfWidths);
217 if (count($pdfWidths) != 0) {
223 $startCode += count($pdfWidths);
224 $pdfWidths = array();
227 $widthsInSequence = 2;
236 if (count($pdfWidths) != 0) {
241 }
else if ($widthsInSequence != 0){
254 $widthsObject = $this->_objectFactory->newObject($widthsArrayElement);
255 $this->_resource->W = $widthsObject;
263 $cidSystemInfoObject = $this->_objectFactory->newObject($cidSystemInfo);
264 $this->_resource->CIDSystemInfo = $cidSystemInfoObject;
289 #require_once 'Zend/Pdf/Exception.php'; 290 throw new Zend_Pdf_Exception(
'CIDFont PDF objects could not be used as the operand of the text drawing operators');
314 #require_once 'Zend/Pdf/Exception.php'; 315 throw new Zend_Pdf_Exception(
'CIDFont PDF objects could not be used as the operand of the text drawing operators');
342 if ($charEncoding !=
'UTF-16BE') {
343 $string = iconv($charEncoding,
'UTF-16BE', $string);
346 $charCount = iconv_strlen($string,
'UTF-16BE');
347 if ($charCount == 0) {
354 $maxIndex = strlen($string);
355 for (
$i = 0;
$i < $maxIndex;
$i++) {
359 $charCode = (ord($string[
$i]) << 8) | ord($string[++
$i]);
362 if (isset($this->_charWidths[$charCode])) {
366 return $score / $charCount;
383 foreach ($charCodes as $key => $charCode) {
384 if (!isset($this->_charWidths[$charCode])) {
387 $widths[$key] = $this->_charWidths[$charCode];
403 if (!isset($this->_charWidths[$charCode])) {
406 return $this->_charWidths[$charCode];
425 #require_once 'Zend/Pdf/Exception.php'; 426 throw new Zend_Pdf_Exception(
'CIDFont PDF objects could not be used as the operand of the text drawing operators');
447 #require_once 'Zend/Pdf/Exception.php'; 448 throw new Zend_Pdf_Exception(
'CIDFont PDF objects could not be used as the operand of the text drawing operators');
468 #require_once 'Zend/Pdf/Exception.php'; 469 throw new Zend_Pdf_Exception(
'CIDFont PDF objects could not be used as the operand of the text drawing operators');
489 #require_once 'Zend/Pdf/Exception.php'; 490 throw new Zend_Pdf_Exception(
'CIDFont PDF objects could not be used as the operand of the text drawing operators');
widthsForChars($charCodes)
decodeString($string, $charEncoding)
widthForGlyph($glyphNumber)
getFontName($nameType, $language, $characterSet=null)
getCoveredPercentage($string, $charEncoding='')
encodeString($string, $charEncoding)
__construct(Zend_Pdf_FileParser_Font_OpenType $fontParser)
glyphNumberForCharacter($characterCode)
glyphNumbersForCharacters($characterCodes)
widthsForGlyphs($glyphNumbers)