67 lines
2.0 KiB
PHP
Raw Normal View History

2014-04-26 19:06:44 +07:00
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @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-04-26 19:06:44 +07:00
*/
namespace PhpOffice\PhpWord\Writer\ODText\Style;
/**
* Font style writer
*
* @since 0.10.0
*/
class Paragraph extends AbstractStyle
{
/**
* Is automatic style
*/
private $isAuto = false;
/**
* Write style
*/
public function write()
{
if (!($this->style instanceof \PhpOffice\PhpWord\Style\Paragraph)) {
return;
}
2014-04-26 19:06:44 +07:00
$marginTop = is_null($this->style->getSpaceBefore()) ? '0' : round(17.6 / $this->style->getSpaceBefore(), 2);
$marginBottom = is_null($this->style->getSpaceAfter()) ? '0' : round(17.6 / $this->style->getSpaceAfter(), 2);
$this->xmlWriter->startElement('style:style');
$this->xmlWriter->writeAttribute('style:name', $this->style->getStyleName());
$this->xmlWriter->writeAttribute('style:family', 'paragraph');
if ($this->isAuto) {
$this->xmlWriter->writeAttribute('style:parent-style-name', 'Standard');
$this->xmlWriter->writeAttribute('style:master-page-name', 'Standard');
}
$this->xmlWriter->startElement('style:paragraph-properties');
if ($this->isAuto) {
$this->xmlWriter->writeAttribute('style:page-number', 'auto');
} else {
$this->xmlWriter->writeAttribute('fo:margin-top', $marginTop . 'cm');
$this->xmlWriter->writeAttribute('fo:margin-bottom', $marginBottom . 'cm');
$this->xmlWriter->writeAttribute('fo:text-align', $this->style->getAlign());
}
$this->xmlWriter->endElement(); //style:paragraph-properties
$this->xmlWriter->endElement(); //style:style
}
/**
* Set is automatic style
*
* @param bool $value
*/
public function setIsAuto($value)
{
$this->isAuto = $value;
}
}