Skip to content

Commit f58524b

Browse files
author
Mark Baker
committed
Merge pull request #11 from deds/pindent
add indentation support to paragraphs
2 parents ad47f39 + 30a7a17 commit f58524b

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/PHPWord/Style/Paragraph.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ class PHPWord_Style_Paragraph {
6464
private $_spacing;
6565

6666

67+
/**
68+
* Indent by how much
69+
*
70+
* @var int
71+
*/
72+
private $_indent;
73+
74+
6775
/**
6876
* New Paragraph Style
6977
*/
@@ -72,6 +80,7 @@ public function __construct() {
7280
$this->_spaceBefore = null;
7381
$this->_spaceAfter = null;
7482
$this->_spacing = null;
83+
$this->_indent = null;
7584
}
7685

7786
/**
@@ -84,6 +93,9 @@ public function setStyleValue($key, $value) {
8493
if($key == '_spacing') {
8594
$value += 240; // because line height of 1 matches 240 twips
8695
}
96+
if($key == '_indent') {
97+
$value = (int)$value * 720; // 720 twips per indent
98+
}
8799
$this->$key = $value;
88100
}
89101

@@ -170,5 +182,25 @@ public function setSpacing($pValue = null) {
170182
$this->_spacing = $pValue;
171183
return $this;
172184
}
185+
186+
/**
187+
* Get indentation
188+
*
189+
* @return int
190+
*/
191+
public function getIndent() {
192+
return $this->_indent;
193+
}
194+
195+
/**
196+
* Set indentation
197+
*
198+
* @param int $pValue
199+
* @return PHPWord_Style_Paragraph
200+
*/
201+
public function setIndent($pValue = null) {
202+
$this->_indent = $pValue;
203+
return $this;
204+
}
173205
}
174206
?>

src/PHPWord/Writer/Word2007/Base.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = nu
113113
$spaceBefore = $style->getSpaceBefore();
114114
$spaceAfter = $style->getSpaceAfter();
115115
$spacing = $style->getSpacing();
116+
$indent = $style->getIndent();
116117

117118

118-
if(!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter)) {
119+
if(!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($indent)) {
119120

120121
if(!$withoutPPR) {
121122
$objWriter->startElement('w:pPr');
@@ -127,6 +128,13 @@ protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = nu
127128
$objWriter->endElement();
128129
}
129130

131+
if(!is_null($indent)) {
132+
$objWriter->startElement('w:ind');
133+
$objWriter->writeAttribute('w:firstLine', 0);
134+
$objWriter->writeAttribute('w:left', $indent);
135+
$objWriter->endElement();
136+
}
137+
130138
if(!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) {
131139

132140
$objWriter->startElement('w:spacing');

0 commit comments

Comments
 (0)