/** * Object constructor * */ public function __construct(CidFont\AbstractCidFont $descendantFont) { parent::__construct(); $this->_objectFactory->attach($descendantFont->getFactory()); $this->_fontType = Pdf\Font::TYPE_TYPE_0; $this->_descendantFont = $descendantFont; $this->_fontNames = $descendantFont->getFontNames(); $this->_isBold = $descendantFont->isBold(); $this->_isItalic = $descendantFont->isItalic(); $this->_isMonospaced = $descendantFont->isMonospace(); $this->_underlinePosition = $descendantFont->getUnderlinePosition(); $this->_underlineThickness = $descendantFont->getUnderlineThickness(); $this->_strikePosition = $descendantFont->getStrikePosition(); $this->_strikeThickness = $descendantFont->getStrikeThickness(); $this->_unitsPerEm = $descendantFont->getUnitsPerEm(); $this->_ascent = $descendantFont->getAscent(); $this->_descent = $descendantFont->getDescent(); $this->_lineGap = $descendantFont->getLineGap(); $this->_resource->Subtype = new InternalType\NameObject('Type0'); $this->_resource->BaseFont = new InternalType\NameObject($descendantFont->getResource()->BaseFont->value); $this->_resource->DescendantFonts = new InternalType\ArrayObject(array($descendantFont->getResource())); $this->_resource->Encoding = new InternalType\NameObject('Identity-H'); $toUnicode = $this->_objectFactory->newStreamObject(self::getToUnicodeCMapData()); $this->_resource->ToUnicode = $toUnicode; }
/** * Object constructor * */ public function __construct() { parent::__construct(); /** * @todo * It's easy to add other encodings support now (Standard-Encoding, MacRomanEncoding, * PDFDocEncoding, MacExpertEncoding, Symbol, and ZapfDingbats). * Steps for the implementation: * - completely describe all PDF single byte encodings in the documentation * - implement non-WinAnsi encodings processing into encodeString()/decodeString() methods * * These encodings will be automatically supported for standard builtin PDF fonts as well * as for external fonts. */ $this->_resource->Encoding = new InternalType\NameObject('WinAnsiEncoding'); }
/** * Object constructor * * @param \ZendPdf\BinaryParser\Font\OpenType\AbstractOpenType $fontParser Font parser object * containing OpenType file. * @param integer $embeddingOptions Options for font embedding. * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(Pdf\BinaryParser\Font\OpenType\AbstractOpenType $fontParser) { parent::__construct(); $fontParser->parse(); /* Object properties */ $this->_fontNames = $fontParser->names; $this->_isBold = $fontParser->isBold; $this->_isItalic = $fontParser->isItalic; $this->_isMonospaced = $fontParser->isMonospaced; $this->_underlinePosition = $fontParser->underlinePosition; $this->_underlineThickness = $fontParser->underlineThickness; $this->_strikePosition = $fontParser->strikePosition; $this->_strikeThickness = $fontParser->strikeThickness; $this->_unitsPerEm = $fontParser->unitsPerEm; $this->_ascent = $fontParser->ascent; $this->_descent = $fontParser->descent; $this->_lineGap = $fontParser->lineGap; $this->_cmap = $fontParser->cmap; /* Resource dictionary */ $baseFont = $this->getFontName(Pdf\Font::NAME_POSTSCRIPT, 'en', 'UTF-8'); $this->_resource->BaseFont = new InternalType\NameObject($baseFont); /** * Prepare widths array. */ /* Constract characters widths array using font CMap and glyphs widths array */ $glyphWidths = $fontParser->glyphWidths; $charGlyphs = $this->_cmap->getCoveredCharactersGlyphs(); $charWidths = array(); foreach ($charGlyphs as $charCode => $glyph) { $charWidths[$charCode] = $glyphWidths[$glyph]; } $this->_charWidths = $charWidths; $this->_missingCharWidth = $glyphWidths[0]; /* Width array optimization. Step1: extract default value */ $widthFrequencies = array_count_values($charWidths); $defaultWidth = null; $defaultWidthFrequency = -1; foreach ($widthFrequencies as $width => $frequency) { if ($frequency > $defaultWidthFrequency) { $defaultWidth = $width; $defaultWidthFrequency = $frequency; } } // Store default value in the font dictionary $this->_resource->DW = new InternalType\NumericObject($this->toEmSpace($defaultWidth)); // Remove characters which corresponds to default width from the widths array $defWidthChars = array_keys($charWidths, $defaultWidth); foreach ($defWidthChars as $charCode) { unset($charWidths[$charCode]); } // Order cheracter widths aray by character codes ksort($charWidths, SORT_NUMERIC); /* Width array optimization. Step2: Compact character codes sequences */ $lastCharCode = -1; $widthsSequences = array(); foreach ($charWidths as $charCode => $width) { if ($lastCharCode == -1) { $charCodesSequense = array(); $sequenceStartCode = $charCode; } elseif ($charCode != $lastCharCode + 1) { // New chracters sequence detected $widthsSequences[$sequenceStartCode] = $charCodesSequense; $charCodesSequense = array(); $sequenceStartCode = $charCode; } $charCodesSequense[] = $width; $lastCharCode = $charCode; } // Save last sequence, if widths array is not empty (it may happens for monospaced fonts) if (count($charWidths) != 0) { $widthsSequences[$sequenceStartCode] = $charCodesSequense; } $pdfCharsWidths = array(); foreach ($widthsSequences as $startCode => $widthsSequence) { /* Width array optimization. Step3: Compact widths sequences */ $pdfWidths = array(); $lastWidth = -1; $widthsInSequence = 0; foreach ($widthsSequence as $width) { if ($lastWidth != $width) { // New width is detected if ($widthsInSequence != 0) { // Previous width value was a part of the widths sequence. Save it as 'c_1st c_last w'. $pdfCharsWidths[] = new InternalType\NumericObject($startCode); // First character code $pdfCharsWidths[] = new InternalType\NumericObject($startCode + $widthsInSequence - 1); // Last character code $pdfCharsWidths[] = new InternalType\NumericObject($this->toEmSpace($lastWidth)); // Width // Reset widths sequence $startCode = $startCode + $widthsInSequence; $widthsInSequence = 0; } // Collect new width $pdfWidths[] = new InternalType\NumericObject($this->toEmSpace($width)); $lastWidth = $width; } else { // Width is equal to previous if (count($pdfWidths) != 0) { // We already have some widths collected // So, we've just detected new widths sequence // Remove last element from widths list, since it's a part of widths sequence array_pop($pdfWidths); // and write the rest if it's not empty if (count($pdfWidths) != 0) { // Save it as 'c_1st [w1 w2 ... wn]'. $pdfCharsWidths[] = new InternalType\NumericObject($startCode); // First character code $pdfCharsWidths[] = new InternalType\ArrayObject($pdfWidths); // Widths array // Reset widths collection $startCode += count($pdfWidths); $pdfWidths = array(); } $widthsInSequence = 2; } else { // Continue widths sequence $widthsInSequence++; } } } // Check if we have widths collection or widths sequence to wite it down if (count($pdfWidths) != 0) { // We have some widths collected // Save it as 'c_1st [w1 w2 ... wn]'. $pdfCharsWidths[] = new InternalType\NumericObject($startCode); // First character code $pdfCharsWidths[] = new InternalType\ArrayObject($pdfWidths); // Widths array } elseif ($widthsInSequence != 0) { // We have widths sequence // Save it as 'c_1st c_last w'. $pdfCharsWidths[] = new InternalType\NumericObject($startCode); // First character code $pdfCharsWidths[] = new InternalType\NumericObject($startCode + $widthsInSequence - 1); // Last character code $pdfCharsWidths[] = new InternalType\NumericObject($this->toEmSpace($lastWidth)); // Width } } /* Create the \ZendPdf\InternalType\ArrayObject object and add it to the font's * object factory and resource dictionary. */ $widthsArrayElement = new InternalType\ArrayObject($pdfCharsWidths); $widthsObject = $this->_objectFactory->newObject($widthsArrayElement); $this->_resource->W = $widthsObject; /* CIDSystemInfo dictionary */ $cidSystemInfo = new InternalType\DictionaryObject(); $cidSystemInfo->Registry = new InternalType\StringObject('Adobe'); $cidSystemInfo->Ordering = new InternalType\StringObject('UCS'); $cidSystemInfo->Supplement = new InternalType\NumericObject(0); $cidSystemInfoObject = $this->_objectFactory->newObject($cidSystemInfo); $this->_resource->CIDSystemInfo = $cidSystemInfoObject; }