/** * Add a paragraph style * * @param string $styleName * @param array $styles */ public static function addParagraphStyle($styleName, $styles) { require_once __DIR__ . '/Style/Paragraph.php'; if (!array_key_exists($styleName, self::$_styleElements)) { $style = new Document_Word_Writer_Style_Paragraph(); foreach ($styles as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; } $style->setStyleValue($key, $value); } self::$_styleElements[$styleName] = $style; } }
protected function _writeParagraphStyle(Document_Word_Writer_Shared_XMLWriter $objWriter = null, Document_Word_Writer_Style_Paragraph $style, $withoutPPR = false) { $align = $style->getAlign(); // microsoft office default line spacing is 10pt, we need to set it to 0 if we have not set the spacing.. $spaceBefore = is_null($style->getSpaceBefore()) ? 0 : $style->getSpaceBefore(); $spaceAfter = is_null($style->getSpaceAfter()) ? 0 : $style->getSpaceAfter(); $spacing = is_nan($style->getSpacing()) ? 0 : $style->getSpacing(); $isList = is_null($style->getListStyle()) ? '' : $style->getListStyle(); if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter) || !empty($isList)) { if (!$withoutPPR) { $objWriter->startElement('w:pPr'); } if (!empty($isList)) { $objWriter->startElement('w:numPr'); $objWriter->startElement('w:ilvl'); $objWriter->writeAttribute('w:val', 0); $objWriter->endElement(); $objWriter->startElement('w:numId'); $objWriter->writeAttribute('w:val', 1); $objWriter->endElement(); $objWriter->endElement(); } if (!is_null($align)) { $objWriter->startElement('w:jc'); $objWriter->writeAttribute('w:val', $align); $objWriter->endElement(); } if (!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) { $objWriter->startElement('w:spacing'); if (!is_null($spaceBefore)) { $objWriter->writeAttribute('w:before', $spaceBefore); } if (!is_null($spaceAfter)) { $objWriter->writeAttribute('w:after', $spaceAfter); } if (!is_null($spacing)) { $objWriter->writeAttribute('w:line', $spacing); $objWriter->writeAttribute('w:lineRule', 'auto'); } $objWriter->endElement(); } if (!$withoutPPR) { $objWriter->endElement(); // w:pPr } } }
public function __construct($type = 'text', $styleParagraph = null) { $this->_type = $type; $this->_name = 'Arial'; $this->_size = 20; $this->_bold = false; $this->_italic = false; $this->_superScript = false; $this->_subScript = false; $this->_underline = Document_Word_Writer_Style_Font::UNDERLINE_NONE; $this->_strikethrough = false; $this->_color = '000000'; $this->_fgColor = null; if (!is_null($styleParagraph)) { require_once __DIR__ . '/Paragraph.php'; $paragraph = new Document_Word_Writer_Style_Paragraph(); foreach ($styleParagraph as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; } $paragraph->setStyleValue($key, $value); } $this->_paragraphStyle = $paragraph; } else { $this->_paragraphStyle = null; } }