/** * @param Slide $oSlide * @return string */ protected function writeSlideComments(Slide $oSlide) { /** * @var Comment[] */ $arrayComment = array(); foreach ($oSlide->getShapeCollection() as $oShape) { if ($oShape instanceof Comment) { $arrayComment[] = $oShape; } } if (empty($arrayComment)) { return ''; } $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // p:cmLst $objWriter->startElement('p:cmLst'); $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); foreach ($arrayComment as $idxComment => $oComment) { $oAuthor = $oComment->getAuthor(); // p:cmLst > p:cm $objWriter->startElement('p:cm'); $objWriter->writeAttribute('authorId', $oAuthor instanceof Comment\Author ? $oAuthor->getIndex() : 0); $objWriter->writeAttribute('dt', date('Y-m-d\\TH:i:s.000000000', $oComment->getDate())); $objWriter->writeAttribute('idx', $idxComment); // p:cmLst > p:cm > p:pos // Uses 1/8pt for positionning // @link : https://social.msdn.microsoft.com/Forums/fr-FR/ebdc12f2-0cff-4fa8-b901-fa6e3198364e/comment-position-units $objWriter->startElement('p:pos'); $objWriter->writeAttribute('x', (int) CommonDrawing::pixelsToPoints($oComment->getOffsetX() * 8)); $objWriter->writeAttribute('y', (int) CommonDrawing::pixelsToPoints($oComment->getOffsetY() * 8)); $objWriter->endElement(); // p:cmLst > p:cm > p:text $objWriter->writeElement('p:text', $oComment->getText()); // p:cmLst > ## p:cm $objWriter->endElement(); } // ## p:cmLst $objWriter->endElement(); return $objWriter->getData(); }
/** * @param Title $oTitle */ private function writeTitle(Title $oTitle) { if ($oTitle->isVisible()) { // chart:title $this->xmlContent->startElement('chart:title'); $this->xmlContent->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($oTitle->getOffsetX()), 3) . 'cm'); $this->xmlContent->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($oTitle->getOffsetY()), 3) . 'cm'); $this->xmlContent->writeAttribute('chart:style-name', 'styleTitle'); // > text:p $this->xmlContent->startElement('text:p'); $this->xmlContent->text($oTitle->getText()); // > text:p $this->xmlContent->endElement(); // > chart:title $this->xmlContent->endElement(); } }
/** * Write Outline * @param XMLWriter $objWriter * @param Outline $oOutline */ protected function writeOutline(XMLWriter $objWriter, $oOutline) { if (!$oOutline instanceof Outline) { return; } // Width : pts $width = $oOutline->getWidth(); // Width : pts => px $width = CommonDrawing::pointsToPixels($width); // Width : px => emu $width = CommonDrawing::pixelsToEmu($width); // a:ln $objWriter->startElement('a:ln'); $objWriter->writeAttribute('w', $width); // Fill $this->writeFill($objWriter, $oOutline->getFill()); // > a:ln $objWriter->endElement(); }
/** * Write Note Slide * @param Note $pNote * @throws \Exception * @return string */ protected function writeNote(Note $pNote) { // Create XML writer $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // p:notes $objWriter->startElement('p:notes'); $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); // p:cSld $objWriter->startElement('p:cSld'); // p:spTree $objWriter->startElement('p:spTree'); // p:nvGrpSpPr $objWriter->startElement('p:nvGrpSpPr'); // p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', '1'); $objWriter->writeAttribute('name', ''); $objWriter->endElement(); // p:cNvGrpSpPr $objWriter->writeElement('p:cNvGrpSpPr', null); // p:nvPr $objWriter->writeElement('p:nvPr', null); // ## p:nvGrpSpPr $objWriter->endElement(); // p:grpSpPr $objWriter->startElement('p:grpSpPr'); // a:xfrm $objWriter->startElement('a:xfrm'); // a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pNote->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pNote->getOffsetY())); $objWriter->endElement(); // a:off // a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pNote->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pNote->getExtentY())); $objWriter->endElement(); // a:ext // a:chOff $objWriter->startElement('a:chOff'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pNote->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pNote->getOffsetY())); $objWriter->endElement(); // a:chOff // a:chExt $objWriter->startElement('a:chExt'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pNote->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pNote->getExtentY())); $objWriter->endElement(); // a:chExt // ## a:xfrm $objWriter->endElement(); // ## p:grpSpPr $objWriter->endElement(); // p:sp $objWriter->startElement('p:sp'); // p:nvSpPr $objWriter->startElement('p:nvSpPr'); $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', '1'); $objWriter->writeAttribute('name', 'Notes Placeholder'); $objWriter->endElement(); // p:cNvSpPr $objWriter->startElement('p:cNvSpPr'); //a:spLocks $objWriter->startElement('a:spLocks'); $objWriter->writeAttribute('noGrp', '1'); $objWriter->endElement(); // ## p:cNvSpPr $objWriter->endElement(); // p:nvPr $objWriter->startElement('p:nvPr'); $objWriter->startElement('p:ph'); $objWriter->writeAttribute('type', 'body'); $objWriter->writeAttribute('idx', '1'); $objWriter->endElement(); // ## p:nvPr $objWriter->endElement(); // ## p:nvSpPr $objWriter->endElement(); $objWriter->writeElement('p:spPr', null); // p:txBody $objWriter->startElement('p:txBody'); $objWriter->writeElement('a:bodyPr', null); $objWriter->writeElement('a:lstStyle', null); // Loop shapes $shapes = $pNote->getShapeCollection(); foreach ($shapes as $shape) { // Check type if ($shape instanceof RichText) { $paragraphs = $shape->getParagraphs(); $this->writeParagraphs($objWriter, $paragraphs); } } // ## p:txBody $objWriter->endElement(); // ## p:sp $objWriter->endElement(); // ## p:spTree $objWriter->endElement(); // ## p:cSld $objWriter->endElement(); // ## p:notes $objWriter->endElement(); // Return return $objWriter->getData(); }
/** * Write Gradient Fill * * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPresentation\Style\Fill $pFill Fill style * @throws \Exception */ protected function writeGradientFill(XMLWriter $objWriter, Fill $pFill) { // a:gradFill $objWriter->startElement('a:gradFill'); // a:gsLst $objWriter->startElement('a:gsLst'); // a:gs $objWriter->startElement('a:gs'); $objWriter->writeAttribute('pos', '0'); // srgbClr $objWriter->startElement('a:srgbClr'); $objWriter->writeAttribute('val', $pFill->getStartColor()->getRGB()); $objWriter->endElement(); $objWriter->endElement(); // a:gs $objWriter->startElement('a:gs'); $objWriter->writeAttribute('pos', '100000'); // srgbClr $objWriter->startElement('a:srgbClr'); $objWriter->writeAttribute('val', $pFill->getEndColor()->getRGB()); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // a:lin $objWriter->startElement('a:lin'); $objWriter->writeAttribute('ang', CommonDrawing::degreesToAngle($pFill->getRotation())); $objWriter->writeAttribute('scaled', '0'); $objWriter->endElement(); $objWriter->endElement(); }
/** * The OfficeArtFOPT record specifies a table of OfficeArtRGFOPTE records. * @param string $stream * @param integer $pos * @link https://msdn.microsoft.com/en-us/library/dd943404(v=office.12).aspx */ private function readRecordOfficeArtFOPT($stream, $pos) { $arrayReturn = array('length' => 0); $data = $this->loadRecordHeader($stream, $pos); if ($data['recVer'] == 0x3 && $data['recType'] == 0xf00b) { // Record Header $arrayReturn['length'] += 8; //@link : http://msdn.microsoft.com/en-us/library/dd906086(v=office.12).aspx $officeArtFOPTE = array(); for ($inc = 0; $inc < $data['recInstance']; $inc++) { $opid = self::getInt2d($this->streamPowerpointDocument, $pos + $arrayReturn['length']); $arrayReturn['length'] += 2; $data['recLen'] -= 2; $optOp = self::getInt4d($this->streamPowerpointDocument, $pos + $arrayReturn['length']); $arrayReturn['length'] += 4; $data['recLen'] -= 4; $officeArtFOPTE[] = array('opid' => $opid >> 0 & bindec('11111111111111'), 'fBid' => $opid >> 14 & bindec('1'), 'fComplex' => $opid >> 15 & bindec('1'), 'op' => $optOp); } //@link : http://code.metager.de/source/xref/kde/calligra/filters/libmso/OPID foreach ($officeArtFOPTE as $opt) { // echo $opt['opid'].'-0x'.dechex($opt['opid']).EOL; switch ($opt['opid']) { case 0x4: // Transform : rotation //@link : https://msdn.microsoft.com/en-us/library/dd949750(v=office.12).aspx $arrayReturn['rotation'] = $opt['op']; break; case 0x7f: // Transform : Protection Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd909131(v=office.12).aspx break; case 0x80: // Text : ltxid //@link : http://msdn.microsoft.com/en-us/library/dd947446(v=office.12).aspx break; case 0x81: // Text : dxTextLeft //@link : http://msdn.microsoft.com/en-us/library/dd953234(v=office.12).aspx $arrayReturn['insetLeft'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']); break; case 0x82: // Text : dyTextTop //@link : http://msdn.microsoft.com/en-us/library/dd925068(v=office.12).aspx $arrayReturn['insetTop'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']); break; case 0x83: // Text : dxTextRight //@link : http://msdn.microsoft.com/en-us/library/dd906782(v=office.12).aspx $arrayReturn['insetRight'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']); break; case 0x84: // Text : dyTextBottom //@link : http://msdn.microsoft.com/en-us/library/dd772858(v=office.12).aspx $arrayReturn['insetBottom'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']); break; case 0x85: // Text : WrapText //@link : http://msdn.microsoft.com/en-us/library/dd924770(v=office.12).aspx break; case 0x87: // Text : anchorText //@link : http://msdn.microsoft.com/en-us/library/dd948575(v=office.12).aspx break; case 0xbf: // Text : Text Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd950905(v=office.12).aspx break; case 0x104: // Blip : pib //@link : http://msdn.microsoft.com/en-us/library/dd772837(v=office.12).aspx if ($opt['fComplex'] == 0) { $arrayReturn['pib'] = $opt['op']; $data['recLen'] -= $opt['op']; } else { // pib Complex } break; case 0x13f: // Blip Boolean Properties //@link : https://msdn.microsoft.com/en-us/library/dd944215(v=office.12).aspx break; case 0x140: // Geometry : geoLeft //@link : http://msdn.microsoft.com/en-us/library/dd947489(v=office.12).aspx // print_r('geoLeft : '.$opt['op'].EOL); break; case 0x141: // Geometry : geoTop //@link : http://msdn.microsoft.com/en-us/library/dd949459(v=office.12).aspx // print_r('geoTop : '.$opt['op'].EOL); break; case 0x142: // Geometry : geoRight //@link : http://msdn.microsoft.com/en-us/library/dd947117(v=office.12).aspx // print_r('geoRight : '.$opt['op'].EOL); break; case 0x143: // Geometry : geoBottom //@link : http://msdn.microsoft.com/en-us/library/dd948602(v=office.12).aspx // print_r('geoBottom : '.$opt['op'].EOL); break; case 0x144: // Geometry : shapePath //@link : http://msdn.microsoft.com/en-us/library/dd945249(v=office.12).aspx $arrayReturn['line'] = true; break; case 0x145: // Geometry : pVertices //@link : http://msdn.microsoft.com/en-us/library/dd949814(v=office.12).aspx if ($opt['fComplex'] == 1) { $arrayReturn['length'] += $opt['op']; $data['recLen'] -= $opt['op']; } break; case 0x146: // Geometry : pSegmentInfo //@link : http://msdn.microsoft.com/en-us/library/dd905742(v=office.12).aspx if ($opt['fComplex'] == 1) { $arrayReturn['length'] += $opt['op']; $data['recLen'] -= $opt['op']; } break; case 0x155: // Geometry : pAdjustHandles //@link : http://msdn.microsoft.com/en-us/library/dd905890(v=office.12).aspx if ($opt['fComplex'] == 1) { $arrayReturn['length'] += $opt['op']; $data['recLen'] -= $opt['op']; } break; case 0x156: // Geometry : pGuides //@link : http://msdn.microsoft.com/en-us/library/dd910801(v=office.12).aspx if ($opt['fComplex'] == 1) { $arrayReturn['length'] += $opt['op']; $data['recLen'] -= $opt['op']; } break; case 0x157: // Geometry : pInscribe //@link : http://msdn.microsoft.com/en-us/library/dd904889(v=office.12).aspx if ($opt['fComplex'] == 1) { $arrayReturn['length'] += $opt['op']; $data['recLen'] -= $opt['op']; } break; case 0x17f: // Geometry Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd944968(v=office.12).aspx break; case 0x180: // Fill : fillType //@link : http://msdn.microsoft.com/en-us/library/dd947909(v=office.12).aspx break; case 0x181: // Fill : fillColor //@link : http://msdn.microsoft.com/en-us/library/dd921332(v=office.12).aspx $strColor = str_pad(dechex($opt['op'] >> 0 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); $strColor .= str_pad(dechex($opt['op'] >> 8 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); $strColor .= str_pad(dechex($opt['op'] >> 16 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); // echo 'fillColor : '.$strColor.EOL; break; case 0x183: // Fill : fillBackColor //@link : http://msdn.microsoft.com/en-us/library/dd950634(v=office.12).aspx $strColor = str_pad(dechex($opt['op'] >> 0 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); $strColor .= str_pad(dechex($opt['op'] >> 8 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); $strColor .= str_pad(dechex($opt['op'] >> 16 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); // echo 'fillBackColor : '.$strColor.EOL; break; case 0x193: // Fill : fillRectRight //@link : http://msdn.microsoft.com/en-us/library/dd951294(v=office.12).aspx // echo 'fillRectRight : '.\PhpOffice\Common\Drawing::emuToPixels($opt['op']).EOL; break; case 0x194: // Fill : fillRectBottom //@link : http://msdn.microsoft.com/en-us/library/dd910194(v=office.12).aspx // echo 'fillRectBottom : '.\PhpOffice\Common\Drawing::emuToPixels($opt['op']).EOL; break; case 0x1bf: // Fill : Fill Style Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd909380(v=office.12).aspx break; case 0x1c0: // Line Style : lineColor //@link : http://msdn.microsoft.com/en-us/library/dd920397(v=office.12).aspx $strColor = str_pad(dechex($opt['op'] >> 0 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); $strColor .= str_pad(dechex($opt['op'] >> 8 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); $strColor .= str_pad(dechex($opt['op'] >> 16 & bindec('11111111')), 2, STR_PAD_LEFT, '0'); $arrayReturn['lineColor'] = $strColor; break; case 0x1c1: // Line Style : lineOpacity //@link : http://msdn.microsoft.com/en-us/library/dd923433(v=office.12).aspx // echo 'lineOpacity : '.dechex($opt['op']).EOL; break; case 0x1c2: // Line Style : lineBackColor //@link : http://msdn.microsoft.com/en-us/library/dd947669(v=office.12).aspx break; case 0x1cb: // Line Style : lineWidth //@link : http://msdn.microsoft.com/en-us/library/dd926964(v=office.12).aspx $arrayReturn['lineWidth'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']); break; case 0x1d6: // Line Style : lineJoinStyle //@link : http://msdn.microsoft.com/en-us/library/dd909643(v=office.12).aspx break; case 0x1d7: // Line Style : lineEndCapStyle //@link : http://msdn.microsoft.com/en-us/library/dd925071(v=office.12).aspx break; case 0x1ff: // Line Style : Line Style Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd951605(v=office.12).aspx break; case 0x201: // Shadow Style : shadowColor //@link : http://msdn.microsoft.com/en-us/library/dd923454(v=office.12).aspx break; case 0x204: // Shadow Style : shadowOpacity //@link : http://msdn.microsoft.com/en-us/library/dd920720(v=office.12).aspx break; case 0x205: // Shadow Style : shadowOffsetX //@link : http://msdn.microsoft.com/en-us/library/dd945280(v=office.12).aspx $arrayReturn['shadowOffsetX'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']); break; case 0x206: // Shadow Style : shadowOffsetY //@link : http://msdn.microsoft.com/en-us/library/dd907855(v=office.12).aspx $arrayReturn['shadowOffsetY'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']); break; case 0x23f: // Shadow Style : Shadow Style Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd947887(v=office.12).aspx break; case 0x304: // Shape : bWMode //@link : http://msdn.microsoft.com/en-us/library/dd947659(v=office.12).aspx break; case 0x33f: // Shape Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd951345(v=office.12).aspx break; case 0x380: // Group Shape Property Set : wzName //@link : http://msdn.microsoft.com/en-us/library/dd950681(v=office.12).aspx if ($opt['fComplex'] == 1) { $arrayReturn['length'] += $opt['op']; $data['recLen'] -= $opt['op']; } break; case 0x3bf: // Group Shape Property Set : Group Shape Boolean Properties //@link : http://msdn.microsoft.com/en-us/library/dd949807(v=office.12).aspx break; default: throw new \Exception('Feature not implemented (l.' . __LINE__ . ' : 0x' . dechex($opt['opid']) . ')'); } } if ($data['recLen'] > 0) { $arrayReturn['length'] += $data['recLen']; } } return $arrayReturn; }
protected function loadShapeRichText(XMLReader $document, \DOMElement $node, $baseFile) { // Core $oShape = $this->oPhpPresentation->getActiveSlide()->createRichTextShape(); $oShape->setParagraphs(array()); // Variables $fileRels = 'ppt/slides/_rels/' . $baseFile . '.rels'; $oElement = $document->getElement('p:spPr/a:xfrm', $node); if ($oElement && $oElement->hasAttribute('rot')) { $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot'))); } $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node); if ($oElement) { if ($oElement->hasAttribute('x')) { $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x'))); } if ($oElement->hasAttribute('y')) { $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y'))); } } $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node); if ($oElement) { if ($oElement->hasAttribute('cx')) { $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx'))); } if ($oElement->hasAttribute('cy')) { $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy'))); } } $arrayElements = $document->getElements('p:txBody/a:p', $node); foreach ($arrayElements as $oElement) { // Core $oParagraph = $oShape->createParagraph(); $oParagraph->setRichTextElements(array()); $oSubElement = $document->getElement('a:pPr', $oElement); if ($oSubElement) { if ($oSubElement->hasAttribute('algn')) { $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn')); } if ($oSubElement->hasAttribute('fontAlgn')) { $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn')); } if ($oSubElement->hasAttribute('marL')) { $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL'))); } if ($oSubElement->hasAttribute('marR')) { $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR'))); } if ($oSubElement->hasAttribute('indent')) { $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent'))); } if ($oSubElement->hasAttribute('lvl')) { $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl')); } $oElementBuFont = $document->getElement('a:buFont', $oSubElement); $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE); if ($oElementBuFont) { if ($oElementBuFont->hasAttribute('typeface')) { $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface')); } } $oElementBuChar = $document->getElement('a:buChar', $oSubElement); if ($oElementBuChar) { $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET); if ($oElementBuChar->hasAttribute('char')) { $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char')); } } /*$oElementBuAutoNum = $document->getElement('a:buAutoNum', $oSubElement); if ($oElementBuAutoNum) { $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC); if ($oElementBuAutoNum->hasAttribute('type')) { $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type')); } if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 1) { $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt')); } }*/ } $arraySubElements = $document->getElements('(a:r|a:br)', $oElement); foreach ($arraySubElements as $oSubElement) { if ($oSubElement->tagName == 'a:br') { $oParagraph->createBreak(); } if ($oSubElement->tagName == 'a:r') { $oElementrPr = $document->getElement('a:rPr', $oSubElement); if (is_object($oElementrPr)) { $oText = $oParagraph->createTextRun(); if ($oElementrPr->hasAttribute('b')) { $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false); } if ($oElementrPr->hasAttribute('i')) { $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false); } if ($oElementrPr->hasAttribute('strike')) { $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true); } if ($oElementrPr->hasAttribute('sz')) { $oText->getFont()->setSize((int) ($oElementrPr->getAttribute('sz') / 100)); } if ($oElementrPr->hasAttribute('u')) { $oText->getFont()->setUnderline($oElementrPr->getAttribute('u')); } // Color $oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr); if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) { $oColor = new Color(); $oColor->setRGB($oElementSrgbClr->getAttribute('val')); $oText->getFont()->setColor($oColor); } // Hyperlink $oElementHlinkClick = $document->getElement('a:hlinkClick', $oElementrPr); if (is_object($oElementHlinkClick)) { if ($oElementHlinkClick->hasAttribute('tooltip')) { $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip')); } if ($oElementHlinkClick->hasAttribute('r:id') && isset($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')])) { $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]); } } //} else { // $oText = $oParagraph->createText(); } $oSubSubElement = $document->getElement('a:t', $oSubElement); $oText->setText($oSubSubElement->nodeValue); } } } if (count($oShape->getParagraphs()) > 0) { $oShape->setActiveParagraph(0); } }
public function testLine() { $valEmu10 = Drawing::pixelsToEmu(10); $valEmu90 = Drawing::pixelsToEmu(90); $oPhpPresentation = new PhpPresentation(); $oSlide = $oPhpPresentation->getActiveSlide(); $oSlide->createLineShape(10, 10, 100, 100); $oSlide->createLineShape(100, 10, 10, 100); $oSlide->createLineShape(10, 100, 100, 10); $oSlide->createLineShape(100, 100, 10, 10); $pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007'); $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:prstGeom'; $this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml')); $this->assertEquals('line', $pres->getElementAttribute($element, 'prst', 'ppt/slides/slide1.xml')); $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:xfrm/a:ext[@cx="' . $valEmu90 . '"][@cy="' . $valEmu90 . '"]'; $this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml')); $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:xfrm/a:off[@x="' . $valEmu10 . '"][@y="' . $valEmu10 . '"]'; $this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml')); $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:xfrm[@flipV="1"]/a:off[@x="' . $valEmu10 . '"][@y="' . $valEmu10 . '"]'; $this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml')); }
/** * Read Shape RichText * * @param \DOMElement $oNodeFrame */ protected function loadShapeRichText(\DOMElement $oNodeFrame) { // Core $oShape = $this->oPhpPresentation->getActiveSlide()->createRichTextShape(); $oShape->setParagraphs(array()); $oShape->setWidth($oNodeFrame->hasAttribute('svg:width') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:width'), 0, -2))) : ''); $oShape->setHeight($oNodeFrame->hasAttribute('svg:height') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:height'), 0, -2))) : ''); $oShape->setOffsetX($oNodeFrame->hasAttribute('svg:x') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:x'), 0, -2))) : ''); $oShape->setOffsetY($oNodeFrame->hasAttribute('svg:y') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:y'), 0, -2))) : ''); foreach ($this->oXMLReader->getElements('draw:text-box/*', $oNodeFrame) as $oNodeParagraph) { $this->levelParagraph = 0; if ($oNodeParagraph->nodeName == 'text:p') { $this->readParagraph($oShape, $oNodeParagraph); } if ($oNodeParagraph->nodeName == 'text:list') { $this->readList($oShape, $oNodeParagraph); } } if (count($oShape->getParagraphs()) > 0) { $oShape->setActiveParagraph(0); } }
/** * Write group * * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPresentation\Shape\Group $group * @param int $shapeId */ protected function writeShapeGroup(XMLWriter $objWriter, Group $group, &$shapeId) { // p:grpSp $objWriter->startElement('p:grpSp'); // p:nvGrpSpPr $objWriter->startElement('p:nvGrpSpPr'); // p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('name', 'Group ' . $shapeId++); $objWriter->writeAttribute('id', $shapeId); $objWriter->endElement(); // p:cNvPr // NOTE: Re: $shapeId This seems to be how PowerPoint 2010 does business. // p:cNvGrpSpPr $objWriter->writeElement('p:cNvGrpSpPr', null); // p:nvPr $objWriter->writeElement('p:nvPr', null); $objWriter->endElement(); // p:nvGrpSpPr // p:grpSpPr $objWriter->startElement('p:grpSpPr'); // a:xfrm $objWriter->startElement('a:xfrm'); // a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($group->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($group->getOffsetY())); $objWriter->endElement(); // a:off // a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($group->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($group->getExtentY())); $objWriter->endElement(); // a:ext // a:chOff $objWriter->startElement('a:chOff'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($group->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($group->getOffsetY())); $objWriter->endElement(); // a:chOff // a:chExt $objWriter->startElement('a:chExt'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($group->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($group->getExtentY())); $objWriter->endElement(); // a:chExt $objWriter->endElement(); // a:xfrm $objWriter->endElement(); // p:grpSpPr $this->writeShapeCollection($objWriter, $group->getShapeCollection(), $shapeId); $objWriter->endElement(); // p:grpSp }
/** * Write slide to XML format * * @param \PhpOffice\PhpPresentation\Slide\SlideLayout $pSlideLayout * @return string XML Output * @throws \Exception */ public function writeSlideLayout(SlideLayout $pSlideLayout) { // Create XML writer $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // p:sldLayout $objWriter->startElement('p:sldLayout'); $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); $objWriter->writeAttribute('preserve', 1); // p:sldLayout\p:cSld $objWriter->startElement('p:cSld'); $objWriter->writeAttributeIf($pSlideLayout->getLayoutName() != '', 'name', $pSlideLayout->getLayoutName()); // Background $this->writeSlideBackground($pSlideLayout, $objWriter); // p:sldLayout\p:cSld\p:spTree $objWriter->startElement('p:spTree'); // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr $objWriter->startElement('p:nvGrpSpPr'); // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', '1'); $objWriter->writeAttribute('name', ''); $objWriter->endElement(); // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvGrpSpPr $objWriter->writeElement('p:cNvGrpSpPr', null); // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:nvPr $objWriter->writeElement('p:nvPr', null); // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr $objWriter->endElement(); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr $objWriter->startElement('p:grpSpPr'); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm $objWriter->startElement('a:xfrm'); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY())); $objWriter->endElement(); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY())); $objWriter->endElement(); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chOff $objWriter->startElement('a:chOff'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY())); $objWriter->endElement(); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chExt $objWriter->startElement('a:chExt'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY())); $objWriter->endElement(); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\ $objWriter->endElement(); // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\ $objWriter->endElement(); // Loop shapes $this->writeShapeCollection($objWriter, $pSlideLayout->getShapeCollection()); // p:sldLayout\p:cSld\p:spTree\ $objWriter->endElement(); // p:sldLayout\p:cSld\ $objWriter->endElement(); // p:sldLayout\p:clrMapOvr $objWriter->startElement('p:clrMapOvr'); $arrayDiff = array_diff_assoc(ColorMap::$mappingDefault, $pSlideLayout->colorMap->getMapping()); if (!empty($arrayDiff)) { // p:sldLayout\p:clrMapOvr\a:overrideClrMapping $objWriter->startElement('a:overrideClrMapping'); foreach ($pSlideLayout->colorMap->getMapping() as $n => $v) { $objWriter->writeAttribute($n, $v); } $objWriter->endElement(); } else { // p:sldLayout\p:clrMapOvr\a:masterClrMapping $objWriter->writeElement('a:masterClrMapping'); } // p:sldLayout\p:clrMapOvr\ $objWriter->endElement(); if (!is_null($pSlideLayout->getTransition())) { $this->writeTransition($objWriter, $pSlideLayout->getTransition()); } // p:sldLayout\ $objWriter->endElement(); return $objWriter->getData(); }
public function testTypeScatterSeriesOutline() { $expectedWidth = rand(1, 100); $expectedWidthCm = number_format(CommonDrawing::pointsToCentimeters($expectedWidth), 3, '.', '') . 'cm'; $expectedElement = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleSeries0\'][@style:family=\'chart\']/style:graphic-properties'; $oColor = new Color(Color::COLOR_YELLOW); $oOutline = new Outline(); // Define the color $oOutline->getFill()->setFillType(Fill::FILL_SOLID); $oOutline->getFill()->setStartColor($oColor); // Define the width (in points) $oOutline->setWidth($expectedWidth); $oPhpPresentation = new PhpPresentation(); $oSlide = $oPhpPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80); $oScatter = new Scatter(); $oSeries = new Series('Downloads', array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2)); $oScatter->addSeries($oSeries); $oShape->getPlotArea()->setType($oScatter); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml')); $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'Object 1/content.xml')); $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-width', 'Object 1/content.xml')); $this->assertEquals('0.079cm', $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-width', 'Object 1/content.xml')); $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-color', 'Object 1/content.xml')); $this->assertEquals('#4a7ebb', $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-color', 'Object 1/content.xml')); $oSeries->setOutline($oOutline); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml')); $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'Object 1/content.xml')); $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-width', 'Object 1/content.xml')); $this->assertEquals($expectedWidthCm, $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-width', 'Object 1/content.xml')); $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-color', 'Object 1/content.xml')); $this->assertEquals('#' . $oColor->getRGB(), $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-color', 'Object 1/content.xml')); }
/** * Write Note Slide * @param Note $pNote * @throws \Exception * @return string */ protected function writeNote(Note $pNote) { // Create XML writer $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // p:notes $objWriter->startElement('p:notes'); $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); // p:notes/p:cSld $objWriter->startElement('p:cSld'); // p:notes/p:cSld/p:spTree $objWriter->startElement('p:spTree'); // p:notes/p:cSld/p:spTree/p:nvGrpSpPr $objWriter->startElement('p:nvGrpSpPr'); // p:notes/p:cSld/p:spTree/p:nvGrpSpPr/p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', '1'); $objWriter->writeAttribute('name', ''); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:nvGrpSpPr/p:cNvGrpSpPr $objWriter->writeElement('p:cNvGrpSpPr', null); // p:notes/p:cSld/p:spTree/p:nvGrpSpPr/p:nvPr $objWriter->writeElement('p:nvPr', null); // p:notes/p:cSld/p:spTree/p:nvGrpSpPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:grpSpPr $objWriter->startElement('p:grpSpPr'); // p:notes/p:cSld/p:spTree/p:grpSpPr/a:xfrm $objWriter->startElement('a:xfrm'); // p:notes/p:cSld/p:spTree/p:grpSpPr/a:xfrm/a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pNote->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pNote->getOffsetY())); $objWriter->endElement(); // a:off // p:notes/p:cSld/p:spTree/p:grpSpPr/a:xfrm/a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pNote->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pNote->getExtentY())); $objWriter->endElement(); // a:ext // p:notes/p:cSld/p:spTree/p:grpSpPr/a:xfrm/a:chOff $objWriter->startElement('a:chOff'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pNote->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pNote->getOffsetY())); $objWriter->endElement(); // a:chOff // p:notes/p:cSld/p:spTree/p:grpSpPr/a:xfrm/a:chExt $objWriter->startElement('a:chExt'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pNote->getExtentX())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pNote->getExtentY())); $objWriter->endElement(); // a:chExt // p:notes/p:cSld/p:spTree/p:grpSpPr/a:xfrm $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:grpSpPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1] $objWriter->startElement('p:sp'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr $objWriter->startElement('p:nvSpPr'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr/p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', '2'); $objWriter->writeAttribute('name', 'Slide Image Placeholder 1'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr/p:cNvSpPr $objWriter->startElement('p:cNvSpPr'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr/p:cNvSpPr/a:spLocks $objWriter->startElement('a:spLocks'); $objWriter->writeAttribute('noGrp', '1'); $objWriter->writeAttribute('noRot', '1'); $objWriter->writeAttribute('noChangeAspect', '1'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr/p:cNvSpPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr/p:nvPr $objWriter->startElement('p:nvPr'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr/p:nvPr/p:ph $objWriter->startElement('p:ph'); $objWriter->writeAttribute('type', 'sldImg'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr/p:nvPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:nvSpPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr $objWriter->startElement('p:spPr'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm $objWriter->startElement('a:xfrm'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm/a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', 0); $objWriter->writeAttribute('y', 0); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm/a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu(round($pNote->getExtentX() / 2))); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu(round($pNote->getExtentY() / 2))); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:prstGeom $objWriter->startElement('a:prstGeom'); $objWriter->writeAttribute('prst', 'rect'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:prstGeom/a:avLst $objWriter->writeElement('a:avLst', null); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:prstGeom $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:noFill $objWriter->writeElement('a:noFill', null); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:ln $objWriter->startElement('a:ln'); $objWriter->writeAttribute('w', '12700'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:ln/a:solidFill $objWriter->startElement('a:solidFill'); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:ln/a:solidFill/a:prstClr $objWriter->startElement('a:prstClr'); $objWriter->writeAttribute('val', 'black'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:ln/a:solidFill $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:ln $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[1] $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2] $objWriter->startElement('p:sp'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr $objWriter->startElement('p:nvSpPr'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr/p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', '3'); $objWriter->writeAttribute('name', 'Notes Placeholder'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr/p:cNvSpPr $objWriter->startElement('p:cNvSpPr'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr/p:cNvSpPr/a:spLocks $objWriter->startElement('a:spLocks'); $objWriter->writeAttribute('noGrp', '1'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr/p:cNvSpPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr/p:nvPr $objWriter->startElement('p:nvPr'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr/p:nvPr/p:ph $objWriter->startElement('p:ph'); $objWriter->writeAttribute('type', 'body'); $objWriter->writeAttribute('idx', '1'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr/p:nvPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:nvSpPr $objWriter->endElement(); // START notes print below rectangle section // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr $objWriter->startElement('p:spPr'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm $objWriter->startElement('a:xfrm'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm/a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pNote->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu(round($pNote->getExtentY() / 2) + $pNote->getOffsetY())); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm/a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', '5486400'); $objWriter->writeAttribute('cy', '3600450'); $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:prstGeom $objWriter->startElement('a:prstGeom'); $objWriter->writeAttribute('prst', 'rect'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:prstGeom/a:avLst $objWriter->writeElement('a:avLst', null); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:prstGeom $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2]/p:txBody $objWriter->startElement('p:txBody'); // p:notes/p:cSld/p:spTree/p:sp[2]/p:txBody/a:bodyPr $objWriter->writeElement('a:bodyPr', null); // p:notes/p:cSld/p:spTree/p:sp[2]/p:txBody/a:lstStyle $objWriter->writeElement('a:lstStyle', null); // Loop shapes $shapes = $pNote->getShapeCollection(); foreach ($shapes as $shape) { // Check type if ($shape instanceof RichText) { $paragraphs = $shape->getParagraphs(); $this->writeParagraphs($objWriter, $paragraphs); } } // p:notes/p:cSld/p:spTree/p:sp[2]/p:txBody $objWriter->endElement(); // p:notes/p:cSld/p:spTree/p:sp[2] $objWriter->endElement(); // p:notes/p:cSld/p:spTree $objWriter->endElement(); // p:notes/p:cSld $objWriter->endElement(); // p:notes $objWriter->endElement(); // Return return $objWriter->getData(); }
public function testHTML() { $this->assertFalse(Drawing::htmlToRGB('0')); $this->assertFalse(Drawing::htmlToRGB('00')); $this->assertFalse(Drawing::htmlToRGB('0000')); $this->assertFalse(Drawing::htmlToRGB('00000')); $this->assertInternalType('array', Drawing::htmlToRGB('ABCDEF')); $this->assertCount(3, Drawing::htmlToRGB('ABCDEF')); $this->assertEquals(array(0xab, 0xcd, 0xef), Drawing::htmlToRGB('ABCDEF')); $this->assertEquals(array(0xab, 0xcd, 0xef), Drawing::htmlToRGB('#ABCDEF')); $this->assertEquals(array(0xaa, 0xbb, 0xcc), Drawing::htmlToRGB('ABC')); $this->assertEquals(array(0xaa, 0xbb, 0xcc), Drawing::htmlToRGB('#ABC')); }
public function testRichTextShadow() { $randAlpha = rand(0, 100); $phpPresentation = new PhpPresentation(); $oSlide = $phpPresentation->getActiveSlide(); $oRichText = $oSlide->createRichTextShape(); $oRichText->createTextRun('AAA'); $oRichText->getShadow()->setVisible(true)->setAlpha($randAlpha)->setBlurRadius(2); $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties'; for ($inc = 0; $inc <= 360; $inc += 45) { $randDistance = rand(0, 100); $oRichText->getShadow()->setDirection($inc)->setDistance($randDistance); $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation'); $this->assertTrue($pres->elementExists($element, 'content.xml')); $this->assertEquals('visible', $pres->getElementAttribute($element, 'draw:shadow', 'content.xml')); $this->assertEquals('none', $pres->getElementAttribute($element, 'style:mirror', 'content.xml')); // Opacity $this->assertStringStartsWith((string) (100 - $randAlpha), $pres->getElementAttribute($element, 'draw:shadow-opacity', 'content.xml')); $this->assertStringEndsWith('%', $pres->getElementAttribute($element, 'draw:shadow-opacity', 'content.xml')); // Color $this->assertStringStartsWith('#', $pres->getElementAttribute($element, 'draw:shadow-color', 'content.xml')); // X $xOffset = $pres->getElementAttribute($element, 'draw:shadow-offset-x', 'content.xml'); if ($inc == 90 || $inc == 270) { $this->assertEquals('0cm', $xOffset); } else { if ($inc > 90 && $inc < 270) { $this->assertEquals('-' . Drawing::pixelsToCentimeters($randDistance) . 'cm', $xOffset); } else { $this->assertEquals(Drawing::pixelsToCentimeters($randDistance) . 'cm', $xOffset); } } // Y $yOffset = $pres->getElementAttribute($element, 'draw:shadow-offset-y', 'content.xml'); if ($inc == 0 || $inc == 180 || $inc == 360) { $this->assertEquals('0cm', $yOffset); } else { if ($inc > 0 && $inc < 180 || $inc == 360) { $this->assertEquals(Drawing::pixelsToCentimeters($randDistance) . 'cm', $yOffset); } else { $this->assertEquals('-' . Drawing::pixelsToCentimeters($randDistance) . 'cm', $yOffset); } } } }
public function testTypeScatterSeriesOutline() { $expectedWidth = rand(1, 100); $expectedWidthEmu = Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidth)); $expectedElement = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:spPr/a:ln'; $oOutline = new Outline(); // Define the color $oOutline->getFill()->setFillType(Fill::FILL_SOLID); $oOutline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW)); // Define the width (in points) $oOutline->setWidth($expectedWidth); $oSlide = $this->oPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80); $oScatter = new Scatter(); $oSeries = new Series('Downloads', $this->seriesData); $oScatter->addSeries($oSeries); $oShape->getPlotArea()->setType($oScatter); $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007'); $this->assertTrue($oXMLDoc->fileExists('ppt/charts/' . $oShape->getIndexedFilename())); $this->assertFalse($oXMLDoc->elementExists($expectedElement, 'ppt/charts/' . $oShape->getIndexedFilename())); $oSeries->setOutline($oOutline); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007'); $this->assertTrue($oXMLDoc->fileExists('ppt/charts/' . $oShape->getIndexedFilename())); $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertEquals($expectedWidthEmu, $oXMLDoc->getElementAttribute($expectedElement, 'w', 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertTrue($oXMLDoc->elementExists($expectedElement . '/a:solidFill', 'ppt/charts/' . $oShape->getIndexedFilename())); }
/** * Write Legend * * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPresentation\Shape\Chart\Legend $subject * @throws \Exception */ protected function writeLegend(XMLWriter $objWriter, Legend $subject) { // c:legend $objWriter->startElement('c:legend'); // c:legendPos $objWriter->startElement('c:legendPos'); $objWriter->writeAttribute('val', $subject->getPosition()); $objWriter->endElement(); // Write layout $this->writeLayout($objWriter, $subject); // c:overlay $objWriter->startElement('c:overlay'); $objWriter->writeAttribute('val', '0'); $objWriter->endElement(); // c:spPr $objWriter->startElement('c:spPr'); // Fill $this->writeFill($objWriter, $subject->getFill()); // Border if ($subject->getBorder()->getLineStyle() != Border::LINE_NONE) { $this->writeBorder($objWriter, $subject->getBorder(), ''); } $objWriter->endElement(); // c:txPr $objWriter->startElement('c:txPr'); // a:bodyPr $objWriter->writeElement('a:bodyPr', null); // a:lstStyle $objWriter->writeElement('a:lstStyle', null); // a:p $objWriter->startElement('a:p'); // a:pPr $objWriter->startElement('a:pPr'); $objWriter->writeAttribute('algn', $subject->getAlignment()->getHorizontal()); $objWriter->writeAttribute('fontAlgn', $subject->getAlignment()->getVertical()); $objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($subject->getAlignment()->getMarginLeft())); $objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($subject->getAlignment()->getMarginRight())); $objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($subject->getAlignment()->getIndent())); $objWriter->writeAttribute('lvl', $subject->getAlignment()->getLevel()); // a:defRPr $objWriter->startElement('a:defRPr'); $objWriter->writeAttribute('b', $subject->getFont()->isBold() ? 'true' : 'false'); $objWriter->writeAttribute('i', $subject->getFont()->isItalic() ? 'true' : 'false'); $objWriter->writeAttribute('strike', $subject->getFont()->isStrikethrough() ? 'sngStrike' : 'noStrike'); $objWriter->writeAttribute('sz', $subject->getFont()->getSize() * 100); $objWriter->writeAttribute('u', $subject->getFont()->getUnderline()); if ($subject->getFont()->isSuperScript() || $subject->getFont()->isSubScript()) { if ($subject->getFont()->isSuperScript()) { $objWriter->writeAttribute('baseline', '30000'); } elseif ($subject->getFont()->isSubScript()) { $objWriter->writeAttribute('baseline', '-25000'); } } // Font - a:solidFill $objWriter->startElement('a:solidFill'); // a:srgbClr $objWriter->startElement('a:srgbClr'); $objWriter->writeAttribute('val', $subject->getFont()->getColor()->getRGB()); $objWriter->endElement(); $objWriter->endElement(); // Font - a:latin $objWriter->startElement('a:latin'); $objWriter->writeAttribute('typeface', $subject->getFont()->getName()); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // a:endParaRPr $objWriter->startElement('a:endParaRPr'); $objWriter->writeAttribute('lang', 'en-US'); $objWriter->writeAttribute('dirty', '0'); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); }
/** * Convert EMUs to differents units * @param $value * @param string $fromUnit * @param string $toUnit */ protected function convertUnit($value, $fromUnit, $toUnit) { // Convert from $fromUnit to EMU switch ($fromUnit) { case self::UNIT_MILLIMETER: $value *= 36000; break; case self::UNIT_CENTIMETER: $value *= 360000; break; case self::UNIT_INCH: $value *= 914400; break; case self::UNIT_PIXEL: $value = Drawing::pixelsToEmu($value); break; case self::UNIT_POINT: $value *= 12700; break; case self::UNIT_EMU: default: // no changes } // Convert from EMU to $toUnit switch ($toUnit) { case self::UNIT_MILLIMETER: $value /= 36000; break; case self::UNIT_CENTIMETER: $value /= 360000; break; case self::UNIT_INCH: $value /= 914400; break; case self::UNIT_PIXEL: $value = Drawing::emuToPixels($value); break; case self::UNIT_POINT: $value /= 12700; break; case self::UNIT_EMU: default: // no changes } return $value; }
/** * Write Meta file to XML format * * @return string XML Output * @throws \Exception */ protected function writePart() { // Create XML writer $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); $objWriter->startDocument('1.0', 'UTF-8'); // office:document-meta $objWriter->startElement('office:document-styles'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0'); $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:officeooo', 'http://openoffice.org/2009/office'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:drawooo', 'http://openoffice.org/2010/draw'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('office:version', '1.2'); // Variables $stylePageLayout = $this->getPresentation()->getLayout()->getDocumentLayout(); if (empty($stylePageLayout)) { $stylePageLayout = 'sPL0'; } // office:styles $objWriter->startElement('office:styles'); // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'sPres0'); $objWriter->writeAttribute('style:display-name', 'sPres0'); $objWriter->writeAttribute('style:family', 'presentation'); // style:graphic-properties $objWriter->startElement('style:graphic-properties'); $objWriter->writeAttribute('draw:fill-color', '#ffffff'); // > style:graphic-properties $objWriter->endElement(); // > style:style $objWriter->endElement(); foreach ($this->getPresentation()->getAllSlides() as $keySlide => $oSlide) { foreach ($oSlide->getShapeCollection() as $shape) { if ($shape instanceof Table) { $this->writeTableStyle($objWriter, $shape); } elseif ($shape instanceof Group) { $this->writeGroupStyle($objWriter, $shape); } elseif ($shape instanceof RichText) { $this->writeRichTextStyle($objWriter, $shape); } } $oBkgImage = $oSlide->getBackground(); if ($oBkgImage instanceof Image) { $this->writeBackgroundStyle($objWriter, $oBkgImage, $keySlide); } } // > office:styles $objWriter->endElement(); // office:automatic-styles $objWriter->startElement('office:automatic-styles'); // style:page-layout $objWriter->startElement('style:page-layout'); $objWriter->writeAttribute('style:name', $stylePageLayout); // style:page-layout-properties $objWriter->startElement('style:page-layout-properties'); $objWriter->writeAttribute('fo:margin-top', '0cm'); $objWriter->writeAttribute('fo:margin-bottom', '0cm'); $objWriter->writeAttribute('fo:margin-left', '0cm'); $objWriter->writeAttribute('fo:margin-right', '0cm'); $objWriter->writeAttribute('fo:page-width', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($this->getPresentation()->getLayout()->getCX())), 1) . 'cm'); $objWriter->writeAttribute('fo:page-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($this->getPresentation()->getLayout()->getCY())), 1) . 'cm'); $printOrientation = 'portrait'; if ($this->getPresentation()->getLayout()->getCX() > $this->getPresentation()->getLayout()->getCY()) { $printOrientation = 'landscape'; } $objWriter->writeAttribute('style:print-orientation', $printOrientation); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // office:master-styles $objWriter->startElement('office:master-styles'); // style:master-page $objWriter->startElement('style:master-page'); $objWriter->writeAttribute('style:name', 'Standard'); $objWriter->writeAttribute('style:display-name', 'Standard'); $objWriter->writeAttribute('style:page-layout-name', $stylePageLayout); $objWriter->writeAttribute('draw:style-name', 'sPres0'); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // Return return $objWriter->getData(); }
protected function writeStylePartShadow(XMLWriter $objWriter, Shadow $oShadow) { $objWriter->writeAttribute('draw:shadow', 'visible'); $objWriter->writeAttribute('draw:shadow-color', '#' . $oShadow->getColor()->getRGB()); if ($oShadow->getDirection() == 0 || $oShadow->getDirection() == 360) { $objWriter->writeAttribute('draw:shadow-offset-x', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); $objWriter->writeAttribute('draw:shadow-offset-y', '0cm'); } elseif ($oShadow->getDirection() == 45) { $objWriter->writeAttribute('draw:shadow-offset-x', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); $objWriter->writeAttribute('draw:shadow-offset-y', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); } elseif ($oShadow->getDirection() == 90) { $objWriter->writeAttribute('draw:shadow-offset-x', '0cm'); $objWriter->writeAttribute('draw:shadow-offset-y', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); } elseif ($oShadow->getDirection() == 135) { $objWriter->writeAttribute('draw:shadow-offset-x', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); $objWriter->writeAttribute('draw:shadow-offset-y', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); } elseif ($oShadow->getDirection() == 180) { $objWriter->writeAttribute('draw:shadow-offset-x', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); $objWriter->writeAttribute('draw:shadow-offset-y', '0cm'); } elseif ($oShadow->getDirection() == 225) { $objWriter->writeAttribute('draw:shadow-offset-x', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); $objWriter->writeAttribute('draw:shadow-offset-y', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); } elseif ($oShadow->getDirection() == 270) { $objWriter->writeAttribute('draw:shadow-offset-x', '0cm'); $objWriter->writeAttribute('draw:shadow-offset-y', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); } elseif ($oShadow->getDirection() == 315) { $objWriter->writeAttribute('draw:shadow-offset-x', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); $objWriter->writeAttribute('draw:shadow-offset-y', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm'); } $objWriter->writeAttribute('draw:shadow-opacity', 100 - $oShadow->getAlpha() . '%'); $objWriter->writeAttribute('style:mirror', 'none'); }
public function testNote() { $oPhpPresentation = new PhpPresentation(); $oLayout = $oPhpPresentation->getLayout(); $oSlide = $oPhpPresentation->getActiveSlide(); $oNote = $oSlide->getNote(); $oRichText = $oNote->createRichTextShape()->setHeight($oLayout->getCY($oLayout::UNIT_PIXEL))->setWidth($oLayout->getCX($oLayout::UNIT_PIXEL))->setOffsetX(170)->setOffsetY(180); $oRichText->createTextRun('testNote'); $pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007'); // Content Types // $element = '/Types/Override[@PartName="/ppt/notesSlides/notesSlide1.xml"][@ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"]'; // $this->assertTrue($pres->elementExists($element, '[Content_Types].xml')); // Rels // $element = '/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide"][@Target="../notesSlides/notesSlide1.xml"]'; // $this->assertTrue($pres->elementExists($element, 'ppt/slides/_rels/slide1.xml.rels')); // Slide $element = '/p:notes'; $this->assertTrue($pres->elementExists($element, 'ppt/notesSlides/notesSlide1.xml')); // Slide Image Placeholder 1 $element = '/p:notes/p:cSld/p:spTree/p:sp/p:nvSpPr/p:cNvPr[@id="2"][@name="Slide Image Placeholder 1"]'; $this->assertTrue($pres->elementExists($element, 'ppt/notesSlides/notesSlide1.xml')); $element = '/p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm/a:off'; $this->assertEquals(0, $pres->getElementAttribute($element, 'x', 'ppt/notesSlides/notesSlide1.xml')); $this->assertEquals(0, $pres->getElementAttribute($element, 'y', 'ppt/notesSlides/notesSlide1.xml')); $element = '/p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm/a:ext'; $this->assertEquals(Drawing::pixelsToEmu(round($oNote->getExtentX() / 2)), $pres->getElementAttribute($element, 'cx', 'ppt/notesSlides/notesSlide1.xml')); $this->assertEquals(Drawing::pixelsToEmu(round($oNote->getExtentY() / 2)), $pres->getElementAttribute($element, 'cy', 'ppt/notesSlides/notesSlide1.xml')); // Notes Placeholder $element = '/p:notes/p:cSld/p:spTree/p:sp/p:nvSpPr/p:cNvPr[@id="3"][@name="Notes Placeholder"]'; $this->assertTrue($pres->elementExists($element, 'ppt/notesSlides/notesSlide1.xml')); // Notes $element = '/p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm/a:off'; $this->assertEquals(Drawing::pixelsToEmu($oNote->getOffsetX()), $pres->getElementAttribute($element, 'x', 'ppt/notesSlides/notesSlide1.xml')); $this->assertEquals(Drawing::pixelsToEmu(round($oNote->getExtentY() / 2) + $oNote->getOffsetY()), $pres->getElementAttribute($element, 'y', 'ppt/notesSlides/notesSlide1.xml')); $element = '/p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm/a:ext'; $this->assertEquals(5486400, $pres->getElementAttribute($element, 'cx', 'ppt/notesSlides/notesSlide1.xml')); $this->assertEquals(3600450, $pres->getElementAttribute($element, 'cy', 'ppt/notesSlides/notesSlide1.xml')); $element = '/p:notes/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:t'; $this->assertTrue($pres->elementExists($element, 'ppt/notesSlides/notesSlide1.xml')); }
/** * @param $data integer * @param $pos integer * @return \stdClass * @link http://msdn.microsoft.com/en-us/library/dd772849%28v=office.12%29.aspx */ private function readPrl($data, $pos, $cbNum) { $posStart = $pos; $oStylePrl = new \stdClass(); // Variables $sprmCPicLocation = null; $sprmCFData = null; $sprmCFSpec = null; do { // Variables $operand = null; $sprm = self::getInt2d($data, $pos); $oSprm = $this->readSprm($sprm); $pos += 2; $cbNum -= 2; $arrayReturn = $this->readSprmSpra($data, $pos, $oSprm); $pos += $arrayReturn['length']; $cbNum -= $arrayReturn['length']; $operand = $arrayReturn['operand']; switch (dechex($oSprm->sgc)) { // Paragraph property case 0x1: break; // Character property // Character property case 0x2: if (!isset($oStylePrl->styleFont)) { $oStylePrl->styleFont = array(); } switch ($oSprm->isPmd) { // sprmCFRMarkIns case 0x1: break; // sprmCFFldVanish // sprmCFFldVanish case 0x2: break; // sprmCPicLocation // sprmCPicLocation case 0x3: $sprmCPicLocation = $operand; break; // sprmCFData // sprmCFData case 0x6: $sprmCFData = dechex($operand) == 0x0 ? false : true; break; // sprmCFItalic // sprmCFItalic case 0x36: // By default, text is not italicized. switch ($operand) { case false: case true: $oStylePrl->styleFont['italic'] = $operand; break; case self::SPRA_VALUE: $oStylePrl->styleFont['italic'] = false; break; case self::SPRA_VALUE_OPPOSITE: $oStylePrl->styleFont['italic'] = true; break; } break; // sprmCIstd // sprmCIstd case 0x30: //print_r('sprmCIstd : '.dechex($operand).PHP_EOL.PHP_EOL); break; // sprmCFBold // sprmCFBold case 0x35: // By default, text is not bold. switch ($operand) { case false: case true: $oStylePrl->styleFont['bold'] = $operand; break; case self::SPRA_VALUE: $oStylePrl->styleFont['bold'] = false; break; case self::SPRA_VALUE_OPPOSITE: $oStylePrl->styleFont['bold'] = true; break; } break; // sprmCFStrike // sprmCFStrike case 0x37: // By default, text is not struck through. switch ($operand) { case false: case true: $oStylePrl->styleFont['strikethrough'] = $operand; break; case self::SPRA_VALUE: $oStylePrl->styleFont['strikethrough'] = false; break; case self::SPRA_VALUE_OPPOSITE: $oStylePrl->styleFont['strikethrough'] = true; break; } break; // sprmCKul // sprmCKul case 0x3e: switch (dechex($operand)) { case 0x0: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_NONE; break; case 0x1: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_SINGLE; break; case 0x2: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WORDS; break; case 0x3: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOUBLE; break; case 0x4: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTTED; break; case 0x6: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_HEAVY; break; case 0x7: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASH; break; case 0x9: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTHASH; break; case 0xa: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTDOTDASH; break; case 0xb: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WAVY; break; case 0x14: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTTEDHEAVY; break; case 0x17: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASHHEAVY; break; case 0x19: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTHASHHEAVY; break; case 0x1a: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTDOTDASHHEAVY; break; case 0x1b: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WAVYHEAVY; break; case 0x27: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASHLONG; break; case 0x2b: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WAVYDOUBLE; break; case 0x37: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASHLONGHEAVY; break; default: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_NONE; break; } break; // sprmCIco //@link http://msdn.microsoft.com/en-us/library/dd773060%28v=office.12%29.aspx // sprmCIco //@link http://msdn.microsoft.com/en-us/library/dd773060%28v=office.12%29.aspx case 0x42: switch (dechex($operand)) { case 0x0: case 0x1: $oStylePrl->styleFont['color'] = '000000'; break; case 0x2: $oStylePrl->styleFont['color'] = '0000FF'; break; case 0x3: $oStylePrl->styleFont['color'] = '00FFFF'; break; case 0x4: $oStylePrl->styleFont['color'] = '00FF00'; break; case 0x5: $oStylePrl->styleFont['color'] = 'FF00FF'; break; case 0x6: $oStylePrl->styleFont['color'] = 'FF0000'; break; case 0x7: $oStylePrl->styleFont['color'] = 'FFFF00'; break; case 0x8: $oStylePrl->styleFont['color'] = 'FFFFFF'; break; case 0x9: $oStylePrl->styleFont['color'] = '000080'; break; case 0xa: $oStylePrl->styleFont['color'] = '008080'; break; case 0xb: $oStylePrl->styleFont['color'] = '008000'; break; case 0xc: $oStylePrl->styleFont['color'] = '800080'; break; case 0xd: $oStylePrl->styleFont['color'] = '800080'; break; case 0xe: $oStylePrl->styleFont['color'] = '808000'; break; case 0xf: $oStylePrl->styleFont['color'] = '808080'; break; case 0x10: $oStylePrl->styleFont['color'] = 'C0C0C0'; } break; // sprmCHps // sprmCHps case 0x43: $oStylePrl->styleFont['size'] = dechex($operand / 2); break; // sprmCIss // sprmCIss case 0x48: if (!isset($oStylePrl->styleFont['superScript'])) { $oStylePrl->styleFont['superScript'] = false; } if (!isset($oStylePrl->styleFont['subScript'])) { $oStylePrl->styleFont['subScript'] = false; } switch (dechex($operand)) { case 0x0: // Normal text break; case 0x1: $oStylePrl->styleFont['superScript'] = true; break; case 0x2: $oStylePrl->styleFont['subScript'] = true; break; } break; // sprmCRgFtc0 // sprmCRgFtc0 case 0x4f: $oStylePrl->styleFont['name'] = ''; if (isset($this->arrayFonts[$operand])) { $oStylePrl->styleFont['name'] = $this->arrayFonts[$operand]['main']; } break; // sprmCRgFtc1 // sprmCRgFtc1 case 0x50: // if the language for the text is an East Asian language break; // sprmCRgFtc2 // sprmCRgFtc2 case 0x51: // if the character falls outside the Unicode character range break; // sprmCFSpec // sprmCFSpec case 0x55: $sprmCFSpec = $operand; break; // sprmCFtcBi // sprmCFtcBi case 0x5e: break; // sprmCFItalicBi // sprmCFItalicBi case 0x5d: break; // sprmCHpsBi // sprmCHpsBi case 0x61: break; // sprmCShd80 //@link http://msdn.microsoft.com/en-us/library/dd923447%28v=office.12%29.aspx // sprmCShd80 //@link http://msdn.microsoft.com/en-us/library/dd923447%28v=office.12%29.aspx case 0x66: // $operand = self::getInt2d($data, $pos); $pos += 2; $cbNum -= 2; // $ipat = ($operand >> 0) && bindec('111111'); // $icoBack = ($operand >> 6) && bindec('11111'); // $icoFore = ($operand >> 11) && bindec('11111'); break; // sprmCCv //@link : http://msdn.microsoft.com/en-us/library/dd952824%28v=office.12%29.aspx // sprmCCv //@link : http://msdn.microsoft.com/en-us/library/dd952824%28v=office.12%29.aspx case 0x70: $red = str_pad(dechex(self::getInt1d($this->dataWorkDocument, $pos)), 2, '0', STR_PAD_LEFT); $pos += 1; $green = str_pad(dechex(self::getInt1d($this->dataWorkDocument, $pos)), 2, '0', STR_PAD_LEFT); $pos += 1; $blue = str_pad(dechex(self::getInt1d($this->dataWorkDocument, $pos)), 2, '0', STR_PAD_LEFT); $pos += 1; $pos += 1; $oStylePrl->styleFont['color'] = $red . $green . $blue; $cbNum -= 4; break; default: // print_r('@todo Character : 0x'.dechex($oSprm->isPmd)); // print_r(PHP_EOL); } break; // Picture property // Picture property case 0x3: break; // Section property // Section property case 0x4: if (!isset($oStylePrl->styleSection)) { $oStylePrl->styleSection = array(); } switch ($oSprm->isPmd) { // sprmSNfcPgn case 0xe: // numbering format used for page numbers break; // sprmSXaPage // sprmSXaPage case 0x1f: $oStylePrl->styleSection['pageSizeW'] = $operand; break; // sprmSYaPage // sprmSYaPage case 0x20: $oStylePrl->styleSection['pageSizeH'] = $operand; break; // sprmSDxaLeft // sprmSDxaLeft case 0x21: $oStylePrl->styleSection['marginLeft'] = $operand; break; // sprmSDxaRight // sprmSDxaRight case 0x22: $oStylePrl->styleSection['marginRight'] = $operand; break; // sprmSDyaTop // sprmSDyaTop case 0x23: $oStylePrl->styleSection['marginTop'] = $operand; break; // sprmSDyaBottom // sprmSDyaBottom case 0x24: $oStylePrl->styleSection['marginBottom'] = $operand; break; // sprmSFBiDi // sprmSFBiDi case 0x28: // RTL layout break; // sprmSDxtCharSpace // sprmSDxtCharSpace case 0x30: // characpter pitch break; // sprmSDyaLinePitch // sprmSDyaLinePitch case 0x31: // line height break; // sprmSClm // sprmSClm case 0x32: // document grid mode break; // sprmSTextFlow // sprmSTextFlow case 0x33: // text flow break; default: // print_r('@todo Section : 0x'.dechex($oSprm->isPmd)); // print_r(PHP_EOL); } break; // Table property // Table property case 0x5: break; } } while ($cbNum > 0); if (!is_null($sprmCPicLocation)) { if (!is_null($sprmCFData) && $sprmCFData == 0x1) { // NilPICFAndBinData //@todo Read Hyperlink structure /*$lcb = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; $cbHeader = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // ignored $sprmCPicLocation += 62; // depending of the element // Hyperlink => HFD // HFD > bits $sprmCPicLocation += 1; // HFD > clsid $sprmCPicLocation += 16; // HFD > hyperlink //@link : http://msdn.microsoft.com/en-us/library/dd909835%28v=office.12%29.aspx $streamVersion = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; $data = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; $hlstmfAbsFromGetdataRel = ($data >> 9) & bindec('1'); $hlstmfMonikerSavedAsStr = ($data >> 8) & bindec('1'); $hlstmfHasFrameName = ($data >> 7) & bindec('1'); $hlstmfHasCreationTime = ($data >> 6) & bindec('1'); $hlstmfHasGUID = ($data >> 5) & bindec('1'); $hlstmfHasDisplayName = ($data >> 4) & bindec('1'); $hlstmfHasLocationStr = ($data >> 3) & bindec('1'); $hlstmfSiteGaveDisplayName = ($data >> 2) & bindec('1'); $hlstmfIsAbsolute = ($data >> 1) & bindec('1'); $hlstmfHasMoniker = ($data >> 0) & bindec('1'); for ($inc = 0; $inc <= 32; $inc++) { echo ($data >> $inc) & bindec('1'); } print_r('$hlstmfHasMoniker > '.$hlstmfHasMoniker.PHP_EOL); print_r('$hlstmfIsAbsolute > '.$hlstmfIsAbsolute.PHP_EOL); print_r('$hlstmfSiteGaveDisplayName > '.$hlstmfSiteGaveDisplayName.PHP_EOL); print_r('$hlstmfHasLocationStr > '.$hlstmfHasLocationStr.PHP_EOL); print_r('$hlstmfHasDisplayName > '.$hlstmfHasDisplayName.PHP_EOL); print_r('$hlstmfHasGUID > '.$hlstmfHasGUID.PHP_EOL); print_r('$hlstmfHasCreationTime > '.$hlstmfHasCreationTime.PHP_EOL); print_r('$hlstmfHasFrameName > '.$hlstmfHasFrameName.PHP_EOL); print_r('$hlstmfMonikerSavedAsStr > '.$hlstmfMonikerSavedAsStr.PHP_EOL); print_r('$hlstmfAbsFromGetdataRel > '.$hlstmfAbsFromGetdataRel.PHP_EOL); if ($streamVersion == 2) { $AAA = self::getInt4d($this->dataData, $sprmCPicLocation); echo 'AAAA : '.$AAA.PHP_EOL; if ($hlstmfHasDisplayName == 1) { echo 'displayName'.PHP_EOL; } if ($hlstmfHasFrameName == 1) { echo 'targetFrameName'.PHP_EOL; } if ($hlstmfHasMoniker == 1 || $hlstmfMonikerSavedAsStr == 1) { $sprmCPicLocation += 16; $length = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; for ($inc = 0; $inc < ($length / 2); $inc++) { $chr = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; print_r(chr($chr)); } echo PHP_EOL; echo 'moniker : '.$length.PHP_EOL; } if ($hlstmfHasMoniker == 1 || $hlstmfMonikerSavedAsStr == 1) { echo 'oleMoniker'.PHP_EOL; } if ($hlstmfHasLocationStr == 1) { echo 'location'.PHP_EOL; } if ($hlstmfHasGUID == 1) { echo 'guid'.PHP_EOL; $sprmCPicLocation += 16; } if ($hlstmfHasCreationTime == 1) { echo 'fileTime'.PHP_EOL; $sprmCPicLocation += 4; } echo 'HYPERLINK'.PHP_EOL; }*/ } else { // Pictures //@link : http://msdn.microsoft.com/en-us/library/dd925458%28v=office.12%29.aspx //@link : http://msdn.microsoft.com/en-us/library/dd926136%28v=office.12%29.aspx // PICF : lcb $sprmCPicLocation += 4; // PICF : cbHeader $sprmCPicLocation += 2; // PICF : mfpf : mm $mfpfMm = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : mfpf : xExt $sprmCPicLocation += 2; // PICF : mfpf : yExt $sprmCPicLocation += 2; // PICF : mfpf : swHMF $sprmCPicLocation += 2; // PICF : innerHeader : grf $sprmCPicLocation += 4; // PICF : innerHeader : padding1 $sprmCPicLocation += 4; // PICF : innerHeader : mmPM $sprmCPicLocation += 2; // PICF : innerHeader : padding2 $sprmCPicLocation += 4; // PICF : picmid : dxaGoal $picmidDxaGoal = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dyaGoal $picmidDyaGoal = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : mx $picmidMx = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : my $picmidMy = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dxaReserved1 $picmidDxaCropLeft = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dyaReserved1 $picmidDxaCropTop = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dxaReserved2 $picmidDxaCropRight = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dyaReserved2 $picmidDxaCropBottom = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : fReserved $sprmCPicLocation += 1; // PICF : picmid : bpp $sprmCPicLocation += 1; // PICF : picmid : brcTop80 $sprmCPicLocation += 4; // PICF : picmid : brcLeft80 $sprmCPicLocation += 4; // PICF : picmid : brcBottom80 $sprmCPicLocation += 4; // PICF : picmid : brcRight80 $sprmCPicLocation += 4; // PICF : picmid : dxaReserved3 $sprmCPicLocation += 2; // PICF : picmid : dyaReserved3 $sprmCPicLocation += 2; // PICF : cProps $sprmCPicLocation += 2; if ($mfpfMm == 0x66) { // cchPicName $cchPicName = self::getInt1d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 1; // stPicName $stPicName = ''; for ($inc = 0; $inc <= $cchPicName; $inc++) { $chr = self::getInt1d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 1; $stPicName .= chr($chr); } } // picture (OfficeArtInlineSpContainer) // picture : shape $shapeRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 8; if ($shapeRH['recVer'] == 0xf && $shapeRH['recInstance'] == 0x0 && $shapeRH['recType'] == 0xf004) { $sprmCPicLocation += $shapeRH['recLen']; } // picture : rgfb //@link : http://msdn.microsoft.com/en-us/library/dd950560%28v=office.12%29.aspx $fileBlockRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); while ($fileBlockRH['recType'] == 0xf007 || $fileBlockRH['recType'] >= 0xf018 && $fileBlockRH['recType'] <= 0xf117) { $sprmCPicLocation += 8; switch ($fileBlockRH['recType']) { // OfficeArtFBSE //@link : http://msdn.microsoft.com/en-us/library/dd944923%28v=office.12%29.aspx case 0xf007: // btWin32 $sprmCPicLocation += 1; // btMacOS $sprmCPicLocation += 1; // rgbUid $sprmCPicLocation += 16; // tag $sprmCPicLocation += 2; // size $sprmCPicLocation += 4; // cRef $sprmCPicLocation += 4; // foDelay $sprmCPicLocation += 4; // unused1 $sprmCPicLocation += 1; // cbName $cbName = self::getInt1d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 1; // unused2 $sprmCPicLocation += 1; // unused3 $sprmCPicLocation += 1; // nameData if ($cbName > 0) { $nameData = ''; for ($inc = 0; $inc <= $cbName / 2; $inc++) { $chr = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; $nameData .= chr($chr); } } // embeddedBlip //@link : http://msdn.microsoft.com/en-us/library/dd910081%28v=office.12%29.aspx $embeddedBlipRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); switch ($embeddedBlipRH['recType']) { case self::OFFICEARTBLIPJPG: case self::OFFICEARTBLIPJPEG: if (!isset($oStylePrl->image)) { $oStylePrl->image = array(); } $sprmCPicLocation += 8; // embeddedBlip : rgbUid1 $sprmCPicLocation += 16; if ($embeddedBlipRH['recInstance'] == 0x6e1) { // rgbUid2 $sprmCPicLocation += 16; } // embeddedBlip : tag $sprmCPicLocation += 1; // embeddedBlip : BLIPFileData $oStylePrl->image['data'] = substr($this->dataData, $sprmCPicLocation, $embeddedBlipRH['recLen']); $oStylePrl->image['format'] = 'jpg'; // Image Size $iCropWidth = $picmidDxaGoal - ($picmidDxaCropLeft + $picmidDxaCropRight); $iCropHeight = $picmidDyaGoal - ($picmidDxaCropTop + $picmidDxaCropBottom); if (!$iCropWidth) { $iCropWidth = 1; } if (!$iCropHeight) { $iCropHeight = 1; } $oStylePrl->image['width'] = Drawing::twipsToPixels($iCropWidth * $picmidMx / 1000); $oStylePrl->image['height'] = Drawing::twipsToPixels($iCropHeight * $picmidMy / 1000); $sprmCPicLocation += $embeddedBlipRH['recLen']; break; default: // print_r(dechex($embeddedBlipRH['recType'])); } break; } $fileBlockRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); } } } $oStylePrl->length = $pos - $posStart; return $oStylePrl; }
/** * Write slide to XML format * * @param \PhpOffice\PhpPresentation\Slide\SlideMaster $pSlide * @return string XML Output * @throws \Exception */ public function writeSlideMaster(SlideMaster $pSlide) { // Create XML writer $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // p:sldMaster $objWriter->startElement('p:sldMaster'); $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); // p:sldMaster\p:cSld $objWriter->startElement('p:cSld'); // Background $this->writeSlideBackground($pSlide, $objWriter); // p:sldMaster\p:cSld\p:spTree $objWriter->startElement('p:spTree'); // p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr $objWriter->startElement('p:nvGrpSpPr'); // p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', '1'); $objWriter->writeAttribute('name', ''); $objWriter->endElement(); // p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvGrpSpPr $objWriter->writeElement('p:cNvGrpSpPr', null); // p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr\p:nvPr $objWriter->writeElement('p:nvPr', null); // p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr $objWriter->endElement(); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr $objWriter->startElement('p:grpSpPr'); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm $objWriter->startElement('a:xfrm'); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', 0); $objWriter->writeAttribute('y', 0); $objWriter->endElement(); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', 0); $objWriter->writeAttribute('cy', 0); $objWriter->endElement(); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chOff $objWriter->startElement('a:chOff'); $objWriter->writeAttribute('x', 0); $objWriter->writeAttribute('y', 0); $objWriter->endElement(); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chExt $objWriter->startElement('a:chExt'); $objWriter->writeAttribute('cx', 0); $objWriter->writeAttribute('cy', 0); $objWriter->endElement(); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\ $objWriter->endElement(); // p:sldMaster\p:cSld\p:spTree\p:grpSpPr\ $objWriter->endElement(); // Loop shapes $this->writeShapeCollection($objWriter, $pSlide->getShapeCollection()); // p:sldMaster\p:cSld\p:spTree\ $objWriter->endElement(); // p:sldMaster\p:cSld\ $objWriter->endElement(); // p:sldMaster\p:clrMap $objWriter->startElement('p:clrMap'); foreach ($pSlide->colorMap->getMapping() as $n => $v) { $objWriter->writeAttribute($n, $v); } $objWriter->endElement(); // p:sldMaster\p:clrMap\ // p:sldMaster\p:sldLayoutIdLst $objWriter->startElement('p:sldLayoutIdLst'); foreach ($pSlide->getAllSlideLayouts() as $layout) { /* @var $layout Slide\SlideLayout */ $objWriter->startElement('p:sldLayoutId'); $objWriter->writeAttribute('id', $layout->layoutId); $objWriter->writeAttribute('r:id', $layout->relationId); $objWriter->endElement(); } $objWriter->endElement(); // p:sldMaster\p:sldLayoutIdLst\ // p:sldMaster\p:txStyles $objWriter->startElement('p:txStyles'); foreach (array('p:titleStyle' => $pSlide->getTextStyles()->getTitleStyle(), 'p:bodyStyle' => $pSlide->getTextStyles()->getBodyStyle(), 'p:otherStyle' => $pSlide->getTextStyles()->getOtherStyle()) as $startElement => $stylesArray) { // titleStyle $objWriter->startElement($startElement); foreach ($stylesArray as $lvl => $oParagraph) { /** @var RichText\Paragraph $oParagraph */ $elementName = $lvl == 0 ? 'a:defPPr' : 'a:lvl' . $lvl . 'pPr'; $objWriter->startElement($elementName); $objWriter->writeAttribute('algn', $oParagraph->getAlignment()->getHorizontal()); $objWriter->writeAttributeIf($oParagraph->getAlignment()->getMarginLeft() != 0, 'marL', CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getMarginLeft())); $objWriter->writeAttributeIf($oParagraph->getAlignment()->getMarginRight() != 0, 'marR', CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getMarginRight())); $objWriter->writeAttributeIf($oParagraph->getAlignment()->getIndent() != 0, 'indent', CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getIndent())); $objWriter->startElement('a:defRPr'); $objWriter->writeAttributeIf($oParagraph->getFont()->getSize() != 10, 'sz', $oParagraph->getFont()->getSize() * 100); $objWriter->writeAttributeIf($oParagraph->getFont()->isBold(), 'b', 1); $objWriter->writeAttributeIf($oParagraph->getFont()->isItalic(), 'i', 1); $objWriter->writeAttribute('kern', '1200'); if ($oParagraph->getFont()->getColor() instanceof SchemeColor) { $objWriter->startElement('a:solidFill'); $objWriter->startElement('a:schemeClr'); $objWriter->writeAttribute('val', $oParagraph->getFont()->getColor()->getValue()); $objWriter->endElement(); $objWriter->endElement(); } $objWriter->endElement(); $objWriter->endElement(); } $objWriter->writeElement('a:extLst'); $objWriter->endElement(); } $objWriter->endElement(); // p:sldMaster\p:txStyles\ if (!is_null($pSlide->getTransition())) { $this->writeTransition($objWriter, $pSlide->getTransition()); } // p:sldMaster\ $objWriter->endElement(); return $objWriter->getData(); }