From 200d846f6195a0801e1ac2c41f6513cf68832094 Mon Sep 17 00:00:00 2001 From: troosan Date: Sun, 5 Nov 2017 21:39:10 +0100 Subject: [PATCH] implement paragraph textAlignment --- src/PhpWord/SimpleType/TextAlignment.php | 45 +++++++++++++++++++ src/PhpWord/Style/Paragraph.php | 33 ++++++++++++++ .../Writer/Word2007/Style/Paragraph.php | 3 ++ tests/PhpWord/Element/ImageTest.php | 1 + tests/PhpWord/Style/FontTest.php | 14 ++++++ tests/PhpWord/Style/ParagraphTest.php | 3 +- .../Writer/Word2007/Part/SettingsTest.php | 2 +- 7 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/PhpWord/SimpleType/TextAlignment.php diff --git a/src/PhpWord/SimpleType/TextAlignment.php b/src/PhpWord/SimpleType/TextAlignment.php new file mode 100644 index 00000000..de36b108 --- /dev/null +++ b/src/PhpWord/SimpleType/TextAlignment.php @@ -0,0 +1,45 @@ + $this->getShading(), 'contextualSpacing' => $this->hasContextualSpacing(), 'bidi' => $this->isBidi(), + 'textAlignment' => $this->getTextAlignment(), ); return $styles; @@ -794,4 +803,28 @@ class Paragraph extends Border return $this; } + + /** + * Get textAlignment + * + * @return string + */ + public function getTextAlignment() + { + return $this->textAlignment; + } + + /** + * Set textAlignment + * + * @param string $textAlignment + * @return self + */ + public function setTextAlignment($textAlignment) + { + TextAlignment::validate($textAlignment); + $this->textAlignment = $textAlignment; + + return $this; + } } diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php index 707bf031..424b87f8 100644 --- a/src/PhpWord/Writer/Word2007/Style/Paragraph.php +++ b/src/PhpWord/Writer/Word2007/Style/Paragraph.php @@ -109,6 +109,9 @@ class Paragraph extends AbstractStyle //Paragraph contextualSpacing $xmlWriter->writeElementIf($styles['contextualSpacing'] === true, 'w:contextualSpacing'); + //Paragraph contextualSpacing + $xmlWriter->writeElementIf($styles['textAlignment'] !== null, 'w:textAlignment', 'w:val', $styles['textAlignment']); + // Child style: alignment, indentation, spacing, and shading $this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']); $this->writeChildStyle($xmlWriter, 'Spacing', $styles['spacing']); diff --git a/tests/PhpWord/Element/ImageTest.php b/tests/PhpWord/Element/ImageTest.php index 80e0bcfc..b681b81f 100644 --- a/tests/PhpWord/Element/ImageTest.php +++ b/tests/PhpWord/Element/ImageTest.php @@ -87,6 +87,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase $this->assertEquals($createFunction, $image->getImageCreateFunction()); $this->assertEquals($imageFunction, $image->getImageFunction()); $this->assertFalse($image->isMemImage()); + $this->assertNotNull($image->getImageStringData()); } } diff --git a/tests/PhpWord/Style/FontTest.php b/tests/PhpWord/Style/FontTest.php index 707784f6..a227d7f9 100644 --- a/tests/PhpWord/Style/FontTest.php +++ b/tests/PhpWord/Style/FontTest.php @@ -69,6 +69,7 @@ class FontTest extends \PHPUnit_Framework_TestCase 'doubleStrikethrough' => false, 'smallCaps' => false, 'allCaps' => false, + 'rtl' => false, 'fgColor' => null, 'bgColor' => null, 'scale' => null, @@ -113,6 +114,8 @@ class FontTest extends \PHPUnit_Framework_TestCase 'scale' => 150, 'spacing' => 240, 'kerning' => 10, + 'rtl' => true, + 'lang' => new Language(Language::EN_US), ); $object->setStyleByArray($attributes); foreach ($attributes as $key => $value) { @@ -173,4 +176,15 @@ class FontTest extends \PHPUnit_Framework_TestCase $object = new Font(); $object->setLineHeight('a'); } + + /** + * Test setting the language as a string + */ + public function testSetLangAsString() + { + $object = new Font(); + $object->setLang(Language::FR_BE); + $this->assertInstanceOf('PhpOffice\PhpWord\Style\Language', $object->getLang()); + $this->assertEquals(Language::FR_BE, $object->getLang()->getLatin()); + } } diff --git a/tests/PhpWord/Style/ParagraphTest.php b/tests/PhpWord/Style/ParagraphTest.php index a702d3f2..e28f54c7 100644 --- a/tests/PhpWord/Style/ParagraphTest.php +++ b/tests/PhpWord/Style/ParagraphTest.php @@ -80,6 +80,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase 'keepLines' => true, 'pageBreakBefore' => true, 'contextualSpacing' => true, + 'textAlignment' => 'auto', 'bidi' => true, ); foreach ($attributes as $key => $value) { @@ -114,7 +115,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase { $object = new Paragraph(); - $attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter'); + $attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter', 'textAlignment'); foreach ($attributes as $key) { $get = $this->findGetter($key, null, $object); $this->assertNull($object->$get()); diff --git a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php index 4715d2da..5b812a0f 100644 --- a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php @@ -17,13 +17,13 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; +use PhpOffice\PhpWord\ComplexType\ProofState; use PhpOffice\PhpWord\ComplexType\TrackChangesView; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\SimpleType\Zoom; use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\TestHelperDOCX; -use PhpOffice\PhpWord\ComplexType\ProofState; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings