Use section "style" instead of "settings" for consistency

This commit is contained in:
Ivan Lanin 2014-06-08 16:44:46 +07:00
parent a9c9c21d3b
commit 63d53ac910
29 changed files with 103 additions and 83 deletions

View File

@ -21,6 +21,7 @@ This release added drawing shapes (arc, curve, line, polyline, rect, oval) eleme
### Deprecated
- `Element\Link::getTarget()` replaced by `Element\Link::getSource()`
- `Element\Section::getSettings()` and `Element\Section::setSettings()` replaced by `Element\Section::getStyle()` and `Element\Section::setStyle()`
### Miscellaneous

View File

@ -32,7 +32,7 @@ section. Example:
Section settings
~~~~~~~~~~~~~~~~
Below are the available settings for section:
Below are the available styles for section:
- ``orientation`` Page orientation, i.e. 'portrait' (default) or
'landscape'
@ -56,8 +56,8 @@ Below are the available settings for section:
- ``breakType`` Section break type (nextPage, nextColumn, continuous,
evenPage, oddPage)
The following two settings are automatically set by the use of the
``orientation`` setting. You can alter them but that's not recommended.
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
@ -66,7 +66,7 @@ Page number
~~~~~~~~~~~
You can change a section page number by using the ``pageNumberingStart``
property of the section.
style of the section.
.. code-block:: php
@ -75,13 +75,13 @@ property of the section.
// Method 2
$section = $phpWord->addSection();
$section->getSettings()->setPageNumberingStart(1);
$section->getStyle()->setPageNumberingStart(1);
Multicolumn
~~~~~~~~~~~
You can change a section layout to multicolumn (like in a newspaper) by
using the ``breakType`` and ``colsNum`` property of the section.
using the ``breakType`` and ``colsNum`` style of the section.
.. code-block:: php
@ -90,14 +90,14 @@ using the ``breakType`` and ``colsNum`` property of the section.
// Method 2
$section = $phpWord->addSection();
$section->getSettings()->setBreakType('continuous');
$section->getSettings()->setColsNum(2);
$section->getStyle()->setBreakType('continuous');
$section->getStyle()->setColsNum(2);
### Line numbering
You can apply line numbering to a section by using the ``lineNumbering``
property of the section.
style of the section.
.. code-block:: php
@ -106,7 +106,7 @@ property of the section.
// Method 2
$section = $phpWord->addSection();
$section->getSettings()->setLineNumbering(array());
$section->getStyle()->setLineNumbering(array());
Below are the properties of the line numbering style.

View File

@ -138,7 +138,7 @@ points to twips.
);
$section = $phpWord->addSection();
$sectionStyle = $section->getSettings();
$sectionStyle = $section->getStyle();
// half inch left margin
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
// 2 cm right margin

View File

@ -304,7 +304,7 @@ $phpWord->addParagraphStyle('My Style', array(
);
$section = $phpWord->addSection();
$sectionStyle = $section->getSettings();
$sectionStyle = $section->getStyle();
// half inch left margin
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
// 2 cm right margin
@ -333,9 +333,9 @@ $sectionSettings = array(
);
```
### Section settings
### Section style
Below are the available settings for section:
Below are the available styles for section:
- `orientation` Page orientation, i.e. 'portrait' (default) or 'landscape'
- `marginTop` Page margin top in twips
@ -357,14 +357,14 @@ Below are the available settings for section:
- `colsSpace` Spacing between columns
- `breakType` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage)
The following two settings are automatically set by the use of the `orientation` setting. You can alter them but that's not recommended.
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
### Page number
You can change a section page number by using the `pageNumberingStart` property of the section.
You can change a section page number by using the `pageNumberingStart` style of the section.
```php
// Method 1
@ -372,12 +372,12 @@ $section = $phpWord->addSection(array('pageNumberingStart' => 1));
// Method 2
$section = $phpWord->addSection();
$section->getSettings()->setPageNumberingStart(1);
$section->getStyle()->setPageNumberingStart(1);
```
### Multicolumn
You can change a section layout to multicolumn (like in a newspaper) by using the `breakType` and `colsNum` property of the section.
You can change a section layout to multicolumn (like in a newspaper) by using the `breakType` and `colsNum` style of the section.
```php
// Method 1
@ -385,13 +385,13 @@ $section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' =>
// Method 2
$section = $phpWord->addSection();
$section->getSettings()->setBreakType('continuous');
$section->getSettings()->setColsNum(2);
$section->getStyle()->setBreakType('continuous');
$section->getStyle()->setColsNum(2);
```
### Line numbering
You can apply line numbering to a section by using the `lineNumbering` property of the section.
You can apply line numbering to a section by using the `lineNumbering` style of the section.
```php
// Method 1
@ -399,7 +399,7 @@ $section = $phpWord->addSection(array('lineNumbering' => array()));
// Method 2
$section = $phpWord->addSection();
$section->getSettings()->setLineNumbering(array());
$section->getStyle()->setLineNumbering(array());
```
Below are the properties of the line numbering style.

View File

@ -343,14 +343,14 @@ abstract class AbstractElement
}
/**
* Set style value
* Set new style value
*
* @param mixed $styleObject Style object
* @param mixed $styleValue Style value
* @param bool $returnObject Always return object
* @return mixed
*/
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
protected function setNewStyle($styleObject, $styleValue = null, $returnObject = false)
{
if (!is_null($styleValue) && is_array($styleValue)) {
$styleObject->setStyleByArray($styleValue);

View File

@ -52,7 +52,7 @@ class Cell extends AbstractContainer
public function __construct($width = null, $style = null)
{
$this->width = $width;
$this->style = $this->setStyle(new CellStyle(), $style, true);
$this->style = $this->setNewStyle(new CellStyle(), $style, true);
}
/**

View File

@ -38,6 +38,6 @@ class Endnote extends Footnote
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
}
}

View File

@ -50,7 +50,7 @@ class Footnote extends AbstractContainer
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->setDocPart($this->container);
}

View File

@ -131,7 +131,7 @@ class Image extends AbstractElement
{
$this->source = $source;
$this->setIsWatermark($watermark);
$this->style = $this->setStyle(new ImageStyle(), $style, true);
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->checkImage($source);
}

View File

@ -38,7 +38,7 @@ class Line extends AbstractElement
*/
public function __construct($style = null)
{
$this->style = $this->setStyle(new LineStyle(), $style);
$this->style = $this->setNewStyle(new LineStyle(), $style);
}
/**

View File

@ -73,8 +73,8 @@ class Link extends AbstractElement
{
$this->source = String::toUTF8($source);
$this->text = is_null($text) ? $this->source : String::toUTF8($text);
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
return $this;
}

View File

@ -64,7 +64,7 @@ class ListItem extends AbstractElement
if (!is_null($listStyle) && is_string($listStyle)) {
$this->style = new ListItemStyle($listStyle);
} else {
$this->style = $this->setStyle(new ListItemStyle(), $listStyle, true);
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}
}

View File

@ -59,9 +59,9 @@ class ListItemRun extends TextRun
if (!is_null($listStyle) && is_string($listStyle)) {
$this->style = new ListItemStyle($listStyle);
} else {
$this->style = $this->setStyle(new ListItemStyle(), $listStyle, true);
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
}
/**

View File

@ -79,7 +79,7 @@ class Object extends AbstractElement
}
$this->source = $source;
$this->style = $this->setStyle(new ImageStyle(), $style, true);
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
return $this;

View File

@ -58,8 +58,8 @@ class PreserveText extends AbstractElement
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->text = String::toUTF8($text);
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

View File

@ -56,7 +56,7 @@ class Row extends AbstractElement
public function __construct($height = null, $style = null)
{
$this->height = $height;
$this->style = $this->setStyle(new RowStyle(), $style, true);
$this->style = $this->setNewStyle(new RowStyle(), $style, true);
}
/**

View File

@ -18,7 +18,7 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Style\Section as SectionSettings;
use PhpOffice\PhpWord\Style\Section as SectionStyle;
/**
* Section
@ -31,11 +31,11 @@ class Section extends AbstractContainer
protected $container = 'Section';
/**
* Section settings
* Section style
*
* @var \PhpOffice\PhpWord\Style\Section
*/
private $settings;
private $style;
/**
* Section headers, indexed from 1, not zero
@ -55,41 +55,36 @@ class Section extends AbstractContainer
* Create new instance
*
* @param int $sectionCount
* @param array $settings
* @param array $style
*/
public function __construct($sectionCount, $settings = null)
public function __construct($sectionCount, $style = null)
{
$this->sectionId = $sectionCount;
$this->setDocPart($this->container, $this->sectionId);
$this->settings = new SectionSettings();
$this->setSettings($settings);
$this->style = new SectionStyle();
$this->setStyle($style);
}
/**
* Set section settings
* Set section style
*
* @param array $settings
* @param array $style
*/
public function setSettings($settings = null)
public function setStyle($style = null)
{
if (!is_null($settings) && is_array($settings)) {
foreach ($settings as $key => $value) {
if (is_null($value)) {
continue;
}
$this->settings->setSettingValue($key, $value);
}
if (!is_null($style) && is_array($style)) {
$this->style->setStyleByArray($style);
}
}
/**
* Get Section Settings
* Get section style
*
* @return \PhpOffice\PhpWord\Style\Section
*/
public function getSettings()
public function getStyle()
{
return $this->settings;
return $this->style;
}
/**
@ -184,6 +179,30 @@ class Section extends AbstractContainer
}
/**
* Set section style
*
* @param array $settings
* @deprecated 0.12.0
* @codeCoverageIgnore
*/
public function setSettings($settings = null)
{
$this->setStyle($settings);
}
/**
* Get section style
*
* @return \PhpOffice\PhpWord\Style\Section
* @deprecated 0.12.0
* @codeCoverageIgnore
*/
public function getSettings()
{
return $this->getStyle();
}
/**
* Create header
*

View File

@ -49,7 +49,7 @@ class Shape extends AbstractElement
public function __construct($type, $style = null)
{
$this->setType($type);
$this->style = $this->setStyle(new ShapeStyle(), $style);
$this->style = $this->setNewStyle(new ShapeStyle(), $style);
}
/**

View File

@ -52,7 +52,7 @@ class Table extends AbstractElement
*/
public function __construct($style = null)
{
$this->style = $this->setStyle(new TableStyle(), $style);
$this->style = $this->setNewStyle(new TableStyle(), $style);
}
/**

View File

@ -45,7 +45,7 @@ class TextBox extends AbstractContainer
*/
public function __construct($style = null)
{
$this->style = $this->setStyle(new TextBoxStyle(), $style);
$this->style = $this->setNewStyle(new TextBoxStyle(), $style);
}
/**

View File

@ -43,7 +43,7 @@ class TextRun extends AbstractContainer
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
}
/**

View File

@ -121,12 +121,12 @@ class PhpWord
/**
* Create new section
*
* @param array $settings
* @param array $style
* @return \PhpOffice\PhpWord\Element\Section
*/
public function addSection($settings = null)
public function addSection($style = null)
{
$section = new Section(count($this->sections) + 1, $settings);
$section = new Section(count($this->sections) + 1, $style);
$section->setPhpWord($this);
$this->sections[] = $section;

View File

@ -175,8 +175,8 @@ class Document extends AbstractPart
*/
private function readWSectPrNode(XMLReader $xmlReader, \DOMElement $node, Section &$section)
{
$settings = $this->readSectionStyle($xmlReader, $node);
$section->setSettings($settings);
$this->readHeaderFooter($settings, $section);
$style = $this->readSectionStyle($xmlReader, $node);
$section->setStyle($style);
$this->readHeaderFooter($style, $section);
}
}

View File

@ -168,7 +168,7 @@ class Content extends AbstractPart
$paragraphStyleCount = 0;
$fontStyleCount = 0;
foreach ($sections as $section) {
$style = $section->getSettings();
$style = $section->getStyle();
$style->setStyleName("Section{$section->getSectionId()}");
$this->autoStyles['Section'][] = $style;
$this->getContainerStyle($section, $paragraphStyleCount, $fontStyleCount);

View File

@ -110,7 +110,7 @@ class Document extends AbstractPart
$sections = $this->getParentWriter()->getPhpWord()->getSections();
foreach ($sections as $section) {
$styleWriter = new SectionStyleWriter($section->getSettings());
$styleWriter = new SectionStyleWriter($section->getStyle());
$styleWriter->setParentWriter($this->getParentWriter());
$content .= $styleWriter->write();

View File

@ -193,7 +193,7 @@ class Header extends AbstractPart
$sections = $phpWord->getSections();
foreach ($sections as $section) {
$elements = $section->getElements();
$this->registerBorderColor($section->getSettings());
$this->registerBorderColor($section->getStyle());
foreach ($elements as $element) {
if (method_exists($element, 'getFontStyle')) {
$style = $element->getFontStyle();

View File

@ -128,7 +128,7 @@ class Document extends AbstractPart
}
// Section settings
$styleWriter = new SectionStyleWriter($xmlWriter, $section->getSettings());
$styleWriter = new SectionStyleWriter($xmlWriter, $section->getStyle());
$styleWriter->write();
$xmlWriter->endElement(); // w:sectPr

View File

@ -31,12 +31,12 @@ use PhpOffice\PhpWord\Style;
class SectionTest extends \PHPUnit_Framework_TestCase
{
/**
* Get settings
* Get style
*/
public function testGetSettings()
public function testGetStyle()
{
$oSection = new Section(0);
$this->assertAttributeEquals($oSection->getSettings(), 'settings', new Section(0));
$this->assertAttributeEquals($oSection->getStyle(), 'style', new Section(0));
}
/**
@ -69,12 +69,12 @@ class SectionTest extends \PHPUnit_Framework_TestCase
/**
* Set settings
*/
public function testSetSettings()
public function testSetStyle()
{
$expected = 'landscape';
$object = new Section(0);
$object->setSettings(array('orientation' => $expected, 'foo' => null));
$this->assertEquals($expected, $object->getSettings()->getOrientation());
$object->setStyle(array('orientation' => $expected, 'foo' => null));
$this->assertEquals($expected, $object->getStyle()->getOrientation());
}
/**

View File

@ -45,11 +45,11 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$section = $phpWord->addSection();
$section->addHeader();
$section->addHeader('first');
$settings = $section->getSettings();
$settings->setLandscape();
$settings->setPageNumberingStart(2);
$settings->setBorderSize(240);
$settings->setBreakType('nextPage');
$style = $section->getStyle();
$style->setLandscape();
$style->setPageNumberingStart(2);
$style->setBorderSize(240);
$style->setBreakType('nextPage');
$doc = TestHelperDOCX::getDocument($phpWord);
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType');