From 30a7a178e235400d689e5cc0998f6dee326a4e31 Mon Sep 17 00:00:00 2001 From: Deds Castillo Date: Wed, 17 Oct 2012 23:48:59 +0800 Subject: [PATCH] add indentation support to paragraphs --- src/PHPWord/Style/Paragraph.php | 32 ++++++++++++++++++++++++++++ src/PHPWord/Writer/Word2007/Base.php | 10 ++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/PHPWord/Style/Paragraph.php b/src/PHPWord/Style/Paragraph.php index 451d1e84ae..9c841c7c59 100644 --- a/src/PHPWord/Style/Paragraph.php +++ b/src/PHPWord/Style/Paragraph.php @@ -64,6 +64,14 @@ class PHPWord_Style_Paragraph { private $_spacing; + /** + * Indent by how much + * + * @var int + */ + private $_indent; + + /** * New Paragraph Style */ @@ -72,6 +80,7 @@ public function __construct() { $this->_spaceBefore = null; $this->_spaceAfter = null; $this->_spacing = null; + $this->_indent = null; } /** @@ -84,6 +93,9 @@ public function setStyleValue($key, $value) { if($key == '_spacing') { $value += 240; // because line height of 1 matches 240 twips } + if($key == '_indent') { + $value = (int)$value * 720; // 720 twips per indent + } $this->$key = $value; } @@ -170,5 +182,25 @@ public function setSpacing($pValue = null) { $this->_spacing = $pValue; return $this; } + + /** + * Get indentation + * + * @return int + */ + public function getIndent() { + return $this->_indent; + } + + /** + * Set indentation + * + * @param int $pValue + * @return PHPWord_Style_Paragraph + */ + public function setIndent($pValue = null) { + $this->_indent = $pValue; + return $this; + } } ?> \ No newline at end of file diff --git a/src/PHPWord/Writer/Word2007/Base.php b/src/PHPWord/Writer/Word2007/Base.php index 1ed5bdeefa..c03342eac1 100644 --- a/src/PHPWord/Writer/Word2007/Base.php +++ b/src/PHPWord/Writer/Word2007/Base.php @@ -113,9 +113,10 @@ protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = nu $spaceBefore = $style->getSpaceBefore(); $spaceAfter = $style->getSpaceAfter(); $spacing = $style->getSpacing(); + $indent = $style->getIndent(); - if(!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter)) { + if(!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($indent)) { if(!$withoutPPR) { $objWriter->startElement('w:pPr'); @@ -127,6 +128,13 @@ protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = nu $objWriter->endElement(); } + if(!is_null($indent)) { + $objWriter->startElement('w:ind'); + $objWriter->writeAttribute('w:firstLine', 0); + $objWriter->writeAttribute('w:left', $indent); + $objWriter->endElement(); + } + if(!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) { $objWriter->startElement('w:spacing');