Ejemplo n.º 1
0
 /**
  * Get bookmark Id
  */
 public function testBookmarkID()
 {
     $oTitle = new Title('text');
     $iVal = rand(1, 1000);
     $oTitle->setBookmarkId($iVal);
     $this->assertEquals($oTitle->getBookmarkId(), $iVal);
 }
Ejemplo n.º 2
0
 /**
  * Write title
  *
  * @param \PhpOffice\Common\XMLWriter $xmlWriter
  * @param \PhpOffice\PhpWord\Element\TOC $element
  * @param \PhpOffice\PhpWord\Element\Title $title
  * @param bool $writeFieldMark
  * @return void
  */
 private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, $title, $writeFieldMark)
 {
     $tocStyle = $element->getStyleTOC();
     $fontStyle = $element->getStyleFont();
     $isObject = $fontStyle instanceof Font ? true : false;
     $rId = $title->getRelationId();
     $indent = ($title->getDepth() - 1) * $tocStyle->getIndent();
     $xmlWriter->startElement('w:p');
     // Write style and field mark
     $this->writeStyle($xmlWriter, $element, $indent);
     if ($writeFieldMark) {
         $this->writeFieldMark($xmlWriter, $element);
     }
     // Hyperlink
     $xmlWriter->startElement('w:hyperlink');
     $xmlWriter->writeAttribute('w:anchor', "_Toc{$rId}");
     $xmlWriter->writeAttribute('w:history', '1');
     // Title text
     $xmlWriter->startElement('w:r');
     if ($isObject) {
         $styleWriter = new FontStyleWriter($xmlWriter, $fontStyle);
         $styleWriter->write();
     }
     if (Settings::isOutputEscapingEnabled()) {
         $xmlWriter->writeElement('w:t', $title->getText());
     } else {
         $xmlWriter->startElement('w:t');
         $xmlWriter->writeRaw($title->getText());
         $xmlWriter->endElement();
     }
     $xmlWriter->endElement();
     // w:r
     $xmlWriter->startElement('w:r');
     $xmlWriter->writeElement('w:tab', null);
     $xmlWriter->endElement();
     $xmlWriter->startElement('w:r');
     $xmlWriter->startElement('w:fldChar');
     $xmlWriter->writeAttribute('w:fldCharType', 'begin');
     $xmlWriter->endElement();
     $xmlWriter->endElement();
     $xmlWriter->startElement('w:r');
     $xmlWriter->startElement('w:instrText');
     $xmlWriter->writeAttribute('xml:space', 'preserve');
     $xmlWriter->text("PAGEREF _Toc{$rId} \\h");
     $xmlWriter->endElement();
     $xmlWriter->endElement();
     $xmlWriter->startElement('w:r');
     $xmlWriter->startElement('w:fldChar');
     $xmlWriter->writeAttribute('w:fldCharType', 'end');
     $xmlWriter->endElement();
     $xmlWriter->endElement();
     $xmlWriter->endElement();
     // w:hyperlink
     $xmlWriter->endElement();
     // w:p
 }
Ejemplo n.º 3
0
 /**
  * Get style null
  */
 public function testStyleNull()
 {
     $oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
     $this->assertNull($oTitle->getStyle());
 }
Ejemplo n.º 4
0
 /**
  * Get style null
  */
 public function testStyleNull()
 {
     $oTitle = new Title('text');
     $this->assertEquals($oTitle->getStyle(), null);
 }
Ejemplo n.º 5
0
 /**
  * Add a Title Element
  *
  * @param string $text
  * @param int $depth
  * @return Title
  * @todo Enable title element in other containers
  */
 public function addTitle($text, $depth = 1)
 {
     $this->checkValidity('title');
     $styles = Style::getStyles();
     if (array_key_exists('Heading_' . $depth, $styles)) {
         $style = 'Heading' . $depth;
     } else {
         $style = null;
     }
     $text = String::toUTF8($text);
     $title = new Title($text, $depth, $style);
     $title->setDocPart($this->getDocPart(), $this->getDocPartId());
     $data = Titles::addTitle($text, $depth);
     $anchor = $data[0];
     $bookmarkId = $data[1];
     $title->setAnchor($anchor);
     $title->setBookmarkId($bookmarkId);
     $this->addElement($title);
     return $title;
 }