From 33570f7cd4e760cbb1c9e1ef26868f6805345907 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sat, 28 Jun 2014 22:59:00 +0700 Subject: [PATCH] #294: Support for paragraph with borders --- CHANGELOG.md | 1 + src/PhpWord/Style/Paragraph.php | 2 +- src/PhpWord/Writer/Word2007/Style/Paragraph.php | 12 ++++++++++++ .../Tests/Writer/Word2007/Part/DocumentTest.php | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f9bf239..0ba632cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap - Setting: Ability to define document protection (readOnly, comments, trackedChanges, forms) - @ivanlanin - Setting: Ability to remove [Compatibility Mode] text in the MS Word title bar - @ivanlanin - SDT: Ability to add structured document tag elements (comboBox, dropDownList, date) - @ivanlanin +- Paragraph: Support for paragraph with borders - @ivanlanin GH-294 ### Bugfixes diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 18254321..964a4ec9 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -47,7 +47,7 @@ use PhpOffice\PhpWord\Shared\String; * * @link http://www.schemacentral.com/sc/ooxml/t-w_CT_PPr.html */ -class Paragraph extends AbstractStyle +class Paragraph extends Border { /** * @const int One line height equals 240 twip diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php index f8d6cf1e..86efda2f 100644 --- a/src/PhpWord/Writer/Word2007/Style/Paragraph.php +++ b/src/PhpWord/Writer/Word2007/Style/Paragraph.php @@ -108,6 +108,18 @@ class Paragraph extends AbstractStyle // Numbering $this->writeNumbering($xmlWriter, $styles['numbering']); + // Border + if ($style->hasBorder()) { + $xmlWriter->startElement('w:pBdr'); + + $styleWriter = new MarginBorder($xmlWriter); + $styleWriter->setSizes($style->getBorderSize()); + $styleWriter->setColors($style->getBorderColor()); + $styleWriter->write(); + + $xmlWriter->endElement(); + } + if (!$this->withoutPPR) { $xmlWriter->endElement(); // w:pPr } diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php index 56be15d0..ef36e0dd 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php @@ -139,6 +139,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase 'align' => 'center', 'tabs' => $tabs, 'shading' => array('fill' => 'FFFF99'), + 'borderSize' => 4, )); // Style #1 $phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true, 'scale' => 200, 'spacing' => 240, 'kerning' => 10)); // Style #2