Skip to content

Commit 9d73173

Browse files
committed
Merge pull request #390 from spikex/develop
Add missing setters for pageSizeW and pageSizeH
2 parents 6c3088e + 1127120 commit 9d73173

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
3636
- Fix specific borders (and margins) were not written correctly in word2007 writer - @pscheit GH-327
3737
- "HTML is not a valid writer" exception while running "Sample_36_RTL.php" - @RomanSyroeshko GH-340
3838
- "addShape()" magic method in AbstractContainer is mistakenly named as "addObject()" - @GMTA GH-356
39+
- `Element\Section::setPageSizeW()` and `Element\Section::setPageSizeH()` were mentioned in the docs but not implemented.
3940

4041
### Deprecated
4142

docs/styles.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Section
88

99
Below are the available styles for section:
1010

11+
- ``pageSizeW`` Page width in twips (the default is 11906/A4 size)
12+
- ``pageSizeH`` Page height in twips (the default is 16838/A4 size)
1113
- ``orientation`` Page orientation, i.e. 'portrait' (default) or
1214
'landscape'
1315
- ``marginTop`` Page margin top in twips
@@ -30,12 +32,6 @@ Below are the available styles for section:
3032
- ``breakType`` Section break type (nextPage, nextColumn, continuous,
3133
evenPage, oddPage)
3234

33-
The following two styles are automatically set by the use of the
34-
``orientation`` style. You can alter them but that's not recommended.
35-
36-
- ``pageSizeW`` Page width in twips
37-
- ``pageSizeH`` Page height in twips
38-
3935
Font
4036
----
4137

src/PhpWord/Style/Section.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ public function getPageSizeW()
282282
return $this->pageSizeW;
283283
}
284284

285+
public function setPageSizeW($value = null)
286+
{
287+
$this->pageSizeW = $this->setNumericVal($value, self::DEFAULT_WIDTH);
288+
289+
return $this;
290+
}
291+
285292
/**
286293
* Get Page Size Height
287294
*
@@ -292,6 +299,13 @@ public function getPageSizeH()
292299
return $this->pageSizeH;
293300
}
294301

302+
public function setPageSizeH($value = null)
303+
{
304+
$this->pageSizeH = $this->setNumericVal($value, self::DEFAULT_HEIGHT);
305+
306+
return $this;
307+
}
308+
295309
/**
296310
* Get Margin Top
297311
*

tests/PhpWord/Tests/Style/SectionTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,34 @@ public function testMargin()
9797
$this->assertEquals($iVal, $oSettings->getMarginRight());
9898
}
9999

100+
/**
101+
* Set/get page width
102+
*/
103+
public function testPageWidth()
104+
{
105+
// Section Settings
106+
$oSettings = new Section();
107+
108+
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW());
109+
$iVal = rand(1, 1000);
110+
$oSettings->setSettingValue('pageSizeW', $iVal);
111+
$this->assertEquals($iVal, $oSettings->getPageSizeW());
112+
}
113+
114+
/**
115+
* Set/get page height
116+
*/
117+
public function testPageHeight()
118+
{
119+
// Section Settings
120+
$oSettings = new Section();
121+
122+
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH());
123+
$iVal = rand(1, 1000);
124+
$oSettings->setSettingValue('pageSizeH', $iVal);
125+
$this->assertEquals($iVal, $oSettings->getPageSizeH());
126+
}
127+
100128
/**
101129
* Set/get landscape orientation
102130
*/

0 commit comments

Comments
 (0)