2014-05-01 18:37:34 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-05-01 18:37:34 +07:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-05-01 18:37:34 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
|
|
|
|
|
|
|
|
|
use PhpOffice\PhpWord\Style\Section as SectionStyle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Section style writer
|
|
|
|
|
*
|
|
|
|
|
* @since 0.10.0
|
|
|
|
|
*/
|
|
|
|
|
class Section extends AbstractStyle
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Write style
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
|
|
|
|
{
|
|
|
|
|
if (!($this->style instanceof \PhpOffice\PhpWord\Style\Section)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Section break
|
|
|
|
|
if (!is_null($this->style->getBreakType())) {
|
|
|
|
|
$this->xmlWriter->startElement('w:type');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:val', $this->style->getBreakType());
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Page size & orientation
|
|
|
|
|
$this->xmlWriter->startElement('w:pgSz');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:orient', $this->style->getOrientation());
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:w', $this->style->getPageSizeW());
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:h', $this->style->getPageSizeH());
|
|
|
|
|
$this->xmlWriter->endElement(); // w:pgSz
|
|
|
|
|
|
|
|
|
|
// Margins
|
2014-05-06 08:50:55 +07:00
|
|
|
$margins = array(
|
|
|
|
|
'w:top' => array('getMarginTop', SectionStyle::DEFAULT_MARGIN),
|
|
|
|
|
'w:right' => array('getMarginRight', SectionStyle::DEFAULT_MARGIN),
|
|
|
|
|
'w:bottom' => array('getMarginBottom', SectionStyle::DEFAULT_MARGIN),
|
|
|
|
|
'w:left' => array('getMarginLeft', SectionStyle::DEFAULT_MARGIN),
|
|
|
|
|
'w:header' => array('getHeaderHeight', SectionStyle::DEFAULT_HEADER_HEIGHT),
|
|
|
|
|
'w:footer' => array('getFooterHeight', SectionStyle::DEFAULT_FOOTER_HEIGHT),
|
|
|
|
|
'w:gutter' => array('getGutter', SectionStyle::DEFAULT_GUTTER),
|
|
|
|
|
);
|
2014-05-01 18:37:34 +07:00
|
|
|
$this->xmlWriter->startElement('w:pgMar');
|
2014-05-06 08:50:55 +07:00
|
|
|
foreach ($margins as $attribute => $value) {
|
|
|
|
|
list($method, $default) = $value;
|
|
|
|
|
$this->xmlWriter->writeAttribute($attribute, $this->convertTwip($this->style->$method(), $default));
|
|
|
|
|
}
|
2014-05-01 18:37:34 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
|
|
|
|
|
// Borders
|
|
|
|
|
$borders = $this->style->getBorderSize();
|
|
|
|
|
$hasBorders = false;
|
|
|
|
|
for ($i = 0; $i < 4; $i++) {
|
|
|
|
|
if (!is_null($borders[$i])) {
|
|
|
|
|
$hasBorders = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($hasBorders) {
|
|
|
|
|
$styleWriter = new MarginBorder($this->xmlWriter);
|
|
|
|
|
$styleWriter->setSizes($borders);
|
|
|
|
|
$styleWriter->setColors($this->style->getBorderColor());
|
|
|
|
|
$styleWriter->setAttributes(array('space' => '24'));
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:pgBorders');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:offsetFrom', 'page');
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Page numbering
|
|
|
|
|
if (!is_null($this->style->getPageNumberingStart())) {
|
|
|
|
|
$this->xmlWriter->startElement('w:pgNumType');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:start', $this->style->getPageNumberingStart());
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Columns
|
|
|
|
|
$this->xmlWriter->startElement('w:cols');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:num', $this->style->getColsNum());
|
2014-05-06 08:50:55 +07:00
|
|
|
$this->xmlWriter->writeAttribute('w:space', $this->convertTwip(
|
|
|
|
|
$this->style->getColsSpace(),
|
|
|
|
|
SectionStyle::DEFAULT_COLUMN_SPACING
|
|
|
|
|
));
|
2014-05-01 18:37:34 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
|
|
|
|
|
// Line numbering
|
|
|
|
|
$styleWriter = new LineNumbering($this->xmlWriter, $this->style->getLineNumbering());
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
}
|
|
|
|
|
}
|