public function testHyperlink()
 {
     $object = new RichText();
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHyperlink());
     $this->assertFalse($object->hasHyperlink());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink());
     $this->assertTrue($object->hasHyperlink());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHyperlink(new Hyperlink('http://www.google.fr')));
     $this->assertTrue($object->hasHyperlink());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink());
     $this->assertTrue($object->hasHyperlink());
 }
Esempio n. 2
0
 /**
  * Write txt
  *
  * @param  \PhpOffice\Common\XMLWriter $objWriter XML Writer
  * @param  \PhpOffice\PhpPresentation\Shape\RichText   $shape
  * @param  int                            $shapeId
  * @throws \Exception
  */
 private function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeId)
 {
     // p:sp
     $objWriter->startElement('p:sp');
     // p:sp\p:nvSpPr
     $objWriter->startElement('p:nvSpPr');
     // p:sp\p:nvSpPr\p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', $shapeId);
     $objWriter->writeAttribute('name', '');
     // Hyperlink
     if ($shape->hasHyperlink()) {
         $this->writeHyperlink($objWriter, $shape);
     }
     // > p:sp\p:nvSpPr
     $objWriter->endElement();
     // p:sp\p:cNvSpPr
     $objWriter->startElement('p:cNvSpPr');
     $objWriter->writeAttribute('txBox', '1');
     $objWriter->endElement();
     // p:sp\p:cNvSpPr\p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     // > p:sp\p:cNvSpPr
     $objWriter->endElement();
     // p:sp\p:spPr
     $objWriter->startElement('p:spPr');
     // p:sp\p:spPr\a:xfrm
     $objWriter->startElement('a:xfrm');
     $objWriter->writeAttribute('rot', CommonDrawing::degreesToAngle($shape->getRotation()));
     // p:sp\p:spPr\a:xfrm\a:off
     $objWriter->startElement('a:off');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY()));
     $objWriter->endElement();
     // p:sp\p:spPr\a:xfrm\a:ext
     $objWriter->startElement('a:ext');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight()));
     $objWriter->endElement();
     // > p:sp\p:spPr\a:xfrm
     $objWriter->endElement();
     // p:sp\p:spPr\a:prstGeom
     $objWriter->startElement('a:prstGeom');
     $objWriter->writeAttribute('prst', 'rect');
     $objWriter->endElement();
     if ($shape->getFill()) {
         $this->writeFill($objWriter, $shape->getFill());
     }
     if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) {
         $this->writeBorder($objWriter, $shape->getBorder(), '');
     }
     if ($shape->getShadow()->isVisible()) {
         $this->writeShadow($objWriter, $shape->getShadow());
     }
     // > p:sp\p:spPr
     $objWriter->endElement();
     // p:txBody
     $objWriter->startElement('p:txBody');
     // a:bodyPr
     //@link :http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.bodyproperties%28v=office.14%29.aspx
     $objWriter->startElement('a:bodyPr');
     $verticalAlign = $shape->getActiveParagraph()->getAlignment()->getVertical();
     if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) {
         $objWriter->writeAttribute('anchor', $verticalAlign);
     }
     if ($shape->getWrap() != RichText::WRAP_SQUARE) {
         $objWriter->writeAttribute('wrap', $shape->getWrap());
     }
     $objWriter->writeAttribute('rtlCol', '0');
     if ($shape->getHorizontalOverflow() != RichText::OVERFLOW_OVERFLOW) {
         $objWriter->writeAttribute('horzOverflow', $shape->getHorizontalOverflow());
     }
     if ($shape->getVerticalOverflow() != RichText::OVERFLOW_OVERFLOW) {
         $objWriter->writeAttribute('vertOverflow', $shape->getVerticalOverflow());
     }
     if ($shape->isUpright()) {
         $objWriter->writeAttribute('upright', '1');
     }
     if ($shape->isVertical()) {
         $objWriter->writeAttribute('vert', 'vert');
     }
     $objWriter->writeAttribute('bIns', CommonDrawing::pixelsToEmu($shape->getInsetBottom()));
     $objWriter->writeAttribute('lIns', CommonDrawing::pixelsToEmu($shape->getInsetLeft()));
     $objWriter->writeAttribute('rIns', CommonDrawing::pixelsToEmu($shape->getInsetRight()));
     $objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop()));
     if ($shape->getColumns() != 1) {
         $objWriter->writeAttribute('numCol', $shape->getColumns());
     }
     // a:spAutoFit
     $objWriter->startElement('a:' . $shape->getAutoFit());
     if ($shape->getAutoFit() == RichText::AUTOFIT_NORMAL) {
         if (!is_null($shape->getFontScale())) {
             $objWriter->writeAttribute('fontScale', (int) ($shape->getFontScale() * 1000));
         }
         if (!is_null($shape->getLineSpaceReduction())) {
             $objWriter->writeAttribute('lnSpcReduction', (int) ($shape->getLineSpaceReduction() * 1000));
         }
     }
     $objWriter->endElement();
     $objWriter->endElement();
     // a:lstStyle
     $objWriter->writeElement('a:lstStyle', null);
     // Write paragraphs
     $this->writeParagraphs($objWriter, $shape->getParagraphs());
     $objWriter->endElement();
     $objWriter->endElement();
 }