Example #1
0
 /**
  */
 public function testPixelsEMU()
 {
     $value = rand(1, 100);
     $this->assertEquals(0, Drawing::pixelsToEmu());
     $this->assertEquals(round($value * 9525), Drawing::pixelsToEmu($value));
     $this->assertEquals(0, Drawing::emuToPixels());
     $this->assertEquals(round($value / 9525), Drawing::emuToPixels($value));
 }
Example #2
0
 /**
  * Write Legend
  *
  * @param  \PhpOffice\PhpPowerpoint\Shared\XMLWriter   $objWriter XML Writer
  * @param  \PhpOffice\PhpPowerpoint\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', SharedDrawing::pixelsToEmu($subject->getAlignment()->getMarginLeft()));
     $objWriter->writeAttribute('marR', SharedDrawing::pixelsToEmu($subject->getAlignment()->getMarginRight()));
     $objWriter->writeAttribute('indent', SharedDrawing::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();
 }
Example #3
0
 /**
  * Write Line Shape
  *
  * @param  \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer
  * @param \PhpOffice\PhpPowerpoint\Shape\Line $shape
  * @param  int $shapeId
  */
 private function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId)
 {
     // p:sp
     $objWriter->startElement('p:cxnSp');
     // p:nvSpPr
     $objWriter->startElement('p:nvCxnSpPr');
     // p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', $shapeId);
     $objWriter->writeAttribute('name', '');
     $objWriter->endElement();
     // p:cNvCxnSpPr
     $objWriter->writeElement('p:cNvCxnSpPr', null);
     // p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     $objWriter->endElement();
     // p:spPr
     $objWriter->startElement('p:spPr');
     // a:xfrm
     $objWriter->startElement('a:xfrm');
     if ($shape->getWidth() >= 0 && $shape->getHeight() >= 0) {
         // 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();
     } elseif ($shape->getWidth() < 0 && $shape->getHeight() < 0) {
         // a:off
         $objWriter->startElement('a:off');
         $objWriter->writeAttribute('x', SharedDrawing::pixelsToEmu($shape->getOffsetX() + $shape->getWidth()));
         $objWriter->writeAttribute('y', SharedDrawing::pixelsToEmu($shape->getOffsetY() + $shape->getHeight()));
         $objWriter->endElement();
         // a:ext
         $objWriter->startElement('a:ext');
         $objWriter->writeAttribute('cx', SharedDrawing::pixelsToEmu(-$shape->getWidth()));
         $objWriter->writeAttribute('cy', SharedDrawing::pixelsToEmu(-$shape->getHeight()));
         $objWriter->endElement();
     } elseif ($shape->getHeight() < 0) {
         $objWriter->writeAttribute('flipV', 1);
         // a:off
         $objWriter->startElement('a:off');
         $objWriter->writeAttribute('x', SharedDrawing::pixelsToEmu($shape->getOffsetX()));
         $objWriter->writeAttribute('y', SharedDrawing::pixelsToEmu($shape->getOffsetY() + $shape->getHeight()));
         $objWriter->endElement();
         // a:ext
         $objWriter->startElement('a:ext');
         $objWriter->writeAttribute('cx', SharedDrawing::pixelsToEmu($shape->getWidth()));
         $objWriter->writeAttribute('cy', SharedDrawing::pixelsToEmu(-$shape->getHeight()));
         $objWriter->endElement();
     } elseif ($shape->getWidth() < 0) {
         $objWriter->writeAttribute('flipV', 1);
         // a:off
         $objWriter->startElement('a:off');
         $objWriter->writeAttribute('x', SharedDrawing::pixelsToEmu($shape->getOffsetX() + $shape->getWidth()));
         $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', 'line');
     $objWriter->endElement();
     if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) {
         $this->writeBorder($objWriter, $shape->getBorder(), '');
     }
     $objWriter->endElement();
     $objWriter->endElement();
 }
Example #4
0
 public function testLine()
 {
     $valEmu10 = Drawing::pixelsToEmu(10);
     $valEmu90 = Drawing::pixelsToEmu(90);
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->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($phpPowerPoint, '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'));
 }