/** * Write picture * * @param \PhpOffice\Common\XMLWriter $objWriter * @param \PhpOffice\PhpPowerpoint\Shape\AbstractDrawing $shape */ public function writeShapePic(XMLWriter $objWriter, AbstractDrawing $shape) { // draw:frame $objWriter->startElement('draw:frame'); $objWriter->writeAttribute('draw:name', $shape->getName()); $objWriter->writeAttribute('svg:width', String::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); $objWriter->writeAttribute('svg:height', String::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); $objWriter->writeAttribute('svg:x', String::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); $objWriter->writeAttribute('svg:y', String::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId); // draw:image $objWriter->startElement('draw:image'); if ($shape instanceof ShapeDrawing) { $objWriter->writeAttribute('xlink:href', 'Pictures/' . md5($shape->getPath()) . '.' . $shape->getExtension()); } elseif ($shape instanceof MemoryDrawing) { $objWriter->writeAttribute('xlink:href', 'Pictures/' . $shape->getIndexedFilename()); } $objWriter->writeAttribute('xlink:type', 'simple'); $objWriter->writeAttribute('xlink:show', 'embed'); $objWriter->writeAttribute('xlink:actuate', 'onLoad'); $objWriter->writeElement('text:p'); $objWriter->endElement(); if ($shape->hasHyperlink()) { // office:event-listeners $objWriter->startElement('office:event-listeners'); // presentation:event-listener $objWriter->startElement('presentation:event-listener'); $objWriter->writeAttribute('script:event-name', 'dom:click'); $objWriter->writeAttribute('presentation:action', 'show'); $objWriter->writeAttribute('xlink:href', $shape->getHyperlink()->getUrl()); $objWriter->writeAttribute('xlink:type', 'simple'); $objWriter->writeAttribute('xlink:show', 'embed'); $objWriter->writeAttribute('xlink:actuate', 'onRequest'); // > presentation:event-listener $objWriter->endElement(); // > office:event-listeners $objWriter->endElement(); } $objWriter->endElement(); }
/** * Write picture * * @param \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter * @param \PhpOffice\PhpPowerpoint\Shape\AbstractDrawing $shape * @param int $shapeId */ public function writeShapePic(XMLWriter $objWriter, AbstractDrawing $shape, $shapeId) { // draw:frame $objWriter->startElement('draw:frame'); $objWriter->writeAttribute('draw:name', $shape->getName()); $objWriter->writeAttribute('svg:width', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); $objWriter->writeAttribute('svg:height', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); $objWriter->writeAttribute('svg:x', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); $objWriter->writeAttribute('svg:y', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); if ($shape->getShadow()->isVisible()) { $objWriter->writeAttribute('draw:style-name', 'gr' . $shapeId); } // draw:image $objWriter->startElement('draw:image'); if ($shape instanceof ShapeDrawing) { $objWriter->writeAttribute('xlink:href', 'Pictures/' . md5($shape->getPath()) . '.' . $shape->getExtension()); } elseif ($shape instanceof MemoryDrawing) { $objWriter->writeAttribute('xlink:href', 'Pictures/' . $shape->getIndexedFilename()); } $objWriter->writeAttribute('xlink:type', 'simple'); $objWriter->writeAttribute('xlink:show', 'embed'); $objWriter->writeAttribute('xlink:actuate', 'onLoad'); $objWriter->writeElement('text:p'); $objWriter->endElement(); $objWriter->endElement(); }
/** * Write pic * * @param \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPowerpoint\Shape\AbstractDrawing $shape * @param int $shapeId * @throws \Exception */ private function writeShapePic(XMLWriter $objWriter, AbstractDrawing $shape, $shapeId) { // p:pic $objWriter->startElement('p:pic'); // p:nvPicPr $objWriter->startElement('p:nvPicPr'); // p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', $shapeId); $objWriter->writeAttribute('name', $shape->getName()); $objWriter->writeAttribute('descr', $shape->getDescription()); $objWriter->endElement(); // p:cNvPicPr $objWriter->startElement('p:cNvPicPr'); // a:picLocks $objWriter->startElement('a:picLocks'); $objWriter->writeAttribute('noChangeAspect', '1'); $objWriter->endElement(); $objWriter->endElement(); // p:nvPr $objWriter->writeElement('p:nvPr', null); $objWriter->endElement(); // p:blipFill $objWriter->startElement('p:blipFill'); // a:blip $objWriter->startElement('a:blip'); $objWriter->writeAttribute('r:embed', $shape->relationId); $objWriter->endElement(); // a:stretch $objWriter->startElement('a:stretch'); $objWriter->writeElement('a:fillRect', null); $objWriter->endElement(); $objWriter->endElement(); // p:spPr $objWriter->startElement('p:spPr'); // a:xfrm $objWriter->startElement('a:xfrm'); $objWriter->writeAttribute('rot', SharedDrawing::degreesToAngle($shape->getRotation())); // a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', SharedDrawing::pixelsToEmu($shape->getOffsetX())); $objWriter->writeAttribute('y', SharedDrawing::pixelsToEmu($shape->getOffsetY())); $objWriter->endElement(); // a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', SharedDrawing::pixelsToEmu($shape->getWidth())); $objWriter->writeAttribute('cy', SharedDrawing::pixelsToEmu($shape->getHeight())); $objWriter->endElement(); $objWriter->endElement(); // a:prstGeom $objWriter->startElement('a:prstGeom'); $objWriter->writeAttribute('prst', 'rect'); // a:avLst $objWriter->writeElement('a:avLst', null); $objWriter->endElement(); if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) { $this->writeBorder($objWriter, $shape->getBorder(), ''); } if ($shape->getShadow()->isVisible()) { // a:effectLst $objWriter->startElement('a:effectLst'); // a:outerShdw $objWriter->startElement('a:outerShdw'); $objWriter->writeAttribute('blurRad', SharedDrawing::pixelsToEmu($shape->getShadow()->getBlurRadius())); $objWriter->writeAttribute('dist', SharedDrawing::pixelsToEmu($shape->getShadow()->getDistance())); $objWriter->writeAttribute('dir', SharedDrawing::degreesToAngle($shape->getShadow()->getDirection())); $objWriter->writeAttribute('algn', $shape->getShadow()->getAlignment()); $objWriter->writeAttribute('rotWithShape', '0'); // a:srgbClr $objWriter->startElement('a:srgbClr'); $objWriter->writeAttribute('val', $shape->getShadow()->getColor()->getRGB()); // a:alpha $objWriter->startElement('a:alpha'); $objWriter->writeAttribute('val', $shape->getShadow()->getAlpha() * 1000); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); } $objWriter->endElement(); $objWriter->endElement(); }
/** * Write pic * * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPowerpoint\Shape\AbstractDrawing $shape * @param int $shapeId * @throws \Exception */ private function writeShapePic(XMLWriter $objWriter, AbstractDrawing $shape, $shapeId) { // p:pic $objWriter->startElement('p:pic'); // p:nvPicPr $objWriter->startElement('p:nvPicPr'); // p:cNvPr $objWriter->startElement('p:cNvPr'); $objWriter->writeAttribute('id', $shapeId); $objWriter->writeAttribute('name', $shape->getName()); $objWriter->writeAttribute('descr', $shape->getDescription()); // a:hlinkClick if ($shape->hasHyperlink()) { $this->writeHyperlink($objWriter, $shape); } $objWriter->endElement(); // p:cNvPicPr $objWriter->startElement('p:cNvPicPr'); // a:picLocks $objWriter->startElement('a:picLocks'); $objWriter->writeAttribute('noChangeAspect', '1'); $objWriter->endElement(); $objWriter->endElement(); // p:nvPr $objWriter->writeElement('p:nvPr', null); $objWriter->endElement(); // p:blipFill $objWriter->startElement('p:blipFill'); // a:blip $objWriter->startElement('a:blip'); $objWriter->writeAttribute('r:embed', $shape->relationId); $objWriter->endElement(); // a:stretch $objWriter->startElement('a:stretch'); $objWriter->writeElement('a:fillRect', null); $objWriter->endElement(); $objWriter->endElement(); // p:spPr $objWriter->startElement('p:spPr'); // a:xfrm $objWriter->startElement('a:xfrm'); $objWriter->writeAttribute('rot', CommonDrawing::degreesToAngle($shape->getRotation())); // a:off $objWriter->startElement('a:off'); $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX())); $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY())); $objWriter->endElement(); // a:ext $objWriter->startElement('a:ext'); $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth())); $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight())); $objWriter->endElement(); $objWriter->endElement(); // a:prstGeom $objWriter->startElement('a:prstGeom'); $objWriter->writeAttribute('prst', 'rect'); // a:avLst $objWriter->writeElement('a:avLst', null); $objWriter->endElement(); if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) { $this->writeBorder($objWriter, $shape->getBorder(), ''); } if ($shape->getShadow()->isVisible()) { $this->writeShadow($objWriter, $shape->getShadow()); } $objWriter->endElement(); $objWriter->endElement(); }