Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add indentation support to paragraphs #11

Merged
merged 1 commit into from
Jan 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/PHPWord/Style/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class PHPWord_Style_Paragraph {
private $_spacing;


/**
* Indent by how much
*
* @var int
*/
private $_indent;


/**
* New Paragraph Style
*/
Expand All @@ -72,6 +80,7 @@ public function __construct() {
$this->_spaceBefore = null;
$this->_spaceAfter = null;
$this->_spacing = null;
$this->_indent = null;
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
?>
10 changes: 9 additions & 1 deletion src/PHPWord/Writer/Word2007/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down