예제 #1
0
 /**
  * Test can read
  */
 public function testConstruct()
 {
     $value = rand(1, 100);
     $object = new Line($value, $value, $value, $value);
     $this->assertEquals(Border::LINE_SINGLE, $object->getBorder()->getLineStyle());
     $this->assertEquals($value, $object->getOffsetX());
     $this->assertEquals($value, $object->getOffsetY());
     $this->assertEquals(0, $object->getWidth());
     $this->assertEquals(0, $object->getHeight());
     $this->assertInternalType('string', $object->getHashCode());
 }
예제 #2
0
 /**
  * Write Line Shape
  *
  * @param  \PhpOffice\Common\XMLWriter $objWriter XML Writer
  * @param \PhpOffice\PhpPresentation\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', 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();
     } elseif ($shape->getWidth() < 0 && $shape->getHeight() < 0) {
         // a:off
         $objWriter->startElement('a:off');
         $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX() + $shape->getWidth()));
         $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY() + $shape->getHeight()));
         $objWriter->endElement();
         // a:ext
         $objWriter->startElement('a:ext');
         $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu(-$shape->getWidth()));
         $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu(-$shape->getHeight()));
         $objWriter->endElement();
     } elseif ($shape->getHeight() < 0) {
         $objWriter->writeAttribute('flipV', 1);
         // a:off
         $objWriter->startElement('a:off');
         $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX()));
         $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY() + $shape->getHeight()));
         $objWriter->endElement();
         // a:ext
         $objWriter->startElement('a:ext');
         $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth()));
         $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu(-$shape->getHeight()));
         $objWriter->endElement();
     } elseif ($shape->getWidth() < 0) {
         $objWriter->writeAttribute('flipV', 1);
         // a:off
         $objWriter->startElement('a:off');
         $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX() + $shape->getWidth()));
         $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', 'line');
     $objWriter->endElement();
     if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) {
         $this->writeBorder($objWriter, $shape->getBorder(), '');
     }
     $objWriter->endElement();
     $objWriter->endElement();
 }
예제 #3
0
 /**
  * @param XMLWriter $objWriter
  * @param Line $shape
  */
 public function writeShapeLine(XMLWriter $objWriter, Line $shape)
 {
     // draw:line
     $objWriter->startElement('draw:line');
     $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId);
     $objWriter->writeAttribute('svg:x1', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
     $objWriter->writeAttribute('svg:y1', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
     $objWriter->writeAttribute('svg:x2', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX() + $shape->getWidth()), 3) . 'cm');
     $objWriter->writeAttribute('svg:y2', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY() + $shape->getHeight()), 3) . 'cm');
     // text:p
     $objWriter->writeElement('text:p');
     $objWriter->endElement();
 }