public function testExtentsAndOffsetsForTwoShapes() { // Since Groups and Slides cache offsets and extents on first // calculation, this test is separate from the above. // Should the calculation be performed every GET, this test can be // combined with the above. $offsetX = 100; $offsetY = 100; $extentX = 1000; $extentY = 450; $increase = 50; $line1 = new Line($offsetX, $offsetY, $extentX, $extentY); $line2 = new Line($offsetX + $increase, $offsetY + $increase, $extentX + $increase, $extentY + $increase); $object = new Group(); $object->addShape($line1); $object->addShape($line2); $this->assertEquals($offsetX, $object->getOffsetX()); $this->assertEquals($offsetY, $object->getOffsetY()); $this->assertEquals($extentX + $increase, $object->getExtentX()); $this->assertEquals($extentY + $increase, $object->getExtentY()); }
/** * The OfficeArtSpgrContainer record specifies a container for groups of shapes. * @param string $stream * @param integer $pos * @param boolean $bInGroup * @link : https://msdn.microsoft.com/en-us/library/dd910416(v=office.12).aspx */ private function readRecordOfficeArtSpgrContainer($stream, $pos, $bInGroup = false) { $arrayReturn = array('length' => 0); $data = $this->loadRecordHeader($stream, $pos); if ($data['recVer'] == 0xf && $data['recInstance'] == 0x0 && $data['recType'] == 0xf003) { $arrayReturn['length'] += 8; do { $rhFileBlock = $this->loadRecordHeader($stream, $pos + $arrayReturn['length']); if (!($rhFileBlock['recVer'] == 0xf && $rhFileBlock['recInstance'] == 0x0 && ($rhFileBlock['recType'] == 0xf003 || $rhFileBlock['recType'] == 0xf004))) { throw new \Exception('PowerPoint97 Reader : readRecordOfficeArtSpgrContainer.'); } switch ($rhFileBlock['recType']) { case 0xf003: // Core $this->oCurrentGroup = $this->oPhpPresentation->getActiveSlide()->createGroup(); $this->bFirstShapeGroup = false; // OfficeArtSpgrContainer $fileBlock = $this->readRecordOfficeArtSpgrContainer($stream, $pos + $arrayReturn['length'], true); $arrayReturn['length'] += $fileBlock['length']; $data['recLen'] -= $fileBlock['length']; break; case 0xf004: // Core if (!$bInGroup) { $this->oCurrentGroup = null; } // OfficeArtSpContainer $fileBlock = $this->readRecordOfficeArtSpContainer($stream, $pos + $arrayReturn['length']); $arrayReturn['length'] += $fileBlock['length']; $data['recLen'] -= $fileBlock['length']; // Core //@todo if (!is_null($fileBlock['shape'])) { if ($bInGroup) { $this->oCurrentGroup->addShape($fileBlock['shape']); } else { $this->oPhpPresentation->getActiveSlide()->addShape($fileBlock['shape']); } } break; } } while ($data['recLen'] > 0); } return $arrayReturn; }
/** * Write group * * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPresentation\Shape\Group $group * @param int $shapeId */ private 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 $shapes = $group->getShapeCollection(); foreach ($shapes as $shape) { // Increment $shapeId ++$shapeId; // Check type if ($shape instanceof RichText) { $this->writeShapeText($objWriter, $shape, $shapeId); } elseif ($shape instanceof ShapeTable) { $this->writeShapeTable($objWriter, $shape, $shapeId); } elseif ($shape instanceof Line) { $this->writeShapeLine($objWriter, $shape, $shapeId); } elseif ($shape instanceof ShapeChart) { $this->writeShapeChart($objWriter, $shape, $shapeId); } elseif ($shape instanceof AbstractDrawing) { $this->writeShapePic($objWriter, $shape, $shapeId); } elseif ($shape instanceof Group) { $this->writeShapeGroup($objWriter, $shape, $shapeId); } } $objWriter->endElement(); // p:grpSp }
public function testCommentInGroupRelationship() { $oPhpPresentation = new PhpPresentation(); $oSlide = $oPhpPresentation->getActiveSlide(); $oGroup = new Group(); $oGroup->addShape(new Comment()); $oSlide->addShape($oGroup); $pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007'); $this->assertTrue($pres->elementExists('/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"]', 'ppt/slides/_rels/slide1.xml.rels')); }
/** * Writes the style information for a group of shapes * * @param XMLWriter $objWriter * @param Group $group */ protected function writeGroupStyle(XMLWriter $objWriter, Group $group) { $shapes = $group->getShapeCollection(); foreach ($shapes as $shape) { if ($shape instanceof Table) { $this->writeTableStyle($objWriter, $shape); } elseif ($shape instanceof Group) { $this->writeGroupStyle($objWriter, $shape); } } }
/** * Writes the style information for a group of shapes * * @param XMLWriter $objWriter * @param Group $group */ public function writeGroupStyle(XMLWriter $objWriter, Group $group) { $shapes = $group->getShapeCollection(); foreach ($shapes as $shape) { // Increment $this->shapeId ++$this->shapeId; // Check type if ($shape instanceof RichText) { $this->writeTxtStyle($objWriter, $shape); } if ($shape instanceof AbstractDrawing) { $this->writeDrawingStyle($objWriter, $shape); } if ($shape instanceof Line) { $this->writeLineStyle($objWriter, $shape); } if ($shape instanceof Table) { $this->writeTableStyle($objWriter, $shape); } } }
/** * 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 }