diff --git a/CHANGELOG.md b/CHANGELOG.md index 7acfecee..19d99348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/containers.rst b/docs/containers.rst index 30566df6..df04e658 100644 --- a/docs/containers.rst +++ b/docs/containers.rst @@ -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. diff --git a/docs/general.rst b/docs/general.rst index f08e29ba..270608f7 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -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 diff --git a/docs/src/documentation.md b/docs/src/documentation.md index e9716401..e0f00dac 100644 --- a/docs/src/documentation.md +++ b/docs/src/documentation.md @@ -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. diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php index 4110351d..fe133fdd 100644 --- a/src/PhpWord/Element/AbstractElement.php +++ b/src/PhpWord/Element/AbstractElement.php @@ -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); diff --git a/src/PhpWord/Element/Cell.php b/src/PhpWord/Element/Cell.php index ea49bc7b..cac37a78 100644 --- a/src/PhpWord/Element/Cell.php +++ b/src/PhpWord/Element/Cell.php @@ -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); } /** diff --git a/src/PhpWord/Element/Endnote.php b/src/PhpWord/Element/Endnote.php index 20278898..10000555 100644 --- a/src/PhpWord/Element/Endnote.php +++ b/src/PhpWord/Element/Endnote.php @@ -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); } } diff --git a/src/PhpWord/Element/Footnote.php b/src/PhpWord/Element/Footnote.php index 82bcd88f..e263933c 100644 --- a/src/PhpWord/Element/Footnote.php +++ b/src/PhpWord/Element/Footnote.php @@ -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); } diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php index 3d6a5545..532905f4 100644 --- a/src/PhpWord/Element/Image.php +++ b/src/PhpWord/Element/Image.php @@ -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); } diff --git a/src/PhpWord/Element/Line.php b/src/PhpWord/Element/Line.php index 4acca8ed..b76ac4fb 100644 --- a/src/PhpWord/Element/Line.php +++ b/src/PhpWord/Element/Line.php @@ -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); } /** diff --git a/src/PhpWord/Element/Link.php b/src/PhpWord/Element/Link.php index d962a3b5..4b00dc90 100644 --- a/src/PhpWord/Element/Link.php +++ b/src/PhpWord/Element/Link.php @@ -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; } diff --git a/src/PhpWord/Element/ListItem.php b/src/PhpWord/Element/ListItem.php index 59bd8391..4cb8d339 100644 --- a/src/PhpWord/Element/ListItem.php +++ b/src/PhpWord/Element/ListItem.php @@ -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); } } diff --git a/src/PhpWord/Element/ListItemRun.php b/src/PhpWord/Element/ListItemRun.php index fb219f91..82c6f1ab 100644 --- a/src/PhpWord/Element/ListItemRun.php +++ b/src/PhpWord/Element/ListItemRun.php @@ -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); } /** diff --git a/src/PhpWord/Element/Object.php b/src/PhpWord/Element/Object.php index ca3ecdf1..ae279ab0 100644 --- a/src/PhpWord/Element/Object.php +++ b/src/PhpWord/Element/Object.php @@ -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; diff --git a/src/PhpWord/Element/PreserveText.php b/src/PhpWord/Element/PreserveText.php index 100385c9..44aef3b4 100644 --- a/src/PhpWord/Element/PreserveText.php +++ b/src/PhpWord/Element/PreserveText.php @@ -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); diff --git a/src/PhpWord/Element/Row.php b/src/PhpWord/Element/Row.php index acbb75dc..e2df6325 100644 --- a/src/PhpWord/Element/Row.php +++ b/src/PhpWord/Element/Row.php @@ -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); } /** diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index 6fc63332..33c69795 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -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 * diff --git a/src/PhpWord/Element/Shape.php b/src/PhpWord/Element/Shape.php index 9b3aae4f..a7a96d18 100644 --- a/src/PhpWord/Element/Shape.php +++ b/src/PhpWord/Element/Shape.php @@ -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); } /** diff --git a/src/PhpWord/Element/Table.php b/src/PhpWord/Element/Table.php index 2d59073e..5e14d6bc 100644 --- a/src/PhpWord/Element/Table.php +++ b/src/PhpWord/Element/Table.php @@ -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); } /** diff --git a/src/PhpWord/Element/TextBox.php b/src/PhpWord/Element/TextBox.php index 06c95181..d929bf35 100644 --- a/src/PhpWord/Element/TextBox.php +++ b/src/PhpWord/Element/TextBox.php @@ -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); } /** diff --git a/src/PhpWord/Element/TextRun.php b/src/PhpWord/Element/TextRun.php index 75837104..c356cfa8 100644 --- a/src/PhpWord/Element/TextRun.php +++ b/src/PhpWord/Element/TextRun.php @@ -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); } /** diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index c54faa36..e06080c1 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -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; diff --git a/src/PhpWord/Reader/Word2007/Document.php b/src/PhpWord/Reader/Word2007/Document.php index be804531..02084189 100644 --- a/src/PhpWord/Reader/Word2007/Document.php +++ b/src/PhpWord/Reader/Word2007/Document.php @@ -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); } } diff --git a/src/PhpWord/Writer/ODText/Part/Content.php b/src/PhpWord/Writer/ODText/Part/Content.php index f16937a0..51326210 100644 --- a/src/PhpWord/Writer/ODText/Part/Content.php +++ b/src/PhpWord/Writer/ODText/Part/Content.php @@ -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); diff --git a/src/PhpWord/Writer/RTF/Part/Document.php b/src/PhpWord/Writer/RTF/Part/Document.php index 2f5c2f8e..f0a9b8f2 100644 --- a/src/PhpWord/Writer/RTF/Part/Document.php +++ b/src/PhpWord/Writer/RTF/Part/Document.php @@ -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(); diff --git a/src/PhpWord/Writer/RTF/Part/Header.php b/src/PhpWord/Writer/RTF/Part/Header.php index 32debb06..4d8d3a27 100644 --- a/src/PhpWord/Writer/RTF/Part/Header.php +++ b/src/PhpWord/Writer/RTF/Part/Header.php @@ -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(); diff --git a/src/PhpWord/Writer/Word2007/Part/Document.php b/src/PhpWord/Writer/Word2007/Part/Document.php index 99570338..e6639511 100644 --- a/src/PhpWord/Writer/Word2007/Part/Document.php +++ b/src/PhpWord/Writer/Word2007/Part/Document.php @@ -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 diff --git a/tests/PhpWord/Tests/Element/SectionTest.php b/tests/PhpWord/Tests/Element/SectionTest.php index af7595e2..853ebc5d 100644 --- a/tests/PhpWord/Tests/Element/SectionTest.php +++ b/tests/PhpWord/Tests/Element/SectionTest.php @@ -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()); } /** diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php index fd36db25..de5d63e8 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php @@ -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');