From cc305bcb1122ef85b724c11c56fabe52666881c9 Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Sat, 21 Feb 2015 17:43:46 +0400 Subject: [PATCH] Fixed broken paragraph alignment for OpenXml. --- src/PhpWord/Style/Paragraph.php | 21 +++++++------------ src/PhpWord/Writer/HTML/Style/Paragraph.php | 7 +++++-- src/PhpWord/Writer/ODText/Style/Paragraph.php | 2 +- .../Writer/Word2007/Style/Paragraph.php | 10 +++------ 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 964a4ec9..ff89b9d5 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -25,6 +25,7 @@ use PhpOffice\PhpWord\Shared\String; * * OOXML: * - General: alignment, outline level + * - Alignment: left, right, center, both * - Indentation: left, right, firstline, hanging * - Spacing: before, after, line spacing * - Pagination: widow control, keep next, keep line, page break before @@ -159,14 +160,6 @@ class Paragraph extends Border */ private $shading; - /** - * Create new instance - */ - public function __construct() - { - $this->alignment = new Alignment(); - } - /** * Set Style value * @@ -202,7 +195,7 @@ class Paragraph extends Border 'name' => $this->getStyleName(), 'basedOn' => $this->getBasedOn(), 'next' => $this->getNext(), - 'alignment' => $this->getAlign(), + 'alignment' => $this->getAlignment(), 'indentation' => $this->getIndentation(), 'spacing' => $this->getSpace(), 'pagination' => array( @@ -225,11 +218,11 @@ class Paragraph extends Border /** * Get alignment * - * @return string + * @return \PhpOffice\PhpWord\Style\Alignment */ - public function getAlign() + public function getAlignment() { - return $this->alignment->getValue(); + return $this->alignment; } /** @@ -238,9 +231,9 @@ class Paragraph extends Border * @param string $value * @return self */ - public function setAlign($value = null) + public function setAlignment($value = null) { - $this->alignment->setValue($value); + $this->setObjectVal(array('value' => $value), 'Alignment', $this->alignment); return $this; } diff --git a/src/PhpWord/Writer/HTML/Style/Paragraph.php b/src/PhpWord/Writer/HTML/Style/Paragraph.php index 8b326a5c..0d7df22d 100644 --- a/src/PhpWord/Writer/HTML/Style/Paragraph.php +++ b/src/PhpWord/Writer/HTML/Style/Paragraph.php @@ -38,8 +38,11 @@ class Paragraph extends AbstractStyle $css = array(); // Alignment - $align = $style->getAlign(); - $css['text-align'] = $this->getValueIf(!is_null($align), $align); + $alignment = $style->getAlignment(); + if (!is_null($alignment)) { + $alignmentValue = $alignment->getValue(); + $css['text-align'] = $this->getValueIf(!is_null($alignmentValue), $alignmentValue); + } // Spacing $spacing = $style->getSpace(); diff --git a/src/PhpWord/Writer/ODText/Style/Paragraph.php b/src/PhpWord/Writer/ODText/Style/Paragraph.php index 03e605a1..f7bb47ad 100644 --- a/src/PhpWord/Writer/ODText/Style/Paragraph.php +++ b/src/PhpWord/Writer/ODText/Style/Paragraph.php @@ -54,7 +54,7 @@ class Paragraph extends AbstractStyle } else { $xmlWriter->writeAttribute('fo:margin-top', $marginTop . 'cm'); $xmlWriter->writeAttribute('fo:margin-bottom', $marginBottom . 'cm'); - $xmlWriter->writeAttribute('fo:text-align', $style->getAlign()); + $xmlWriter->writeAttribute('fo:text-align', $style->getAlignment()); } $xmlWriter->endElement(); //style:paragraph-properties diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php index 039b78bf..f9a49bba 100644 --- a/src/PhpWord/Writer/Word2007/Style/Paragraph.php +++ b/src/PhpWord/Writer/Word2007/Style/Paragraph.php @@ -18,9 +18,8 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Style\Alignment as AlignmentStyle; -use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; /** * Paragraph style writer @@ -91,17 +90,14 @@ class Paragraph extends AbstractStyle $xmlWriter->writeElementIf($styles['name'] !== null, 'w:pStyle', 'w:val', $styles['name']); } - // Alignment - $styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $styles['alignment']))); - $styleWriter->write(); - // Pagination $xmlWriter->writeElementIf($styles['pagination']['widowControl'] === false, 'w:widowControl', 'w:val', '0'); $xmlWriter->writeElementIf($styles['pagination']['keepNext'] === true, 'w:keepNext', 'w:val', '1'); $xmlWriter->writeElementIf($styles['pagination']['keepLines'] === true, 'w:keepLines', 'w:val', '1'); $xmlWriter->writeElementIf($styles['pagination']['pageBreak'] === true, 'w:pageBreakBefore', 'w:val', '1'); - // Child style: indentation, spacing, and shading + // Child style: alignment, indentation, spacing, and shading + $this->writeChildStyle($xmlWriter, 'Alignment', $styles['alignment']); $this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']); $this->writeChildStyle($xmlWriter, 'Spacing', $styles['spacing']); $this->writeChildStyle($xmlWriter, 'Shading', $styles['shading']);