/** * Write tabs. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Tab[] $tabs * @return void */ private function writeTabs(XMLWriter $xmlWriter, $tabs) { if (!empty($tabs)) { $xmlWriter->startElement("w:tabs"); foreach ($tabs as $tab) { $styleWriter = new Tab($xmlWriter, $tab); $styleWriter->write(); } $xmlWriter->endElement(); } }
/** * Write style * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\TOC $element * @param int $indent */ private function writeStyle(XMLWriter $xmlWriter, TOCElement $element, $indent) { $tocStyle = $element->getStyleTOC(); $fontStyle = $element->getStyleFont(); $isObject = $fontStyle instanceof Font ? true : false; $xmlWriter->startElement('w:pPr'); // Paragraph if ($isObject && !is_null($fontStyle->getParagraph())) { $styleWriter = new ParagraphStyleWriter($xmlWriter, $fontStyle->getParagraph()); $styleWriter->write(); } // Font if (!empty($fontStyle) && !$isObject) { $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rStyle'); $xmlWriter->writeAttribute('w:val', $fontStyle); $xmlWriter->endElement(); $xmlWriter->endElement(); // w:rPr } // Tab $xmlWriter->startElement('w:tabs'); $styleWriter = new TabStyleWriter($xmlWriter, $tocStyle); $styleWriter->write(); $xmlWriter->endElement(); // Indent if ($indent > 0) { $xmlWriter->startElement('w:ind'); $xmlWriter->writeAttribute('w:left', $indent); $xmlWriter->endElement(); } $xmlWriter->endElement(); // w:pPr }
/** * Write full style */ private function writeStyle() { if (!$this->style instanceof \PhpOffice\PhpWord\Style\Paragraph) { return; } $widowControl = $this->style->getWidowControl(); $keepNext = $this->style->getKeepNext(); $keepLines = $this->style->getKeepLines(); $pageBreakBefore = $this->style->getPageBreakBefore(); if (!$this->withoutPPR) { $this->xmlWriter->startElement('w:pPr'); } // Alignment if (!is_null($this->style->getAlign())) { $this->xmlWriter->startElement('w:jc'); $this->xmlWriter->writeAttribute('w:val', $this->style->getAlign()); $this->xmlWriter->endElement(); } // Indentation if (!is_null($this->style->getIndentation())) { $styleWriter = new Indentation($this->xmlWriter, $this->style->getIndentation()); $styleWriter->write(); } // Spacing if (!is_null($this->style->getSpace())) { $styleWriter = new Spacing($this->xmlWriter, $this->style->getSpace()); $styleWriter->write(); } // Pagination if (!$widowControl) { $this->xmlWriter->startElement('w:widowControl'); $this->xmlWriter->writeAttribute('w:val', '0'); $this->xmlWriter->endElement(); } if ($keepNext) { $this->xmlWriter->startElement('w:keepNext'); $this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->endElement(); } if ($keepLines) { $this->xmlWriter->startElement('w:keepLines'); $this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->endElement(); } if ($pageBreakBefore) { $this->xmlWriter->startElement('w:pageBreakBefore'); $this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->endElement(); } // Tabs $tabs = $this->style->getTabs(); if (!empty($tabs)) { $this->xmlWriter->startElement("w:tabs"); foreach ($tabs as $tab) { $styleWriter = new Tab($this->xmlWriter, $tab); $styleWriter->write(); } $this->xmlWriter->endElement(); } if (!$this->withoutPPR) { $this->xmlWriter->endElement(); // w:pPr } }