Refactor writer classes

This commit is contained in:
Ivan Lanin 2014-03-30 18:51:25 +07:00
parent 4127860f1e
commit 45b0baf7bc
31 changed files with 1019 additions and 1193 deletions

View File

@ -25,6 +25,10 @@
{ {
"name": "Ivan Lanin", "name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org" "homepage": "http://ivan.lanin.org"
},
{
"name": "Roman Syroeshko",
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
} }
], ],
"require": { "require": {

View File

@ -39,14 +39,14 @@ class DocumentProperties
/** /**
* Created * Created
* *
* @var datetime * @var datetime|int
*/ */
private $_created; private $_created;
/** /**
* Modified * Modified
* *
* @var datetime * @var datetime|int
*/ */
private $_modified; private $_modified;
@ -102,7 +102,7 @@ class DocumentProperties
/** /**
* Custom Properties * Custom Properties
* *
* @var string * @var array
*/ */
private $_customProperties = array(); private $_customProperties = array();
@ -542,26 +542,21 @@ class DocumentProperties
case 'ui8': // 8-Byte Unsigned Integer case 'ui8': // 8-Byte Unsigned Integer
case 'uint': // Unsigned Integer case 'uint': // Unsigned Integer
return self::PROPERTY_TYPE_INTEGER; return self::PROPERTY_TYPE_INTEGER;
break;
case 'r4': // 4-Byte Real Number case 'r4': // 4-Byte Real Number
case 'r8': // 8-Byte Real Number case 'r8': // 8-Byte Real Number
case 'decimal': // Decimal case 'decimal': // Decimal
return self::PROPERTY_TYPE_FLOAT; return self::PROPERTY_TYPE_FLOAT;
break;
case 'empty': // Empty case 'empty': // Empty
case 'null': // Null case 'null': // Null
case 'lpstr': // LPSTR case 'lpstr': // LPSTR
case 'lpwstr': // LPWSTR case 'lpwstr': // LPWSTR
case 'bstr': // Basic String case 'bstr': // Basic String
return self::PROPERTY_TYPE_STRING; return self::PROPERTY_TYPE_STRING;
break;
case 'date': // Date and Time case 'date': // Date and Time
case 'filetime': // File Time case 'filetime': // File Time
return self::PROPERTY_TYPE_DATE; return self::PROPERTY_TYPE_DATE;
break;
case 'bool': // Boolean case 'bool': // Boolean
return self::PROPERTY_TYPE_BOOLEAN; return self::PROPERTY_TYPE_BOOLEAN;
break;
case 'cy': // Currency case 'cy': // Currency
case 'error': // Error Status Code case 'error': // Error Status Code
case 'vector': // Vector case 'vector': // Vector
@ -576,7 +571,6 @@ class DocumentProperties
case 'clsid': // Class ID case 'clsid': // Class ID
case 'cf': // Clipboard Data case 'cf': // Clipboard Data
return self::PROPERTY_TYPE_UNKNOWN; return self::PROPERTY_TYPE_UNKNOWN;
break;
} }
return self::PROPERTY_TYPE_UNKNOWN; return self::PROPERTY_TYPE_UNKNOWN;
} }

View File

@ -34,14 +34,14 @@ class CheckBox
/** /**
* Text style * Text style
* *
* @var Font * @var string|Font
*/ */
private $fontStyle; private $fontStyle;
/** /**
* Paragraph style * Paragraph style
* *
* @var Paragraph * @var string|Paragraph
*/ */
private $paragraphStyle; private $paragraphStyle;
@ -50,8 +50,8 @@ class CheckBox
* *
* @param string $name * @param string $name
* @param string $text * @param string $text
* @param Font $fontStyle * @param mixed $fontStyle
* @param Paragraph $paragraphStyle * @param mixed $paragraphStyle
*/ */
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null) public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
{ {
@ -66,9 +66,9 @@ class CheckBox
/** /**
* Set Text style * Set Text style
* *
* @param Font $style * @param mixed $style
* @param Paragraph $paragraphStyle * @param mixed $paragraphStyle
* @return Font * @return string|Font
*/ */
public function setFontStyle($style = null, $paragraphStyle = null) public function setFontStyle($style = null, $paragraphStyle = null)
{ {
@ -90,7 +90,7 @@ class CheckBox
/** /**
* Get Text style * Get Text style
* *
* @return Font * @return string|Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -100,8 +100,8 @@ class CheckBox
/** /**
* Set Paragraph style * Set Paragraph style
* *
* @param Paragraph $style * @param mixed $style
* @return Paragraph * @return string|Paragraph
*/ */
public function setParagraphStyle($style = null) public function setParagraphStyle($style = null)
{ {
@ -121,7 +121,7 @@ class CheckBox
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return Paragraph * @return string|Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -27,14 +27,14 @@ class PreserveText
/** /**
* Text style * Text style
* *
* @var \PhpOffice\PhpWord\Style\Font * @var string|Font
*/ */
private $_styleFont; private $_styleFont;
/** /**
* Paragraph style * Paragraph style
* *
* @var \PhpOffice\PhpWord\Style\Paragraph * @var string|Paragraph
*/ */
private $_styleParagraph; private $_styleParagraph;
@ -45,7 +45,7 @@ class PreserveText
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText * @return $this
*/ */
public function __construct($text = null, $styleFont = null, $styleParagraph = null) public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{ {
@ -88,7 +88,7 @@ class PreserveText
/** /**
* Get Text style * Get Text style
* *
* @return \PhpOffice\PhpWord\Style\Font * @return string|Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -98,7 +98,7 @@ class PreserveText
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return \PhpOffice\PhpWord\Style\Paragraph * @return string|Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -41,14 +41,14 @@ class Link
/** /**
* Link style * Link style
* *
* @var \PhpOffice\PhpWord\Style\Font * @var string|Font
*/ */
private $_styleFont; private $_styleFont;
/** /**
* Paragraph style * Paragraph style
* *
* @var \PhpOffice\PhpWord\Style\Paragraph * @var string|Paragraph
*/ */
private $_styleParagraph; private $_styleParagraph;
@ -140,7 +140,7 @@ class Link
/** /**
* Get Text style * Get Text style
* *
* @return \PhpOffice\PhpWord\Style\Font * @return string|Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -150,7 +150,7 @@ class Link
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return \PhpOffice\PhpWord\Style\Paragraph * @return string|Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -27,14 +27,14 @@ class Text
/** /**
* Text style * Text style
* *
* @var \PhpOffice\PhpWord\Style\Font * @var string|Font
*/ */
private $fontStyle; private $fontStyle;
/** /**
* Paragraph style * Paragraph style
* *
* @var \PhpOffice\PhpWord\Style\Paragraph * @var string|Paragraph
*/ */
private $paragraphStyle; private $paragraphStyle;
@ -42,8 +42,8 @@ class Text
* Create a new Text Element * Create a new Text Element
* *
* @param string $text * @param string $text
* @param null|array|\PhpOffice\PhpWord\Style\Font $fontStyle * @param mixed $fontStyle
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle * @param mixed $paragraphStyle
*/ */
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{ {
@ -55,9 +55,9 @@ class Text
/** /**
* Set Text style * Set Text style
* *
* @param null|array|\PhpOffice\PhpWord\Style\Font $style * @param string|array|Font $style
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle * @param string|array|Paragraph $paragraphStyle
* @return \PhpOffice\PhpWord\Style\Font * @return string|Font
*/ */
public function setFontStyle($style = null, $paragraphStyle = null) public function setFontStyle($style = null, $paragraphStyle = null)
{ {
@ -79,7 +79,7 @@ class Text
/** /**
* Get Text style * Get Text style
* *
* @return \PhpOffice\PhpWord\Style\Font * @return string|Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -89,8 +89,8 @@ class Text
/** /**
* Set Paragraph style * Set Paragraph style
* *
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style * @param string|array|Paragraph $style
* @return null|\PhpOffice\PhpWord\Style\Paragraph * @return string|Paragraph
*/ */
public function setParagraphStyle($style = null) public function setParagraphStyle($style = null)
{ {
@ -110,7 +110,7 @@ class Text
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return \PhpOffice\PhpWord\Style\Paragraph * @return string|Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -20,14 +20,14 @@ class TextBreak
/** /**
* Paragraph style * Paragraph style
* *
* @var \PhpOffice\PhpWord\Style\Pagaraph * @var string|Paragraph
*/ */
private $paragraphStyle = null; private $paragraphStyle = null;
/** /**
* Text style * Text style
* *
* @var \PhpOffice\PhpWord\Style\Font * @var string|Font
*/ */
private $fontStyle = null; private $fontStyle = null;
@ -50,9 +50,9 @@ class TextBreak
/** /**
* Set Text style * Set Text style
* *
* @param null|array|\PhpOffice\PhpWord\Style\Font $style * @param mixed $style
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle * @param mixed $paragraphStyle
* @return \PhpOffice\PhpWord\Style\Font * @return string|Font
*/ */
public function setFontStyle($style = null, $paragraphStyle = null) public function setFontStyle($style = null, $paragraphStyle = null)
{ {
@ -72,7 +72,7 @@ class TextBreak
/** /**
* Get Text style * Get Text style
* *
* @return \PhpOffice\PhpWord\Style\Font * @return string|Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -82,8 +82,8 @@ class TextBreak
/** /**
* Set Paragraph style * Set Paragraph style
* *
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style * @param string|array|Paragraph $style
* @return null|\PhpOffice\PhpWord\Style\Paragraph * @return string|Paragraph
*/ */
public function setParagraphStyle($style = null) public function setParagraphStyle($style = null)
{ {
@ -101,7 +101,7 @@ class TextBreak
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return \PhpOffice\PhpWord\Style\Paragraph * @return string|Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -12,6 +12,7 @@ namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\InvalidImageException; use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String; use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
/** /**
@ -22,7 +23,7 @@ class TextRun
/** /**
* Paragraph style * Paragraph style
* *
* @var \PhpOffice\PhpWord\Style\Paragraph * @var Paragraph
*/ */
private $_styleParagraph; private $_styleParagraph;
@ -123,8 +124,8 @@ class TextRun
* Add TextBreak * Add TextBreak
* *
* @param int $count * @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle * @param mixed $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle * @param mixed $paragraphStyle
*/ */
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{ {
@ -161,7 +162,7 @@ class TextRun
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return \PhpOffice\PhpWord\Style\Paragraph * @return string|Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -479,8 +479,8 @@ class Font
/** /**
* Set background color * Set background color
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_Style_Font * @return $this
*/ */
public function setBgColor($pValue = null) public function setBgColor($pValue = null)
{ {

View File

@ -57,7 +57,7 @@ class Row
* Set tblHeader * Set tblHeader
* *
* @param boolean $pValue * @param boolean $pValue
* @return PHPWord_Style_Row * @return $this
*/ */
public function setTblHeader($pValue = false) public function setTblHeader($pValue = false)
{ {
@ -82,7 +82,7 @@ class Row
* Set cantSplit * Set cantSplit
* *
* @param boolean $pValue * @param boolean $pValue
* @return PHPWord_Style_Row * @return $this
*/ */
public function setCantSplit($pValue = false) public function setCantSplit($pValue = false)
{ {
@ -107,7 +107,7 @@ class Row
* Set exactHeight * Set exactHeight
* *
* @param bool $pValue * @param bool $pValue
* @return PHPWord_Style_Row * @return $this
*/ */
public function setExactHeight($pValue = false) public function setExactHeight($pValue = false)
{ {

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord; namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
/** /**
* Table of contents * Table of contents
@ -26,14 +27,14 @@ class TOC
/** /**
* TOC style * TOC style
* *
* @var PhpOffice\PhpWord\Style\TOC * @var TOCStyle
*/ */
private static $_styleTOC; private static $_styleTOC;
/** /**
* Font style * Font style
* *
* @var PhpOffice\PhpWord\Style\Font|array|string * @var Font|array|string
*/ */
private static $_styleFont; private static $_styleFont;
@ -60,7 +61,7 @@ class TOC
*/ */
public function __construct($styleFont = null, $styleTOC = null) public function __construct($styleFont = null, $styleTOC = null)
{ {
self::$_styleTOC = new \PhpOffice\PhpWord\Style\TOC(); self::$_styleTOC = new TOCStyle();
if (!is_null($styleTOC) && is_array($styleTOC)) { if (!is_null($styleTOC) && is_array($styleTOC)) {
foreach ($styleTOC as $key => $value) { foreach ($styleTOC as $key => $value) {
@ -122,7 +123,7 @@ class TOC
/** /**
* Get TOC Style * Get TOC Style
* *
* @return \PhpOffice\PhpWord\Style\TOC * @return TOCStyle
*/ */
public static function getStyleTOC() public static function getStyleTOC()
{ {
@ -132,7 +133,7 @@ class TOC
/** /**
* Get Font Style * Get Font Style
* *
* @return \PhpOffice\PhpWord\Style\Font * @return Font
*/ */
public static function getStyleFont() public static function getStyleFont()
{ {

View File

@ -26,13 +26,13 @@ class ODText extends Writer implements IWriter
/** /**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable * Private unique PHPWord_Worksheet_BaseDrawing HashTable
* *
* @var \PhpOffice\PhpWord\HashTable * @var HashTable
*/ */
private $drawingHashTable; private $drawingHashTable;
/** /**
* Create new ODText writer * Create new ODText writer
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
*/ */
public function __construct(PhpWord $phpWord = null) public function __construct(PhpWord $phpWord = null)
{ {
@ -57,7 +57,7 @@ class ODText extends Writer implements IWriter
* Save PhpWord to file * Save PhpWord to file
* *
* @param string $pFilename * @param string $pFilename
* @throws \PhpOffice\PhpWord\Exceptions\Exception * @throws Exception
*/ */
public function save($pFilename = null) public function save($pFilename = null)
{ {
@ -139,7 +139,7 @@ class ODText extends Writer implements IWriter
/** /**
* Get PHPWord_Worksheet_BaseDrawing HashTable * Get PHPWord_Worksheet_BaseDrawing HashTable
* *
* @return \PhpOffice\PhpWord\HashTable * @return HashTable
*/ */
public function getDrawingHashTable() public function getDrawingHashTable()
{ {

View File

@ -35,7 +35,7 @@ class Content extends WriterPart
/** /**
* Write content file to XML format * Write content file to XML format
* *
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
* @return string XML Output * @return string XML Output
*/ */
public function writeContent(PhpWord $phpWord = null) public function writeContent(PhpWord $phpWord = null)
@ -126,7 +126,7 @@ class Content extends WriterPart
$numFonts = 0; $numFonts = 0;
if (count($styles) > 0) { if (count($styles) > 0) {
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font // Font
if ($style instanceof Font) { if ($style instanceof Font) {
$numFonts++; $numFonts++;
$name = $style->getName(); $name = $style->getName();
@ -158,7 +158,7 @@ class Content extends WriterPart
if (preg_match('#^T[0-9]+$#', $styleName) != 0 if (preg_match('#^T[0-9]+$#', $styleName) != 0
|| preg_match('#^P[0-9]+$#', $styleName) != 0 || preg_match('#^P[0-9]+$#', $styleName) != 0
) { ) {
// PhpOffice\PhpWord\Style\Font // Font
if ($style instanceof Font) { if ($style instanceof Font) {
$xmlWriter->startElement('style:style'); $xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName); $xmlWriter->writeAttribute('style:name', $styleName);
@ -244,11 +244,11 @@ class Content extends WriterPart
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof Text) { if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element); $this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) { } elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element); $this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) { } elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter); $this->writeTextBreak($xmlWriter);
} elseif ($element instanceof Link) { } elseif ($element instanceof Link) {
$this->writeUnsupportedElement($xmlWriter, 'Link'); $this->writeUnsupportedElement($xmlWriter, 'Link');
} elseif ($element instanceof Title) { } elseif ($element instanceof Title) {
@ -271,9 +271,9 @@ class Content extends WriterPart
} }
if ($pSection == $countSections) { if ($pSection == $countSections) {
$this->_writeEndSection($xmlWriter, $section); $this->writeEndSection($xmlWriter, $section);
} else { } else {
$this->_writeSection($xmlWriter, $section); $this->writeSection($xmlWriter, $section);
} }
} }
} }
@ -288,11 +288,11 @@ class Content extends WriterPart
/** /**
* Write text * Write text
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Section\Text $text * @param Text $text
* @param bool $withoutP * @param bool $withoutP
*/ */
protected function _writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false) protected function writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
{ {
$styleFont = $text->getFontStyle(); $styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle(); $styleParagraph = $text->getParagraphStyle();
@ -336,18 +336,18 @@ class Content extends WriterPart
/** /**
* Write TextRun section * Write TextRun section
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Section\TextRun $textrun * @param TextRun $textrun
* @todo Enable all other section types * @todo Enable all other section types
*/ */
protected function _writeTextRun(XMLWriter $xmlWriter, TextRun $textrun) protected function writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
{ {
$elements = $textrun->getElements(); $elements = $textrun->getElements();
$xmlWriter->startElement('text:p'); $xmlWriter->startElement('text:p');
if (count($elements) > 0) { if (count($elements) > 0) {
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element instanceof Text) { if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element, true); $this->writeText($xmlWriter, $element, true);
} }
} }
} }
@ -357,9 +357,9 @@ class Content extends WriterPart
/** /**
* Write TextBreak * Write TextBreak
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
*/ */
protected function _writeTextBreak(XMLWriter $xmlWriter = null) protected function writeTextBreak(XMLWriter $xmlWriter = null)
{ {
$xmlWriter->startElement('text:p'); $xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard'); $xmlWriter->writeAttribute('text:style-name', 'Standard');
@ -370,20 +370,20 @@ class Content extends WriterPart
/** /**
* Write end section * Write end section
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section * @param Section $section
*/ */
private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null) private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
{ {
} }
/** /**
* Write section * Write section
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section * @param Section $section
*/ */
private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null) private function writeSection(XMLWriter $xmlWriter = null, Section $section = null)
{ {
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
@ -391,7 +391,7 @@ class Content extends WriterPart
/** /**
* Write unsupported element * Write unsupported element
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param string $element * @param string $element
*/ */
private function writeUnsupportedElement($xmlWriter, $element) private function writeUnsupportedElement($xmlWriter, $element)

View File

@ -21,7 +21,7 @@ class Manifest extends WriterPart
/** /**
* Write Manifest file to XML format * Write Manifest file to XML format
* *
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
* @return string XML Output * @return string XML Output
*/ */
public function writeManifest(PhpWord $phpWord = null) public function writeManifest(PhpWord $phpWord = null)
@ -64,7 +64,7 @@ class Manifest extends WriterPart
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) { for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) { if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension()); $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
$mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath()); $mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
$xmlWriter->startElement('manifest:file-entry'); $xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType); $xmlWriter->writeAttribute('manifest:media-type', $mimeType);
@ -97,9 +97,9 @@ class Manifest extends WriterPart
* *
* @param string $pFile Filename * @param string $pFile Filename
* @return string Mime Type * @return string Mime Type
* @throws \PhpOffice\PhpWord\Exceptions\Exception * @throws Exception
*/ */
private function _getImageMimeType($pFile = '') private function getImageMimeType($pFile = '')
{ {
if (file_exists($pFile)) { if (file_exists($pFile)) {
$image = getimagesize($pFile); $image = getimagesize($pFile);

View File

@ -20,7 +20,7 @@ class Meta extends WriterPart
/** /**
* Write Meta file to XML format * Write Meta file to XML format
* *
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
* @return string XML Output * @return string XML Output
*/ */
public function writeMeta(PhpWord $phpWord = null) public function writeMeta(PhpWord $phpWord = null)

View File

@ -19,7 +19,7 @@ class Mimetype extends WriterPart
/** /**
* Write Mimetype to Text format * Write Mimetype to Text format
* *
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
* @return string Text Output * @return string Text Output
*/ */
public function writeMimetype(PhpWord $phpWord = null) public function writeMimetype(PhpWord $phpWord = null)

View File

@ -24,7 +24,7 @@ class Styles extends WriterPart
/** /**
* Write Styles file to XML format * Write Styles file to XML format
* *
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
* @return string XML Output * @return string XML Output
*/ */
public function writeStyles(PhpWord $phpWord = null) public function writeStyles(PhpWord $phpWord = null)
@ -73,7 +73,7 @@ class Styles extends WriterPart
$numFonts = 0; $numFonts = 0;
if (count($styles) > 0) { if (count($styles) > 0) {
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font // Font
if ($style instanceof Font) { if ($style instanceof Font) {
$numFonts++; $numFonts++;
$name = $style->getName(); $name = $style->getName();
@ -144,7 +144,7 @@ class Styles extends WriterPart
if (preg_match('#^T[0-9]+$#', $styleName) == 0 if (preg_match('#^T[0-9]+$#', $styleName) == 0
&& preg_match('#^P[0-9]+$#', $styleName) == 0 && preg_match('#^P[0-9]+$#', $styleName) == 0
) { ) {
// PhpOffice\PhpWord\Style\Font // Font
if ($style instanceof Font) { if ($style instanceof Font) {
// style:style // style:style
$xmlWriter->startElement('style:style'); $xmlWriter->startElement('style:style');
@ -168,7 +168,7 @@ class Styles extends WriterPart
$xmlWriter->endElement(); $xmlWriter->endElement();
$xmlWriter->endElement(); $xmlWriter->endElement();
} elseif ($style instanceof Paragraph) { } elseif ($style instanceof Paragraph) {
// PhpOffice\PhpWord\Style\Paragraph // Paragraph
// style:style // style:style
$xmlWriter->startElement('style:style'); $xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName); $xmlWriter->writeAttribute('style:name', $styleName);
@ -183,7 +183,7 @@ class Styles extends WriterPart
$xmlWriter->endElement(); $xmlWriter->endElement();
} elseif ($style instanceof Table) { } elseif ($style instanceof Table) {
// PhpOffice\PhpWord\Style\Table // Table
} }
} }
} }

View File

@ -36,7 +36,7 @@ class RTF extends Writer implements IWriter
/** /**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable * Private unique PHPWord_Worksheet_BaseDrawing HashTable
* *
* @var \PhpOffice\PhpWord\HashTable * @var HashTable
*/ */
private $drawingHashTable; private $drawingHashTable;
@ -63,7 +63,7 @@ class RTF extends Writer implements IWriter
/** /**
* Create new RTF writer * Create new RTF writer
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
*/ */
public function __construct(PhpWord $phpWord = null) public function __construct(PhpWord $phpWord = null)
{ {
@ -78,7 +78,7 @@ class RTF extends Writer implements IWriter
* Save PhpWord to file * Save PhpWord to file
* *
* @param string $pFilename * @param string $pFilename
* @throws \PhpOffice\PhpWord\Exceptions\Exception * @throws Exception
*/ */
public function save($pFilename = null) public function save($pFilename = null)
{ {
@ -98,7 +98,7 @@ class RTF extends Writer implements IWriter
/** /**
* Get PHPWord_Worksheet_BaseDrawing HashTable * Get PHPWord_Worksheet_BaseDrawing HashTable
* *
* @return \PhpOffice\PhpWord\HashTable * @return HashTable
*/ */
public function getDrawingHashTable() public function getDrawingHashTable()
{ {
@ -179,10 +179,9 @@ class RTF extends Writer implements IWriter
// Browse styles // Browse styles
$styles = Style::getStyles(); $styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) { if (count($styles) > 0) {
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font // Font
if ($style instanceof Font) { if ($style instanceof Font) {
if (in_array($style->getName(), $arrFonts) == false) { if (in_array($style->getName(), $arrFonts) == false) {
$arrFonts[] = $style->getName(); $arrFonts[] = $style->getName();
@ -232,7 +231,6 @@ class RTF extends Writer implements IWriter
// Browse styles // Browse styles
$styles = Style::getStyles(); $styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) { if (count($styles) > 0) {
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// Font // Font

View File

@ -34,19 +34,19 @@ class Word2007 extends Writer implements IWriter
* *
* @var array * @var array
*/ */
private $_imageTypes = array(); private $imageTypes = array();
/** /**
* Types of objects * Types of objects
* *
* @var array * @var array
*/ */
private $_objectTypes = array(); private $objectTypes = array();
/** /**
* Create new Word2007 writer * Create new Word2007 writer
* *
* @param PhpOffice\PhpWord\PhpWord * @param PhpWord
*/ */
public function __construct(PhpWord $phpWord = null) public function __construct(PhpWord $phpWord = null)
{ {
@ -167,8 +167,8 @@ class Word2007 extends Writer implements IWriter
$objZip->addFromString( $objZip->addFromString(
'[Content_Types].xml', '[Content_Types].xml',
$this->getWriterPart('contenttypes')->writeContentTypes( $this->getWriterPart('contenttypes')->writeContentTypes(
$this->_imageTypes, $this->imageTypes,
$this->_objectTypes, $this->objectTypes,
$_cHdrs, $_cHdrs,
$footers $footers
) )
@ -235,12 +235,12 @@ class Word2007 extends Writer implements IWriter
if ($imageExtension === 'jpeg') { if ($imageExtension === 'jpeg') {
$imageExtension = 'jpg'; $imageExtension = 'jpg';
} }
if (!in_array($imageType, $this->_imageTypes)) { if (!in_array($imageType, $this->imageTypes)) {
$this->_imageTypes[$imageExtension] = $imageType; $this->imageTypes[$imageExtension] = $imageType;
} }
} else { } else {
if (!in_array($extension, $this->_objectTypes)) { if (!in_array($extension, $this->objectTypes)) {
$this->_objectTypes[] = $extension; $this->objectTypes[] = $extension;
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -19,12 +19,12 @@ class ContentTypes extends WriterPart
{ {
/** /**
* Write [Content_Types].xml * Write [Content_Types].xml
* @param array $_imageTypes * @param array $imageTypes
* @param array $_objectTypes * @param array $objectTypes
* @param int $_cHdrs * @param int $_cHdrs
* @param array $footers * @param array $footers
*/ */
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers) public function writeContentTypes($imageTypes, $objectTypes, $_cHdrs, $footers)
{ {
// Create XML writer // Create XML writer
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
@ -37,27 +37,27 @@ class ContentTypes extends WriterPart
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
// Rels // Rels
$this->_writeDefaultContentType( $this->writeDefaultContentType(
$xmlWriter, $xmlWriter,
'rels', 'rels',
'application/vnd.openxmlformats-package.relationships+xml' 'application/vnd.openxmlformats-package.relationships+xml'
); );
// XML // XML
$this->_writeDefaultContentType( $this->writeDefaultContentType(
$xmlWriter, $xmlWriter,
'xml', 'xml',
'application/xml' 'application/xml'
); );
// Add media content-types // Add media content-types
foreach ($_imageTypes as $key => $value) { foreach ($imageTypes as $key => $value) {
$this->_writeDefaultContentType($xmlWriter, $key, $value); $this->writeDefaultContentType($xmlWriter, $key, $value);
} }
// Add embedding content-types // Add embedding content-types
if (count($_objectTypes) > 0) { if (count($objectTypes) > 0) {
$this->_writeDefaultContentType( $this->writeDefaultContentType(
$xmlWriter, $xmlWriter,
'bin', 'bin',
'application/vnd.openxmlformats-officedocument.oleObject' 'application/vnd.openxmlformats-officedocument.oleObject'
@ -65,76 +65,76 @@ class ContentTypes extends WriterPart
} }
// DocProps // DocProps
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/docProps/app.xml', '/docProps/app.xml',
'application/vnd.openxmlformats-officedocument.extended-properties+xml' 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
); );
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/docProps/core.xml', '/docProps/core.xml',
'application/vnd.openxmlformats-package.core-properties+xml' 'application/vnd.openxmlformats-package.core-properties+xml'
); );
// Document // Document
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/document.xml', '/word/document.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
); );
// Styles // Styles
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/styles.xml', '/word/styles.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
); );
// Numbering // Numbering
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/numbering.xml', '/word/numbering.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
); );
// Settings // Settings
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/settings.xml', '/word/settings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
); );
// Theme1 // Theme1
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/theme/theme1.xml', '/word/theme/theme1.xml',
'application/vnd.openxmlformats-officedocument.theme+xml' 'application/vnd.openxmlformats-officedocument.theme+xml'
); );
// WebSettings // WebSettings
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/webSettings.xml', '/word/webSettings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
); );
// Font Table // Font Table
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/fontTable.xml', '/word/fontTable.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
); );
// Footnotes // Footnotes
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/footnotes.xml', '/word/footnotes.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
); );
for ($i = 1; $i <= $_cHdrs; $i++) { for ($i = 1; $i <= $_cHdrs; $i++) {
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/header' . $i . '.xml', '/word/header' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
@ -143,7 +143,7 @@ class ContentTypes extends WriterPart
for ($i = 1; $i <= count($footers); $i++) { for ($i = 1; $i <= count($footers); $i++) {
if (!is_null($footers[$i])) { if (!is_null($footers[$i])) {
$this->_writeOverrideContentType( $this->writeOverrideContentType(
$xmlWriter, $xmlWriter,
'/word/footer' . $i . '.xml', '/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
@ -158,32 +158,15 @@ class ContentTypes extends WriterPart
return $xmlWriter->getData(); return $xmlWriter->getData();
} }
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
private function _getImageMimeType($pFile = '')
{
if (file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
/** /**
* Write Default XML element * Write Default XML element
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer * @param XMLWriter $xmlWriter XML Writer
* @param string $pPartname Part name * @param string $pPartname Part name
* @param string $pContentType Content type * @param string $pContentType Content type
* @throws \PhpOffice\PhpWord\Exceptions\Exception * @throws Exception
*/ */
private function _writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '') private function writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{ {
if ($pPartname != '' && $pContentType != '') { if ($pPartname != '' && $pContentType != '') {
// Write content type // Write content type
@ -199,12 +182,12 @@ class ContentTypes extends WriterPart
/** /**
* Write Override XML element * Write Override XML element
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param string $pPartname Part name * @param string $pPartname Part name
* @param string $pContentType Content type * @param string $pContentType Content type
* @throws \PhpOffice\PhpWord\Exceptions\Exception * @throws Exception
*/ */
private function _writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '') private function writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{ {
if ($pPartname != '' && $pContentType != '') { if ($pPartname != '' && $pContentType != '') {
// Write content type // Write content type
@ -216,4 +199,21 @@ class ContentTypes extends WriterPart
throw new Exception("Invalid parameters passed."); throw new Exception("Invalid parameters passed.");
} }
} }
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws Exception
*/
private function getImageMimeType($pFile = '')
{
if (file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
} }

View File

@ -110,7 +110,7 @@ class DocProps extends WriterPart
/** /**
* Write docProps/core.xml * Write docProps/core.xml
* *
* @param PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
*/ */
public function writeDocPropsCore(PhpWord $phpWord = null) public function writeDocPropsCore(PhpWord $phpWord = null)
{ {

View File

@ -36,7 +36,7 @@ class Document extends Base
/** /**
* Write word/document.xml * Write word/document.xml
* *
* @param PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
*/ */
public function writeDocument(PhpWord $phpWord = null) public function writeDocument(PhpWord $phpWord = null)
{ {
@ -72,38 +72,38 @@ class Document extends Base
$_elements = $section->getElements(); $_elements = $section->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof Text) { if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element); $this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) { } elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element); $this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof Link) { } elseif ($element instanceof Link) {
$this->_writeLink($xmlWriter, $element); $this->writeLink($xmlWriter, $element);
} elseif ($element instanceof Title) { } elseif ($element instanceof Title) {
$this->_writeTitle($xmlWriter, $element); $this->writeTitle($xmlWriter, $element);
} elseif ($element instanceof TextBreak) { } elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element); $this->writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof PageBreak) { } elseif ($element instanceof PageBreak) {
$this->_writePageBreak($xmlWriter); $this->writePageBreak($xmlWriter);
} elseif ($element instanceof Table) { } elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element); $this->writeTable($xmlWriter, $element);
} elseif ($element instanceof ListItem) { } elseif ($element instanceof ListItem) {
$this->_writeListItem($xmlWriter, $element); $this->writeListItem($xmlWriter, $element);
} elseif ($element instanceof Image) { } elseif ($element instanceof Image) {
$this->_writeImage($xmlWriter, $element); $this->writeImage($xmlWriter, $element);
} elseif ($element instanceof Object) { } elseif ($element instanceof Object) {
$this->_writeObject($xmlWriter, $element); $this->writeObject($xmlWriter, $element);
} elseif ($element instanceof TOC) { } elseif ($element instanceof TOC) {
$this->_writeTOC($xmlWriter); $this->writeTOC($xmlWriter);
} elseif ($element instanceof Footnote) { } elseif ($element instanceof Footnote) {
$this->_writeFootnote($xmlWriter, $element); $this->writeFootnote($xmlWriter, $element);
} elseif ($element instanceof CheckBox) { } elseif ($element instanceof CheckBox) {
$this->_writeCheckBox($xmlWriter, $element); $this->writeCheckBox($xmlWriter, $element);
} }
} }
if ($pSection == $countSections) { if ($pSection == $countSections) {
$this->_writeEndSection($xmlWriter, $section); $this->writeEndSection($xmlWriter, $section);
} else { } else {
$this->_writeSection($xmlWriter, $section); $this->writeSection($xmlWriter, $section);
} }
} }
} }
@ -118,14 +118,14 @@ class Document extends Base
/** /**
* Write begin section * Write begin section
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section * @param Section $section
*/ */
private function _writeSection(XMLWriter $xmlWriter, Section $section) private function writeSection(XMLWriter $xmlWriter, Section $section)
{ {
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
$this->_writeEndSection($xmlWriter, $section, 3); $this->writeEndSection($xmlWriter, $section, 3);
$xmlWriter->endElement(); $xmlWriter->endElement();
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
@ -133,10 +133,10 @@ class Document extends Base
/** /**
* Write end section * Write end section
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section * @param Section $section
*/ */
private function _writeEndSection(XMLWriter $xmlWriter, Section $section) private function writeEndSection(XMLWriter $xmlWriter, Section $section)
{ {
$settings = $section->getSettings(); $settings = $section->getSettings();
$_headers = $section->getHeaders(); $_headers = $section->getHeaders();
@ -272,9 +272,9 @@ class Document extends Base
/** /**
* Write page break element * Write page break element
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
*/ */
private function _writePageBreak(XMLWriter $xmlWriter) private function writePageBreak(XMLWriter $xmlWriter)
{ {
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
@ -285,122 +285,12 @@ class Document extends Base
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
/**
* Write list item element
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\ListItem $listItem
*/
public function _writeListItem(XMLWriter $xmlWriter, ListItem $listItem)
{
$textObject = $listItem->getTextObject();
$text = $textObject->getText();
$styleParagraph = $textObject->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType();
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr');
if ($SpIsObject) {
$this->_writeParagraphStyle($xmlWriter, $styleParagraph, true);
} elseif (!$SpIsObject && !is_null($styleParagraph)) {
$xmlWriter->startElement('w:pStyle');
$xmlWriter->writeAttribute('w:val', $styleParagraph);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:numPr');
$xmlWriter->startElement('w:ilvl');
$xmlWriter->writeAttribute('w:val', $depth);
$xmlWriter->endElement();
$xmlWriter->startElement('w:numId');
$xmlWriter->writeAttribute('w:val', $listType);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
$this->_writeText($xmlWriter, $textObject, true);
$xmlWriter->endElement();
}
/**
* Write object element
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\Object $object
*/
protected function _writeObject(XMLWriter $xmlWriter, Object $object)
{
$rIdObject = $object->getRelationId();
$rIdImage = $object->getImageRelationId();
$shapeId = md5($rIdObject . '_' . $rIdImage);
$objectId = $object->getObjectId();
$style = $object->getStyle();
$width = $style->getWidth();
$height = $style->getHeight();
$align = $style->getAlign();
$xmlWriter->startElement('w:p');
if (!is_null($align)) {
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:jc');
$xmlWriter->writeAttribute('w:val', $align);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:object');
$xmlWriter->writeAttribute('w:dxaOrig', '249');
$xmlWriter->writeAttribute('w:dyaOrig', '160');
$xmlWriter->startElement('v:shape');
$xmlWriter->writeAttribute('id', $shapeId);
$xmlWriter->writeAttribute('type', '#_x0000_t75');
$xmlWriter->writeAttribute('style', 'width:104px;height:67px');
$xmlWriter->writeAttribute('o:ole', '');
$xmlWriter->startElement('v:imagedata');
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage);
$xmlWriter->writeAttribute('o:title', '');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('o:OLEObject');
$xmlWriter->writeAttribute('Type', 'Embed');
$xmlWriter->writeAttribute('ProgID', 'Package');
$xmlWriter->writeAttribute('ShapeID', $shapeId);
$xmlWriter->writeAttribute('DrawAspect', 'Icon');
$xmlWriter->writeAttribute('ObjectID', '_' . $objectId);
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
}
/** /**
* Write TOC element * Write TOC element
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
*/ */
private function _writeTOC(XMLWriter $xmlWriter) private function writeTOC(XMLWriter $xmlWriter)
{ {
$titles = TOC::getTitles(); $titles = TOC::getTitles();
$styleFont = TOC::getStyleFont(); $styleFont = TOC::getStyleFont();
@ -421,7 +311,7 @@ class Document extends Base
$xmlWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
if ($isObject && !is_null($styleFont->getParagraphStyle())) { if ($isObject && !is_null($styleFont->getParagraphStyle())) {
$this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle()); $this->writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
} }
if ($indent > 0) { if ($indent > 0) {
@ -479,7 +369,7 @@ class Document extends Base
$xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
if ($isObject) { if ($isObject) {
$this->_writeTextStyle($xmlWriter, $styleFont); $this->writeFontStyle($xmlWriter, $styleFont);
} }
$xmlWriter->startElement('w:t'); $xmlWriter->startElement('w:t');

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Word2007 document rels part writer * Word2007 document rels part writer
*/ */
class DocumentRels extends WriterPart class DocumentRels extends Base
{ {
/** /**
* Write word/_rels/document.xml.rels * Write word/_rels/document.xml.rels
@ -35,7 +35,7 @@ class DocumentRels extends WriterPart
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationship word/document.xml // Relationship word/document.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
1, 1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
@ -43,7 +43,7 @@ class DocumentRels extends WriterPart
); );
// Relationship word/numbering.xml // Relationship word/numbering.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
2, 2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
@ -51,7 +51,7 @@ class DocumentRels extends WriterPart
); );
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
3, 3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
@ -59,7 +59,7 @@ class DocumentRels extends WriterPart
); );
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
4, 4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
@ -67,7 +67,7 @@ class DocumentRels extends WriterPart
); );
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
5, 5,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
@ -75,7 +75,7 @@ class DocumentRels extends WriterPart
); );
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
6, 6,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
@ -89,7 +89,7 @@ class DocumentRels extends WriterPart
$relationId = $relation['rID']; $relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : ''; $targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
$relationId, $relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
@ -128,7 +128,7 @@ class DocumentRels extends WriterPart
$relationName = $relation['target']; $relationName = $relation['target'];
$relationId = $relation['rID']; $relationId = $relation['rID'];
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
$relationId, $relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
@ -142,36 +142,4 @@ class DocumentRels extends WriterPart
// Return // Return
return $xmlWriter->getData(); return $xmlWriter->getData();
} }
/**
* Write individual rels entry
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID
* @param string $pType Relationship type
* @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode
*/
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
} }

View File

@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text; use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak; use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun; use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Footer as FooterElement;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
@ -25,9 +26,9 @@ class Footer extends Base
/** /**
* Write word/footnotes.xml * Write word/footnotes.xml
* *
* @param PhpOffice\PhpWord\Section\Footer $footer * @param FooterElement $footer
*/ */
public function writeFooter(\PhpOffice\PhpWord\Section\Footer $footer) public function writeFooter(FooterElement $footer)
{ {
// Create XML writer // Create XML writer
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
@ -50,17 +51,17 @@ class Footer extends Base
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof Text) { if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element); $this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) { } elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element); $this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) { } elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element); $this->writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) { } elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element); $this->writeTable($xmlWriter, $element);
} elseif ($element instanceof Image) { } elseif ($element instanceof Image) {
$this->_writeImage($xmlWriter, $element); $this->writeImage($xmlWriter, $element);
} elseif ($element instanceof PreserveText) { } elseif ($element instanceof PreserveText) {
$this->_writePreserveText($xmlWriter, $element); $this->writePreserveText($xmlWriter, $element);
} }
} }

View File

@ -77,26 +77,18 @@ class Footnotes extends Base
/** /**
* Write footnote content, overrides method in parent class * Write footnote content, overrides method in parent class
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\Footnote $footnote * @param Footnote $footnote
* @param boolean $withoutP
*/ */
private function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote) protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
{ {
$xmlWriter->startElement('w:footnote'); $xmlWriter->startElement('w:footnote');
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId()); $xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
// Paragraph style // Paragraph style
$paragraphStyle = $footnote->getParagraphStyle(); $styleParagraph = $footnote->getParagraphStyle();
$spIsObject = ($paragraphStyle instanceof Paragraph) ? true : false; $this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
if ($spIsObject) {
$this->_writeParagraphStyle($xmlWriter, $paragraphStyle);
} elseif (!$spIsObject && !is_null($paragraphStyle)) {
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:pStyle');
$xmlWriter->writeAttribute('w:val', $paragraphStyle);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
// Reference symbol // Reference symbol
$xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rPr');
@ -118,9 +110,9 @@ class Footnotes extends Base
if (count($elements) > 0) { if (count($elements) > 0) {
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element instanceof Text) { if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element, true); $this->writeText($xmlWriter, $element, true);
} elseif ($element instanceof Link) { } elseif ($element instanceof Link) {
$this->_writeLink($xmlWriter, $element, true); $this->writeLink($xmlWriter, $element, true);
} elseif ($element instanceof TextBreak) { } elseif ($element instanceof TextBreak) {
$xmlWriter->writeElement('w:br'); $xmlWriter->writeElement('w:br');
} }

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Word2007 footnotes rel part writer * Word2007 footnotes rel part writer
*/ */
class FootnotesRels extends WriterPart class FootnotesRels extends Base
{ {
/** /**
* Write word/_rels/footnotes.xml.rels * Write word/_rels/footnotes.xml.rels
@ -41,7 +41,7 @@ class FootnotesRels extends WriterPart
$relationId = $relation['rID']; $relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : ''; $targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode); $this->writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
} }
$xmlWriter->endElement(); $xmlWriter->endElement();
@ -49,36 +49,4 @@ class FootnotesRels extends WriterPart
// Return // Return
return $xmlWriter->getData(); return $xmlWriter->getData();
} }
/**
* Write individual rels entry
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID
* @param string $pType Relationship type
* @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode
*/
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
} }

View File

@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text; use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak; use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun; use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Header as HeaderElement;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
@ -25,9 +26,9 @@ class Header extends Base
/** /**
* Write word/headerx.xml * Write word/headerx.xml
* *
* @param PhpOffice\PhpWord\Section\Header $header * @param HeaderElement $header
*/ */
public function writeHeader(\PhpOffice\PhpWord\Section\Header $header) public function writeHeader(HeaderElement $header)
{ {
// Create XML writer // Create XML writer
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
@ -51,21 +52,21 @@ class Header extends Base
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof Text) { if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element); $this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) { } elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element); $this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) { } elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element); $this->writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) { } elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element); $this->writeTable($xmlWriter, $element);
} elseif ($element instanceof Image) { } elseif ($element instanceof Image) {
if (!$element->getIsWatermark()) { if (!$element->getIsWatermark()) {
$this->_writeImage($xmlWriter, $element); $this->writeImage($xmlWriter, $element);
} else { } else {
$this->_writeWatermark($xmlWriter, $element); $this->writeWatermark($xmlWriter, $element);
} }
} elseif ($element instanceof PreserveText) { } elseif ($element instanceof PreserveText) {
$this->_writePreserveText($xmlWriter, $element); $this->writePreserveText($xmlWriter, $element);
} }
} }

View File

@ -16,12 +16,12 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Word2007 rels part writer * Word2007 rels part writer
*/ */
class Rels extends WriterPart class Rels extends Base
{ {
/** /**
* Write _rels/.rels * Write _rels/.rels
* *
* @param PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
*/ */
public function writeRelationships(PhpWord $phpWord = null) public function writeRelationships(PhpWord $phpWord = null)
{ {
@ -38,7 +38,7 @@ class Rels extends WriterPart
$relationId = 1; $relationId = 1;
// Relationship word/document.xml // Relationship word/document.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
$relationId, $relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
@ -46,7 +46,7 @@ class Rels extends WriterPart
); );
// Relationship docProps/core.xml // Relationship docProps/core.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
++$relationId, ++$relationId,
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
@ -54,7 +54,7 @@ class Rels extends WriterPart
); );
// Relationship docProps/app.xml // Relationship docProps/app.xml
$this->_writeRelationship( $this->writeRelationship(
$xmlWriter, $xmlWriter,
++$relationId, ++$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
@ -65,37 +65,4 @@ class Rels extends WriterPart
return $xmlWriter->getData(); return $xmlWriter->getData();
} }
/**
* Write Override content type
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID. rId will be prepended!
* @param string $pType Relationship type
* @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
} }

View File

@ -14,28 +14,20 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\Table;
/** /**
* Word2007 styles part writer * Word2007 styles part writer
*/ */
class Styles extends Base class Styles extends Base
{ {
/**
* PhpWord object
*
* @var PhpWord
*/
private $phpWord;
/** /**
* Write word/styles.xml * Write word/styles.xml
* *
* @param PhpOffice\PhpWord\PhpWord $phpWord * @param PhpWord $phpWord
*/ */
public function writeStyles(PhpWord $phpWord = null) public function writeStyles(PhpWord $phpWord = null)
{ {
$this->phpWord = $phpWord;
// Create XML writer // Create XML writer
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
@ -52,7 +44,7 @@ class Styles extends Base
); );
// Write default styles // Write default styles
$styles = Style::getStyles(); $styles = Style::getStyles();
$this->writeDefaultStyles($xmlWriter, $styles); $this->writeDefaultStyles($xmlWriter, $phpWord, $styles);
// Write other styles // Write other styles
if (count($styles) > 0) { if (count($styles) > 0) {
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
@ -94,10 +86,10 @@ class Styles extends Base
$xmlWriter->startElement('w:basedOn'); $xmlWriter->startElement('w:basedOn');
$xmlWriter->writeAttribute('w:val', 'Normal'); $xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement(); $xmlWriter->endElement();
$this->_writeParagraphStyle($xmlWriter, $paragraphStyle); $this->writeParagraphStyle($xmlWriter, $paragraphStyle);
} }
$this->_writeTextStyle($xmlWriter, $style); $this->writeFontStyle($xmlWriter, $style);
$xmlWriter->endElement(); $xmlWriter->endElement();
@ -127,10 +119,10 @@ class Styles extends Base
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
$this->_writeParagraphStyle($xmlWriter, $style); $this->writeParagraphStyle($xmlWriter, $style);
$xmlWriter->endElement(); $xmlWriter->endElement();
} elseif ($style instanceof \PhpOffice\PhpWord\Style\Table) { } elseif ($style instanceof Table) {
$xmlWriter->startElement('w:style'); $xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'table'); $xmlWriter->writeAttribute('w:type', 'table');
$xmlWriter->writeAttribute('w:customStyle', '1'); $xmlWriter->writeAttribute('w:customStyle', '1');
@ -144,7 +136,7 @@ class Styles extends Base
$xmlWriter->writeAttribute('w:val', '99'); $xmlWriter->writeAttribute('w:val', '99');
$xmlWriter->endElement(); $xmlWriter->endElement();
$this->_writeTableStyle($xmlWriter, $style); $this->writeTableStyle($xmlWriter, $style);
$xmlWriter->endElement(); // w:style $xmlWriter->endElement(); // w:style
} }
@ -160,13 +152,13 @@ class Styles extends Base
/** /**
* Write default font and other default styles * Write default font and other default styles
* *
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param array $styles * @param array $styles
*/ */
private function writeDefaultStyles(XMLWriter $xmlWriter, $styles) private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles)
{ {
$fontName = $this->phpWord->getDefaultFontName(); $fontName = $phpWord->getDefaultFontName();
$fontSize = $this->phpWord->getDefaultFontSize(); $fontSize = $phpWord->getDefaultFontSize();
// Default font // Default font
$xmlWriter->startElement('w:docDefaults'); $xmlWriter->startElement('w:docDefaults');
@ -197,7 +189,7 @@ class Styles extends Base
$xmlWriter->writeAttribute('w:val', 'Normal'); $xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement(); // w:name $xmlWriter->endElement(); // w:name
if (array_key_exists('Normal', $styles)) { if (array_key_exists('Normal', $styles)) {
$this->_writeParagraphStyle($xmlWriter, $styles['Normal']); $this->writeParagraphStyle($xmlWriter, $styles['Normal']);
} }
$xmlWriter->endElement(); // w:style $xmlWriter->endElement(); // w:style

View File

@ -22,7 +22,7 @@ abstract class Writer implements IWriter
/** /**
* PHPWord object * PHPWord object
* *
* @var PhpOffice\PhpWord\PhpWord * @var PhpWord
*/ */
protected $phpWord = null; protected $phpWord = null;