diff --git a/CHANGELOG.md b/CHANGELOG.md index 77314485..1ad2d884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap - Fix specific borders (and margins) were not written correctly in word2007 writer - @pscheit GH-327 - "HTML is not a valid writer" exception while running "Sample_36_RTL.php" - @RomanSyroeshko GH-340 - "addShape()" magic method in AbstractContainer is mistakenly named as "addObject()" - @GMTA GH-356 +- `Element\Section::setPageSizeW()` and `Element\Section::setPageSizeH()` were mentioned in the docs but not implemented. ### Deprecated diff --git a/docs/styles.rst b/docs/styles.rst index 91d5ed7a..f4c1e8eb 100644 --- a/docs/styles.rst +++ b/docs/styles.rst @@ -8,6 +8,8 @@ Section Below are the available styles for section: +- ``pageSizeW`` Page width in twips (the default is 11906/A4 size) +- ``pageSizeH`` Page height in twips (the default is 16838/A4 size) - ``orientation`` Page orientation, i.e. 'portrait' (default) or 'landscape' - ``marginTop`` Page margin top in twips @@ -30,12 +32,6 @@ Below are the available styles for section: - ``breakType`` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage) -The following two styles are automatically set by the use of the -``orientation`` style. You can alter them but that's not recommended. - -- ``pageSizeW`` Page width in twips -- ``pageSizeH`` Page height in twips - Font ---- diff --git a/src/PhpWord/Style/Section.php b/src/PhpWord/Style/Section.php index c56b0a19..e196dfbd 100644 --- a/src/PhpWord/Style/Section.php +++ b/src/PhpWord/Style/Section.php @@ -282,6 +282,13 @@ class Section extends Border return $this->pageSizeW; } + public function setPageSizeW($value = null) + { + $this->pageSizeW = $this->setNumericVal($value, self::DEFAULT_WIDTH); + + return $this; + } + /** * Get Page Size Height * @@ -292,6 +299,13 @@ class Section extends Border return $this->pageSizeH; } + public function setPageSizeH($value = null) + { + $this->pageSizeH = $this->setNumericVal($value, self::DEFAULT_HEIGHT); + + return $this; + } + /** * Get Margin Top * diff --git a/tests/PhpWord/Tests/Style/SectionTest.php b/tests/PhpWord/Tests/Style/SectionTest.php index 8e8c1e87..e5becd72 100644 --- a/tests/PhpWord/Tests/Style/SectionTest.php +++ b/tests/PhpWord/Tests/Style/SectionTest.php @@ -97,6 +97,34 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $this->assertEquals($iVal, $oSettings->getMarginRight()); } + /** + * Set/get page width + */ + public function testPageWidth() + { + // Section Settings + $oSettings = new Section(); + + $this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW()); + $iVal = rand(1, 1000); + $oSettings->setSettingValue('pageSizeW', $iVal); + $this->assertEquals($iVal, $oSettings->getPageSizeW()); + } + + /** + * Set/get page height + */ + public function testPageHeight() + { + // Section Settings + $oSettings = new Section(); + + $this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH()); + $iVal = rand(1, 1000); + $oSettings->setSettingValue('pageSizeH', $iVal); + $this->assertEquals($iVal, $oSettings->getPageSizeH()); + } + /** * Set/get landscape orientation */