Refactor writer classes
This commit is contained in:
parent
4127860f1e
commit
45b0baf7bc
|
|
@ -25,6 +25,10 @@
|
|||
{
|
||||
"name": "Ivan Lanin",
|
||||
"homepage": "http://ivan.lanin.org"
|
||||
},
|
||||
{
|
||||
"name": "Roman Syroeshko",
|
||||
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ class DocumentProperties
|
|||
/**
|
||||
* Created
|
||||
*
|
||||
* @var datetime
|
||||
* @var datetime|int
|
||||
*/
|
||||
private $_created;
|
||||
|
||||
/**
|
||||
* Modified
|
||||
*
|
||||
* @var datetime
|
||||
* @var datetime|int
|
||||
*/
|
||||
private $_modified;
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ class DocumentProperties
|
|||
/**
|
||||
* Custom Properties
|
||||
*
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
private $_customProperties = array();
|
||||
|
||||
|
|
@ -542,26 +542,21 @@ class DocumentProperties
|
|||
case 'ui8': // 8-Byte Unsigned Integer
|
||||
case 'uint': // Unsigned Integer
|
||||
return self::PROPERTY_TYPE_INTEGER;
|
||||
break;
|
||||
case 'r4': // 4-Byte Real Number
|
||||
case 'r8': // 8-Byte Real Number
|
||||
case 'decimal': // Decimal
|
||||
return self::PROPERTY_TYPE_FLOAT;
|
||||
break;
|
||||
case 'empty': // Empty
|
||||
case 'null': // Null
|
||||
case 'lpstr': // LPSTR
|
||||
case 'lpwstr': // LPWSTR
|
||||
case 'bstr': // Basic String
|
||||
return self::PROPERTY_TYPE_STRING;
|
||||
break;
|
||||
case 'date': // Date and Time
|
||||
case 'filetime': // File Time
|
||||
return self::PROPERTY_TYPE_DATE;
|
||||
break;
|
||||
case 'bool': // Boolean
|
||||
return self::PROPERTY_TYPE_BOOLEAN;
|
||||
break;
|
||||
case 'cy': // Currency
|
||||
case 'error': // Error Status Code
|
||||
case 'vector': // Vector
|
||||
|
|
@ -576,7 +571,6 @@ class DocumentProperties
|
|||
case 'clsid': // Class ID
|
||||
case 'cf': // Clipboard Data
|
||||
return self::PROPERTY_TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
return self::PROPERTY_TYPE_UNKNOWN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ class CheckBox
|
|||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $fontStyle;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var Paragraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $paragraphStyle;
|
||||
|
||||
|
|
@ -50,8 +50,8 @@ class CheckBox
|
|||
*
|
||||
* @param string $name
|
||||
* @param string $text
|
||||
* @param Font $fontStyle
|
||||
* @param Paragraph $paragraphStyle
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -66,9 +66,9 @@ class CheckBox
|
|||
/**
|
||||
* Set Text style
|
||||
*
|
||||
* @param Font $style
|
||||
* @param Paragraph $paragraphStyle
|
||||
* @return Font
|
||||
* @param mixed $style
|
||||
* @param mixed $paragraphStyle
|
||||
* @return string|Font
|
||||
*/
|
||||
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -90,7 +90,7 @@ class CheckBox
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -100,8 +100,8 @@ class CheckBox
|
|||
/**
|
||||
* Set Paragraph style
|
||||
*
|
||||
* @param Paragraph $style
|
||||
* @return Paragraph
|
||||
* @param mixed $style
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function setParagraphStyle($style = null)
|
||||
{
|
||||
|
|
@ -121,7 +121,7 @@ class CheckBox
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ class PreserveText
|
|||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $_styleFont;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $_styleParagraph;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class PreserveText
|
|||
* @param string $text
|
||||
* @param mixed $styleFont
|
||||
* @param mixed $styleParagraph
|
||||
* @return PHPWord_Section_Footer_PreserveText
|
||||
* @return $this
|
||||
*/
|
||||
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
|
||||
{
|
||||
|
|
@ -88,7 +88,7 @@ class PreserveText
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -98,7 +98,7 @@ class PreserveText
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ class Link
|
|||
/**
|
||||
* Link style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $_styleFont;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $_styleParagraph;
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ class Link
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -150,7 +150,7 @@ class Link
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ class Text
|
|||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $fontStyle;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $paragraphStyle;
|
||||
|
||||
|
|
@ -42,8 +42,8 @@ class Text
|
|||
* Create a new Text Element
|
||||
*
|
||||
* @param string $text
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Font $fontStyle
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -55,9 +55,9 @@ class Text
|
|||
/**
|
||||
* Set Text style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @param string|array|Font $style
|
||||
* @param string|array|Paragraph $paragraphStyle
|
||||
* @return string|Font
|
||||
*/
|
||||
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -79,7 +79,7 @@ class Text
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -89,8 +89,8 @@ class Text
|
|||
/**
|
||||
* Set Paragraph style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
|
||||
* @return null|\PhpOffice\PhpWord\Style\Paragraph
|
||||
* @param string|array|Paragraph $style
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function setParagraphStyle($style = null)
|
||||
{
|
||||
|
|
@ -110,7 +110,7 @@ class Text
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ class TextBreak
|
|||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Pagaraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $paragraphStyle = null;
|
||||
|
||||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $fontStyle = null;
|
||||
|
||||
|
|
@ -50,9 +50,9 @@ class TextBreak
|
|||
/**
|
||||
* Set Text style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @param mixed $style
|
||||
* @param mixed $paragraphStyle
|
||||
* @return string|Font
|
||||
*/
|
||||
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -72,7 +72,7 @@ class TextBreak
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -82,8 +82,8 @@ class TextBreak
|
|||
/**
|
||||
* Set Paragraph style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
|
||||
* @return null|\PhpOffice\PhpWord\Style\Paragraph
|
||||
* @param string|array|Paragraph $style
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function setParagraphStyle($style = null)
|
||||
{
|
||||
|
|
@ -101,7 +101,7 @@ class TextBreak
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace PhpOffice\PhpWord\Section;
|
|||
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
|
||||
use PhpOffice\PhpWord\Media;
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
/**
|
||||
|
|
@ -22,7 +23,7 @@ class TextRun
|
|||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var Paragraph
|
||||
*/
|
||||
private $_styleParagraph;
|
||||
|
||||
|
|
@ -123,8 +124,8 @@ class TextRun
|
|||
* Add TextBreak
|
||||
*
|
||||
* @param int $count
|
||||
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
|
||||
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -161,7 +162,7 @@ class TextRun
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -479,8 +479,8 @@ class Font
|
|||
/**
|
||||
* Set background color
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return PHPWord_Style_Font
|
||||
* @param string $pValue
|
||||
* @return $this
|
||||
*/
|
||||
public function setBgColor($pValue = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Row
|
|||
* Set tblHeader
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @return PHPWord_Style_Row
|
||||
* @return $this
|
||||
*/
|
||||
public function setTblHeader($pValue = false)
|
||||
{
|
||||
|
|
@ -82,7 +82,7 @@ class Row
|
|||
* Set cantSplit
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @return PHPWord_Style_Row
|
||||
* @return $this
|
||||
*/
|
||||
public function setCantSplit($pValue = false)
|
||||
{
|
||||
|
|
@ -107,7 +107,7 @@ class Row
|
|||
* Set exactHeight
|
||||
*
|
||||
* @param bool $pValue
|
||||
* @return PHPWord_Style_Row
|
||||
* @return $this
|
||||
*/
|
||||
public function setExactHeight($pValue = false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
namespace PhpOffice\PhpWord;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
|
||||
|
||||
/**
|
||||
* Table of contents
|
||||
|
|
@ -26,14 +27,14 @@ class TOC
|
|||
/**
|
||||
* TOC style
|
||||
*
|
||||
* @var PhpOffice\PhpWord\Style\TOC
|
||||
* @var TOCStyle
|
||||
*/
|
||||
private static $_styleTOC;
|
||||
|
||||
/**
|
||||
* Font style
|
||||
*
|
||||
* @var PhpOffice\PhpWord\Style\Font|array|string
|
||||
* @var Font|array|string
|
||||
*/
|
||||
private static $_styleFont;
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ class TOC
|
|||
*/
|
||||
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)) {
|
||||
foreach ($styleTOC as $key => $value) {
|
||||
|
|
@ -122,7 +123,7 @@ class TOC
|
|||
/**
|
||||
* Get TOC Style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\TOC
|
||||
* @return TOCStyle
|
||||
*/
|
||||
public static function getStyleTOC()
|
||||
{
|
||||
|
|
@ -132,7 +133,7 @@ class TOC
|
|||
/**
|
||||
* Get Font Style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return Font
|
||||
*/
|
||||
public static function getStyleFont()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ class ODText extends Writer implements IWriter
|
|||
/**
|
||||
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\HashTable
|
||||
* @var HashTable
|
||||
*/
|
||||
private $drawingHashTable;
|
||||
|
||||
/**
|
||||
* Create new ODText writer
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
{
|
||||
|
|
@ -57,7 +57,7 @@ class ODText extends Writer implements IWriter
|
|||
* Save PhpWord to file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save($pFilename = null)
|
||||
{
|
||||
|
|
@ -139,7 +139,7 @@ class ODText extends Writer implements IWriter
|
|||
/**
|
||||
* Get PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\HashTable
|
||||
* @return HashTable
|
||||
*/
|
||||
public function getDrawingHashTable()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write content file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeContent(PhpWord $phpWord = null)
|
||||
|
|
@ -126,7 +126,7 @@ class Content extends WriterPart
|
|||
$numFonts = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
$numFonts++;
|
||||
$name = $style->getName();
|
||||
|
|
@ -158,7 +158,7 @@ class Content extends WriterPart
|
|||
if (preg_match('#^T[0-9]+$#', $styleName) != 0
|
||||
|| preg_match('#^P[0-9]+$#', $styleName) != 0
|
||||
) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
$xmlWriter->startElement('style:style');
|
||||
$xmlWriter->writeAttribute('style:name', $styleName);
|
||||
|
|
@ -244,11 +244,11 @@ class Content extends WriterPart
|
|||
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter);
|
||||
$this->writeTextBreak($xmlWriter);
|
||||
} elseif ($element instanceof Link) {
|
||||
$this->writeUnsupportedElement($xmlWriter, 'Link');
|
||||
} elseif ($element instanceof Title) {
|
||||
|
|
@ -271,9 +271,9 @@ class Content extends WriterPart
|
|||
}
|
||||
|
||||
if ($pSection == $countSections) {
|
||||
$this->_writeEndSection($xmlWriter, $section);
|
||||
$this->writeEndSection($xmlWriter, $section);
|
||||
} else {
|
||||
$this->_writeSection($xmlWriter, $section);
|
||||
$this->writeSection($xmlWriter, $section);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -288,11 +288,11 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write text
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param \PhpOffice\PhpWord\Section\Text $text
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Text $text
|
||||
* @param bool $withoutP
|
||||
*/
|
||||
protected function _writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
|
||||
protected function writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
|
||||
{
|
||||
$styleFont = $text->getFontStyle();
|
||||
$styleParagraph = $text->getParagraphStyle();
|
||||
|
|
@ -336,18 +336,18 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write TextRun section
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param \PhpOffice\PhpWord\Section\TextRun $textrun
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param TextRun $textrun
|
||||
* @todo Enable all other section types
|
||||
*/
|
||||
protected function _writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
|
||||
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);
|
||||
$this->writeText($xmlWriter, $element, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -357,9 +357,9 @@ class Content extends WriterPart
|
|||
/**
|
||||
* 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->writeAttribute('text:style-name', 'Standard');
|
||||
|
|
@ -370,20 +370,20 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write end section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Write section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
private function writeSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
{
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
@ -391,7 +391,7 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write unsupported element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param string $element
|
||||
*/
|
||||
private function writeUnsupportedElement($xmlWriter, $element)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class Manifest extends WriterPart
|
|||
/**
|
||||
* Write Manifest file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeManifest(PhpWord $phpWord = null)
|
||||
|
|
@ -64,7 +64,7 @@ class Manifest extends WriterPart
|
|||
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
|
||||
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
|
||||
$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->writeAttribute('manifest:media-type', $mimeType);
|
||||
|
|
@ -97,9 +97,9 @@ class Manifest extends WriterPart
|
|||
*
|
||||
* @param string $pFile Filename
|
||||
* @return string Mime Type
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private function _getImageMimeType($pFile = '')
|
||||
private function getImageMimeType($pFile = '')
|
||||
{
|
||||
if (file_exists($pFile)) {
|
||||
$image = getimagesize($pFile);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Meta extends WriterPart
|
|||
/**
|
||||
* Write Meta file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeMeta(PhpWord $phpWord = null)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Mimetype extends WriterPart
|
|||
/**
|
||||
* Write Mimetype to Text format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string Text Output
|
||||
*/
|
||||
public function writeMimetype(PhpWord $phpWord = null)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class Styles extends WriterPart
|
|||
/**
|
||||
* Write Styles file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeStyles(PhpWord $phpWord = null)
|
||||
|
|
@ -73,7 +73,7 @@ class Styles extends WriterPart
|
|||
$numFonts = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
$numFonts++;
|
||||
$name = $style->getName();
|
||||
|
|
@ -144,7 +144,7 @@ class Styles extends WriterPart
|
|||
if (preg_match('#^T[0-9]+$#', $styleName) == 0
|
||||
&& preg_match('#^P[0-9]+$#', $styleName) == 0
|
||||
) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
// style:style
|
||||
$xmlWriter->startElement('style:style');
|
||||
|
|
@ -168,7 +168,7 @@ class Styles extends WriterPart
|
|||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
} elseif ($style instanceof Paragraph) {
|
||||
// PhpOffice\PhpWord\Style\Paragraph
|
||||
// Paragraph
|
||||
// style:style
|
||||
$xmlWriter->startElement('style:style');
|
||||
$xmlWriter->writeAttribute('style:name', $styleName);
|
||||
|
|
@ -183,7 +183,7 @@ class Styles extends WriterPart
|
|||
|
||||
$xmlWriter->endElement();
|
||||
} elseif ($style instanceof Table) {
|
||||
// PhpOffice\PhpWord\Style\Table
|
||||
// Table
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class RTF extends Writer implements IWriter
|
|||
/**
|
||||
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\HashTable
|
||||
* @var HashTable
|
||||
*/
|
||||
private $drawingHashTable;
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ class RTF extends Writer implements IWriter
|
|||
|
||||
/**
|
||||
* Create new RTF writer
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
{
|
||||
|
|
@ -78,7 +78,7 @@ class RTF extends Writer implements IWriter
|
|||
* Save PhpWord to file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save($pFilename = null)
|
||||
{
|
||||
|
|
@ -98,7 +98,7 @@ class RTF extends Writer implements IWriter
|
|||
/**
|
||||
* Get PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\HashTable
|
||||
* @return HashTable
|
||||
*/
|
||||
public function getDrawingHashTable()
|
||||
{
|
||||
|
|
@ -179,10 +179,9 @@ class RTF extends Writer implements IWriter
|
|||
|
||||
// Browse styles
|
||||
$styles = Style::getStyles();
|
||||
$numPStyles = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
if (in_array($style->getName(), $arrFonts) == false) {
|
||||
$arrFonts[] = $style->getName();
|
||||
|
|
@ -232,7 +231,6 @@ class RTF extends Writer implements IWriter
|
|||
|
||||
// Browse styles
|
||||
$styles = Style::getStyles();
|
||||
$numPStyles = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// Font
|
||||
|
|
|
|||
|
|
@ -34,19 +34,19 @@ class Word2007 extends Writer implements IWriter
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_imageTypes = array();
|
||||
private $imageTypes = array();
|
||||
|
||||
/**
|
||||
* Types of objects
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_objectTypes = array();
|
||||
private $objectTypes = array();
|
||||
|
||||
/**
|
||||
* Create new Word2007 writer
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord
|
||||
* @param PhpWord
|
||||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
{
|
||||
|
|
@ -167,8 +167,8 @@ class Word2007 extends Writer implements IWriter
|
|||
$objZip->addFromString(
|
||||
'[Content_Types].xml',
|
||||
$this->getWriterPart('contenttypes')->writeContentTypes(
|
||||
$this->_imageTypes,
|
||||
$this->_objectTypes,
|
||||
$this->imageTypes,
|
||||
$this->objectTypes,
|
||||
$_cHdrs,
|
||||
$footers
|
||||
)
|
||||
|
|
@ -235,12 +235,12 @@ class Word2007 extends Writer implements IWriter
|
|||
if ($imageExtension === 'jpeg') {
|
||||
$imageExtension = 'jpg';
|
||||
}
|
||||
if (!in_array($imageType, $this->_imageTypes)) {
|
||||
$this->_imageTypes[$imageExtension] = $imageType;
|
||||
if (!in_array($imageType, $this->imageTypes)) {
|
||||
$this->imageTypes[$imageExtension] = $imageType;
|
||||
}
|
||||
} else {
|
||||
if (!in_array($extension, $this->_objectTypes)) {
|
||||
$this->_objectTypes[] = $extension;
|
||||
if (!in_array($extension, $this->objectTypes)) {
|
||||
$this->objectTypes[] = $extension;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -19,12 +19,12 @@ class ContentTypes extends WriterPart
|
|||
{
|
||||
/**
|
||||
* Write [Content_Types].xml
|
||||
* @param array $_imageTypes
|
||||
* @param array $_objectTypes
|
||||
* @param array $imageTypes
|
||||
* @param array $objectTypes
|
||||
* @param int $_cHdrs
|
||||
* @param array $footers
|
||||
*/
|
||||
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers)
|
||||
public function writeContentTypes($imageTypes, $objectTypes, $_cHdrs, $footers)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
@ -37,27 +37,27 @@ class ContentTypes extends WriterPart
|
|||
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
|
||||
|
||||
// Rels
|
||||
$this->_writeDefaultContentType(
|
||||
$this->writeDefaultContentType(
|
||||
$xmlWriter,
|
||||
'rels',
|
||||
'application/vnd.openxmlformats-package.relationships+xml'
|
||||
);
|
||||
|
||||
// XML
|
||||
$this->_writeDefaultContentType(
|
||||
$this->writeDefaultContentType(
|
||||
$xmlWriter,
|
||||
'xml',
|
||||
'application/xml'
|
||||
);
|
||||
|
||||
// Add media content-types
|
||||
foreach ($_imageTypes as $key => $value) {
|
||||
$this->_writeDefaultContentType($xmlWriter, $key, $value);
|
||||
foreach ($imageTypes as $key => $value) {
|
||||
$this->writeDefaultContentType($xmlWriter, $key, $value);
|
||||
}
|
||||
|
||||
// Add embedding content-types
|
||||
if (count($_objectTypes) > 0) {
|
||||
$this->_writeDefaultContentType(
|
||||
if (count($objectTypes) > 0) {
|
||||
$this->writeDefaultContentType(
|
||||
$xmlWriter,
|
||||
'bin',
|
||||
'application/vnd.openxmlformats-officedocument.oleObject'
|
||||
|
|
@ -65,76 +65,76 @@ class ContentTypes extends WriterPart
|
|||
}
|
||||
|
||||
// DocProps
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/docProps/app.xml',
|
||||
'application/vnd.openxmlformats-officedocument.extended-properties+xml'
|
||||
);
|
||||
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/docProps/core.xml',
|
||||
'application/vnd.openxmlformats-package.core-properties+xml'
|
||||
);
|
||||
|
||||
// Document
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/document.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
|
||||
);
|
||||
|
||||
// Styles
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/styles.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
|
||||
);
|
||||
|
||||
// Numbering
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/numbering.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
|
||||
);
|
||||
|
||||
// Settings
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/settings.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
|
||||
);
|
||||
|
||||
// Theme1
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/theme/theme1.xml',
|
||||
'application/vnd.openxmlformats-officedocument.theme+xml'
|
||||
);
|
||||
|
||||
// WebSettings
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/webSettings.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
|
||||
);
|
||||
|
||||
// Font Table
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/fontTable.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
|
||||
);
|
||||
|
||||
// Footnotes
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/footnotes.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
|
||||
);
|
||||
|
||||
for ($i = 1; $i <= $_cHdrs; $i++) {
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/header' . $i . '.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
|
||||
|
|
@ -143,7 +143,7 @@ class ContentTypes extends WriterPart
|
|||
|
||||
for ($i = 1; $i <= count($footers); $i++) {
|
||||
if (!is_null($footers[$i])) {
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/footer' . $i . '.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
|
||||
|
|
@ -158,32 +158,15 @@ class ContentTypes extends WriterPart
|
|||
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
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
|
||||
* @param XMLWriter $xmlWriter XML Writer
|
||||
* @param string $pPartname Part name
|
||||
* @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 != '') {
|
||||
// Write content type
|
||||
|
|
@ -199,12 +182,12 @@ class ContentTypes extends WriterPart
|
|||
/**
|
||||
* Write Override XML element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param string $pPartname Part name
|
||||
* @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 != '') {
|
||||
// Write content type
|
||||
|
|
@ -216,4 +199,21 @@ class ContentTypes extends WriterPart
|
|||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class DocProps extends WriterPart
|
|||
/**
|
||||
* Write docProps/core.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeDocPropsCore(PhpWord $phpWord = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Document extends Base
|
|||
/**
|
||||
* Write word/document.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeDocument(PhpWord $phpWord = null)
|
||||
{
|
||||
|
|
@ -72,38 +72,38 @@ class Document extends Base
|
|||
$_elements = $section->getElements();
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof Link) {
|
||||
$this->_writeLink($xmlWriter, $element);
|
||||
$this->writeLink($xmlWriter, $element);
|
||||
} elseif ($element instanceof Title) {
|
||||
$this->_writeTitle($xmlWriter, $element);
|
||||
$this->writeTitle($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter, $element);
|
||||
$this->writeTextBreak($xmlWriter, $element);
|
||||
} elseif ($element instanceof PageBreak) {
|
||||
$this->_writePageBreak($xmlWriter);
|
||||
$this->writePageBreak($xmlWriter);
|
||||
} elseif ($element instanceof Table) {
|
||||
$this->_writeTable($xmlWriter, $element);
|
||||
$this->writeTable($xmlWriter, $element);
|
||||
} elseif ($element instanceof ListItem) {
|
||||
$this->_writeListItem($xmlWriter, $element);
|
||||
$this->writeListItem($xmlWriter, $element);
|
||||
} elseif ($element instanceof Image) {
|
||||
$this->_writeImage($xmlWriter, $element);
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} elseif ($element instanceof Object) {
|
||||
$this->_writeObject($xmlWriter, $element);
|
||||
$this->writeObject($xmlWriter, $element);
|
||||
} elseif ($element instanceof TOC) {
|
||||
$this->_writeTOC($xmlWriter);
|
||||
$this->writeTOC($xmlWriter);
|
||||
} elseif ($element instanceof Footnote) {
|
||||
$this->_writeFootnote($xmlWriter, $element);
|
||||
$this->writeFootnote($xmlWriter, $element);
|
||||
} elseif ($element instanceof CheckBox) {
|
||||
$this->_writeCheckBox($xmlWriter, $element);
|
||||
$this->writeCheckBox($xmlWriter, $element);
|
||||
}
|
||||
}
|
||||
|
||||
if ($pSection == $countSections) {
|
||||
$this->_writeEndSection($xmlWriter, $section);
|
||||
$this->writeEndSection($xmlWriter, $section);
|
||||
} else {
|
||||
$this->_writeSection($xmlWriter, $section);
|
||||
$this->writeSection($xmlWriter, $section);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -118,14 +118,14 @@ class Document extends Base
|
|||
/**
|
||||
* Write begin section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeSection(XMLWriter $xmlWriter, Section $section)
|
||||
private function writeSection(XMLWriter $xmlWriter, Section $section)
|
||||
{
|
||||
$xmlWriter->startElement('w:p');
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$this->_writeEndSection($xmlWriter, $section, 3);
|
||||
$this->writeEndSection($xmlWriter, $section, 3);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
|
@ -133,10 +133,10 @@ class Document extends Base
|
|||
/**
|
||||
* Write end section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeEndSection(XMLWriter $xmlWriter, Section $section)
|
||||
private function writeEndSection(XMLWriter $xmlWriter, Section $section)
|
||||
{
|
||||
$settings = $section->getSettings();
|
||||
$_headers = $section->getHeaders();
|
||||
|
|
@ -272,9 +272,9 @@ class Document extends Base
|
|||
/**
|
||||
* 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:r');
|
||||
|
|
@ -285,122 +285,12 @@ class Document extends Base
|
|||
$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
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
*/
|
||||
private function _writeTOC(XMLWriter $xmlWriter)
|
||||
private function writeTOC(XMLWriter $xmlWriter)
|
||||
{
|
||||
$titles = TOC::getTitles();
|
||||
$styleFont = TOC::getStyleFont();
|
||||
|
|
@ -421,7 +311,7 @@ class Document extends Base
|
|||
$xmlWriter->startElement('w:pPr');
|
||||
|
||||
if ($isObject && !is_null($styleFont->getParagraphStyle())) {
|
||||
$this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
|
||||
$this->writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
|
||||
}
|
||||
|
||||
if ($indent > 0) {
|
||||
|
|
@ -479,7 +369,7 @@ class Document extends Base
|
|||
$xmlWriter->startElement('w:r');
|
||||
|
||||
if ($isObject) {
|
||||
$this->_writeTextStyle($xmlWriter, $styleFont);
|
||||
$this->writeFontStyle($xmlWriter, $styleFont);
|
||||
}
|
||||
|
||||
$xmlWriter->startElement('w:t');
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
/**
|
||||
* Word2007 document rels part writer
|
||||
*/
|
||||
class DocumentRels extends WriterPart
|
||||
class DocumentRels extends Base
|
||||
{
|
||||
/**
|
||||
* Write word/_rels/document.xml.rels
|
||||
|
|
@ -35,7 +35,7 @@ class DocumentRels extends WriterPart
|
|||
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
|
||||
|
||||
// Relationship word/document.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
1,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
|
||||
|
|
@ -43,7 +43,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/numbering.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
2,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
|
||||
|
|
@ -51,7 +51,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
3,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
|
||||
|
|
@ -59,7 +59,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
4,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
|
||||
|
|
@ -67,7 +67,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
5,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
|
||||
|
|
@ -75,7 +75,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
6,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
|
||||
|
|
@ -89,7 +89,7 @@ class DocumentRels extends WriterPart
|
|||
$relationId = $relation['rID'];
|
||||
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
|
||||
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
|
||||
|
|
@ -128,7 +128,7 @@ class DocumentRels extends WriterPart
|
|||
$relationName = $relation['target'];
|
||||
$relationId = $relation['rID'];
|
||||
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
|
||||
|
|
@ -142,36 +142,4 @@ class DocumentRels extends WriterPart
|
|||
// Return
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
|
|||
use PhpOffice\PhpWord\Section\Text;
|
||||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Section\TextRun;
|
||||
use PhpOffice\PhpWord\Section\Footer as FooterElement;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
|
|
@ -25,9 +26,9 @@ class Footer extends Base
|
|||
/**
|
||||
* 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
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
@ -50,17 +51,17 @@ class Footer extends Base
|
|||
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter, $element);
|
||||
$this->writeTextBreak($xmlWriter, $element);
|
||||
} elseif ($element instanceof Table) {
|
||||
$this->_writeTable($xmlWriter, $element);
|
||||
$this->writeTable($xmlWriter, $element);
|
||||
} elseif ($element instanceof Image) {
|
||||
$this->_writeImage($xmlWriter, $element);
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} elseif ($element instanceof PreserveText) {
|
||||
$this->_writePreserveText($xmlWriter, $element);
|
||||
$this->writePreserveText($xmlWriter, $element);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,26 +77,18 @@ class Footnotes extends Base
|
|||
/**
|
||||
* Write footnote content, overrides method in parent class
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section\Footnote $footnote
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @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->writeAttribute('w:id', $footnote->getReferenceId());
|
||||
$xmlWriter->startElement('w:p');
|
||||
// Paragraph style
|
||||
$paragraphStyle = $footnote->getParagraphStyle();
|
||||
$spIsObject = ($paragraphStyle instanceof Paragraph) ? true : false;
|
||||
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();
|
||||
}
|
||||
$styleParagraph = $footnote->getParagraphStyle();
|
||||
$this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
|
||||
// Reference symbol
|
||||
$xmlWriter->startElement('w:r');
|
||||
$xmlWriter->startElement('w:rPr');
|
||||
|
|
@ -118,9 +110,9 @@ class Footnotes extends Base
|
|||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element, true);
|
||||
$this->writeText($xmlWriter, $element, true);
|
||||
} elseif ($element instanceof Link) {
|
||||
$this->_writeLink($xmlWriter, $element, true);
|
||||
$this->writeLink($xmlWriter, $element, true);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$xmlWriter->writeElement('w:br');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
/**
|
||||
* Word2007 footnotes rel part writer
|
||||
*/
|
||||
class FootnotesRels extends WriterPart
|
||||
class FootnotesRels extends Base
|
||||
{
|
||||
/**
|
||||
* Write word/_rels/footnotes.xml.rels
|
||||
|
|
@ -41,7 +41,7 @@ class FootnotesRels extends WriterPart
|
|||
$relationId = $relation['rID'];
|
||||
$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();
|
||||
|
|
@ -49,36 +49,4 @@ class FootnotesRels extends WriterPart
|
|||
// Return
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
|
|||
use PhpOffice\PhpWord\Section\Text;
|
||||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Section\TextRun;
|
||||
use PhpOffice\PhpWord\Section\Header as HeaderElement;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
|
|
@ -25,9 +26,9 @@ class Header extends Base
|
|||
/**
|
||||
* 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
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
@ -51,21 +52,21 @@ class Header extends Base
|
|||
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter, $element);
|
||||
$this->writeTextBreak($xmlWriter, $element);
|
||||
} elseif ($element instanceof Table) {
|
||||
$this->_writeTable($xmlWriter, $element);
|
||||
$this->writeTable($xmlWriter, $element);
|
||||
} elseif ($element instanceof Image) {
|
||||
if (!$element->getIsWatermark()) {
|
||||
$this->_writeImage($xmlWriter, $element);
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} else {
|
||||
$this->_writeWatermark($xmlWriter, $element);
|
||||
$this->writeWatermark($xmlWriter, $element);
|
||||
}
|
||||
} elseif ($element instanceof PreserveText) {
|
||||
$this->_writePreserveText($xmlWriter, $element);
|
||||
$this->writePreserveText($xmlWriter, $element);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
/**
|
||||
* Word2007 rels part writer
|
||||
*/
|
||||
class Rels extends WriterPart
|
||||
class Rels extends Base
|
||||
{
|
||||
/**
|
||||
* Write _rels/.rels
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeRelationships(PhpWord $phpWord = null)
|
||||
{
|
||||
|
|
@ -38,7 +38,7 @@ class Rels extends WriterPart
|
|||
$relationId = 1;
|
||||
|
||||
// Relationship word/document.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
|
||||
|
|
@ -46,7 +46,7 @@ class Rels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship docProps/core.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
++$relationId,
|
||||
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
|
||||
|
|
@ -54,7 +54,7 @@ class Rels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship docProps/app.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
++$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
|
||||
|
|
@ -65,37 +65,4 @@ class Rels extends WriterPart
|
|||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,28 +14,20 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
use PhpOffice\PhpWord\Style\Table;
|
||||
|
||||
/**
|
||||
* Word2007 styles part writer
|
||||
*/
|
||||
class Styles extends Base
|
||||
{
|
||||
/**
|
||||
* PhpWord object
|
||||
*
|
||||
* @var PhpWord
|
||||
*/
|
||||
private $phpWord;
|
||||
|
||||
/**
|
||||
* Write word/styles.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeStyles(PhpWord $phpWord = null)
|
||||
{
|
||||
$this->phpWord = $phpWord;
|
||||
|
||||
// Create XML writer
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
|
|
@ -52,7 +44,7 @@ class Styles extends Base
|
|||
);
|
||||
// Write default styles
|
||||
$styles = Style::getStyles();
|
||||
$this->writeDefaultStyles($xmlWriter, $styles);
|
||||
$this->writeDefaultStyles($xmlWriter, $phpWord, $styles);
|
||||
// Write other styles
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
|
|
@ -94,10 +86,10 @@ class Styles extends Base
|
|||
$xmlWriter->startElement('w:basedOn');
|
||||
$xmlWriter->writeAttribute('w:val', 'Normal');
|
||||
$xmlWriter->endElement();
|
||||
$this->_writeParagraphStyle($xmlWriter, $paragraphStyle);
|
||||
$this->writeParagraphStyle($xmlWriter, $paragraphStyle);
|
||||
}
|
||||
|
||||
$this->_writeTextStyle($xmlWriter, $style);
|
||||
$this->writeFontStyle($xmlWriter, $style);
|
||||
|
||||
$xmlWriter->endElement();
|
||||
|
||||
|
|
@ -127,10 +119,10 @@ class Styles extends Base
|
|||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
$this->_writeParagraphStyle($xmlWriter, $style);
|
||||
$this->writeParagraphStyle($xmlWriter, $style);
|
||||
$xmlWriter->endElement();
|
||||
|
||||
} elseif ($style instanceof \PhpOffice\PhpWord\Style\Table) {
|
||||
} elseif ($style instanceof Table) {
|
||||
$xmlWriter->startElement('w:style');
|
||||
$xmlWriter->writeAttribute('w:type', 'table');
|
||||
$xmlWriter->writeAttribute('w:customStyle', '1');
|
||||
|
|
@ -144,7 +136,7 @@ class Styles extends Base
|
|||
$xmlWriter->writeAttribute('w:val', '99');
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$this->_writeTableStyle($xmlWriter, $style);
|
||||
$this->writeTableStyle($xmlWriter, $style);
|
||||
|
||||
$xmlWriter->endElement(); // w:style
|
||||
}
|
||||
|
|
@ -160,13 +152,13 @@ class Styles extends Base
|
|||
/**
|
||||
* Write default font and other default styles
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param array $styles
|
||||
*/
|
||||
private function writeDefaultStyles(XMLWriter $xmlWriter, $styles)
|
||||
private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles)
|
||||
{
|
||||
$fontName = $this->phpWord->getDefaultFontName();
|
||||
$fontSize = $this->phpWord->getDefaultFontSize();
|
||||
$fontName = $phpWord->getDefaultFontName();
|
||||
$fontSize = $phpWord->getDefaultFontSize();
|
||||
|
||||
// Default font
|
||||
$xmlWriter->startElement('w:docDefaults');
|
||||
|
|
@ -197,7 +189,7 @@ class Styles extends Base
|
|||
$xmlWriter->writeAttribute('w:val', 'Normal');
|
||||
$xmlWriter->endElement(); // w:name
|
||||
if (array_key_exists('Normal', $styles)) {
|
||||
$this->_writeParagraphStyle($xmlWriter, $styles['Normal']);
|
||||
$this->writeParagraphStyle($xmlWriter, $styles['Normal']);
|
||||
}
|
||||
$xmlWriter->endElement(); // w:style
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ abstract class Writer implements IWriter
|
|||
/**
|
||||
* PHPWord object
|
||||
*
|
||||
* @var PhpOffice\PhpWord\PhpWord
|
||||
* @var PhpWord
|
||||
*/
|
||||
protected $phpWord = null;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue