Refactor: Apply composite design pattern to ODText/OpenDocument writer
This commit is contained in:
parent
b7480d81c0
commit
559a798acb
|
|
@ -12,21 +12,11 @@ namespace PhpOffice\PhpWord\Writer\ODText;
|
|||
use PhpOffice\PhpWord\Media;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Element\Image;
|
||||
use PhpOffice\PhpWord\Element\Link;
|
||||
use PhpOffice\PhpWord\Element\ListItem;
|
||||
use PhpOffice\PhpWord\Element\Object;
|
||||
use PhpOffice\PhpWord\Element\PageBreak;
|
||||
use PhpOffice\PhpWord\Element\Table;
|
||||
use PhpOffice\PhpWord\Element\Text;
|
||||
use PhpOffice\PhpWord\Element\TextBreak;
|
||||
use PhpOffice\PhpWord\Element\TextRun;
|
||||
use PhpOffice\PhpWord\Element\Title;
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
use PhpOffice\PhpWord\Shared\Drawing;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
use PhpOffice\PhpWord\Writer\ODText\Element\Element as ElementWriter;
|
||||
|
||||
/**
|
||||
* ODText content part writer
|
||||
|
|
@ -90,27 +80,8 @@ class Content extends Base
|
|||
|
||||
// $xmlWriter->startElement('text:section');
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof Link) {
|
||||
$this->writeLink($xmlWriter, $element);
|
||||
} elseif ($element instanceof Title) {
|
||||
$this->writeTitle($xmlWriter, $element);
|
||||
} elseif ($element instanceof ListItem) {
|
||||
$this->writeListItem($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->writeTextBreak($xmlWriter);
|
||||
} elseif ($element instanceof PageBreak) {
|
||||
$this->writePageBreak($xmlWriter);
|
||||
} elseif ($element instanceof Table) {
|
||||
$this->writeTable($xmlWriter, $element);
|
||||
} elseif ($element instanceof Image) {
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} elseif ($element instanceof Object) {
|
||||
$this->writeObject($xmlWriter, $element);
|
||||
}
|
||||
$elementWriter = new ElementWriter($xmlWriter, $this, $element, false);
|
||||
$elementWriter->write();
|
||||
}
|
||||
// $xmlWriter->endElement(); // text:section
|
||||
}
|
||||
|
|
@ -122,226 +93,6 @@ class Content extends Base
|
|||
return $xmlWriter->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write text
|
||||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Text $text
|
||||
* @param bool $withoutP
|
||||
*/
|
||||
protected function writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
|
||||
{
|
||||
$styleFont = $text->getFontStyle();
|
||||
$styleParagraph = $text->getParagraphStyle();
|
||||
|
||||
// @todo Commented for TextRun. Should really checkout this value
|
||||
// $SfIsObject = ($styleFont instanceof Font) ? true : false;
|
||||
$SfIsObject = false;
|
||||
|
||||
if ($SfIsObject) {
|
||||
// Don't never be the case, because I browse all sections for cleaning all styles not declared
|
||||
throw new Exception('PhpWord : $SfIsObject wouldn\'t be an object');
|
||||
} else {
|
||||
if (!$withoutP) {
|
||||
$xmlWriter->startElement('text:p'); // text:p
|
||||
}
|
||||
if (empty($styleFont)) {
|
||||
if (empty($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', 'P1');
|
||||
} elseif (is_string($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', $styleParagraph);
|
||||
}
|
||||
$xmlWriter->writeRaw($text->getText());
|
||||
} else {
|
||||
if (empty($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
} elseif (is_string($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', $styleParagraph);
|
||||
}
|
||||
// text:span
|
||||
$xmlWriter->startElement('text:span');
|
||||
if (is_string($styleFont)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', $styleFont);
|
||||
}
|
||||
$xmlWriter->writeRaw($text->getText());
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
if (!$withoutP) {
|
||||
$xmlWriter->endElement(); // text:p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write TextRun section
|
||||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param TextRun $textrun
|
||||
* @todo Enable all other section types
|
||||
*/
|
||||
protected function writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
|
||||
{
|
||||
$elements = $textrun->getElements();
|
||||
$xmlWriter->startElement('text:p');
|
||||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->writeText($xmlWriter, $element, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write link element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
*/
|
||||
protected function writeLink(XMLWriter $xmlWriter, Link $link)
|
||||
{
|
||||
$this->writeUnsupportedElement($xmlWriter, 'Link');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write title element
|
||||
*/
|
||||
protected function writeTitle(XMLWriter $xmlWriter, Title $title)
|
||||
{
|
||||
$this->writeUnsupportedElement($xmlWriter, 'Title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write list item
|
||||
*/
|
||||
protected function writeListItem(XMLWriter $xmlWriter, ListItem $listItem)
|
||||
{
|
||||
$this->writeUnsupportedElement($xmlWriter, 'ListItem');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write text break
|
||||
*/
|
||||
protected function writeTextBreak(XMLWriter $xmlWriter)
|
||||
{
|
||||
$xmlWriter->startElement('text:p');
|
||||
$xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write page break
|
||||
*/
|
||||
protected function writePageBreak(XMLWriter $xmlWriter)
|
||||
{
|
||||
$this->writeUnsupportedElement($xmlWriter, 'PageBreak');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write table
|
||||
*/
|
||||
protected function writeTable(XMLWriter $xmlWriter, Table $table)
|
||||
{
|
||||
$rows = $table->getRows();
|
||||
$rowCount = count($rows);
|
||||
$colCount = $table->countColumns();
|
||||
if ($rowCount > 0) {
|
||||
$xmlWriter->startElement('table:table');
|
||||
$xmlWriter->writeAttribute('table:name', $table->getElementId());
|
||||
$xmlWriter->writeAttribute('table:style', $table->getElementId());
|
||||
|
||||
$xmlWriter->startElement('table:table-column');
|
||||
$xmlWriter->writeAttribute('table:number-columns-repeated', $colCount);
|
||||
$xmlWriter->endElement(); // table:table-column
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$xmlWriter->startElement('table:table-row');
|
||||
foreach ($row->getCells() as $cell) {
|
||||
$xmlWriter->startElement('table:table-cell');
|
||||
$xmlWriter->writeAttribute('office:value-type', 'string');
|
||||
$elements = $cell->getElements();
|
||||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof ListItem) {
|
||||
$this->writeListItem($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->writeTextBreak($xmlWriter);
|
||||
} elseif ($element instanceof Image) {
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} elseif ($element instanceof Object) {
|
||||
$this->writeObject($xmlWriter, $element);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->writeTextBreak($xmlWriter);
|
||||
}
|
||||
$xmlWriter->endElement(); // table:table-cell
|
||||
}
|
||||
$xmlWriter->endElement(); // table:table-row
|
||||
}
|
||||
$xmlWriter->endElement(); // table:table
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write image
|
||||
*/
|
||||
protected function writeImage(XMLWriter $xmlWriter, Image $element)
|
||||
{
|
||||
$mediaIndex = $element->getMediaIndex();
|
||||
$target = 'Pictures/' . $element->getTarget();
|
||||
$style = $element->getStyle();
|
||||
$width = Drawing::pixelsToCentimeters($style->getWidth());
|
||||
$height = Drawing::pixelsToCentimeters($style->getHeight());
|
||||
|
||||
$xmlWriter->startElement('text:p');
|
||||
$xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
|
||||
$xmlWriter->startElement('draw:frame');
|
||||
$xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex);
|
||||
$xmlWriter->writeAttribute('draw:name', $element->getElementId());
|
||||
$xmlWriter->writeAttribute('text:anchor-type', 'as-char');
|
||||
$xmlWriter->writeAttribute('svg:width', $width . 'cm');
|
||||
$xmlWriter->writeAttribute('svg:height', $height . 'cm');
|
||||
$xmlWriter->writeAttribute('draw:z-index', $mediaIndex);
|
||||
|
||||
$xmlWriter->startElement('draw:image');
|
||||
$xmlWriter->writeAttribute('xlink:href', $target);
|
||||
$xmlWriter->writeAttribute('xlink:type', 'simple');
|
||||
$xmlWriter->writeAttribute('xlink:show', 'embed');
|
||||
$xmlWriter->writeAttribute('xlink:actuate', 'onLoad');
|
||||
$xmlWriter->endElement(); // draw:image
|
||||
|
||||
$xmlWriter->endElement(); // draw:frame
|
||||
|
||||
$xmlWriter->endElement(); // text:p
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object
|
||||
*/
|
||||
protected function writeObject(XMLWriter $xmlWriter, Object $element)
|
||||
{
|
||||
$this->writeUnsupportedElement($xmlWriter, 'Object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write unsupported element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param string $element
|
||||
*/
|
||||
private function writeUnsupportedElement(XMLWriter $xmlWriter, $element)
|
||||
{
|
||||
$xmlWriter->startElement('text:p');
|
||||
$xmlWriter->writeRaw($element);
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write automatic styles
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\AbstractElement;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
use PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart;
|
||||
|
||||
/**
|
||||
* Generic element writer
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Element
|
||||
{
|
||||
/**
|
||||
* XML writer
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Shared\XMLWriter
|
||||
*/
|
||||
protected $xmlWriter;
|
||||
|
||||
/**
|
||||
* Parent writer
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart
|
||||
*/
|
||||
protected $parentWriter;
|
||||
|
||||
/**
|
||||
* Element
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Element\AbstractElement
|
||||
*/
|
||||
protected $element;
|
||||
|
||||
/**
|
||||
* Without paragraph
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $withoutP = false;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param bool $withoutP
|
||||
*/
|
||||
public function __construct(XMLWriter $xmlWriter, AbstractWriterPart $parentWriter, AbstractElement $element, $withoutP = false)
|
||||
{
|
||||
$this->xmlWriter = $xmlWriter;
|
||||
$this->parentWriter = $parentWriter;
|
||||
$this->element = $element;
|
||||
$this->withoutP = $withoutP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$elmName = str_replace('PhpOffice\\PhpWord\\Element\\', '', get_class($this->element));
|
||||
$elmWriterClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $elmName;
|
||||
if (class_exists($elmWriterClass) === true) {
|
||||
$elmWriter = new $elmWriterClass($this->xmlWriter, $this->parentWriter, $this->element, $this->withoutP);
|
||||
$elmWriter->write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\Drawing;
|
||||
|
||||
/**
|
||||
* Image element writer
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Image extends Element
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$mediaIndex = $this->element->getMediaIndex();
|
||||
$target = 'Pictures/' . $this->element->getTarget();
|
||||
$style = $this->element->getStyle();
|
||||
$width = Drawing::pixelsToCentimeters($style->getWidth());
|
||||
$height = Drawing::pixelsToCentimeters($style->getHeight());
|
||||
|
||||
$this->xmlWriter->startElement('text:p');
|
||||
$this->xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
|
||||
$this->xmlWriter->startElement('draw:frame');
|
||||
$this->xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex);
|
||||
$this->xmlWriter->writeAttribute('draw:name', $this->element->getElementId());
|
||||
$this->xmlWriter->writeAttribute('text:anchor-type', 'as-char');
|
||||
$this->xmlWriter->writeAttribute('svg:width', $width . 'cm');
|
||||
$this->xmlWriter->writeAttribute('svg:height', $height . 'cm');
|
||||
$this->xmlWriter->writeAttribute('draw:z-index', $mediaIndex);
|
||||
|
||||
$this->xmlWriter->startElement('draw:image');
|
||||
$this->xmlWriter->writeAttribute('xlink:href', $target);
|
||||
$this->xmlWriter->writeAttribute('xlink:type', 'simple');
|
||||
$this->xmlWriter->writeAttribute('xlink:show', 'embed');
|
||||
$this->xmlWriter->writeAttribute('xlink:actuate', 'onLoad');
|
||||
$this->xmlWriter->endElement(); // draw:image
|
||||
|
||||
$this->xmlWriter->endElement(); // draw:frame
|
||||
|
||||
$this->xmlWriter->endElement(); // text:p
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Cell;
|
||||
use PhpOffice\PhpWord\Style\Table as TableStyle;
|
||||
use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
|
||||
use PhpOffice\PhpWord\Writer\ODText\Element\Element as ElementWriter;
|
||||
|
||||
/**
|
||||
* Table element writer
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Table extends Element
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$rows = $this->element->getRows();
|
||||
$rowCount = count($rows);
|
||||
$colCount = $this->element->countColumns();
|
||||
if ($rowCount > 0) {
|
||||
$this->xmlWriter->startElement('table:table');
|
||||
$this->xmlWriter->writeAttribute('table:name', $this->element->getElementId());
|
||||
$this->xmlWriter->writeAttribute('table:style', $this->element->getElementId());
|
||||
|
||||
$this->xmlWriter->startElement('table:table-column');
|
||||
$this->xmlWriter->writeAttribute('table:number-columns-repeated', $colCount);
|
||||
$this->xmlWriter->endElement(); // table:table-column
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$this->xmlWriter->startElement('table:table-row');
|
||||
foreach ($row->getCells() as $cell) {
|
||||
$this->xmlWriter->startElement('table:table-cell');
|
||||
$this->xmlWriter->writeAttribute('office:value-type', 'string');
|
||||
$elements = $cell->getElements();
|
||||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
$elementWriter = new ElementWriter($this->xmlWriter, $this->parentWriter, $element);
|
||||
$elementWriter->write();
|
||||
}
|
||||
} else {
|
||||
$elementWriter = new ElementWriter($this->xmlWriter, $this->parentWriter, new TextBreakElement());
|
||||
$elementWriter->write();
|
||||
}
|
||||
$this->xmlWriter->endElement(); // table:table-cell
|
||||
}
|
||||
$this->xmlWriter->endElement(); // table:table-row
|
||||
}
|
||||
$this->xmlWriter->endElement(); // table:table
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
/**
|
||||
* Text element writer
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Text extends Element
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$styleFont = $this->element->getFontStyle();
|
||||
$styleParagraph = $this->element->getParagraphStyle();
|
||||
|
||||
// @todo Commented for TextRun. Should really checkout this value
|
||||
// $SfIsObject = ($styleFont instanceof Font) ? true : false;
|
||||
$SfIsObject = false;
|
||||
|
||||
if ($SfIsObject) {
|
||||
// Don't never be the case, because I browse all sections for cleaning all styles not declared
|
||||
throw new Exception('PhpWord : $SfIsObject wouldn\'t be an object');
|
||||
} else {
|
||||
if (!$this->withoutP) {
|
||||
$this->xmlWriter->startElement('text:p'); // text:p
|
||||
}
|
||||
if (empty($styleFont)) {
|
||||
if (empty($styleParagraph)) {
|
||||
$this->xmlWriter->writeAttribute('text:style-name', 'P1');
|
||||
} elseif (is_string($styleParagraph)) {
|
||||
$this->xmlWriter->writeAttribute('text:style-name', $styleParagraph);
|
||||
}
|
||||
$this->xmlWriter->writeRaw($this->element->getText());
|
||||
} else {
|
||||
if (empty($styleParagraph)) {
|
||||
$this->xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
} elseif (is_string($styleParagraph)) {
|
||||
$this->xmlWriter->writeAttribute('text:style-name', $styleParagraph);
|
||||
}
|
||||
// text:span
|
||||
$this->xmlWriter->startElement('text:span');
|
||||
if (is_string($styleFont)) {
|
||||
$this->xmlWriter->writeAttribute('text:style-name', $styleFont);
|
||||
}
|
||||
$this->xmlWriter->writeRaw($this->element->getText());
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
if (!$this->withoutP) {
|
||||
$this->xmlWriter->endElement(); // text:p
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
/**
|
||||
* TextBreak element writer
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class TextBreak extends Element
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$this->xmlWriter->startElement('text:p');
|
||||
$this->xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\Text as TextElement;
|
||||
use PhpOffice\PhpWord\Writer\ODText\Element\Element as ElementWriter;
|
||||
|
||||
/**
|
||||
* TextRun element writer
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class TextRun extends Element
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$elements = $this->element->getElements();
|
||||
$this->xmlWriter->startElement('text:p');
|
||||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof TextElement) {
|
||||
$elementWriter = new ElementWriter($this->xmlWriter, $this->parentWriter, $element, true);
|
||||
$elementWriter->write();
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ class Endnote extends Note
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
parent::write('endnoteReference');
|
||||
$this->referenceType = 'endnoteReference';
|
||||
parent::write();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class Footnote extends Note
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
parent::write('footnoteReference');
|
||||
$this->referenceType = 'footnoteReference';
|
||||
parent::write();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,16 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
|||
class Note extends Element
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
* Reference type footnoteReference|endnoteReference
|
||||
*
|
||||
* @param string $referenceType footnoteReference|endnoteReference
|
||||
* @var string
|
||||
*/
|
||||
public function write($referenceType = 'footnoteReference')
|
||||
protected $referenceType = 'footnoteReference';
|
||||
|
||||
/**
|
||||
* Write element
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->withoutP) {
|
||||
$this->xmlWriter->startElement('w:p');
|
||||
|
|
@ -29,10 +34,10 @@ class Note extends Element
|
|||
$this->xmlWriter->startElement('w:r');
|
||||
$this->xmlWriter->startElement('w:rPr');
|
||||
$this->xmlWriter->startElement('w:rStyle');
|
||||
$this->xmlWriter->writeAttribute('w:val', ucfirst($referenceType));
|
||||
$this->xmlWriter->writeAttribute('w:val', ucfirst($this->referenceType));
|
||||
$this->xmlWriter->endElement(); // w:rStyle
|
||||
$this->xmlWriter->endElement(); // w:rPr
|
||||
$this->xmlWriter->startElement("w:{$referenceType}");
|
||||
$this->xmlWriter->startElement("w:{$this->referenceType}");
|
||||
$this->xmlWriter->writeAttribute('w:id', $this->element->getRelationId());
|
||||
$this->xmlWriter->endElement(); // w:$referenceType
|
||||
$this->xmlWriter->endElement(); // w:r
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
|||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Style as StyleWriter;
|
||||
|
||||
/**
|
||||
* Text element writer
|
||||
|
|
|
|||
Loading…
Reference in New Issue