Part II.
This commit is contained in:
Roman Syroeshko 2014-03-18 15:04:14 +04:00
parent 510f9cdf79
commit b32c198824
21 changed files with 602 additions and 635 deletions

View File

@ -25,12 +25,10 @@
* @version 0.8.0
*/
/**
* PHPWord_Style_Cell
*/
class PHPWord_Style_Cell
{
namespace PhpOffice\PhpWord\Style;
class Cell
{
const TEXT_DIR_BTLR = 'btLr';
const TEXT_DIR_TBRL = 'tbRl';

View File

@ -1,5 +1,4 @@
<?php
/**
* PHPWord
*
@ -25,12 +24,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
/**
* Class PHPWord_Style_Font
*/
class PHPWord_Style_Font
class Font
{
const UNDERLINE_NONE = 'none';
const UNDERLINE_DASH = 'dash';
@ -76,7 +75,7 @@ class PHPWord_Style_Font
/**
* Paragraph Style
*
* @var PHPWord_Style_Paragraph
* @var PhpOffice\PhpWord\Style\Paragraph
*/
private $_paragraphStyle;
@ -127,7 +126,7 @@ class PHPWord_Style_Font
*
* @var string
*/
private $_underline = PHPWord_Style_Font::UNDERLINE_NONE;
private $_underline = self::UNDERLINE_NONE;
/**
* Strikethrough
@ -174,10 +173,10 @@ class PHPWord_Style_Font
{
$this->_type = $type;
if ($paragraphStyle instanceof PHPWord_Style_Paragraph) {
if ($paragraphStyle instanceof Paragraph) {
$this->_paragraphStyle = $paragraphStyle;
} elseif (is_array($paragraphStyle)) {
$this->_paragraphStyle = new PHPWord_Style_Paragraph;
$this->_paragraphStyle = new Paragraph;
$this->_paragraphStyle->setArrayStyle($paragraphStyle);
} else {
$this->_paragraphStyle = $paragraphStyle;
@ -230,8 +229,8 @@ class PHPWord_Style_Font
/**
* Set font name
*
* @param string $pValue
* @return PHPWord_Style_Font
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setName($pValue = PHPWord::DEFAULT_FONT_NAME)
{
@ -256,8 +255,8 @@ class PHPWord_Style_Font
/**
* Set font size
*
* @param int|float $pValue
* @return PHPWord_Style_Font
* @param int|float $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
{
@ -281,8 +280,8 @@ class PHPWord_Style_Font
/**
* Set bold
*
* @param bool $pValue
* @return PHPWord_Style_Font
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setBold($pValue = false)
{
@ -306,8 +305,8 @@ class PHPWord_Style_Font
/**
* Set italics
*
* @param bool $pValue
* @return PHPWord_Style_Font
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setItalic($pValue = false)
{
@ -331,8 +330,8 @@ class PHPWord_Style_Font
/**
* Set superscript
*
* @param bool $pValue
* @return PHPWord_Style_Font
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setSuperScript($pValue = false)
{
@ -357,8 +356,8 @@ class PHPWord_Style_Font
/**
* Set subscript
*
* @param bool $pValue
* @return PHPWord_Style_Font
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setSubScript($pValue = false)
{
@ -383,13 +382,13 @@ class PHPWord_Style_Font
/**
* Set underline
*
* @param string $pValue
* @return PHPWord_Style_Font
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
public function setUnderline($pValue = self::UNDERLINE_NONE)
{
if ($pValue == '') {
$pValue = PHPWord_Style_Font::UNDERLINE_NONE;
$pValue = self::UNDERLINE_NONE;
}
$this->_underline = $pValue;
return $this;
@ -408,8 +407,8 @@ class PHPWord_Style_Font
/**
* Set strikethrough
*
* @param bool $pValue
* @return PHPWord_Style_Font
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setStrikethrough($pValue = false)
{
@ -433,8 +432,8 @@ class PHPWord_Style_Font
/**
* Set font color
*
* @param string $pValue
* @return PHPWord_Style_Font
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR)
{
@ -458,8 +457,8 @@ class PHPWord_Style_Font
/**
* Set foreground/highlight color
*
* @param string $pValue
* @return PHPWord_Style_Font
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setFgColor($pValue = null)
{
@ -480,7 +479,7 @@ class PHPWord_Style_Font
/**
* Get paragraph style
*
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
@ -530,8 +529,8 @@ class PHPWord_Style_Font
/**
* Set Font Content Type
*
* @param string $pValue
* @return PHPWord_Style_Font
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setHint($pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE)
{

View File

@ -25,10 +25,9 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Style_Image
*/
class PHPWord_Style_Image
namespace PhpOffice\PhpWord\Style;
class Image
{
const WRAPPING_STYLE_INLINE = 'inline';
const WRAPPING_STYLE_SQUARE = 'square';

View File

@ -25,12 +25,10 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Style_ListItem
*/
class PHPWord_Style_ListItem
{
namespace PhpOffice\PhpWord\Style;
class ListItem
{
const TYPE_NUMBER = 7;
const TYPE_NUMBER_NESTED = 8;
const TYPE_ALPHANUM = 9;
@ -48,7 +46,7 @@ class PHPWord_Style_ListItem
*/
public function __construct()
{
$this->_listType = PHPWord_Style_ListItem::TYPE_BULLET_FILLED;
$this->_listType = self::TYPE_BULLET_FILLED;
}
/**
@ -67,7 +65,7 @@ class PHPWord_Style_ListItem
*
* @param int $pValue
*/
public function setListType($pValue = PHPWord_Style_ListItem::TYPE_BULLET_FILLED)
public function setListType($pValue = self::TYPE_BULLET_FILLED)
{
$this->_listType = $pValue;
}

View File

@ -25,12 +25,11 @@
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
/**
* PHPWord_Style_Paragraph
*/
class PHPWord_Style_Paragraph
class Paragraph
{
const LINE_HEIGHT = 240;
@ -187,7 +186,7 @@ class PHPWord_Style_Paragraph
* Set Paragraph Alignment
*
* @param string $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setAlign($pValue = null)
{
@ -213,7 +212,7 @@ class PHPWord_Style_Paragraph
* Set Space before Paragraph
*
* @param int $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setSpaceBefore($pValue = null)
{
@ -235,7 +234,7 @@ class PHPWord_Style_Paragraph
* Set Space after Paragraph
*
* @param int $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setSpaceAfter($pValue = null)
{
@ -257,7 +256,7 @@ class PHPWord_Style_Paragraph
* Set Spacing between breaks
*
* @param int $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setSpacing($pValue = null)
{
@ -279,7 +278,7 @@ class PHPWord_Style_Paragraph
* Set indentation
*
* @param int $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setIndent($pValue = null)
{
@ -301,7 +300,7 @@ class PHPWord_Style_Paragraph
* Set hanging
*
* @param int $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setHanging($pValue = null)
{
@ -312,7 +311,7 @@ class PHPWord_Style_Paragraph
/**
* Get tabs
*
* @return PHPWord_Style_Tabs
* @return PhpOffice\PhpWord\Style\Tabs
*/
public function getTabs()
{
@ -323,12 +322,12 @@ class PHPWord_Style_Paragraph
* Set tabs
*
* @param array $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setTabs($pValue = null)
{
if (is_array($pValue)) {
$this->_tabs = new PHPWord_Style_Tabs($pValue);
$this->_tabs = new Tabs($pValue);
}
return $this;
}
@ -347,7 +346,7 @@ class PHPWord_Style_Paragraph
* Set parent style ID
*
* @param string $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setBasedOn($pValue = 'Normal')
{
@ -369,7 +368,7 @@ class PHPWord_Style_Paragraph
* Set style for next paragraph
*
* @param string $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setNext($pValue = null)
{
@ -391,7 +390,7 @@ class PHPWord_Style_Paragraph
* Set keep paragraph with next paragraph setting
*
* @param bool $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setWidowControl($pValue = true)
{
@ -416,7 +415,7 @@ class PHPWord_Style_Paragraph
* Set keep paragraph with next paragraph setting
*
* @param bool $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setKeepNext($pValue = false)
{
@ -441,7 +440,7 @@ class PHPWord_Style_Paragraph
* Set keep all lines on one page setting
*
* @param bool $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setKeepLines($pValue = false)
{
@ -466,7 +465,7 @@ class PHPWord_Style_Paragraph
* Set start paragraph on next page setting
*
* @param bool $pValue
* @return PHPWord_Style_Paragraph
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setPageBreakBefore($pValue = false)
{

View File

@ -25,12 +25,10 @@
* @version 0.8.0
*/
/**
* PHPWord_Style_Row
*/
class PHPWord_Style_Row
{
namespace PhpOffice\PhpWord\Style;
class Row
{
/**
* Repeat table row on every new page
*

View File

@ -25,12 +25,10 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Style_TOC
*/
class PHPWord_Style_TOC
{
namespace PhpOffice\PhpWord\Style;
class TOC
{
const TABLEADER_DOT = 'dot';
const TABLEADER_UNDERSCORE = 'underscore';
const TABLEADER_LINE = 'hyphen';
@ -64,7 +62,7 @@ class PHPWord_Style_TOC
public function __construct()
{
$this->_tabPos = 9062;
$this->_tabLeader = PHPWord_Style_TOC::TABLEADER_DOT;
$this->_tabLeader = self::TABLEADER_DOT;
$this->_indent = 200;
}
@ -103,7 +101,7 @@ class PHPWord_Style_TOC
*
* @param string $pValue
*/
public function setTabLeader($pValue = PHPWord_Style_TOC::TABLEADER_DOT)
public function setTabLeader($pValue = self::TABLEADER_DOT)
{
$this->_tabLeader = $pValue;
}

View File

@ -25,12 +25,12 @@
* @version 0.8.0
*/
/**
* PHPWord_Style_Tabs
*/
class PHPWord_Style_Tab
{
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Tab
{
/**
* Tab Stop Type
*
@ -84,7 +84,7 @@ class PHPWord_Style_Tab
);
/**
* Create a new instance of PHPWord_Style_Tab. Both $val and $leader
* Create a new instance of Tab. Both $val and $leader
* must conform to the values put forth in the schema. If they do not
* they will be changed to default values.
*
@ -105,20 +105,20 @@ class PHPWord_Style_Tab
}
/**
* Creates the XML DOM for the instance of PHPWord_Style_Tab.
* Creates the XML DOM for the instance of Tab.
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PhpOffice\PhpWord\Shared\XMLWriter &$xmlWriter
*/
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = null)
public function toXml(XMLWriter &$xmlWriter = null)
{
if (isset($objWriter)) {
$objWriter->startElement("w:tab");
$objWriter->writeAttribute("w:val", $this->_val);
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tab");
$xmlWriter->writeAttribute("w:val", $this->_val);
if (!is_null($this->_leader)) {
$objWriter->writeAttribute("w:leader", $this->_leader);
$xmlWriter->writeAttribute("w:leader", $this->_leader);
}
$objWriter->writeAttribute("w:pos", $this->_position);
$objWriter->endElement();
$xmlWriter->writeAttribute("w:pos", $this->_position);
$xmlWriter->endElement();
}
}

View File

@ -25,12 +25,10 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Style_Table
*/
class PHPWord_Style_Table
{
namespace PhpOffice\PhpWord\Style;
class Table
{
private $_cellMarginTop;
private $_cellMarginLeft;
private $_cellMarginRight;

View File

@ -25,145 +25,104 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Style_TableFull
*/
class PHPWord_Style_TableFull
{
namespace PhpOffice\PhpWord\Style;
class TableFull
{
/**
* Style for first row
*
* @var PHPWord_Style_Table
* @var PhpOffice\PhpWord\Style\TableFull
*/
private $_firstRow = null;
/**
* Cell Margin Top
*
* @var int
*/
private $_cellMarginTop = null;
/**
* Cell Margin Left
*
* @var int
*/
private $_cellMarginLeft = null;
/**
* Cell Margin Right
*
* @var int
*/
private $_cellMarginRight = null;
/**
* Cell Margin Bottom
*
* @var int
*/
private $_cellMarginBottom = null;
/**
* Background-Color
*
* @var string
*/
private $_bgColor;
/**
* Border Top Size
*
* @var int
*/
private $_borderTopSize;
/**
* Border Top Color
*
* @var string
*/
private $_borderTopColor;
/**
* Border Left Size
*
* @var int
*/
private $_borderLeftSize;
/**
* Border Left Color
*
* @var string
*/
private $_borderLeftColor;
/**
* Border Right Size
*
* @var int
*/
private $_borderRightSize;
/**
* Border Right Color
*
* @var string
*/
private $_borderRightColor;
/**
* Border Bottom Size
*
* @var int
*/
private $_borderBottomSize;
/**
* Border Bottom Color
*
* @var string
*/
private $_borderBottomColor;
/**
* Border InsideH Size
*
* @var int
*/
private $_borderInsideHSize;
/**
* Border InsideH Color
*
* @var string
*/
private $_borderInsideHColor;
/**
* Border InsideV Size
*
* @var int
*/
private $_borderInsideVSize;
/**
* Border InsideV Color
*
* @var string
*/
private $_borderInsideVColor;
/**
* Create a new TableFull Font
*/
public function __construct($styleTable = null, $styleFirstRow = null, $styleLastRow = null)
public function __construct($styleTable = null, $styleFirstRow = null)
{
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->_firstRow = clone $this;
@ -196,8 +155,6 @@ class PHPWord_Style_TableFull
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
@ -217,7 +174,7 @@ class PHPWord_Style_TableFull
/**
* Get First Row Style
*
* @return PHPWord_Style_TableFull
* @return PhpOffice\PhpWord\Style\TableFull
*/
public function getFirstRow()
{
@ -227,7 +184,7 @@ class PHPWord_Style_TableFull
/**
* Get Last Row Style
*
* @return PHPWord_Style_TableFull
* @return PhpOffice\PhpWord\Style\TableFull
*/
public function getLastRow()
{

View File

@ -25,12 +25,12 @@
* @version 0.8.0
*/
/**
* PHPWord_Style_Tabs
*/
class PHPWord_Style_Tabs
{
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Tabs
{
/**
* Tabs
*
@ -48,17 +48,16 @@ class PHPWord_Style_Tabs
}
/**
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PhpOffice\PhpWord\Shared\XMLWriter &$xmlWriter
*/
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = null)
public function toXml(XMLWriter &$xmlWriter = null)
{
if (isset($objWriter)) {
$objWriter->startElement("w:tabs");
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tabs");
foreach ($this->_tabs as &$tab) {
$tab->toXml($objWriter);
$tab->toXml($xmlWriter);
}
$objWriter->endElement();
$xmlWriter->endElement();
}
}
}

View File

@ -25,12 +25,12 @@
* @version 0.8.0
*/
/**
* Class PHPWord_TOC
*/
class PHPWord_TOC
{
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font;
class TOC
{
/**
* Title Elements
*
@ -75,7 +75,7 @@ class PHPWord_TOC
*/
public function __construct($styleFont = null, $styleTOC = null)
{
self::$_styleTOC = new PHPWord_Style_TOC();
self::$_styleTOC = new PhpOffice\PhpWord\Style\TOC();
if (!is_null($styleTOC) && is_array($styleTOC)) {
foreach ($styleTOC as $key => $value) {
@ -88,7 +88,7 @@ class PHPWord_TOC
if (!is_null($styleFont)) {
if (is_array($styleFont)) {
self::$_styleFont = new PHPWord_Style_Font();
self::$_styleFont = new Font();
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -136,7 +136,7 @@ class PHPWord_TOC
/**
* Get TOC Style
*
* @return PHPWord_Style_TOC
* @return PhpOffice\PhpWord\Style\TOC
*/
public static function getStyleTOC()
{
@ -146,7 +146,7 @@ class PHPWord_TOC
/**
* Get Font Style
*
* @return PHPWord_Style_Font
* @return PhpOffice\PhpWord\Style\Font
*/
public static function getStyleFont()
{

View File

@ -25,14 +25,13 @@
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Shared\String;
/**
* PHPWord_DocumentProperties
*/
class PHPWord_Template
class Template
{
/**
* ZipArchive
*
@ -132,7 +131,7 @@ class PHPWord_Template
}
if (!is_array($replace)) {
if (!PHPWord_Shared_String::IsUTF8($replace)) {
if (!String::IsUTF8($replace)) {
$replace = utf8_encode($replace);
}
$replace = htmlspecialchars($replace);

View File

@ -25,10 +25,9 @@
* @version 0.8.0
*/
/**
* Interface PHPWord_Writer_IWriter
*/
interface PHPWord_Writer_IWriter
namespace PhpOffice\PhpWord\Writer;
interface IWriter
{
/**
* Save PHPWord to file

View File

@ -25,10 +25,16 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText
*/
class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\HashTable;
use PhpOffice\PhpWord\Writer\ODText\Content;
use PhpOffice\PhpWord\Writer\ODText\Manifest;
use PhpOffice\PhpWord\Writer\ODText\Meta;
use PhpOffice\PhpWord\Writer\ODText\Mimetype;
use PhpOffice\PhpWord\Writer\ODText\Styles;
class ODText implements IWriter
{
/**
* Private PHPWord
@ -40,14 +46,14 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
/**
* Private writer parts
*
* @var PHPWord_Writer_ODText_WriterPart[]
* @var PhpOffice\PhpWord\Writer\ODText\WriterPart[]
*/
private $_writerParts;
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var PHPWord_HashTable
* @var PhpOffice\PhpWord\HashTable
*/
private $_drawingHashTable;
@ -66,9 +72,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
private $_diskCachingDirectory;
/**
* Create a new PHPWord_Writer_ODText
*
* @param PHPWord $pPHPWord
* @param PHPWord $pPHPWord
*/
public function __construct(PHPWord $pPHPWord = null)
{
@ -79,11 +83,11 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
$this->_diskCachingDirectory = './';
// Initialise writer parts
$this->_writerParts['content'] = new PHPWord_Writer_ODText_Content();
$this->_writerParts['manifest'] = new PHPWord_Writer_ODText_Manifest();
$this->_writerParts['meta'] = new PHPWord_Writer_ODText_Meta();
$this->_writerParts['mimetype'] = new PHPWord_Writer_ODText_Mimetype();
$this->_writerParts['styles'] = new PHPWord_Writer_ODText_Styles();
$this->_writerParts['content'] = new Content();
$this->_writerParts['manifest'] = new Manifest();
$this->_writerParts['meta'] = new Meta();
$this->_writerParts['mimetype'] = new Mimetype();
$this->_writerParts['styles'] = new Styles();
// Assign parent IWriter
@ -92,7 +96,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
}
// Set HashTable variables
$this->_drawingHashTable = new PHPWord_HashTable();
$this->_drawingHashTable = new HashTable();
}
/**
@ -212,9 +216,9 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
/**
* Get PHPWord object
*
* @param PHPWord $pPHPWord PHPWord object
* @throws Exception
* @return PHPWord_Writer_ODText
* @param PHPWord $pPHPWord PHPWord object
* @throws Exception
* @return PhpOffice\PhpWord\Writer\ODText
*/
public function setPHPWord(PHPWord $pPHPWord = null)
{
@ -225,7 +229,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return PHPWord_HashTable
* @return PhpOffice\PhpWord\HashTable
*/
public function getDrawingHashTable()
{
@ -235,8 +239,8 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
/**
* Get writer part
*
* @param string $pPartName Writer part name
* @return PHPWord_Writer_ODText_WriterPart
* @param string $pPartName Writer part name
* @return PhpOffice\PhpWord\Writer\ODText\WriterPart
*/
public function getWriterPart($pPartName = '')
{
@ -260,10 +264,10 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
/**
* Set use disk caching where possible?
*
* @param boolean $pValue
* @param string $pDirectory Disk caching directory
* @throws Exception Exception when directory does not exist
* @return PHPWord_Writer_ODText
* @param boolean $pValue
* @param string $pDirectory Disk caching directory
* @throws Exception Exception when directory does not exist
* @return PhpOffice\PhpWord\Writer\ODText
*/
public function setUseDiskCaching($pValue = false, $pDirectory = null)
{

View File

@ -25,68 +25,85 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Manifest
*/
class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TOC;
class Content extends WriterPart
{
/**
* Write content file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
* @param PHPWord $phpWord
* @return string XML Output
* @throws Exception
*/
public function writeContent(PHPWord $pPHPWord = null)
public function writeContent(PHPWord $phpWord = null)
{
// Create XML writer
$objWriter = null;
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startDocument('1.0', 'UTF-8');
// office:document-content
$objWriter->startElement('office:document-content');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
$objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2');
$xmlWriter->startElement('office:document-content');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
$xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$xmlWriter->writeAttribute('office:version', '1.2');
// We firstly search all fonts used
$_sections = $pPHPWord->getSections();
$_sections = $phpWord->getSections();
$countSections = count($_sections);
if ($countSections > 0) {
$pSection = 0;
@ -98,23 +115,23 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
$pStyle = $element->getParagraphStyle();
if ($fStyle instanceof PHPWord_Style_Font) {
if ($fStyle instanceof Font) {
$numFStyles++;
$arrStyle = array(
'color' => $fStyle->getColor(),
'name' => $fStyle->getName()
);
$pPHPWord->addFontStyle('T' . $numFStyles, $arrStyle);
$phpWord->addFontStyle('T' . $numFStyles, $arrStyle);
$element->setFontStyle('T' . $numFStyles);
} elseif ($pStyle instanceof PHPWord_Style_Paragraph) {
} elseif ($pStyle instanceof Paragraph) {
$numPStyles++;
$pPHPWord->addParagraphStyle('P' . $numPStyles, array());
$phpWord->addParagraphStyle('P' . $numPStyles, array());
$element->setParagraphStyle('P' . $numPStyles);
}
}
@ -123,120 +140,120 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
}
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = PHPWord_Style::getStyles();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$objWriter->endElement();
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
}
$objWriter->endElement();
$xmlWriter->endElement();
$objWriter->startElement('office:automatic-styles');
$styles = PHPWord_Style::getStyles();
$xmlWriter->startElement('office:automatic-styles');
$styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if (preg_match('#^T[0-9]+$#', $styleName) != 0
|| preg_match('#^P[0-9]+$#', $styleName) != 0
) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:color', '#' . $style->getColor());
$objWriter->writeAttribute('style:font-name', $style->getName());
$objWriter->writeAttribute('style:font-name-complex', $style->getName());
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('fo:color', '#' . $style->getColor());
$xmlWriter->writeAttribute('style:font-name', $style->getName());
$xmlWriter->writeAttribute('style:font-name-complex', $style->getName());
$xmlWriter->endElement();
$xmlWriter->endElement();
}
if ($style instanceof PHPWord_Style_Paragraph) {
if ($style instanceof Paragraph) {
$numPStyles++;
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'paragraph');
$xmlWriter->writeAttribute('style:parent-style-name', 'Standard');
$xmlWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('style:page-number', 'auto');
$xmlWriter->endElement();
$xmlWriter->endElement();
}
}
}
if ($numPStyles == 0) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', 'P1');
$objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', 'P1');
$xmlWriter->writeAttribute('style:family', 'paragraph');
$xmlWriter->writeAttribute('style:parent-style-name', 'Standard');
$xmlWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('style:page-number', 'auto');
$xmlWriter->endElement();
$xmlWriter->endElement();
}
}
$objWriter->endElement();
$xmlWriter->endElement();
// office:body
$objWriter->startElement('office:body');
$xmlWriter->startElement('office:body');
// office:text
$objWriter->startElement('office:text');
$xmlWriter->startElement('office:text');
// text:sequence-decls
$objWriter->startElement('text:sequence-decls');
$xmlWriter->startElement('text:sequence-decls');
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Illustration');
$objWriter->endElement();
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Illustration');
$xmlWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Table');
$objWriter->endElement();
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Table');
$xmlWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Text');
$objWriter->endElement();
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Text');
$xmlWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Drawing');
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Drawing');
$xmlWriter->endElement();
$xmlWriter->endElement();
$_sections = $pPHPWord->getSections();
$_sections = $phpWord->getSections();
$countSections = count($_sections);
$pSection = 0;
@ -247,66 +264,63 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter);
} elseif ($element instanceof PHPWord_Section_Link) {
$this->writeUnsupportedElement($objWriter, 'Link');
} elseif ($element instanceof PHPWord_Section_Title) {
$this->writeUnsupportedElement($objWriter, 'Title');
} elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->writeUnsupportedElement($objWriter, 'Page Break');
} elseif ($element instanceof PHPWord_Section_Table) {
$this->writeUnsupportedElement($objWriter, 'Table');
} elseif ($element instanceof PHPWord_Section_ListItem) {
$this->writeUnsupportedElement($objWriter, 'List Item');
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) {
$this->writeUnsupportedElement($objWriter, 'Image');
} elseif ($element instanceof PHPWord_Section_Object) {
$this->writeUnsupportedElement($objWriter, 'Object');
} elseif ($element instanceof PHPWord_TOC) {
$this->writeUnsupportedElement($objWriter, 'TOC');
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter);
} elseif ($element instanceof Link) {
$this->writeUnsupportedElement($xmlWriter, 'Link');
} elseif ($element instanceof Title) {
$this->writeUnsupportedElement($xmlWriter, 'Title');
} elseif ($element instanceof PageBreak) {
$this->writeUnsupportedElement($xmlWriter, 'Page Break');
} elseif ($element instanceof Table) {
$this->writeUnsupportedElement($xmlWriter, 'Table');
} elseif ($element instanceof ListItem) {
$this->writeUnsupportedElement($xmlWriter, 'List Item');
} elseif ($element instanceof Image ||
$element instanceof MemoryImage) {
$this->writeUnsupportedElement($xmlWriter, 'Image');
} elseif ($element instanceof Object) {
$this->writeUnsupportedElement($xmlWriter, 'Object');
} elseif ($element instanceof TOC) {
$this->writeUnsupportedElement($xmlWriter, 'TOC');
} else {
$this->writeUnsupportedElement($objWriter, 'Element');
$this->writeUnsupportedElement($xmlWriter, 'Element');
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
$this->_writeEndSection($xmlWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
$this->_writeSection($xmlWriter, $section);
}
}
}
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
// Return
return $objWriter->getData();
return $xmlWriter->getData();
}
/**
* Write text
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section_Text $text
* @param bool $withoutP
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\Text $text
* @param bool $withoutP
*/
protected function _writeText(
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section_Text $text,
$withoutP = false
) {
protected function _writeText(XMLWriter $xmlWriter = null, Text $text, $withoutP = false)
{
$styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value
// $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
// $SfIsObject = ($styleFont instanceof Font) ? true : false;
$SfIsObject = false;
if ($SfIsObject) {
@ -314,29 +328,29 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
die('PHPWord : $SfIsObject wouldn\'t be an object');
} else {
if (!$withoutP) {
$objWriter->startElement('text:p'); // text:p
$xmlWriter->startElement('text:p'); // text:p
}
if (empty($styleFont)) {
if (empty($styleParagraph)) {
$objWriter->writeAttribute('text:style-name', 'P1');
$xmlWriter->writeAttribute('text:style-name', 'P1');
} else {
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
$objWriter->writeRaw($text->getText());
$xmlWriter->writeRaw($text->getText());
} else {
if (empty($styleParagraph)) {
$objWriter->writeAttribute('text:style-name', 'Standard');
$xmlWriter->writeAttribute('text:style-name', 'Standard');
} else {
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
// text:span
$objWriter->startElement('text:span');
$objWriter->writeAttribute('text:style-name', $styleFont);
$objWriter->writeRaw($text->getText());
$objWriter->endElement();
$xmlWriter->startElement('text:span');
$xmlWriter->writeAttribute('text:style-name', $styleFont);
$xmlWriter->writeRaw($text->getText());
$xmlWriter->endElement();
}
if (!$withoutP) {
$objWriter->endElement(); // text:p
$xmlWriter->endElement(); // text:p
}
}
}
@ -344,40 +358,40 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
/**
* Write TextRun section
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section_TextRun $textrun
* @todo Enable all other section types
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\TextRun $textrun
* @todo Enable all other section types
*/
protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun)
protected function _writeTextRun(XMLWriter $xmlWriter = null, TextRun $textrun)
{
$elements = $textrun->getElements();
$objWriter->startElement('text:p');
$xmlWriter->startElement('text:p');
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element, true);
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element, true);
}
}
}
$objWriter->endElement();
$xmlWriter->endElement();
}
/**
* Write TextBreak
*/
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null)
protected function _writeTextBreak(XMLWriter $xmlWriter = null)
{
$objWriter->startElement('text:p');
$objWriter->writeAttribute('text:style-name', 'Standard');
$objWriter->endElement();
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard');
$xmlWriter->endElement();
}
// @codeCoverageIgnoreStart
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
// @codeCoverageIgnoreEnd
@ -385,13 +399,13 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
/**
* Write unsupported element
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param string $element
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $element
*/
private function writeUnsupportedElement($objWriter, $element)
private function writeUnsupportedElement($xmlWriter, $element)
{
$objWriter->startElement('text:p');
$objWriter->writeRaw("{$element}");
$objWriter->endElement();
$xmlWriter->startElement('text:p');
$xmlWriter->writeRaw($element);
$xmlWriter->endElement();
}
}

View File

@ -25,10 +25,12 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Manifest
*/
class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Shared\File;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Manifest extends WriterPart
{
/**
* Write Manifest file to XML format
@ -40,42 +42,42 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
public function writeManifest(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startDocument('1.0', 'UTF-8');
// manifest:manifest
$objWriter->startElement('manifest:manifest');
$objWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
$objWriter->writeAttribute('manifest:version', '1.2');
$xmlWriter->startElement('manifest:manifest');
$xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
$xmlWriter->writeAttribute('manifest:version', '1.2');
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
$objWriter->writeAttribute('manifest:version', '1.2');
$objWriter->writeAttribute('manifest:full-path', '/');
$objWriter->endElement();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
$xmlWriter->writeAttribute('manifest:version', '1.2');
$xmlWriter->writeAttribute('manifest:full-path', '/');
$xmlWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'content.xml');
$objWriter->endElement();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'content.xml');
$xmlWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'meta.xml');
$objWriter->endElement();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'meta.xml');
$xmlWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'styles.xml');
$objWriter->endElement();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'styles.xml');
$xmlWriter->endElement();
// Not used yet. Legacy from PHPExcel
// @codeCoverageIgnoreStart
@ -84,10 +86,10 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
$mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', $mimeType);
$objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$objWriter->endElement();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
$xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$xmlWriter->endElement();
} elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
$extension = explode('/', $extension);
@ -95,18 +97,18 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
$mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType();
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', $mimeType);
$objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$objWriter->endElement();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
$xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$xmlWriter->endElement();
}
}
// @codeCoverageIgnoreEnd
$objWriter->endElement();
$xmlWriter->endElement();
// Return
return $objWriter->getData();
return $xmlWriter->getData();
}
@ -119,7 +121,7 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
*/
private function _getImageMimeType($pFile = '')
{
if (PHPWord_Shared_File::file_exists($pFile)) {
if (File::file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {

View File

@ -25,10 +25,11 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Meta
*/
class PHPWord_Writer_ODText_Meta extends PHPWord_Writer_ODText_WriterPart
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Meta extends WriterPart
{
/**
* Write Meta file to XML format
@ -40,55 +41,55 @@ class PHPWord_Writer_ODText_Meta extends PHPWord_Writer_ODText_WriterPart
public function writeMeta(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startDocument('1.0', 'UTF-8');
// office:document-meta
$objWriter->startElement('office:document-meta');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('office:version', '1.2');
$xmlWriter->startElement('office:document-meta');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('office:version', '1.2');
// office:meta
$objWriter->startElement('office:meta');
$xmlWriter->startElement('office:meta');
// dc:creator
$objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getLastModifiedBy());
$xmlWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getLastModifiedBy());
// dc:date
$objWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getModified()));
$xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getModified()));
// dc:description
$objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
$xmlWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
// dc:subject
$objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
$xmlWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
// dc:title
$objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
$xmlWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
// meta:creation-date
$objWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getCreated()));
$xmlWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getCreated()));
// meta:initial-creator
$objWriter->writeElement('meta:initial-creator', $pPHPWord->getProperties()->getCreator());
$xmlWriter->writeElement('meta:initial-creator', $pPHPWord->getProperties()->getCreator());
// meta:keyword
$objWriter->writeElement('meta:keyword', $pPHPWord->getProperties()->getKeywords());
$xmlWriter->writeElement('meta:keyword', $pPHPWord->getProperties()->getKeywords());
// @todo : Where these properties are written ?
// $pPHPWord->getProperties()->getCategory()
// $pPHPWord->getProperties()->getCompany()
$objWriter->endElement();
$xmlWriter->endElement();
$objWriter->endElement();
$xmlWriter->endElement();
// Return
return $objWriter->getData();
return $xmlWriter->getData();
}
}

View File

@ -25,10 +25,9 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Mimetype
*/
class PHPWord_Writer_ODText_Mimetype extends PHPWord_Writer_ODText_WriterPart
namespace PhpOffice\PhpWord\Writer\ODText;
class Mimetype extends WriterPart
{
/**
* Write Mimetype to Text format

View File

@ -25,10 +25,15 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Styles
*/
class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
class Styles extends WriterPart
{
/**
* Write Styles file to XML format
@ -40,228 +45,228 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
public function writeStyles(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startDocument('1.0', 'UTF-8');
// Styles:Styles
$objWriter->startElement('office:document-styles');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2');
$xmlWriter->startElement('office:document-styles');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$xmlWriter->writeAttribute('office:version', '1.2');
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = PHPWord_Style::getStyles();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
}
if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$objWriter->endElement();
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
$objWriter->endElement();
$xmlWriter->endElement();
// office:styles
$objWriter->startElement('office:styles');
$xmlWriter->startElement('office:styles');
// style:default-style
$objWriter->startElement('style:default-style');
$objWriter->writeAttribute('style:family', 'paragraph');
$xmlWriter->startElement('style:default-style');
$xmlWriter->writeAttribute('style:family', 'paragraph');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
$objWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
$objWriter->writeAttribute('style:punctuation-wrap', 'hanging');
$objWriter->writeAttribute('style:line-break', 'strict');
$objWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
$objWriter->writeAttribute('style:writing-mode', 'page');
$objWriter->endElement();
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
$xmlWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
$xmlWriter->writeAttribute('style:punctuation-wrap', 'hanging');
$xmlWriter->writeAttribute('style:line-break', 'strict');
$xmlWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
$xmlWriter->writeAttribute('style:writing-mode', 'page');
$xmlWriter->endElement();
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('style:use-window-font-color', 'true');
$objWriter->writeAttribute('style:font-name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('fo:font-size', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('fo:language', 'fr');
$objWriter->writeAttribute('fo:country', 'FR');
$objWriter->writeAttribute('style:letter-kerning', 'true');
$objWriter->writeAttribute('style:font-name-asian', PHPWord::DEFAULT_FONT_NAME . '2');
$objWriter->writeAttribute('style:font-size-asian', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('style:language-asian', 'zh');
$objWriter->writeAttribute('style:country-asian', 'CN');
$objWriter->writeAttribute('style:font-name-complex', PHPWord::DEFAULT_FONT_NAME . '2');
$objWriter->writeAttribute('style:font-size-complex', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('style:language-complex', 'hi');
$objWriter->writeAttribute('style:country-complex', 'IN');
$objWriter->writeAttribute('fo:hyphenate', 'false');
$objWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
$objWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
$objWriter->endElement();
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('style:use-window-font-color', 'true');
$xmlWriter->writeAttribute('style:font-name', PHPWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('fo:font-size', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$xmlWriter->writeAttribute('fo:language', 'fr');
$xmlWriter->writeAttribute('fo:country', 'FR');
$xmlWriter->writeAttribute('style:letter-kerning', 'true');
$xmlWriter->writeAttribute('style:font-name-asian', PHPWord::DEFAULT_FONT_NAME . '2');
$xmlWriter->writeAttribute('style:font-size-asian', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$xmlWriter->writeAttribute('style:language-asian', 'zh');
$xmlWriter->writeAttribute('style:country-asian', 'CN');
$xmlWriter->writeAttribute('style:font-name-complex', PHPWord::DEFAULT_FONT_NAME . '2');
$xmlWriter->writeAttribute('style:font-size-complex', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$xmlWriter->writeAttribute('style:language-complex', 'hi');
$xmlWriter->writeAttribute('style:country-complex', 'IN');
$xmlWriter->writeAttribute('fo:hyphenate', 'false');
$xmlWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
$xmlWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
$xmlWriter->endElement();
$objWriter->endElement();
$xmlWriter->endElement();
// Write Style Definitions
$styles = PHPWord_Style::getStyles();
$styles = Style::getStyles();
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if (preg_match('#^T[0-9]+$#', $styleName) == 0
&& preg_match('#^P[0-9]+$#', $styleName) == 0
) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:font-size', ($style->getSize()) . 'pt');
$objWriter->writeAttribute('style:font-size-asian', ($style->getSize()) . 'pt');
$objWriter->writeAttribute('style:font-size-complex', ($style->getSize()) . 'pt');
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('fo:font-size', ($style->getSize()) . 'pt');
$xmlWriter->writeAttribute('style:font-size-asian', ($style->getSize()) . 'pt');
$xmlWriter->writeAttribute('style:font-size-complex', ($style->getSize()) . 'pt');
if ($style->getItalic()) {
$objWriter->writeAttribute('fo:font-style', 'italic');
$objWriter->writeAttribute('style:font-style-asian', 'italic');
$objWriter->writeAttribute('style:font-style-complex', 'italic');
$xmlWriter->writeAttribute('fo:font-style', 'italic');
$xmlWriter->writeAttribute('style:font-style-asian', 'italic');
$xmlWriter->writeAttribute('style:font-style-complex', 'italic');
}
if ($style->getBold()) {
$objWriter->writeAttribute('fo:font-weight', 'bold');
$objWriter->writeAttribute('style:font-weight-asian', 'bold');
$xmlWriter->writeAttribute('fo:font-weight', 'bold');
$xmlWriter->writeAttribute('style:font-weight-asian', 'bold');
}
$objWriter->endElement();
$objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_Paragraph) {
// PHPWord_Style_Paragraph
$xmlWriter->endElement();
$xmlWriter->endElement();
} elseif ($style instanceof Paragraph) {
// PhpOffice\PhpWord\Style\Paragraph
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'paragraph');
//style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)) . 'cm');
$objWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)) . 'cm');
$objWriter->writeAttribute('fo:text-align', $style->getAlign());
$objWriter->endElement();
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)) . 'cm');
$xmlWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)) . 'cm');
$xmlWriter->writeAttribute('fo:text-align', $style->getAlign());
$xmlWriter->endElement();
$objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_TableFull) {
// PHPWord_Style_TableFull
$xmlWriter->endElement();
} elseif ($style instanceof TableFull) {
// PhpOffice\PhpWord\Style\TableFull
}
}
}
}
$objWriter->endElement();
$xmlWriter->endElement();
// office:automatic-styles
$objWriter->startElement('office:automatic-styles');
$xmlWriter->startElement('office:automatic-styles');
// style:page-layout
$objWriter->startElement('style:page-layout');
$objWriter->writeAttribute('style:name', 'Mpm1');
$xmlWriter->startElement('style:page-layout');
$xmlWriter->writeAttribute('style:name', 'Mpm1');
// style:page-layout-properties
$objWriter->startElement('style:page-layout-properties');
$objWriter->writeAttribute('fo:page-width', "21.001cm");
$objWriter->writeAttribute('fo:page-height', '29.7cm');
$objWriter->writeAttribute('style:num-format', '1');
$objWriter->writeAttribute('style:print-orientation', 'portrait');
$objWriter->writeAttribute('fo:margin-top', '2.501cm');
$objWriter->writeAttribute('fo:margin-bottom', '2cm');
$objWriter->writeAttribute('fo:margin-left', '2.501cm');
$objWriter->writeAttribute('fo:margin-right', '2.501cm');
$objWriter->writeAttribute('style:writing-mode', 'lr-tb');
$objWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
$objWriter->writeAttribute('style:layout-grid-lines', '25199');
$objWriter->writeAttribute('style:layout-grid-base-height', '0.423cm');
$objWriter->writeAttribute('style:layout-grid-ruby-height', '0cm');
$objWriter->writeAttribute('style:layout-grid-mode', 'none');
$objWriter->writeAttribute('style:layout-grid-ruby-below', 'false');
$objWriter->writeAttribute('style:layout-grid-print', 'false');
$objWriter->writeAttribute('style:layout-grid-display', 'false');
$objWriter->writeAttribute('style:layout-grid-base-width', '0.37cm');
$objWriter->writeAttribute('style:layout-grid-snap-to', 'true');
$objWriter->writeAttribute('style:footnote-max-height', '0cm');
$xmlWriter->startElement('style:page-layout-properties');
$xmlWriter->writeAttribute('fo:page-width', "21.001cm");
$xmlWriter->writeAttribute('fo:page-height', '29.7cm');
$xmlWriter->writeAttribute('style:num-format', '1');
$xmlWriter->writeAttribute('style:print-orientation', 'portrait');
$xmlWriter->writeAttribute('fo:margin-top', '2.501cm');
$xmlWriter->writeAttribute('fo:margin-bottom', '2cm');
$xmlWriter->writeAttribute('fo:margin-left', '2.501cm');
$xmlWriter->writeAttribute('fo:margin-right', '2.501cm');
$xmlWriter->writeAttribute('style:writing-mode', 'lr-tb');
$xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
$xmlWriter->writeAttribute('style:layout-grid-lines', '25199');
$xmlWriter->writeAttribute('style:layout-grid-base-height', '0.423cm');
$xmlWriter->writeAttribute('style:layout-grid-ruby-height', '0cm');
$xmlWriter->writeAttribute('style:layout-grid-mode', 'none');
$xmlWriter->writeAttribute('style:layout-grid-ruby-below', 'false');
$xmlWriter->writeAttribute('style:layout-grid-print', 'false');
$xmlWriter->writeAttribute('style:layout-grid-display', 'false');
$xmlWriter->writeAttribute('style:layout-grid-base-width', '0.37cm');
$xmlWriter->writeAttribute('style:layout-grid-snap-to', 'true');
$xmlWriter->writeAttribute('style:footnote-max-height', '0cm');
//style:footnote-sep
$objWriter->startElement('style:footnote-sep');
$objWriter->writeAttribute('style:width', '0.018cm');
$objWriter->writeAttribute('style:line-style', 'solid');
$objWriter->writeAttribute('style:adjustment', 'left');
$objWriter->writeAttribute('style:rel-width', '25%');
$objWriter->writeAttribute('style:color', '#000000');
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->startElement('style:footnote-sep');
$xmlWriter->writeAttribute('style:width', '0.018cm');
$xmlWriter->writeAttribute('style:line-style', 'solid');
$xmlWriter->writeAttribute('style:adjustment', 'left');
$xmlWriter->writeAttribute('style:rel-width', '25%');
$xmlWriter->writeAttribute('style:color', '#000000');
$xmlWriter->endElement();
$xmlWriter->endElement();
// style:header-style
$objWriter->startElement('style:header-style');
$objWriter->endElement();
$xmlWriter->startElement('style:header-style');
$xmlWriter->endElement();
// style:footer-style
$objWriter->startElement('style:footer-style');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->startElement('style:footer-style');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
// office:master-styles
$objWriter->startElement('office:master-styles');
$xmlWriter->startElement('office:master-styles');
// style:master-page
$objWriter->startElement('style:master-page');
$objWriter->writeAttribute('style:name', 'Standard');
$objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$objWriter->endElement();
$objWriter->endElement();
$xmlWriter->startElement('style:master-page');
$xmlWriter->writeAttribute('style:name', 'Standard');
$xmlWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$xmlWriter->endElement();
$xmlWriter->endElement();
$objWriter->endElement();
$xmlWriter->endElement();
// Return
return $objWriter->getData();
return $xmlWriter->getData();
}
}

View File

@ -25,25 +25,26 @@
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_WriterPart
*/
abstract class PHPWord_Writer_ODText_WriterPart
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Writer\IWriter;
abstract class WriterPart
{
/**
* Parent IWriter object
*
* @var PHPWord_Writer_IWriter
* @var PhpOffice\PhpWord\Writer\IWriter
*/
private $_parentWriter;
/**
* Set parent IWriter object
*
* @param PHPWord_Writer_IWriter $pWriter
* @param PhpOffice\PhpWord\Writer\IWriter $pWriter
* @throws Exception
*/
public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null)
public function setParentWriter(IWriter $pWriter = null)
{
$this->_parentWriter = $pWriter;
}
@ -51,7 +52,7 @@ abstract class PHPWord_Writer_ODText_WriterPart
/**
* Get parent IWriter object
*
* @return PHPWord_Writer_IWriter
* @return PhpOffice\PhpWord\Writer\IWriter
* @throws Exception
*/
public function getParentWriter()
@ -59,7 +60,7 @@ abstract class PHPWord_Writer_ODText_WriterPart
if (!is_null($this->_parentWriter)) {
return $this->_parentWriter;
} else {
throw new Exception("No parent PHPWord_Writer_IWriter assigned.");
throw new Exception("No parent IWriter assigned.");
}
}
}