add indentation support to paragraphs

This commit is contained in:
Deds Castillo 2012-10-17 23:48:59 +08:00
parent ad47f3997c
commit 30a7a178e2
2 changed files with 41 additions and 1 deletions

View File

@ -64,6 +64,14 @@ class PHPWord_Style_Paragraph {
private $_spacing; private $_spacing;
/**
* Indent by how much
*
* @var int
*/
private $_indent;
/** /**
* New Paragraph Style * New Paragraph Style
*/ */
@ -72,6 +80,7 @@ class PHPWord_Style_Paragraph {
$this->_spaceBefore = null; $this->_spaceBefore = null;
$this->_spaceAfter = null; $this->_spaceAfter = null;
$this->_spacing = null; $this->_spacing = null;
$this->_indent = null;
} }
/** /**
@ -84,6 +93,9 @@ class PHPWord_Style_Paragraph {
if($key == '_spacing') { if($key == '_spacing') {
$value += 240; // because line height of 1 matches 240 twips $value += 240; // because line height of 1 matches 240 twips
} }
if($key == '_indent') {
$value = (int)$value * 720; // 720 twips per indent
}
$this->$key = $value; $this->$key = $value;
} }
@ -170,5 +182,25 @@ class PHPWord_Style_Paragraph {
$this->_spacing = $pValue; $this->_spacing = $pValue;
return $this; 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;
}
} }
?> ?>

View File

@ -113,9 +113,10 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
$spaceBefore = $style->getSpaceBefore(); $spaceBefore = $style->getSpaceBefore();
$spaceAfter = $style->getSpaceAfter(); $spaceAfter = $style->getSpaceAfter();
$spacing = $style->getSpacing(); $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) { if(!$withoutPPR) {
$objWriter->startElement('w:pPr'); $objWriter->startElement('w:pPr');
@ -127,6 +128,13 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
$objWriter->endElement(); $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)) { if(!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) {
$objWriter->startElement('w:spacing'); $objWriter->startElement('w:spacing');