This commit is contained in:
Roman Syroeshko 2014-03-18 17:26:03 +04:00
parent b32c198824
commit 51ced7db8e
50 changed files with 1818 additions and 1780 deletions

View File

@ -99,10 +99,10 @@ class Style
* @param string $styleName * @param string $styleName
* @param array $styles * @param array $styles
*/ */
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null, $styleLastRow = null) public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{ {
if (!array_key_exists($styleName, self::$_styleElements)) { if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new TableFull($styleTable, $styleFirstRow, $styleLastRow); $style = new TableFull($styleTable, $styleFirstRow);
self::$_styleElements[$styleName] = $style; self::$_styleElements[$styleName] = $style;
} }

View File

@ -72,12 +72,12 @@ class ODText implements IWriter
private $_diskCachingDirectory; private $_diskCachingDirectory;
/** /**
* @param PHPWord $pPHPWord * @param PHPWord $phpWord
*/ */
public function __construct(PHPWord $pPHPWord = null) public function __construct(PHPWord $phpWord = null)
{ {
// Assign PHPWord // Assign PHPWord
$this->setPHPWord($pPHPWord); $this->setPHPWord($phpWord);
// Set up disk caching location // Set up disk caching location
$this->_diskCachingDirectory = './'; $this->_diskCachingDirectory = './';
@ -216,13 +216,13 @@ class ODText implements IWriter
/** /**
* Get PHPWord object * Get PHPWord object
* *
* @param PHPWord $pPHPWord PHPWord object * @param PHPWord $phpWord PHPWord object
* @throws Exception * @throws Exception
* @return PhpOffice\PhpWord\Writer\ODText * @return PhpOffice\PhpWord\Writer\ODText
*/ */
public function setPHPWord(PHPWord $pPHPWord = null) public function setPHPWord(PHPWord $phpWord = null)
{ {
$this->_document = $pPHPWord; $this->_document = $phpWord;
return $this; return $this;
} }

View File

@ -35,11 +35,11 @@ class Manifest extends WriterPart
/** /**
* Write Manifest file to XML format * Write Manifest file to XML format
* *
* @param PHPWord $pPHPWord * @param PHPWord $phpWord
* @return string XML Output * @return string XML Output
* @throws Exception * @throws Exception
*/ */
public function writeManifest(PHPWord $pPHPWord = null) public function writeManifest(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
$xmlWriter = null; $xmlWriter = null;

View File

@ -34,11 +34,11 @@ class Meta extends WriterPart
/** /**
* Write Meta file to XML format * Write Meta file to XML format
* *
* @param PHPWord $pPHPWord * @param PHPWord $phpWord
* @return string XML Output * @return string XML Output
* @throws Exception * @throws Exception
*/ */
public function writeMeta(PHPWord $pPHPWord = null) public function writeMeta(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
$xmlWriter = null; $xmlWriter = null;
@ -65,25 +65,25 @@ class Meta extends WriterPart
$xmlWriter->startElement('office:meta'); $xmlWriter->startElement('office:meta');
// dc:creator // dc:creator
$xmlWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getLastModifiedBy()); $xmlWriter->writeElement('dc:creator', $phpWord->getProperties()->getLastModifiedBy());
// dc:date // dc:date
$xmlWriter->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', $phpWord->getProperties()->getModified()));
// dc:description // dc:description
$xmlWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription()); $xmlWriter->writeElement('dc:description', $phpWord->getProperties()->getDescription());
// dc:subject // dc:subject
$xmlWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject()); $xmlWriter->writeElement('dc:subject', $phpWord->getProperties()->getSubject());
// dc:title // dc:title
$xmlWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle()); $xmlWriter->writeElement('dc:title', $phpWord->getProperties()->getTitle());
// meta:creation-date // meta:creation-date
$xmlWriter->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', $phpWord->getProperties()->getCreated()));
// meta:initial-creator // meta:initial-creator
$xmlWriter->writeElement('meta:initial-creator', $pPHPWord->getProperties()->getCreator()); $xmlWriter->writeElement('meta:initial-creator', $phpWord->getProperties()->getCreator());
// meta:keyword // meta:keyword
$xmlWriter->writeElement('meta:keyword', $pPHPWord->getProperties()->getKeywords()); $xmlWriter->writeElement('meta:keyword', $phpWord->getProperties()->getKeywords());
// @todo : Where these properties are written ? // @todo : Where these properties are written ?
// $pPHPWord->getProperties()->getCategory() // $phpWord->getProperties()->getCategory()
// $pPHPWord->getProperties()->getCompany() // $phpWord->getProperties()->getCompany()
$xmlWriter->endElement(); $xmlWriter->endElement();

View File

@ -32,11 +32,11 @@ class Mimetype extends WriterPart
/** /**
* Write Mimetype to Text format * Write Mimetype to Text format
* *
* @param PHPWord $pPHPWord * @param PHPWord $phpWord
* @return string Text Output * @return string Text Output
* @throws Exception * @throws Exception
*/ */
public function writeMimetype(PHPWord $pPHPWord = null) public function writeMimetype(PHPWord $phpWord = null)
{ {
return 'application/vnd.oasis.opendocument.text'; return 'application/vnd.oasis.opendocument.text';

View File

@ -38,11 +38,11 @@ class Styles extends WriterPart
/** /**
* Write Styles file to XML format * Write Styles file to XML format
* *
* @param PHPWord $pPHPWord * @param PHPWord $phpWord
* @return string XML Output * @return string XML Output
* @throws Exception * @throws Exception
*/ */
public function writeStyles(PHPWord $pPHPWord = null) public function writeStyles(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
$xmlWriter = null; $xmlWriter = null;

View File

@ -25,10 +25,27 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer;
* Class PHPWord_Writer_RTF
*/ use PhpOffice\PhpWord\HashTable;
class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter 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\Drawing;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TOC;
class RTF implements IWriter
{ {
/** /**
* Private PHPWord * Private PHPWord
@ -40,7 +57,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/** /**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable * Private unique PHPWord_Worksheet_BaseDrawing HashTable
* *
* @var PHPWord_HashTable * @var PhpOffice\PhpWord\HashTable
*/ */
private $_drawingHashTable; private $_drawingHashTable;
@ -49,17 +66,15 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
private $_lastParagraphStyle; private $_lastParagraphStyle;
/** /**
* Create a new PHPWord_Writer_ODText * @param PHPWord $phpWord
*
* @param PHPWord $pPHPWord
*/ */
public function __construct(PHPWord $pPHPWord = null) public function __construct(PHPWord $phpWord = null)
{ {
// Assign PHPWord // Assign PHPWord
$this->setPHPWord($pPHPWord); $this->setPHPWord($phpWord);
// Set HashTable variables // Set HashTable variables
$this->_drawingHashTable = new PHPWord_HashTable(); $this->_drawingHashTable = new HashTable();
} }
/** /**
@ -113,22 +128,20 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
/** /**
* Get PHPWord object * @param PHPWord $phpWord PHPWord object
* * @throws Exception
* @param PHPWord $pPHPWord PHPWord object * @return PhpOffice\PhpWord\Writer\RTF
* @throws Exception
* @return PHPWord_Writer_RTF
*/ */
public function setPHPWord(PHPWord $pPHPWord = null) public function setPHPWord(PHPWord $phpWord = null)
{ {
$this->_document = $pPHPWord; $this->_document = $phpWord;
return $this; return $this;
} }
/** /**
* Get PHPWord_Worksheet_BaseDrawing HashTable * Get PHPWord_Worksheet_BaseDrawing HashTable
* *
* @return PHPWord_HashTable * @return PhpOffice\PhpWord\HashTable
*/ */
public function getDrawingHashTable() public function getDrawingHashTable()
{ {
@ -158,7 +171,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
// Set the color tbl group // Set the color tbl group
$sRTFContent .= '{\colortbl '; $sRTFContent .= '{\colortbl ';
foreach ($this->_colorTable as $idx => $color) { foreach ($this->_colorTable as $idx => $color) {
$arrColor = PHPWord_Shared_Drawing::htmlToRGB($color); $arrColor = Drawing::htmlToRGB($color);
$sRTFContent .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . ''; $sRTFContent .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . '';
} }
$sRTFContent .= ';}' . PHP_EOL; $sRTFContent .= ';}' . PHP_EOL;
@ -190,7 +203,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
private function getDataFont() private function getDataFont()
{ {
$pPHPWord = $this->_document; $phpWord = $this->_document;
$arrFonts = array(); $arrFonts = array();
// Default font : PHPWord::DEFAULT_FONT_NAME // Default font : PHPWord::DEFAULT_FONT_NAME
@ -198,12 +211,12 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
// PHPWord object : $this->_document // PHPWord object : $this->_document
// Browse styles // Browse styles
$styles = PHPWord_Style::getStyles(); $styles = Style::getStyles();
$numPStyles = 0; $numPStyles = 0;
if (count($styles) > 0) { if (count($styles) > 0) {
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font // PhpOffice\PhpWord\Style\Font
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof Font) {
if (in_array($style->getName(), $arrFonts) == false) { if (in_array($style->getName(), $arrFonts) == false) {
$arrFonts[] = $style->getName(); $arrFonts[] = $style->getName();
} }
@ -212,7 +225,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
// Search all fonts used // Search all fonts used
$_sections = $pPHPWord->getSections(); $_sections = $phpWord->getSections();
$countSections = count($_sections); $countSections = count($_sections);
if ($countSections > 0) { if ($countSections > 0) {
$pSection = 0; $pSection = 0;
@ -222,10 +235,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$_elements = $section->getElements(); $_elements = $section->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof Text) {
$fStyle = $element->getFontStyle(); $fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) { if ($fStyle instanceof Font) {
if (in_array($fStyle->getName(), $arrFonts) == false) { if (in_array($fStyle->getName(), $arrFonts) == false) {
$arrFonts[] = $fStyle->getName(); $arrFonts[] = $fStyle->getName();
} }
@ -240,18 +253,18 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
private function getDataColor() private function getDataColor()
{ {
$pPHPWord = $this->_document; $phpWord = $this->_document;
$arrColors = array(); $arrColors = array();
// PHPWord object : $this->_document // PHPWord object : $this->_document
// Browse styles // Browse styles
$styles = PHPWord_Style::getStyles(); $styles = Style::getStyles();
$numPStyles = 0; $numPStyles = 0;
if (count($styles) > 0) { if (count($styles) > 0) {
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font // Font
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof Font) {
$color = $style->getColor(); $color = $style->getColor();
$fgcolor = $style->getFgColor(); $fgcolor = $style->getFgColor();
if (in_array($color, $arrColors) == false && $color != PHPWord::DEFAULT_FONT_COLOR && !empty($color)) { if (in_array($color, $arrColors) == false && $color != PHPWord::DEFAULT_FONT_COLOR && !empty($color)) {
@ -265,7 +278,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
// Search all fonts used // Search all fonts used
$_sections = $pPHPWord->getSections(); $_sections = $phpWord->getSections();
$countSections = count($_sections); $countSections = count($_sections);
if ($countSections > 0) { if ($countSections > 0) {
$pSection = 0; $pSection = 0;
@ -275,10 +288,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$_elements = $section->getElements(); $_elements = $section->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof Text) {
$fStyle = $element->getFontStyle(); $fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) { if ($fStyle instanceof Font) {
if (in_array($fStyle->getColor(), $arrColors) == false) { if (in_array($fStyle->getColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getColor(); $arrColors[] = $fStyle->getColor();
} }
@ -296,10 +309,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
private function getDataContent() private function getDataContent()
{ {
$pPHPWord = $this->_document; $phpWord = $this->_document;
$sRTFBody = ''; $sRTFBody = '';
$_sections = $pPHPWord->getSections(); $_sections = $phpWord->getSections();
$countSections = count($_sections); $countSections = count($_sections);
$pSection = 0; $pSection = 0;
@ -308,28 +321,28 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$pSection++; $pSection++;
$_elements = $section->getElements(); $_elements = $section->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof Text) {
$sRTFBody .= $this->getDataContentText($element); $sRTFBody .= $this->getDataContentText($element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof TextBreak) {
$sRTFBody .= $this->getDataContentTextBreak(); $sRTFBody .= $this->getDataContentTextBreak();
} elseif ($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof TextRun) {
$sRTFBody .= $this->getDataContentTextRun($element); $sRTFBody .= $this->getDataContentTextRun($element);
} elseif ($element instanceof PHPWord_Section_Link) { } elseif ($element instanceof Link) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Link'); $sRTFBody .= $this->getDataContentUnsupportedElement('Link');
} elseif ($element instanceof PHPWord_Section_Title) { } elseif ($element instanceof Title) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Title'); $sRTFBody .= $this->getDataContentUnsupportedElement('Title');
} elseif ($element instanceof PHPWord_Section_PageBreak) { } elseif ($element instanceof PageBreak) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Page Break'); $sRTFBody .= $this->getDataContentUnsupportedElement('Page Break');
} elseif ($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof Table) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Table'); $sRTFBody .= $this->getDataContentUnsupportedElement('Table');
} elseif ($element instanceof PHPWord_Section_ListItem) { } elseif ($element instanceof ListItem) {
$sRTFBody .= $this->getDataContentUnsupportedElement('List Item'); $sRTFBody .= $this->getDataContentUnsupportedElement('List Item');
} elseif ($element instanceof PHPWord_Section_Image || } elseif ($element instanceof Image ||
$element instanceof PHPWord_Section_MemoryImage) { $element instanceof MemoryImage) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Image'); $sRTFBody .= $this->getDataContentUnsupportedElement('Image');
} elseif ($element instanceof PHPWord_Section_Object) { } elseif ($element instanceof Object) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Object'); $sRTFBody .= $this->getDataContentUnsupportedElement('Object');
} elseif ($element instanceof PHPWord_TOC) { } elseif ($element instanceof TOC) {
$sRTFBody .= $this->getDataContentUnsupportedElement('TOC'); $sRTFBody .= $this->getDataContentUnsupportedElement('TOC');
} else { } else {
$sRTFBody .= $this->getDataContentUnsupportedElement('Other'); $sRTFBody .= $this->getDataContentUnsupportedElement('Other');
@ -343,20 +356,20 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/** /**
* Get text * Get text
*/ */
private function getDataContentText(PHPWord_Section_Text $text, $withoutP = false) private function getDataContentText(Text $text, $withoutP = false)
{ {
$sRTFText = ''; $sRTFText = '';
$styleFont = $text->getFontStyle(); $styleFont = $text->getFontStyle();
$SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; $SfIsObject = ($styleFont instanceof Font) ? true : false;
if (!$SfIsObject) { if (!$SfIsObject) {
$styleFont = PHPWord_Style::getStyle($styleFont); $styleFont = Style::getStyle($styleFont);
} }
$styleParagraph = $text->getParagraphStyle(); $styleParagraph = $text->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
if (!$SpIsObject) { if (!$SpIsObject) {
$styleParagraph = PHPWord_Style::getStyle($styleParagraph); $styleParagraph = Style::getStyle($styleParagraph);
} }
if ($styleParagraph && !$withoutP) { if ($styleParagraph && !$withoutP) {
@ -378,7 +391,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$this->_lastParagraphStyle = ''; $this->_lastParagraphStyle = '';
} }
if ($styleFont instanceof PHPWord_Style_Font) { if ($styleFont instanceof Font) {
if ($styleFont->getColor() != null) { if ($styleFont->getColor() != null) {
$idxColor = array_search($styleFont->getColor(), $this->_colorTable); $idxColor = array_search($styleFont->getColor(), $this->_colorTable);
if ($idxColor !== false) { if ($idxColor !== false) {
@ -410,7 +423,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
$sRTFText .= $text->getText(); $sRTFText .= $text->getText();
if ($styleFont instanceof PHPWord_Style_Font) { if ($styleFont instanceof Font) {
$sRTFText .= '\cf0'; $sRTFText .= '\cf0';
$sRTFText .= '\f0'; $sRTFText .= '\f0';
@ -434,14 +447,14 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/** /**
* Get text run content * Get text run content
*/ */
private function getDataContentTextRun(PHPWord_Section_TextRun $textrun) private function getDataContentTextRun(TextRun $textrun)
{ {
$sRTFText = ''; $sRTFText = '';
$elements = $textrun->getElements(); $elements = $textrun->getElements();
if (count($elements) > 0) { if (count($elements) > 0) {
$sRTFText .= '\pard\nowidctlpar' . PHP_EOL; $sRTFText .= '\pard\nowidctlpar' . PHP_EOL;
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof Text) {
$sRTFText .= '{'; $sRTFText .= '{';
$sRTFText .= $this->getDataContentText($element, true); $sRTFText .= $this->getDataContentText($element, true);
$sRTFText .= '}' . PHP_EOL; $sRTFText .= '}' . PHP_EOL;

View File

@ -25,15 +25,23 @@
* @version 0.8.0 * @version 0.8.0
*/ */
use PhpOffice\PhpWord\Exceptions\InvalidImageException; namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
/** use PhpOffice\PhpWord\Footnote;
* Class PHPWord_Writer_Word2007 use PhpOffice\PhpWord\Media;
*/ use PhpOffice\PhpWord\Writer\Word2007\ContentTypes;
class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter use PhpOffice\PhpWord\Writer\Word2007\DocProps;
use PhpOffice\PhpWord\Writer\Word2007\Document;
use PhpOffice\PhpWord\Writer\Word2007\DocumentRels;
use PhpOffice\PhpWord\Writer\Word2007\Footer;
use PhpOffice\PhpWord\Writer\Word2007\Footnotes;
use PhpOffice\PhpWord\Writer\Word2007\FootnotesRels;
use PhpOffice\PhpWord\Writer\Word2007\Header;
use PhpOffice\PhpWord\Writer\Word2007\Rels;
use PhpOffice\PhpWord\Writer\Word2007\Styles;
class Word2007 implements IWriter
{ {
private $_document; private $_document;
private $_writerParts; private $_writerParts;
private $_diskCachingDirectory; private $_diskCachingDirectory;
@ -47,16 +55,16 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$this->_diskCachingDirectory = './'; $this->_diskCachingDirectory = './';
$this->_writerParts['contenttypes'] = new PHPWord_Writer_Word2007_ContentTypes(); $this->_writerParts['contenttypes'] = new ContentTypes();
$this->_writerParts['rels'] = new PHPWord_Writer_Word2007_Rels(); $this->_writerParts['rels'] = new Rels();
$this->_writerParts['docprops'] = new PHPWord_Writer_Word2007_DocProps(); $this->_writerParts['docprops'] = new DocProps();
$this->_writerParts['documentrels'] = new PHPWord_Writer_Word2007_DocumentRels(); $this->_writerParts['documentrels'] = new DocumentRels();
$this->_writerParts['document'] = new PHPWord_Writer_Word2007_Document(); $this->_writerParts['document'] = new Document();
$this->_writerParts['styles'] = new PHPWord_Writer_Word2007_Styles(); $this->_writerParts['styles'] = new Styles();
$this->_writerParts['header'] = new PHPWord_Writer_Word2007_Header(); $this->_writerParts['header'] = new Header();
$this->_writerParts['footer'] = new PHPWord_Writer_Word2007_Footer(); $this->_writerParts['footer'] = new Footer();
$this->_writerParts['footnotes'] = new PHPWord_Writer_Word2007_Footnotes(); $this->_writerParts['footnotes'] = new Footnotes();
$this->_writerParts['footnotesrels'] = new PHPWord_Writer_Word2007_FootnotesRels(); $this->_writerParts['footnotesrels'] = new FootnotesRels();
foreach ($this->_writerParts as $writer) { foreach ($this->_writerParts as $writer) {
$writer->setParentWriter($this); $writer->setParentWriter($this);
@ -88,7 +96,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$sectionElements = array(); $sectionElements = array();
$_secElements = PHPWord_Media::getSectionMediaElements(); $_secElements = Media::getSectionMediaElements();
foreach ($_secElements as $element) { // loop through section media elements foreach ($_secElements as $element) { // loop through section media elements
if ($element['type'] != 'hyperlink') { if ($element['type'] != 'hyperlink') {
$this->_addFileToPackage($objZip, $element); $this->_addFileToPackage($objZip, $element);
@ -96,7 +104,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$sectionElements[] = $element; $sectionElements[] = $element;
} }
$_hdrElements = PHPWord_Media::getHeaderMediaElements(); $_hdrElements = Media::getHeaderMediaElements();
foreach ($_hdrElements as $_headerFile => $_hdrMedia) { // loop through headers foreach ($_hdrElements as $_headerFile => $_hdrMedia) { // loop through headers
if (count($_hdrMedia) > 0) { if (count($_hdrMedia) > 0) {
$objZip->addFromString('word/_rels/' . $_headerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_hdrMedia)); $objZip->addFromString('word/_rels/' . $_headerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_hdrMedia));
@ -106,7 +114,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
} }
} }
$_ftrElements = PHPWord_Media::getFooterMediaElements(); $_ftrElements = Media::getFooterMediaElements();
foreach ($_ftrElements as $_footerFile => $_ftrMedia) { // loop through footers foreach ($_ftrElements as $_footerFile => $_ftrMedia) { // loop through footers
if (count($_ftrMedia) > 0) { if (count($_ftrMedia) > 0) {
$objZip->addFromString('word/_rels/' . $_footerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_ftrMedia)); $objZip->addFromString('word/_rels/' . $_footerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_ftrMedia));
@ -117,7 +125,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
} }
$footnoteLinks = array(); $footnoteLinks = array();
$_footnoteElements = PHPWord_Footnote::getFootnoteLinkElements(); $_footnoteElements = Footnote::getFootnoteLinkElements();
// loop through footnote link elements // loop through footnote link elements
foreach ($_footnoteElements as $element) { foreach ($_footnoteElements as $element) {
$footnoteLinks[] = $element; $footnoteLinks[] = $element;
@ -125,7 +133,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$_cHdrs = 0; $_cHdrs = 0;
$_cFtrs = 0; $_cFtrs = 0;
$rID = PHPWord_Media::countSectionMediaElements() + 6; $rID = Media::countSectionMediaElements() + 6;
$_sections = $this->_document->getSections(); $_sections = $this->_document->getSections();
$footers = array(); $footers = array();
@ -150,8 +158,8 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
} }
} }
if (PHPWord_Footnote::countFootnoteElements() > 0) { if (Footnote::countFootnoteElements() > 0) {
$_allFootnotesCollection = PHPWord_Footnote::getFootnoteElements(); $_allFootnotesCollection = Footnote::getFootnoteElements();
$_footnoteFile = 'footnotes.xml'; $_footnoteFile = 'footnotes.xml';
$sectionElements[] = array('target'=>$_footnoteFile, 'type'=>'footnotes', 'rID'=>++$rID); $sectionElements[] = array('target'=>$_footnoteFile, 'type'=>'footnotes', 'rID'=>++$rID);
$objZip->addFromString('word/'.$_footnoteFile, $this->getWriterPart('footnotes')->writeFootnotes($_allFootnotesCollection)); $objZip->addFromString('word/'.$_footnoteFile, $this->getWriterPart('footnotes')->writeFootnotes($_allFootnotesCollection));

File diff suppressed because it is too large Load Diff

View File

@ -25,52 +25,53 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_ContentTypes
*/
class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_WriterPart
{
use PhpOffice\PhpWord\Shared\File;
use PhpOffice\PhpWord\Shared\XMLWriter;
class ContentTypes extends WriterPart
{
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers) public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Types // Types
$objWriter->startElement('Types'); $xmlWriter->startElement('Types');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
// Rels // Rels
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, $xmlWriter,
'rels', 'rels',
'application/vnd.openxmlformats-package.relationships+xml' 'application/vnd.openxmlformats-package.relationships+xml'
); );
// XML // XML
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, $xmlWriter,
'xml', 'xml',
'application/xml' 'application/xml'
); );
// Add media content-types // Add media content-types
foreach ($_imageTypes as $key => $value) { foreach ($_imageTypes as $key => $value) {
$this->_writeDefaultContentType($objWriter, $key, $value); $this->_writeDefaultContentType($xmlWriter, $key, $value);
} }
// Add embedding content-types // Add embedding content-types
if (count($_objectTypes) > 0) { if (count($_objectTypes) > 0) {
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, $xmlWriter,
'bin', 'bin',
'application/vnd.openxmlformats-officedocument.oleObject' 'application/vnd.openxmlformats-officedocument.oleObject'
); );
@ -78,76 +79,76 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
// DocProps // DocProps
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/docProps/app.xml', '/docProps/app.xml',
'application/vnd.openxmlformats-officedocument.extended-properties+xml' 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
); );
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/docProps/core.xml', '/docProps/core.xml',
'application/vnd.openxmlformats-package.core-properties+xml' 'application/vnd.openxmlformats-package.core-properties+xml'
); );
// Document // Document
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/document.xml', '/word/document.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
); );
// Styles // Styles
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/styles.xml', '/word/styles.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
); );
// Numbering // Numbering
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/numbering.xml', '/word/numbering.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
); );
// Settings // Settings
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/settings.xml', '/word/settings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
); );
// Theme1 // Theme1
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/theme/theme1.xml', '/word/theme/theme1.xml',
'application/vnd.openxmlformats-officedocument.theme+xml' 'application/vnd.openxmlformats-officedocument.theme+xml'
); );
// WebSettings // WebSettings
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/webSettings.xml', '/word/webSettings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
); );
// Font Table // Font Table
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/fontTable.xml', '/word/fontTable.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
); );
// Footnotes // Footnotes
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/footnotes.xml', '/word/footnotes.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
); );
for ($i = 1; $i <= $_cHdrs; $i++) { for ($i = 1; $i <= $_cHdrs; $i++) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/header' . $i . '.xml', '/word/header' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
); );
@ -156,7 +157,7 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
for ($i = 1; $i <= count($footers); $i++) { for ($i = 1; $i <= count($footers); $i++) {
if (!is_null($footers[$i])) { if (!is_null($footers[$i])) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, $xmlWriter,
'/word/footer' . $i . '.xml', '/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml' 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
); );
@ -164,10 +165,10 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
/** /**
@ -179,7 +180,7 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
*/ */
private function _getImageMimeType($pFile = '') private function _getImageMimeType($pFile = '')
{ {
if (PHPWord_Shared_File::file_exists($pFile)) { if (File::file_exists($pFile)) {
$image = getimagesize($pFile); $image = getimagesize($pFile);
return image_type_to_mime_type($image[2]); return image_type_to_mime_type($image[2]);
} else { } else {
@ -188,42 +189,38 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
} }
/** /**
* Write Default content type * @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* * @param string $pPartname Part name
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer * @param string $pContentType Content type
* @param string $pPartname Part name * @throws Exception
* @param string $pContentType Content type
* @throws Exception
*/ */
private function _writeDefaultContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') private function _writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{ {
if ($pPartname != '' && $pContentType != '') { if ($pPartname != '' && $pContentType != '') {
// Write content type // Write content type
$objWriter->startElement('Default'); $xmlWriter->startElement('Default');
$objWriter->writeAttribute('Extension', $pPartname); $xmlWriter->writeAttribute('Extension', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType); $xmlWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement(); $xmlWriter->endElement();
} else { } else {
throw new Exception("Invalid parameters passed."); throw new Exception("Invalid parameters passed.");
} }
} }
/** /**
* Write Override content type * @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* * @param string $pPartname Part name
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer * @param string $pContentType Content type
* @param string $pPartname Part name * @throws Exception
* @param string $pContentType Content type
* @throws Exception
*/ */
private function _writeOverrideContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') private function _writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{ {
if ($pPartname != '' && $pContentType != '') { if ($pPartname != '' && $pContentType != '') {
// Write content type // Write content type
$objWriter->startElement('Override'); $xmlWriter->startElement('Override');
$objWriter->writeAttribute('PartName', $pPartname); $xmlWriter->writeAttribute('PartName', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType); $xmlWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement(); $xmlWriter->endElement();
} else { } else {
throw new Exception("Invalid parameters passed."); throw new Exception("Invalid parameters passed.");
} }

View File

@ -25,161 +25,161 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_DocProps
*/
class PHPWord_Writer_Word2007_DocProps extends PHPWord_Writer_Word2007_WriterPart
{
public function writeDocPropsApp(PHPWord $pPHPWord = null) use PhpOffice\PhpWord\Shared\XMLWriter;
class DocProps extends WriterPart
{
public function writeDocPropsApp(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Properties // Properties
$objWriter->startElement('Properties'); $xmlWriter->startElement('Properties');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
$objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); $xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
// Application // Application
$objWriter->writeElement('Application', 'Microsoft Office Word'); $xmlWriter->writeElement('Application', 'Microsoft Office Word');
// ScaleCrop // ScaleCrop
$objWriter->writeElement('ScaleCrop', 'false'); $xmlWriter->writeElement('ScaleCrop', 'false');
// HeadingPairs // HeadingPairs
$objWriter->startElement('HeadingPairs'); $xmlWriter->startElement('HeadingPairs');
// Vector // Vector
$objWriter->startElement('vt:vector'); $xmlWriter->startElement('vt:vector');
$objWriter->writeAttribute('size', '4'); $xmlWriter->writeAttribute('size', '4');
$objWriter->writeAttribute('baseType', 'variant'); $xmlWriter->writeAttribute('baseType', 'variant');
// Variant // Variant
$objWriter->startElement('vt:variant'); $xmlWriter->startElement('vt:variant');
$objWriter->writeElement('vt:lpstr', 'Theme'); $xmlWriter->writeElement('vt:lpstr', 'Theme');
$objWriter->endElement(); $xmlWriter->endElement();
// Variant // Variant
$objWriter->startElement('vt:variant'); $xmlWriter->startElement('vt:variant');
$objWriter->writeElement('vt:i4', '1'); $xmlWriter->writeElement('vt:i4', '1');
$objWriter->endElement(); $xmlWriter->endElement();
// Variant // Variant
$objWriter->startElement('vt:variant'); $xmlWriter->startElement('vt:variant');
$objWriter->writeElement('vt:lpstr', 'Slide Titles'); $xmlWriter->writeElement('vt:lpstr', 'Slide Titles');
$objWriter->endElement(); $xmlWriter->endElement();
// Variant // Variant
$objWriter->startElement('vt:variant'); $xmlWriter->startElement('vt:variant');
$objWriter->writeElement('vt:i4', '1'); $xmlWriter->writeElement('vt:i4', '1');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
// TitlesOfParts // TitlesOfParts
$objWriter->startElement('TitlesOfParts'); $xmlWriter->startElement('TitlesOfParts');
// Vector // Vector
$objWriter->startElement('vt:vector'); $xmlWriter->startElement('vt:vector');
$objWriter->writeAttribute('size', '1'); $xmlWriter->writeAttribute('size', '1');
$objWriter->writeAttribute('baseType', 'lpstr'); $xmlWriter->writeAttribute('baseType', 'lpstr');
$objWriter->writeElement('vt:lpstr', 'Office Theme'); $xmlWriter->writeElement('vt:lpstr', 'Office Theme');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
// Company // Company
$objWriter->writeElement('Company', $pPHPWord->getProperties()->getCompany()); $xmlWriter->writeElement('Company', $phpWord->getProperties()->getCompany());
// LinksUpToDate // LinksUpToDate
$objWriter->writeElement('LinksUpToDate', 'false'); $xmlWriter->writeElement('LinksUpToDate', 'false');
// SharedDoc // SharedDoc
$objWriter->writeElement('SharedDoc', 'false'); $xmlWriter->writeElement('SharedDoc', 'false');
// HyperlinksChanged // HyperlinksChanged
$objWriter->writeElement('HyperlinksChanged', 'false'); $xmlWriter->writeElement('HyperlinksChanged', 'false');
// AppVersion // AppVersion
$objWriter->writeElement('AppVersion', '12.0000'); $xmlWriter->writeElement('AppVersion', '12.0000');
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
public function writeDocPropsCore(PHPWord $pPHPWord = null) public function writeDocPropsCore(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// cp:coreProperties // cp:coreProperties
$objWriter->startElement('cp:coreProperties'); $xmlWriter->startElement('cp:coreProperties');
$objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'); $xmlWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); $xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
$objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/'); $xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
// dc:creator // dc:creator
$objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getCreator()); $xmlWriter->writeElement('dc:creator', $phpWord->getProperties()->getCreator());
// cp:lastModifiedBy // cp:lastModifiedBy
$objWriter->writeElement('cp:lastModifiedBy', $pPHPWord->getProperties()->getLastModifiedBy()); $xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getProperties()->getLastModifiedBy());
// dcterms:created // dcterms:created
$objWriter->startElement('dcterms:created'); $xmlWriter->startElement('dcterms:created');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getCreated())); $xmlWriter->writeRaw(date(DATE_W3C, $phpWord->getProperties()->getCreated()));
$objWriter->endElement(); $xmlWriter->endElement();
// dcterms:modified // dcterms:modified
$objWriter->startElement('dcterms:modified'); $xmlWriter->startElement('dcterms:modified');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getModified())); $xmlWriter->writeRaw(date(DATE_W3C, $phpWord->getProperties()->getModified()));
$objWriter->endElement(); $xmlWriter->endElement();
// dc:title // dc:title
$objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle()); $xmlWriter->writeElement('dc:title', $phpWord->getProperties()->getTitle());
// dc:description // dc:description
$objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription()); $xmlWriter->writeElement('dc:description', $phpWord->getProperties()->getDescription());
// dc:subject // dc:subject
$objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject()); $xmlWriter->writeElement('dc:subject', $phpWord->getProperties()->getSubject());
// cp:keywords // cp:keywords
$objWriter->writeElement('cp:keywords', $pPHPWord->getProperties()->getKeywords()); $xmlWriter->writeElement('cp:keywords', $phpWord->getProperties()->getKeywords());
// cp:category // cp:category
$objWriter->writeElement('cp:category', $pPHPWord->getProperties()->getCategory()); $xmlWriter->writeElement('cp:category', $phpWord->getProperties()->getCategory());
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
} }

View File

@ -25,41 +25,55 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_Document
*/
class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
{
public function writeDocument(PHPWord $pPHPWord = null) use PhpOffice\PhpWord\Section\Footnote;
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\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TOC;
class Document extends Base
{
public function writeDocument(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// w:document // w:document
$objWriter->startElement('w:document'); $xmlWriter->startElement('w:document');
$objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$objWriter->startElement('w:body'); $xmlWriter->startElement('w:body');
$_sections = $pPHPWord->getSections(); $_sections = $phpWord->getSections();
$countSections = count($_sections); $countSections = count($_sections);
$pSection = 0; $pSection = 0;
@ -70,60 +84,60 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
$_elements = $section->getElements(); $_elements = $section->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof Text) {
$this->_writeText($objWriter, $element); $this->_writeText($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof TextRun) {
$this->_writeTextRun($objWriter, $element); $this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Link) { } elseif ($element instanceof Link) {
$this->_writeLink($objWriter, $element); $this->_writeLink($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Title) { } elseif ($element instanceof Title) {
$this->_writeTitle($objWriter, $element); $this->_writeTitle($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($objWriter, $element); $this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_PageBreak) { } elseif ($element instanceof PageBreak) {
$this->_writePageBreak($objWriter); $this->_writePageBreak($xmlWriter);
} elseif ($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof Table) {
$this->_writeTable($objWriter, $element); $this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_ListItem) { } elseif ($element instanceof ListItem) {
$this->_writeListItem($objWriter, $element); $this->_writeListItem($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image || } elseif ($element instanceof Image ||
$element instanceof PHPWord_Section_MemoryImage $element instanceof MemoryImage
) { ) {
$this->_writeImage($objWriter, $element); $this->_writeImage($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Object) { } elseif ($element instanceof Object) {
$this->_writeObject($objWriter, $element); $this->_writeObject($xmlWriter, $element);
} elseif ($element instanceof PHPWord_TOC) { } elseif ($element instanceof TOC) {
$this->_writeTOC($objWriter); $this->_writeTOC($xmlWriter);
} elseif ($element instanceof PHPWord_Section_Footnote) { } elseif ($element instanceof Footnote) {
$this->_writeFootnoteReference($objWriter, $element); $this->_writeFootnoteReference($xmlWriter, $element);
} }
} }
if ($pSection == $countSections) { if ($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section); $this->_writeEndSection($xmlWriter, $section);
} else { } else {
$this->_writeSection($objWriter, $section); $this->_writeSection($xmlWriter, $section);
} }
} }
} }
$objWriter->endElement(); // End w:body $xmlWriter->endElement(); // End w:body
$objWriter->endElement(); // End w:document $xmlWriter->endElement(); // End w:document
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) private function _writeSection(XMLWriter $xmlWriter = null, Section $section)
{ {
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$objWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
$this->_writeEndSection($objWriter, $section, 3); $this->_writeEndSection($xmlWriter, $section, 3);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section)
{ {
$settings = $section->getSettings(); $settings = $section->getSettings();
$_headers = $section->getHeaders(); $_headers = $section->getHeaders();
@ -146,167 +160,167 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
$colsSpace = $settings->getColsSpace(); $colsSpace = $settings->getColsSpace();
$breakType = $settings->getBreakType(); $breakType = $settings->getBreakType();
$objWriter->startElement('w:sectPr'); $xmlWriter->startElement('w:sectPr');
foreach ($_headers as &$_header) { foreach ($_headers as &$_header) {
$rId = $_header->getRelationId(); $rId = $_header->getRelationId();
$objWriter->startElement('w:headerReference'); $xmlWriter->startElement('w:headerReference');
$objWriter->writeAttribute('w:type', $_header->getType()); $xmlWriter->writeAttribute('w:type', $_header->getType());
$objWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($section->hasDifferentFirstPage()) { if ($section->hasDifferentFirstPage()) {
$objWriter->startElement('w:titlePg'); $xmlWriter->startElement('w:titlePg');
$objWriter->endElement(); $xmlWriter->endElement();
} }
if (!is_null($breakType)) { if (!is_null($breakType)) {
$objWriter->startElement('w:type'); $xmlWriter->startElement('w:type');
$objWriter->writeAttribute('w:val', $breakType); $xmlWriter->writeAttribute('w:val', $breakType);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if (!is_null($_footer)) { if (!is_null($_footer)) {
$rId = $_footer->getRelationId(); $rId = $_footer->getRelationId();
$objWriter->startElement('w:footerReference'); $xmlWriter->startElement('w:footerReference');
$objWriter->writeAttribute('w:type', 'default'); $xmlWriter->writeAttribute('w:type', 'default');
$objWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:pgSz'); $xmlWriter->startElement('w:pgSz');
$objWriter->writeAttribute('w:w', $pgSzW); $xmlWriter->writeAttribute('w:w', $pgSzW);
$objWriter->writeAttribute('w:h', $pgSzH); $xmlWriter->writeAttribute('w:h', $pgSzH);
if (!is_null($orientation) && strtolower($orientation) != 'portrait') { if (!is_null($orientation) && strtolower($orientation) != 'portrait') {
$objWriter->writeAttribute('w:orient', $orientation); $xmlWriter->writeAttribute('w:orient', $orientation);
} }
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:pgMar'); $xmlWriter->startElement('w:pgMar');
$objWriter->writeAttribute('w:top', $marginTop); $xmlWriter->writeAttribute('w:top', $marginTop);
$objWriter->writeAttribute('w:right', $marginRight); $xmlWriter->writeAttribute('w:right', $marginRight);
$objWriter->writeAttribute('w:bottom', $marginBottom); $xmlWriter->writeAttribute('w:bottom', $marginBottom);
$objWriter->writeAttribute('w:left', $marginLeft); $xmlWriter->writeAttribute('w:left', $marginLeft);
$objWriter->writeAttribute('w:header', $headerHeight); $xmlWriter->writeAttribute('w:header', $headerHeight);
$objWriter->writeAttribute('w:footer', $footerHeight); $xmlWriter->writeAttribute('w:footer', $footerHeight);
$objWriter->writeAttribute('w:gutter', '0'); $xmlWriter->writeAttribute('w:gutter', '0');
$objWriter->endElement(); $xmlWriter->endElement();
if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) { if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
$borderColor = $settings->getBorderColor(); $borderColor = $settings->getBorderColor();
$objWriter->startElement('w:pgBorders'); $xmlWriter->startElement('w:pgBorders');
$objWriter->writeAttribute('w:offsetFrom', 'page'); $xmlWriter->writeAttribute('w:offsetFrom', 'page');
if (!is_null($borders[0])) { if (!is_null($borders[0])) {
$objWriter->startElement('w:top'); $xmlWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[0]); $xmlWriter->writeAttribute('w:sz', $borders[0]);
$objWriter->writeAttribute('w:space', '24'); $xmlWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[0]); $xmlWriter->writeAttribute('w:color', $borderColor[0]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if (!is_null($borders[1])) { if (!is_null($borders[1])) {
$objWriter->startElement('w:left'); $xmlWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[1]); $xmlWriter->writeAttribute('w:sz', $borders[1]);
$objWriter->writeAttribute('w:space', '24'); $xmlWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[1]); $xmlWriter->writeAttribute('w:color', $borderColor[1]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if (!is_null($borders[2])) { if (!is_null($borders[2])) {
$objWriter->startElement('w:right'); $xmlWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[2]); $xmlWriter->writeAttribute('w:sz', $borders[2]);
$objWriter->writeAttribute('w:space', '24'); $xmlWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[2]); $xmlWriter->writeAttribute('w:color', $borderColor[2]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if (!is_null($borders[3])) { if (!is_null($borders[3])) {
$objWriter->startElement('w:bottom'); $xmlWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[3]); $xmlWriter->writeAttribute('w:sz', $borders[3]);
$objWriter->writeAttribute('w:space', '24'); $xmlWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[3]); $xmlWriter->writeAttribute('w:color', $borderColor[3]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->endElement(); $xmlWriter->endElement();
} }
// Page numbering // Page numbering
if (null !== $settings->getPageNumberingStart()) { if (null !== $settings->getPageNumberingStart()) {
$objWriter->startElement('w:pgNumType'); $xmlWriter->startElement('w:pgNumType');
$objWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart()); $xmlWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart());
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:cols'); $xmlWriter->startElement('w:cols');
$objWriter->writeAttribute('w:num', $colsNum); $xmlWriter->writeAttribute('w:num', $colsNum);
$objWriter->writeAttribute('w:space', $colsSpace); $xmlWriter->writeAttribute('w:space', $colsSpace);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
private function _writePageBreak(PHPWord_Shared_XMLWriter $objWriter = null) private function _writePageBreak(XMLWriter $xmlWriter = null)
{ {
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:br'); $xmlWriter->startElement('w:br');
$objWriter->writeAttribute('w:type', 'page'); $xmlWriter->writeAttribute('w:type', 'page');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
public function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem) public function _writeListItem(XMLWriter $xmlWriter = null, ListItem $listItem)
{ {
$textObject = $listItem->getTextObject(); $textObject = $listItem->getTextObject();
$text = $textObject->getText(); $text = $textObject->getText();
$styleParagraph = $textObject->getParagraphStyle(); $styleParagraph = $textObject->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$depth = $listItem->getDepth(); $depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType(); $listType = $listItem->getStyle()->getListType();
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$objWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
if ($SpIsObject) { if ($SpIsObject) {
$this->_writeParagraphStyle($objWriter, $styleParagraph, true); $this->_writeParagraphStyle($xmlWriter, $styleParagraph, true);
} elseif (!$SpIsObject && !is_null($styleParagraph)) { } elseif (!$SpIsObject && !is_null($styleParagraph)) {
$objWriter->startElement('w:pStyle'); $xmlWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleParagraph); $xmlWriter->writeAttribute('w:val', $styleParagraph);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:numPr'); $xmlWriter->startElement('w:numPr');
$objWriter->startElement('w:ilvl'); $xmlWriter->startElement('w:ilvl');
$objWriter->writeAttribute('w:val', $depth); $xmlWriter->writeAttribute('w:val', $depth);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:numId'); $xmlWriter->startElement('w:numId');
$objWriter->writeAttribute('w:val', $listType); $xmlWriter->writeAttribute('w:val', $listType);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$this->_writeText($objWriter, $textObject, true); $this->_writeText($xmlWriter, $textObject, true);
$objWriter->endElement(); $xmlWriter->endElement();
} }
protected function _writeObject(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Object $object) protected function _writeObject(XMLWriter $xmlWriter = null, Object $object)
{ {
$rIdObject = $object->getRelationId(); $rIdObject = $object->getRelationId();
$rIdImage = $object->getImageRelationId(); $rIdImage = $object->getImageRelationId();
@ -320,172 +334,172 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
$align = $style->getAlign(); $align = $style->getAlign();
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
if (!is_null($align)) { if (!is_null($align)) {
$objWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
$objWriter->startElement('w:jc'); $xmlWriter->startElement('w:jc');
$objWriter->writeAttribute('w:val', $align); $xmlWriter->writeAttribute('w:val', $align);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:object'); $xmlWriter->startElement('w:object');
$objWriter->writeAttribute('w:dxaOrig', '249'); $xmlWriter->writeAttribute('w:dxaOrig', '249');
$objWriter->writeAttribute('w:dyaOrig', '160'); $xmlWriter->writeAttribute('w:dyaOrig', '160');
$objWriter->startElement('v:shape'); $xmlWriter->startElement('v:shape');
$objWriter->writeAttribute('id', $shapeId); $xmlWriter->writeAttribute('id', $shapeId);
$objWriter->writeAttribute('type', '#_x0000_t75'); $xmlWriter->writeAttribute('type', '#_x0000_t75');
$objWriter->writeAttribute('style', 'width:104px;height:67px'); $xmlWriter->writeAttribute('style', 'width:104px;height:67px');
$objWriter->writeAttribute('o:ole', ''); $xmlWriter->writeAttribute('o:ole', '');
$objWriter->startElement('v:imagedata'); $xmlWriter->startElement('v:imagedata');
$objWriter->writeAttribute('r:id', 'rId' . $rIdImage); $xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage);
$objWriter->writeAttribute('o:title', ''); $xmlWriter->writeAttribute('o:title', '');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('o:OLEObject'); $xmlWriter->startElement('o:OLEObject');
$objWriter->writeAttribute('Type', 'Embed'); $xmlWriter->writeAttribute('Type', 'Embed');
$objWriter->writeAttribute('ProgID', 'Package'); $xmlWriter->writeAttribute('ProgID', 'Package');
$objWriter->writeAttribute('ShapeID', $shapeId); $xmlWriter->writeAttribute('ShapeID', $shapeId);
$objWriter->writeAttribute('DrawAspect', 'Icon'); $xmlWriter->writeAttribute('DrawAspect', 'Icon');
$objWriter->writeAttribute('ObjectID', '_' . $objectId); $xmlWriter->writeAttribute('ObjectID', '_' . $objectId);
$objWriter->writeAttribute('r:id', 'rId' . $rIdObject); $xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); // w:r $xmlWriter->endElement(); // w:r
$objWriter->endElement(); // w:p $xmlWriter->endElement(); // w:p
} }
private function _writeTOC(PHPWord_Shared_XMLWriter $objWriter = null) private function _writeTOC(XMLWriter $xmlWriter = null)
{ {
$titles = PHPWord_TOC::getTitles(); $titles = TOC::getTitles();
$styleFont = PHPWord_TOC::getStyleFont(); $styleFont = TOC::getStyleFont();
$styleTOC = PHPWord_TOC::getStyleTOC(); $styleTOC = TOC::getStyleTOC();
$fIndent = $styleTOC->getIndent(); $fIndent = $styleTOC->getIndent();
$tabLeader = $styleTOC->getTabLeader(); $tabLeader = $styleTOC->getTabLeader();
$tabPos = $styleTOC->getTabPos(); $tabPos = $styleTOC->getTabPos();
$isObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; $isObject = ($styleFont instanceof Font) ? true : false;
for ($i = 0; $i < count($titles); $i++) { for ($i = 0; $i < count($titles); $i++) {
$title = $titles[$i]; $title = $titles[$i];
$indent = ($title['depth'] - 1) * $fIndent; $indent = ($title['depth'] - 1) * $fIndent;
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$objWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
if ($isObject && !is_null($styleFont->getParagraphStyle())) { if ($isObject && !is_null($styleFont->getParagraphStyle())) {
$this->_writeParagraphStyle($objWriter, $styleFont->getParagraphStyle()); $this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
} }
if ($indent > 0) { if ($indent > 0) {
$objWriter->startElement('w:ind'); $xmlWriter->startElement('w:ind');
$objWriter->writeAttribute('w:left', $indent); $xmlWriter->writeAttribute('w:left', $indent);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if (!empty($styleFont) && !$isObject) { if (!empty($styleFont) && !$isObject) {
$objWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
$objWriter->startElement('w:pStyle'); $xmlWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleFont); $xmlWriter->writeAttribute('w:val', $styleFont);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:tabs'); $xmlWriter->startElement('w:tabs');
$objWriter->startElement('w:tab'); $xmlWriter->startElement('w:tab');
$objWriter->writeAttribute('w:val', 'right'); $xmlWriter->writeAttribute('w:val', 'right');
if (!empty($tabLeader)) { if (!empty($tabLeader)) {
$objWriter->writeAttribute('w:leader', $tabLeader); $xmlWriter->writeAttribute('w:leader', $tabLeader);
} }
$objWriter->writeAttribute('w:pos', $tabPos); $xmlWriter->writeAttribute('w:pos', $tabPos);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); // w:pPr $xmlWriter->endElement(); // w:pPr
if ($i == 0) { if ($i == 0) {
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:fldChar'); $xmlWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:instrText'); $xmlWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->writeAttribute('xml:space', 'preserve');
$objWriter->writeRaw('TOC \o "1-9" \h \z \u'); $xmlWriter->writeRaw('TOC \o "1-9" \h \z \u');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:fldChar'); $xmlWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'separate'); $xmlWriter->writeAttribute('w:fldCharType', 'separate');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:hyperlink'); $xmlWriter->startElement('w:hyperlink');
$objWriter->writeAttribute('w:anchor', $title['anchor']); $xmlWriter->writeAttribute('w:anchor', $title['anchor']);
$objWriter->writeAttribute('w:history', '1'); $xmlWriter->writeAttribute('w:history', '1');
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
if ($isObject) { if ($isObject) {
$this->_writeTextStyle($objWriter, $styleFont); $this->_writeTextStyle($xmlWriter, $styleFont);
} }
$objWriter->startElement('w:t'); $xmlWriter->startElement('w:t');
$objWriter->writeRaw($title['text']); $xmlWriter->writeRaw($title['text']);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->writeElement('w:tab', null); $xmlWriter->writeElement('w:tab', null);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:fldChar'); $xmlWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:instrText'); $xmlWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->writeAttribute('xml:space', 'preserve');
$objWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h'); $xmlWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:fldChar'); $xmlWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); // w:hyperlink $xmlWriter->endElement(); // w:hyperlink
$objWriter->endElement(); // w:p $xmlWriter->endElement(); // w:p
} }
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:fldChar'); $xmlWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
} }

View File

@ -25,32 +25,32 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_DocumentRels
*/
class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_WriterPart
{
use PhpOffice\PhpWord\Shared\XMLWriter;
class DocumentRels extends WriterPart
{
public function writeDocumentRels($_relsCollection) public function writeDocumentRels($_relsCollection)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships // Relationships
$objWriter->startElement('Relationships'); $xmlWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationship word/document.xml // Relationship word/document.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
1, 1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
'styles.xml' 'styles.xml'
@ -58,7 +58,7 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
// Relationship word/numbering.xml // Relationship word/numbering.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
2, 2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
'numbering.xml' 'numbering.xml'
@ -66,7 +66,7 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
3, 3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
'settings.xml' 'settings.xml'
@ -74,7 +74,7 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
4, 4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
'theme/theme1.xml' 'theme/theme1.xml'
@ -82,7 +82,7 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
5, 5,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
'webSettings.xml' 'webSettings.xml'
@ -90,7 +90,7 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
// Relationship word/settings.xml // Relationship word/settings.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
6, 6,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
'fontTable.xml' 'fontTable.xml'
@ -104,7 +104,7 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
$targetMode = ($relationType == 'hyperlink') ? 'External' : ''; $targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
$relationId, $relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName, $relationName,
@ -113,28 +113,28 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
public function writeHeaderFooterRels($_relsCollection) public function writeHeaderFooterRels($_relsCollection)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships // Relationships
$objWriter->startElement('Relationships'); $xmlWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationships to Images / Embeddings / Headers / Footers // Relationships to Images / Embeddings / Headers / Footers
foreach ($_relsCollection as $relation) { foreach ($_relsCollection as $relation) {
@ -143,7 +143,7 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
$relationId = $relation['rID']; $relationId = $relation['rID'];
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
$relationId, $relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName $relationName
@ -151,13 +151,13 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{ {
if ($pType != '' && $pTarget != '') { if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) { if (strpos($pId, 'rId') === false) {
@ -165,16 +165,16 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write
} }
// Write relationship // Write relationship
$objWriter->startElement('Relationship'); $xmlWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId); $xmlWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType); $xmlWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget); $xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') { if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode); $xmlWriter->writeAttribute('TargetMode', $pTargetMode);
} }
$objWriter->endElement(); $xmlWriter->endElement();
} else { } else {
throw new Exception("Invalid parameters passed."); throw new Exception("Invalid parameters passed.");
} }

View File

@ -25,59 +25,66 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_Footer
*/
class PHPWord_Writer_Word2007_Footer extends PHPWord_Writer_Word2007_Base
{
public function writeFooter(PHPWord_Section_Footer $footer) use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Footer extends Base
{
public function writeFooter(PhpOffice\PhpWord\Section\Footer $footer)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:ftr'); $xmlWriter->startElement('w:ftr');
$objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$_elements = $footer->getElements(); $_elements = $footer->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof Text) {
$this->_writeText($objWriter, $element); $this->_writeText($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof TextRun) {
$this->_writeTextRun($objWriter, $element); $this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($objWriter, $element); $this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof Table) {
$this->_writeTable($objWriter, $element); $this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image || } elseif ($element instanceof Image ||
$element instanceof PHPWord_Section_MemoryImage $element instanceof MemoryImage
) { ) {
$this->_writeImage($objWriter, $element); $this->_writeImage($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Footer_PreserveText) { } elseif ($element instanceof PreserveText) {
$this->_writePreserveText($objWriter, $element); $this->_writePreserveText($xmlWriter, $element);
} }
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
} }

View File

@ -25,59 +25,63 @@
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord\Writer\Word2007;
class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base use PhpOffice\PhpWord\Section\Footnote;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Footnotes extends Base
{ {
public function writeFootnotes($allFootnotesCollection) public function writeFootnotes($allFootnotesCollection)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:footnotes'); $xmlWriter->startElement('w:footnotes');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// write separator and continuation separator // write separator and continuation separator
$objWriter->startElement('w:footnote'); $xmlWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', 0); $xmlWriter->writeAttribute('w:id', 0);
$objWriter->writeAttribute('w:type', 'separator'); $xmlWriter->writeAttribute('w:type', 'separator');
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:separator'); $xmlWriter->startElement('w:separator');
$objWriter->endElement(); // w:separator $xmlWriter->endElement(); // w:separator
$objWriter->endElement(); // w:r $xmlWriter->endElement(); // w:r
$objWriter->endElement(); // w:p $xmlWriter->endElement(); // w:p
$objWriter->endElement(); // w:footnote $xmlWriter->endElement(); // w:footnote
$objWriter->startElement('w:footnote'); $xmlWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', 1); $xmlWriter->writeAttribute('w:id', 1);
$objWriter->writeAttribute('w:type', 'continuationSeparator'); $xmlWriter->writeAttribute('w:type', 'continuationSeparator');
$objWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$objWriter->startElement('w:r'); $xmlWriter->startElement('w:r');
$objWriter->startElement('w:continuationSeparator'); $xmlWriter->startElement('w:continuationSeparator');
$objWriter->endElement(); // w:continuationSeparator $xmlWriter->endElement(); // w:continuationSeparator
$objWriter->endElement(); // w:r $xmlWriter->endElement(); // w:r
$objWriter->endElement(); // w:p $xmlWriter->endElement(); // w:p
$objWriter->endElement(); // w:footnote $xmlWriter->endElement(); // w:footnote
foreach ($allFootnotesCollection as $footnote) { foreach ($allFootnotesCollection as $footnote) {
if ($footnote instanceof PHPWord_Section_Footnote) { if ($footnote instanceof Footnote) {
$this->_writeFootnote($objWriter, $footnote); $this->_writeFootnote($xmlWriter, $footnote);
} }
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
} }

View File

@ -25,25 +25,28 @@
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord\Writer\Word2007;
class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart use PhpOffice\PhpWord\Shared\XMLWriter;
class FootnotesRels extends WriterPart
{ {
public function writeFootnotesRels($_relsCollection) public function writeFootnotesRels($_relsCollection)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships // Relationships
$objWriter->startElement('Relationships'); $xmlWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationships to Links // Relationships to Links
foreach ($_relsCollection as $relation) { foreach ($_relsCollection as $relation) {
@ -52,16 +55,16 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
$relationId = $relation['rID']; $relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : ''; $targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship($objWriter, $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);
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{ {
if ($pType != '' && $pTarget != '') { if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) { if (strpos($pId, 'rId') === false) {
@ -69,16 +72,16 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
} }
// Write relationship // Write relationship
$objWriter->startElement('Relationship'); $xmlWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId); $xmlWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType); $xmlWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget); $xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') { if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode); $xmlWriter->writeAttribute('TargetMode', $pTargetMode);
} }
$objWriter->endElement(); $xmlWriter->endElement();
} else { } else {
throw new Exception("Invalid parameters passed."); throw new Exception("Invalid parameters passed.");
} }

View File

@ -25,63 +25,70 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_Header
*/
class PHPWord_Writer_Word2007_Header extends PHPWord_Writer_Word2007_Base
{
public function writeHeader(PHPWord_Section_Header $header) use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Header extends Base
{
public function writeHeader(PhpOffice\PhpWord\Section\Header $header)
{ {
// Create XML writer // Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:hdr'); $xmlWriter->startElement('w:hdr');
$objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$_elements = $header->getElements(); $_elements = $header->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof Text) {
$this->_writeText($objWriter, $element); $this->_writeText($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof TextRun) {
$this->_writeTextRun($objWriter, $element); $this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($objWriter, $element); $this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof Table) {
$this->_writeTable($objWriter, $element); $this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image || } elseif ($element instanceof Image ||
$element instanceof PHPWord_Section_MemoryImage $element instanceof MemoryImage
) { ) {
if (!$element->getIsWatermark()) { if (!$element->getIsWatermark()) {
$this->_writeImage($objWriter, $element); $this->_writeImage($xmlWriter, $element);
} else { } else {
$this->_writeWatermark($objWriter, $element); $this->_writeWatermark($xmlWriter, $element);
} }
} elseif ($element instanceof PHPWord_Section_Footer_PreserveText) { } elseif ($element instanceof PreserveText) {
$this->_writePreserveText($objWriter, $element); $this->_writePreserveText($xmlWriter, $element);
} }
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
} }

View File

@ -25,34 +25,34 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_Rels
*/
class PHPWord_Writer_Word2007_Rels extends PHPWord_Writer_Word2007_WriterPart
{
public function writeRelationships(PHPWord $pPHPWord = null) use PhpOffice\PhpWord\Shared\XMLWriter;
class Rels extends WriterPart
{
public function writeRelationships(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships // Relationships
$objWriter->startElement('Relationships'); $xmlWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
$relationId = 1; $relationId = 1;
// Relationship word/document.xml // Relationship word/document.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
$relationId, $relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
'word/document.xml' 'word/document.xml'
@ -60,7 +60,7 @@ class PHPWord_Writer_Word2007_Rels extends PHPWord_Writer_Word2007_WriterPart
// Relationship docProps/core.xml // Relationship docProps/core.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
++$relationId, ++$relationId,
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
'docProps/core.xml' 'docProps/core.xml'
@ -68,29 +68,28 @@ class PHPWord_Writer_Word2007_Rels extends PHPWord_Writer_Word2007_WriterPart
// Relationship docProps/app.xml // Relationship docProps/app.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $xmlWriter,
++$relationId, ++$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
'docProps/app.xml' 'docProps/app.xml'
); );
$objWriter->endElement(); $xmlWriter->endElement();
// Return return $xmlWriter->getData();
return $objWriter->getData();
} }
/** /**
* Write Override content type * Write Override content type
* *
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer * @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID. rId will be prepended! * @param int $pId Relationship ID. rId will be prepended!
* @param string $pType Relationship type * @param string $pType Relationship type
* @param string $pTarget Relationship target * @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode * @param string $pTargetMode Relationship target mode
* @throws Exception * @throws Exception
*/ */
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{ {
if ($pType != '' && $pTarget != '') { if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) { if (strpos($pId, 'rId') === false) {
@ -98,16 +97,16 @@ class PHPWord_Writer_Word2007_Rels extends PHPWord_Writer_Word2007_WriterPart
} }
// Write relationship // Write relationship
$objWriter->startElement('Relationship'); $xmlWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId); $xmlWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType); $xmlWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget); $xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') { if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode); $xmlWriter->writeAttribute('TargetMode', $pTargetMode);
} }
$objWriter->endElement(); $xmlWriter->endElement();
} else { } else {
throw new Exception("Invalid parameters passed."); throw new Exception("Invalid parameters passed.");
} }

View File

@ -25,57 +25,61 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Class PHPWord_Writer_Word2007_Styles
*/
class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
{
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 Base
{
private $_document; private $_document;
public function writeStyles(PHPWord $pPHPWord = null) public function writeStyles(PHPWord $phpWord = null)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { 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 { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
} }
$this->_document = $pPHPWord; $this->_document = $phpWord;
// XML header // XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:styles'); $xmlWriter->startElement('w:styles');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// Write DocDefaults // Write DocDefaults
$this->_writeDocDefaults($objWriter); $this->_writeDocDefaults($xmlWriter);
// Write Style Definitions // Write Style Definitions
$styles = PHPWord_Style::getStyles(); $styles = Style::getStyles();
// Write normal paragraph style // Write normal paragraph style
$normalStyle = null; $normalStyle = null;
if (array_key_exists('Normal', $styles)) { if (array_key_exists('Normal', $styles)) {
$normalStyle = $styles['Normal']; $normalStyle = $styles['Normal'];
} }
$objWriter->startElement('w:style'); $xmlWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'paragraph'); $xmlWriter->writeAttribute('w:type', 'paragraph');
$objWriter->writeAttribute('w:default', '1'); $xmlWriter->writeAttribute('w:default', '1');
$objWriter->writeAttribute('w:styleId', 'Normal'); $xmlWriter->writeAttribute('w:styleId', 'Normal');
$objWriter->startElement('w:name'); $xmlWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', 'Normal'); $xmlWriter->writeAttribute('w:val', 'Normal');
$objWriter->endElement(); $xmlWriter->endElement();
if (!is_null($normalStyle)) { if (!is_null($normalStyle)) {
$this->_writeParagraphStyle($objWriter, $normalStyle); $this->_writeParagraphStyle($xmlWriter, $normalStyle);
} }
$objWriter->endElement(); $xmlWriter->endElement();
// Write other styles // Write other styles
if (count($styles) > 0) { if (count($styles) > 0) {
@ -83,7 +87,7 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
if ($styleName == 'Normal') { if ($styleName == 'Normal') {
continue; continue;
} }
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof Font) {
$paragraphStyle = $style->getParagraphStyle(); $paragraphStyle = $style->getParagraphStyle();
$styleType = $style->getStyleType(); $styleType = $style->getStyleType();
@ -94,94 +98,94 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
$type = 'paragraph'; $type = 'paragraph';
} }
$objWriter->startElement('w:style'); $xmlWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', $type); $xmlWriter->writeAttribute('w:type', $type);
if ($styleType == 'title') { if ($styleType == 'title') {
$arrStyle = explode('_', $styleName); $arrStyle = explode('_', $styleName);
$styleId = 'Heading' . $arrStyle[1]; $styleId = 'Heading' . $arrStyle[1];
$styleName = 'heading ' . $arrStyle[1]; $styleName = 'heading ' . $arrStyle[1];
$styleLink = 'Heading' . $arrStyle[1] . 'Char'; $styleLink = 'Heading' . $arrStyle[1] . 'Char';
$objWriter->writeAttribute('w:styleId', $styleId); $xmlWriter->writeAttribute('w:styleId', $styleId);
$objWriter->startElement('w:link'); $xmlWriter->startElement('w:link');
$objWriter->writeAttribute('w:val', $styleLink); $xmlWriter->writeAttribute('w:val', $styleLink);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:name'); $xmlWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName); $xmlWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement(); $xmlWriter->endElement();
if (!is_null($paragraphStyle)) { if (!is_null($paragraphStyle)) {
// Point parent style to Normal // Point parent style to Normal
$objWriter->startElement('w:basedOn'); $xmlWriter->startElement('w:basedOn');
$objWriter->writeAttribute('w:val', 'Normal'); $xmlWriter->writeAttribute('w:val', 'Normal');
$objWriter->endElement(); $xmlWriter->endElement();
$this->_writeParagraphStyle($objWriter, $paragraphStyle); $this->_writeParagraphStyle($xmlWriter, $paragraphStyle);
} }
$this->_writeTextStyle($objWriter, $style); $this->_writeTextStyle($xmlWriter, $style);
$objWriter->endElement(); $xmlWriter->endElement();
} elseif ($style instanceof PHPWord_Style_Paragraph) { } elseif ($style instanceof Paragraph) {
$objWriter->startElement('w:style'); $xmlWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'paragraph'); $xmlWriter->writeAttribute('w:type', 'paragraph');
$objWriter->writeAttribute('w:customStyle', '1'); $xmlWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:styleId', $styleName); $xmlWriter->writeAttribute('w:styleId', $styleName);
$objWriter->startElement('w:name'); $xmlWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName); $xmlWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement(); $xmlWriter->endElement();
// Parent style // Parent style
$basedOn = $style->getBasedOn(); $basedOn = $style->getBasedOn();
if (!is_null($basedOn)) { if (!is_null($basedOn)) {
$objWriter->startElement('w:basedOn'); $xmlWriter->startElement('w:basedOn');
$objWriter->writeAttribute('w:val', $basedOn); $xmlWriter->writeAttribute('w:val', $basedOn);
$objWriter->endElement(); $xmlWriter->endElement();
} }
// Next paragraph style // Next paragraph style
$next = $style->getNext(); $next = $style->getNext();
if (!is_null($next)) { if (!is_null($next)) {
$objWriter->startElement('w:next'); $xmlWriter->startElement('w:next');
$objWriter->writeAttribute('w:val', $next); $xmlWriter->writeAttribute('w:val', $next);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$this->_writeParagraphStyle($objWriter, $style); $this->_writeParagraphStyle($xmlWriter, $style);
$objWriter->endElement(); $xmlWriter->endElement();
} elseif ($style instanceof PHPWord_Style_TableFull) { } elseif ($style instanceof TableFull) {
$objWriter->startElement('w:style'); $xmlWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'table'); $xmlWriter->writeAttribute('w:type', 'table');
$objWriter->writeAttribute('w:customStyle', '1'); $xmlWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:styleId', $styleName); $xmlWriter->writeAttribute('w:styleId', $styleName);
$objWriter->startElement('w:name'); $xmlWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName); $xmlWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:uiPriority'); $xmlWriter->startElement('w:uiPriority');
$objWriter->writeAttribute('w:val', '99'); $xmlWriter->writeAttribute('w:val', '99');
$objWriter->endElement(); $xmlWriter->endElement();
$this->_writeFullTableStyle($objWriter, $style); $this->_writeFullTableStyle($xmlWriter, $style);
$objWriter->endElement(); $xmlWriter->endElement();
} }
} }
} }
$objWriter->endElement(); // w:styles $xmlWriter->endElement(); // w:styles
// Return // Return
return $objWriter->getData(); return $xmlWriter->getData();
} }
private function _writeFullTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_TableFull $style) private function _writeFullTableStyle(XMLWriter $xmlWriter = null, TableFull $style)
{ {
$brdSz = $style->getBorderSize(); $brdSz = $style->getBorderSize();
@ -203,106 +207,106 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
$mBottom = (!is_null($cellMargin[3])) ? true : false; $mBottom = (!is_null($cellMargin[3])) ? true : false;
$margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false; $margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
$objWriter->startElement('w:tblPr'); $xmlWriter->startElement('w:tblPr');
if ($margins) { if ($margins) {
$objWriter->startElement('w:tblCellMar'); $xmlWriter->startElement('w:tblCellMar');
if ($mTop) { if ($mTop) {
echo $margins[0]; echo $margins[0];
$objWriter->startElement('w:top'); $xmlWriter->startElement('w:top');
$objWriter->writeAttribute('w:w', $cellMargin[0]); $xmlWriter->writeAttribute('w:w', $cellMargin[0]);
$objWriter->writeAttribute('w:type', 'dxa'); $xmlWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($mLeft) { if ($mLeft) {
$objWriter->startElement('w:left'); $xmlWriter->startElement('w:left');
$objWriter->writeAttribute('w:w', $cellMargin[1]); $xmlWriter->writeAttribute('w:w', $cellMargin[1]);
$objWriter->writeAttribute('w:type', 'dxa'); $xmlWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($mRight) { if ($mRight) {
$objWriter->startElement('w:right'); $xmlWriter->startElement('w:right');
$objWriter->writeAttribute('w:w', $cellMargin[2]); $xmlWriter->writeAttribute('w:w', $cellMargin[2]);
$objWriter->writeAttribute('w:type', 'dxa'); $xmlWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($mBottom) { if ($mBottom) {
$objWriter->startElement('w:bottom'); $xmlWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:w', $cellMargin[3]); $xmlWriter->writeAttribute('w:w', $cellMargin[3]);
$objWriter->writeAttribute('w:type', 'dxa'); $xmlWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($borders) { if ($borders) {
$objWriter->startElement('w:tblBorders'); $xmlWriter->startElement('w:tblBorders');
if ($bTop) { if ($bTop) {
$objWriter->startElement('w:top'); $xmlWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[0]); $xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$objWriter->writeAttribute('w:color', $brdCol[0]); $xmlWriter->writeAttribute('w:color', $brdCol[0]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bLeft) { if ($bLeft) {
$objWriter->startElement('w:left'); $xmlWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[1]); $xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$objWriter->writeAttribute('w:color', $brdCol[1]); $xmlWriter->writeAttribute('w:color', $brdCol[1]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bRight) { if ($bRight) {
$objWriter->startElement('w:right'); $xmlWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[2]); $xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$objWriter->writeAttribute('w:color', $brdCol[2]); $xmlWriter->writeAttribute('w:color', $brdCol[2]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bBottom) { if ($bBottom) {
$objWriter->startElement('w:bottom'); $xmlWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[3]); $xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$objWriter->writeAttribute('w:color', $brdCol[3]); $xmlWriter->writeAttribute('w:color', $brdCol[3]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bInsH) { if ($bInsH) {
$objWriter->startElement('w:insideH'); $xmlWriter->startElement('w:insideH');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[4]); $xmlWriter->writeAttribute('w:sz', $brdSz[4]);
$objWriter->writeAttribute('w:color', $brdCol[4]); $xmlWriter->writeAttribute('w:color', $brdCol[4]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bInsV) { if ($bInsV) {
$objWriter->startElement('w:insideV'); $xmlWriter->startElement('w:insideV');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[5]); $xmlWriter->writeAttribute('w:sz', $brdSz[5]);
$objWriter->writeAttribute('w:color', $brdCol[5]); $xmlWriter->writeAttribute('w:color', $brdCol[5]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->endElement(); $xmlWriter->endElement();
if (!is_null($bgColor)) { if (!is_null($bgColor)) {
$objWriter->startElement('w:tcPr'); $xmlWriter->startElement('w:tcPr');
$objWriter->startElement('w:shd'); $xmlWriter->startElement('w:shd');
$objWriter->writeAttribute('w:val', 'clear'); $xmlWriter->writeAttribute('w:val', 'clear');
$objWriter->writeAttribute('w:color', 'auto'); $xmlWriter->writeAttribute('w:color', 'auto');
$objWriter->writeAttribute('w:fill', $bgColor); $xmlWriter->writeAttribute('w:fill', $bgColor);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
// First Row // First Row
$firstRow = $style->getFirstRow(); $firstRow = $style->getFirstRow();
if (!is_null($firstRow)) { if (!is_null($firstRow)) {
$this->_writeRowStyle($objWriter, 'firstRow', $firstRow); $this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow);
} }
} }
private function _writeRowStyle(PHPWord_Shared_XMLWriter $objWriter = null, $type, PHPWord_Style_TableFull $style) private function _writeRowStyle(XMLWriter $xmlWriter = null, $type, TableFull $style)
{ {
$brdSz = $style->getBorderSize(); $brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor(); $brdCol = $style->getBorderColor();
@ -314,81 +318,81 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
$bBottom = (!is_null($brdSz[3])) ? true : false; $bBottom = (!is_null($brdSz[3])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false; $borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
$objWriter->startElement('w:tblStylePr'); $xmlWriter->startElement('w:tblStylePr');
$objWriter->writeAttribute('w:type', $type); $xmlWriter->writeAttribute('w:type', $type);
$objWriter->startElement('w:tcPr'); $xmlWriter->startElement('w:tcPr');
if (!is_null($bgColor)) { if (!is_null($bgColor)) {
$objWriter->startElement('w:shd'); $xmlWriter->startElement('w:shd');
$objWriter->writeAttribute('w:val', 'clear'); $xmlWriter->writeAttribute('w:val', 'clear');
$objWriter->writeAttribute('w:color', 'auto'); $xmlWriter->writeAttribute('w:color', 'auto');
$objWriter->writeAttribute('w:fill', $bgColor); $xmlWriter->writeAttribute('w:fill', $bgColor);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->startElement('w:tcBorders'); $xmlWriter->startElement('w:tcBorders');
if ($bTop) { if ($bTop) {
$objWriter->startElement('w:top'); $xmlWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[0]); $xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$objWriter->writeAttribute('w:color', $brdCol[0]); $xmlWriter->writeAttribute('w:color', $brdCol[0]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bLeft) { if ($bLeft) {
$objWriter->startElement('w:left'); $xmlWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[1]); $xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$objWriter->writeAttribute('w:color', $brdCol[1]); $xmlWriter->writeAttribute('w:color', $brdCol[1]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bRight) { if ($bRight) {
$objWriter->startElement('w:right'); $xmlWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[2]); $xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$objWriter->writeAttribute('w:color', $brdCol[2]); $xmlWriter->writeAttribute('w:color', $brdCol[2]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
if ($bBottom) { if ($bBottom) {
$objWriter->startElement('w:bottom'); $xmlWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single'); $xmlWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[3]); $xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$objWriter->writeAttribute('w:color', $brdCol[3]); $xmlWriter->writeAttribute('w:color', $brdCol[3]);
$objWriter->endElement(); $xmlWriter->endElement();
} }
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
private function _writeDocDefaults(PHPWord_Shared_XMLWriter $objWriter = null) private function _writeDocDefaults(XMLWriter $xmlWriter = null)
{ {
$fontName = $this->_document->getDefaultFontName(); $fontName = $this->_document->getDefaultFontName();
$fontSize = $this->_document->getDefaultFontSize(); $fontSize = $this->_document->getDefaultFontSize();
$objWriter->startElement('w:docDefaults'); $xmlWriter->startElement('w:docDefaults');
$objWriter->startElement('w:rPrDefault'); $xmlWriter->startElement('w:rPrDefault');
$objWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rPr');
$objWriter->startElement('w:rFonts'); $xmlWriter->startElement('w:rFonts');
$objWriter->writeAttribute('w:ascii', $fontName); $xmlWriter->writeAttribute('w:ascii', $fontName);
$objWriter->writeAttribute('w:hAnsi', $fontName); $xmlWriter->writeAttribute('w:hAnsi', $fontName);
$objWriter->writeAttribute('w:eastAsia', $fontName); $xmlWriter->writeAttribute('w:eastAsia', $fontName);
$objWriter->writeAttribute('w:cs', $fontName); $xmlWriter->writeAttribute('w:cs', $fontName);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:sz'); $xmlWriter->startElement('w:sz');
$objWriter->writeAttribute('w:val', $fontSize * 2); $xmlWriter->writeAttribute('w:val', $fontSize * 2);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->startElement('w:szCs'); $xmlWriter->startElement('w:szCs');
$objWriter->writeAttribute('w:val', $fontSize * 2); $xmlWriter->writeAttribute('w:val', $fontSize * 2);
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
$objWriter->endElement(); $xmlWriter->endElement();
} }
} }

View File

@ -25,14 +25,15 @@
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Writer\Word2007;
* Abstract Class PHPWord_Writer_Word2007_WriterPart
*/ use PhpOffice\PhpWord\Writer\IWriter;
abstract class PHPWord_Writer_Word2007_WriterPart
abstract class WriterPart
{ {
private $_parentWriter; private $_parentWriter;
public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null) public function setParentWriter(IWriter $pWriter = null)
{ {
$this->_parentWriter = $pWriter; $this->_parentWriter = $pWriter;
} }
@ -42,7 +43,7 @@ abstract class PHPWord_Writer_Word2007_WriterPart
if (!is_null($this->_parentWriter)) { if (!is_null($this->_parentWriter)) {
return $this->_parentWriter; return $this->_parentWriter;
} else { } else {
throw new Exception("No parent PHPWord_Writer_IWriter assigned."); throw new Exception("No parent IWriter assigned.");
} }
} }
} }

View File

@ -103,7 +103,7 @@ $section->addText('Hello world! I am formatted by a user defined style',
'myOwnStyle'); 'myOwnStyle');
// You can also put the appended element to local object like this: // You can also put the appended element to local object like this:
$fontStyle = new PHPWord_Style_Font(); $fontStyle = new PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true); $fontStyle->setBold(true);
$fontStyle->setName('Verdana'); $fontStyle->setName('Verdana');
$fontStyle->setSize(22); $fontStyle->setSize(22);
@ -111,8 +111,8 @@ $myTextElement = $section->addText('Hello World!');
$myTextElement->setFontStyle($fontStyle); $myTextElement->setFontStyle($fontStyle);
// Finally, write the document: // Finally, write the document:
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $xmlWriter = PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('helloWorld.docx'); $xmlWriter->save('helloWorld.docx');
``` ```
<a name="measurement-units"></a> <a name="measurement-units"></a>
@ -125,15 +125,15 @@ You can use PHPWord helper functions to convert inches, centimeters, or points t
```php ```php
// Paragraph with 6 points space after // Paragraph with 6 points space after
$PHPWord->addParagraphStyle('My Style', array( $PHPWord->addParagraphStyle('My Style', array(
'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(6)) 'spaceAfter' => PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
); );
$section = $PHPWord->createSection(); $section = $PHPWord->createSection();
$sectionStyle = $section->getSettings(); $sectionStyle = $section->getSettings();
// half inch left margin // half inch left margin
$sectionStyle->setMarginLeft(PHPWord_Shared_Font::inchSizeToTwips(.5)); $sectionStyle->setMarginLeft(PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
// 2 cm right margin // 2 cm right margin
$sectionStyle->setMarginRight(PHPWord_Shared_Font::centimeterSizeToTwips(2)); $sectionStyle->setMarginRight(PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));
``` ```
<a name="sections"></a> <a name="sections"></a>

View File

@ -46,4 +46,4 @@ class AutoloaderTest extends \PHPUnit_Framework_TestCase
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class' 'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
); );
} }
} }

View File

@ -1,20 +1,18 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests;
use PHPWord_DocumentProperties; use PhpOffice\PhpWord\DocumentProperties;
/** /**
* Class DocumentPropertiesTest * @package PHPWord\Tests
* * @coversDefaultClass PhpOffice\PhpWord\DocumentProperties
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_DocumentProperties
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
*/ */
class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
{ {
public function testCreator() public function testCreator()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setCreator(); $oProperties->setCreator();
$this->assertEquals('', $oProperties->getCreator()); $this->assertEquals('', $oProperties->getCreator());
@ -24,7 +22,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testLastModifiedBy() public function testLastModifiedBy()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setLastModifiedBy(); $oProperties->setLastModifiedBy();
$this->assertEquals('', $oProperties->getLastModifiedBy()); $this->assertEquals('', $oProperties->getLastModifiedBy());
@ -34,7 +32,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testCreated() public function testCreated()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setCreated(); $oProperties->setCreated();
$this->assertEquals(time(), $oProperties->getCreated()); $this->assertEquals(time(), $oProperties->getCreated());
@ -45,7 +43,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testModified() public function testModified()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setModified(); $oProperties->setModified();
$this->assertEquals(time(), $oProperties->getModified()); $this->assertEquals(time(), $oProperties->getModified());
@ -56,7 +54,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testTitle() public function testTitle()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setTitle(); $oProperties->setTitle();
$this->assertEquals('', $oProperties->getTitle()); $this->assertEquals('', $oProperties->getTitle());
@ -66,7 +64,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testDescription() public function testDescription()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setDescription(); $oProperties->setDescription();
$this->assertEquals('', $oProperties->getDescription()); $this->assertEquals('', $oProperties->getDescription());
@ -76,7 +74,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testSubject() public function testSubject()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setSubject(); $oProperties->setSubject();
$this->assertEquals('', $oProperties->getSubject()); $this->assertEquals('', $oProperties->getSubject());
@ -86,7 +84,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testKeywords() public function testKeywords()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setKeywords(); $oProperties->setKeywords();
$this->assertEquals('', $oProperties->getKeywords()); $this->assertEquals('', $oProperties->getKeywords());
@ -96,7 +94,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testCategory() public function testCategory()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setCategory(); $oProperties->setCategory();
$this->assertEquals('', $oProperties->getCategory()); $this->assertEquals('', $oProperties->getCategory());
@ -106,7 +104,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testCompany() public function testCompany()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setCompany(); $oProperties->setCompany();
$this->assertEquals('', $oProperties->getCompany()); $this->assertEquals('', $oProperties->getCompany());
@ -116,7 +114,7 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testManager() public function testManager()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setManager(); $oProperties->setManager();
$this->assertEquals('', $oProperties->getManager()); $this->assertEquals('', $oProperties->getManager());
@ -126,30 +124,30 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testCustomProperty() public function testCustomProperty()
{ {
$oProperties = new PHPWord_DocumentProperties(); $oProperties = new DocumentProperties();
$oProperties->setCustomProperty('key1', null); $oProperties->setCustomProperty('key1', null);
$oProperties->setCustomProperty('key2', true); $oProperties->setCustomProperty('key2', true);
$oProperties->setCustomProperty('key3', 3); $oProperties->setCustomProperty('key3', 3);
$oProperties->setCustomProperty('key4', 4.4); $oProperties->setCustomProperty('key4', 4.4);
$oProperties->setCustomProperty('key5', 'value5'); $oProperties->setCustomProperty('key5', 'value5');
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, DocumentProperties::PROPERTY_TYPE_STRING,
$oProperties->getCustomPropertyType('key1') $oProperties->getCustomPropertyType('key1')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, DocumentProperties::PROPERTY_TYPE_BOOLEAN,
$oProperties->getCustomPropertyType('key2') $oProperties->getCustomPropertyType('key2')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, DocumentProperties::PROPERTY_TYPE_INTEGER,
$oProperties->getCustomPropertyType('key3') $oProperties->getCustomPropertyType('key3')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, DocumentProperties::PROPERTY_TYPE_FLOAT,
$oProperties->getCustomPropertyType('key4') $oProperties->getCustomPropertyType('key4')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, DocumentProperties::PROPERTY_TYPE_STRING,
$oProperties->getCustomPropertyType('key5') $oProperties->getCustomPropertyType('key5')
); );
$this->assertEquals(null, $oProperties->getCustomPropertyType('key6')); $this->assertEquals(null, $oProperties->getCustomPropertyType('key6'));
@ -172,50 +170,50 @@ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase
public function testConvertProperty() public function testConvertProperty()
{ {
$this->assertEquals('', PHPWord_DocumentProperties::convertProperty('a', 'empty')); $this->assertEquals('', DocumentProperties::convertProperty('a', 'empty'));
$this->assertEquals(null, PHPWord_DocumentProperties::convertProperty('a', 'null')); $this->assertEquals(null, DocumentProperties::convertProperty('a', 'null'));
$this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8', 'int')); $this->assertEquals(8, DocumentProperties::convertProperty('8', 'int'));
$this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8.3', 'uint')); $this->assertEquals(8, DocumentProperties::convertProperty('8.3', 'uint'));
$this->assertEquals(8.3, PHPWord_DocumentProperties::convertProperty('8.3', 'decimal')); $this->assertEquals(8.3, DocumentProperties::convertProperty('8.3', 'decimal'));
$this->assertEquals('8.3', PHPWord_DocumentProperties::convertProperty('8.3', 'lpstr')); $this->assertEquals('8.3', DocumentProperties::convertProperty('8.3', 'lpstr'));
$this->assertEquals(strtotime('10/11/2013'), PHPWord_DocumentProperties::convertProperty('10/11/2013', 'date')); $this->assertEquals(strtotime('10/11/2013'), DocumentProperties::convertProperty('10/11/2013', 'date'));
$this->assertEquals(true, PHPWord_DocumentProperties::convertProperty('true', 'bool')); $this->assertEquals(true, DocumentProperties::convertProperty('true', 'bool'));
$this->assertEquals(false, PHPWord_DocumentProperties::convertProperty('1', 'bool')); $this->assertEquals(false, DocumentProperties::convertProperty('1', 'bool'));
$this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', 'array')); $this->assertEquals('1', DocumentProperties::convertProperty('1', 'array'));
$this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', '')); $this->assertEquals('1', DocumentProperties::convertProperty('1', ''));
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, DocumentProperties::PROPERTY_TYPE_INTEGER,
PHPWord_DocumentProperties::convertPropertyType('int') DocumentProperties::convertPropertyType('int')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, DocumentProperties::PROPERTY_TYPE_INTEGER,
PHPWord_DocumentProperties::convertPropertyType('uint') DocumentProperties::convertPropertyType('uint')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, DocumentProperties::PROPERTY_TYPE_FLOAT,
PHPWord_DocumentProperties::convertPropertyType('decimal') DocumentProperties::convertPropertyType('decimal')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, DocumentProperties::PROPERTY_TYPE_STRING,
PHPWord_DocumentProperties::convertPropertyType('lpstr') DocumentProperties::convertPropertyType('lpstr')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_DATE, DocumentProperties::PROPERTY_TYPE_DATE,
PHPWord_DocumentProperties::convertPropertyType('date') DocumentProperties::convertPropertyType('date')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, DocumentProperties::PROPERTY_TYPE_BOOLEAN,
PHPWord_DocumentProperties::convertPropertyType('bool') DocumentProperties::convertPropertyType('bool')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, DocumentProperties::PROPERTY_TYPE_UNKNOWN,
PHPWord_DocumentProperties::convertPropertyType('array') DocumentProperties::convertPropertyType('array')
); );
$this->assertEquals( $this->assertEquals(
PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, DocumentProperties::PROPERTY_TYPE_UNKNOWN,
PHPWord_DocumentProperties::convertPropertyType('') DocumentProperties::convertPropertyType('')
); );
} }
} }

View File

@ -6,8 +6,8 @@ use PhpOffice\PhpWord\Exceptions\Exception;
class ExceptionTest extends \PHPUnit_Framework_TestCase class ExceptionTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception * @expectedException PhpOffice\PhpWord\Exceptions\Exception
* @covers \PhpOffice\PhpWord\Exceptions\Exception * @covers PhpOffice\PhpWord\Exceptions\Exception
*/ */
public function testThrowException() public function testThrowException()
{ {

View File

@ -6,8 +6,8 @@ use PhpOffice\PhpWord\Exceptions\InvalidImageException;
class InvalidImageExceptionTest extends \PHPUnit_Framework_TestCase class InvalidImageExceptionTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException * @expectedException PhpOffice\PhpWord\Exceptions\InvalidImageException
* @covers \PhpOffice\PhpWord\Exceptions\InvalidImageException * @covers PhpOffice\PhpWord\Exceptions\InvalidImageException
*/ */
public function testThrowException() public function testThrowException()
{ {

View File

@ -6,8 +6,8 @@ use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
class InvalidStyleExceptionTest extends \PHPUnit_Framework_TestCase class InvalidStyleExceptionTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidStyleException * @expectedException PhpOffice\PhpWord\Exceptions\InvalidStyleException
* @covers \PhpOffice\PhpWord\Exceptions\InvalidStyleException * @covers PhpOffice\PhpWord\Exceptions\InvalidStyleException
*/ */
public function testThrowException() public function testThrowException()
{ {

View File

@ -6,8 +6,8 @@ use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
class UnsupportedImageTypeExceptionTest extends \PHPUnit_Framework_TestCase class UnsupportedImageTypeExceptionTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException * @expectedException PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
* @covers \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException * @covers PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
*/ */
public function testThrowException() public function testThrowException()
{ {

View File

@ -2,13 +2,12 @@
namespace PHPWord\Tests; namespace PHPWord\Tests;
use PHPWord; use PHPWord;
use PHPWord_IOFactory; use PhpOffice\PhpWord\IOFactory;
use PHPWord_Writer_Word2007; use PhpOffice\PhpWord\Writer\Word2007;
use Exception; use Exception;
/** /**
* Class IOFactoryTest * @package PHPWord\Tests
* @package PHPWord\Tests
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
*/ */
class IOFactoryTest extends \PHPUnit_Framework_TestCase class IOFactoryTest extends \PHPUnit_Framework_TestCase
@ -16,48 +15,45 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
public function testGetSearchLocations() public function testGetSearchLocations()
{ {
$this->assertAttributeEquals( $this->assertAttributeEquals(
PHPWord_IOFactory::getSearchLocations(), IOFactory::getSearchLocations(),
'_searchLocations', '_searchLocations',
'PHPWord_IOFactory' 'PhpOffice\\PhpWord\\IOFactory'
); );
} }
public function testSetSearchLocationsWithArray() public function testSetSearchLocationsWithArray()
{ {
PHPWord_IOFactory::setSearchLocations(array()); IOFactory::setSearchLocations(array());
$this->assertAttributeEquals(array(), '_searchLocations', 'PHPWord_IOFactory'); $this->assertAttributeEquals(array(), '_searchLocations', 'PhpOffice\\PhpWord\\IOFactory');
} }
public function testAddSearchLocation() public function testAddSearchLocation()
{ {
PHPWord_IOFactory::setSearchLocations(array()); IOFactory::setSearchLocations(array());
PHPWord_IOFactory::addSearchLocation('type', 'location', 'classname'); IOFactory::addSearchLocation('interface', 'classname');
$this->assertAttributeEquals( $this->assertAttributeEquals(
array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')), array(array('interface' => 'interface', 'class' => 'classname')),
'_searchLocations', '_searchLocations',
'PHPWord_IOFactory' 'PhpOffice\\PhpWord\\IOFactory'
); );
} }
/** /**
* @expectedException Exception * @expectedException Exception
* @expectedExceptionMessage No IWriter found for type * @expectedExceptionMessage No IWriter found for type
*/ */
public function testCreateWriterException() public function testCreateWriterException()
{ {
$oPHPWord = new PHPWord(); $oPHPWord = new PHPWord();
PHPWord_IOFactory::setSearchLocations(array()); IOFactory::setSearchLocations(array());
PHPWord_IOFactory::createWriter($oPHPWord); IOFactory::createWriter($oPHPWord);
} }
public function testCreateWriter() public function testCreateWriter()
{ {
$oPHPWord = new PHPWord(); $oPHPWord = new PHPWord();
$this->assertEquals( $this->assertEquals(IOFactory::createWriter($oPHPWord, 'Word2007'), new Word2007($oPHPWord));
PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'),
new PHPWord_Writer_Word2007($oPHPWord)
);
} }
} }

View File

@ -1,39 +1,47 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests;
use PHPWord_Media; use PhpOffice\PhpWord\Media;
use PHPWord_Section; use PhpOffice\PhpWord\Section;
class MediaTest extends \PHPUnit_Framework_TestCase class MediaTest extends \PHPUnit_Framework_TestCase
{ {
public function testGetSectionMediaElementsWithNull() public function testGetSectionMediaElementsWithNull()
{ {
$this->assertEquals(PHPWord_Media::getSectionMediaElements(), array()); $this->assertEquals(Media::getSectionMediaElements(), array());
} }
public function testCountSectionMediaElementsWithNull() public function testCountSectionMediaElementsWithNull()
{ {
$this->assertEquals(PHPWord_Media::countSectionMediaElements(), 0); $this->assertEquals(Media::countSectionMediaElements(), 0);
} }
public function testGetHeaderMediaElements() public function testGetHeaderMediaElements()
{ {
$this->assertAttributeEquals(PHPWord_Media::getHeaderMediaElements(), '_headerMedia', 'PHPWord_Media'); $this->assertAttributeEquals(
Media::getHeaderMediaElements(),
'_headerMedia',
'PhpOffice\\PhpWord\\Media'
);
} }
public function testGetFooterMediaElements() public function testGetFooterMediaElements()
{ {
$this->assertAttributeEquals(PHPWord_Media::getFooterMediaElements(), '_footerMedia', 'PHPWord_Media'); $this->assertAttributeEquals(
Media::getFooterMediaElements(),
'_footerMedia',
'PhpOffice\\PhpWord\\Media'
);
} }
/** /**
* Todo: add memory image to this test * Todo: add memory image to this test
* *
* @covers PHPWord_Media::addSectionMediaElement * @covers PhpOffice\PhpWord\Media::addSectionMediaElement
*/ */
public function testAddSectionMediaElement() public function testAddSectionMediaElement()
{ {
$section = new PHPWord_Section(0); $section = new Section(0);
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg"); $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg"); $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif"); $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
@ -44,7 +52,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
$elements = $section->getElements(); $elements = $section->getElements();
$this->assertEquals(6, count($elements)); $this->assertEquals(6, count($elements));
foreach ($elements as $element) { foreach ($elements as $element) {
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
} }
} }
} }

View File

@ -1,12 +1,10 @@
<?php <?php
namespace PHPWord\Tests\Reader; namespace PHPWord\Tests\Reader;
use PHPWord_Reader_Word2007; use PhpOffice\PhpWord\Reader\Word2007;
use PHPWord_IOFactory; use PhpOffice\PhpWord\IOFactory;
/** /**
* Class Word2007Test
*
* @package PHPWord\Tests * @package PHPWord\Tests
*/ */
class Word2007Test extends \PHPUnit_Framework_TestCase class Word2007Test extends \PHPUnit_Framework_TestCase
@ -30,7 +28,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents') array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
); );
$object = new PHPWord_Reader_Word2007; $object = new Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx'; $file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$this->assertTrue($object->canRead($file)); $this->assertTrue($object->canRead($file));
} }
@ -46,10 +44,10 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents') array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
); );
$object = new PHPWord_Reader_Word2007; $object = new Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'foo.docx'; $file = $dir . DIRECTORY_SEPARATOR . 'foo.docx';
$this->assertFalse($object->canRead($file)); $this->assertFalse($object->canRead($file));
$object = PHPWord_IOFactory::load($file); $object = IOFactory::load($file);
} }
/** /**
@ -62,7 +60,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents') array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
); );
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx'; $file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$object = PHPWord_IOFactory::load($file); $object = IOFactory::load($file);
$this->assertInstanceOf('PHPWord', $object); $this->assertInstanceOf('PhpOffice\\PHPWord', $object);
} }
} }

View File

@ -1,15 +1,15 @@
<?php <?php
namespace PHPWord\Tests\Section\Footer; namespace PHPWord\Tests\Section\Footer;
use PHPWord_Section_Footer_PreserveText; use PhpOffice\PhpWord\Section\Footer\PreserveText;
class PreserveTextTest extends \PHPUnit_Framework_TestCase class PreserveTextTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$oPreserveText = new PHPWord_Section_Footer_PreserveText(); $oPreserveText = new PreserveText();
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $oPreserveText); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $oPreserveText);
$this->assertEquals($oPreserveText->getText(), null); $this->assertEquals($oPreserveText->getText(), null);
$this->assertEquals($oPreserveText->getFontStyle(), null); $this->assertEquals($oPreserveText->getFontStyle(), null);
$this->assertEquals($oPreserveText->getParagraphStyle(), null); $this->assertEquals($oPreserveText->getParagraphStyle(), null);
@ -17,7 +17,7 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
public function testConstructWithString() public function testConstructWithString()
{ {
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', 'styleFont', 'styleParagraph'); $oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph');
$this->assertEquals($oPreserveText->getText(), 'text'); $this->assertEquals($oPreserveText->getText(), 'text');
$this->assertEquals($oPreserveText->getFontStyle(), 'styleFont'); $this->assertEquals($oPreserveText->getFontStyle(), 'styleFont');
$this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); $this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph');
@ -25,12 +25,15 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
public function testConstructWithArray() public function testConstructWithArray()
{ {
$oPreserveText = new PHPWord_Section_Footer_PreserveText( $oPreserveText = new PreserveText(
'text', 'text',
array('align' => 'center'), array('align' => 'center'),
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
); );
$this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle()); $this->assertInstanceOf(
'PhpOffice\\PhpWord\\Style\\Paragraph',
$oPreserveText->getParagraphStyle()
);
} }
} }

View File

@ -1,22 +1,22 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Footer; use PhpOffice\PhpWord\Section\Footer;
class FooterTest extends \PHPUnit_Framework_TestCase class FooterTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oFooter = new PHPWord_Section_Footer($iVal); $oFooter = new Footer($iVal);
$this->assertInstanceOf('PHPWord_Section_Footer', $oFooter); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer', $oFooter);
$this->assertEquals($oFooter->getFooterCount(), $iVal); $this->assertEquals($oFooter->getFooterCount(), $iVal);
} }
public function testRelationID() public function testRelationID()
{ {
$oFooter = new PHPWord_Section_Footer(0); $oFooter = new Footer(0);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oFooter->setRelationId($iVal); $oFooter->setRelationId($iVal);
@ -25,27 +25,27 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testAddText() public function testAddText()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addText('text'); $element = $oFooter->addText('text');
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
} }
public function testAddTextNotUTF8() public function testAddTextNotUTF8()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addText(utf8_decode('ééé')); $element = $oFooter->addText(utf8_decode('ééé'));
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddTextBreak() public function testAddTextBreak()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oFooter->addTextBreak($iVal); $oFooter->addTextBreak($iVal);
@ -54,20 +54,20 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testCreateTextRun() public function testCreateTextRun()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->createTextRun(); $element = $oFooter->createTextRun();
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_TextRun', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
} }
public function testAddTable() public function testAddTable()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addTable(); $element = $oFooter->addTable();
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_Table', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element);
} }
public function testAddImage() public function testAddImage()
@ -76,47 +76,47 @@ class FooterTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addImage($src); $element = $oFooter->addImage($src);
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
} }
public function testAddMemoryImage() public function testAddMemoryImage()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addMemoryImage( $element = $oFooter->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
); );
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
} }
public function testAddPreserveText() public function testAddPreserveText()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addPreserveText('text'); $element = $oFooter->addPreserveText('text');
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
} }
public function testAddPreserveTextNotUTF8() public function testAddPreserveTextNotUTF8()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addPreserveText(utf8_decode('ééé')); $element = $oFooter->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testGetElements() public function testGetElements()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new Footer(1);
$this->assertInternalType('array', $oFooter->getElements()); $this->assertInternalType('array', $oFooter->getElements());
} }
} }

View File

@ -1,54 +1,57 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Footnote; use PhpOffice\PhpWord\Section\Footnote;
class FootnoteTest extends \PHPUnit_Framework_TestCase class FootnoteTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$oFootnote = new PHPWord_Section_Footnote(); $oFootnote = new Footnote();
$this->assertInstanceOf('PHPWord_Section_Footnote', $oFootnote); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footnote', $oFootnote);
$this->assertCount(0, $oFootnote->getElements()); $this->assertCount(0, $oFootnote->getElements());
$this->assertEquals($oFootnote->getParagraphStyle(), null); $this->assertEquals($oFootnote->getParagraphStyle(), null);
} }
public function testConstructString() public function testConstructString()
{ {
$oFootnote = new PHPWord_Section_Footnote('pStyle'); $oFootnote = new Footnote('pStyle');
$this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle'); $this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle');
} }
public function testConstructArray() public function testConstructArray()
{ {
$oFootnote = new PHPWord_Section_Footnote(array('spacing' => 100)); $oFootnote = new Footnote(array('spacing' => 100));
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oFootnote->getParagraphStyle()); $this->assertInstanceOf(
'PhpOffice\\PhpWord\\Style\\Paragraph',
$oFootnote->getParagraphStyle()
);
} }
public function testAddText() public function testAddText()
{ {
$oFootnote = new PHPWord_Section_Footnote(); $oFootnote = new Footnote();
$element = $oFootnote->addText('text'); $element = $oFootnote->addText('text');
$this->assertCount(1, $oFootnote->getElements()); $this->assertCount(1, $oFootnote->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
} }
public function testAddLink() public function testAddLink()
{ {
$oFootnote = new PHPWord_Section_Footnote(); $oFootnote = new Footnote();
$element = $oFootnote->addLink('http://www.google.fr'); $element = $oFootnote->addLink('http://www.google.fr');
$this->assertCount(1, $oFootnote->getElements()); $this->assertCount(1, $oFootnote->getElements());
$this->assertInstanceOf('PHPWord_Section_Link', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
} }
public function testReferenceId() public function testReferenceId()
{ {
$oFootnote = new PHPWord_Section_Footnote(); $oFootnote = new Footnote();
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oFootnote->setReferenceId($iVal); $oFootnote->setReferenceId($iVal);
@ -57,7 +60,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
public function testGetElements() public function testGetElements()
{ {
$oFootnote = new PHPWord_Section_Footnote(); $oFootnote = new Footnote();
$this->assertInternalType('array', $oFootnote->getElements()); $this->assertInternalType('array', $oFootnote->getElements());
} }
} }

View File

@ -1,50 +1,50 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Header; use PhpOffice\PhpWord\Section\Header;
class HeaderTest extends \PHPUnit_Framework_TestCase class HeaderTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructDefault() public function testConstructDefault()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oHeader = new PHPWord_Section_Header($iVal); $oHeader = new Header($iVal);
$this->assertInstanceOf('PHPWord_Section_Header', $oHeader); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Header', $oHeader);
$this->assertEquals($oHeader->getHeaderCount(), $iVal); $this->assertEquals($oHeader->getHeaderCount(), $iVal);
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO); $this->assertEquals($oHeader->getType(), Header::AUTO);
} }
public function testAddText() public function testAddText()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addText('text'); $element = $oHeader->addText('text');
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertEquals($element->getText(), 'text'); $this->assertEquals($element->getText(), 'text');
} }
public function testAddTextNotUTF8() public function testAddTextNotUTF8()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addText(utf8_decode('ééé')); $element = $oHeader->addText(utf8_decode('ééé'));
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddTextBreak() public function testAddTextBreak()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$oHeader->addTextBreak(); $oHeader->addTextBreak();
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
} }
public function testAddTextBreakWithParams() public function testAddTextBreakWithParams()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oHeader->addTextBreak($iVal); $oHeader->addTextBreak($iVal);
$this->assertCount($iVal, $oHeader->getElements()); $this->assertCount($iVal, $oHeader->getElements());
@ -52,17 +52,17 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testCreateTextRun() public function testCreateTextRun()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->createTextRun(); $element = $oHeader->createTextRun();
$this->assertInstanceOf('PHPWord_Section_TextRun', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
} }
public function testAddTable() public function testAddTable()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addTable(); $element = $oHeader->addTable();
$this->assertInstanceOf('PHPWord_Section_Table', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
} }
@ -72,40 +72,40 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addImage($src); $element = $oHeader->addImage($src);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
} }
public function testAddMemoryImage() public function testAddMemoryImage()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addMemoryImage( $element = $oHeader->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
); );
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
} }
public function testAddPreserveText() public function testAddPreserveText()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addPreserveText('text'); $element = $oHeader->addPreserveText('text');
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
} }
public function testAddPreserveTextNotUTF8() public function testAddPreserveTextNotUTF8()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addPreserveText(utf8_decode('ééé')); $element = $oHeader->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
@ -115,23 +115,23 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$element = $oHeader->addWatermark($src); $element = $oHeader->addWatermark($src);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
} }
public function testGetElements() public function testGetElements()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$this->assertInternalType('array', $oHeader->getElements()); $this->assertInternalType('array', $oHeader->getElements());
} }
public function testRelationId() public function testRelationId()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oHeader->setRelationId($iVal); $oHeader->setRelationId($iVal);
@ -140,26 +140,26 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testResetType() public function testResetType()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$oHeader->firstPage(); $oHeader->firstPage();
$oHeader->resetType(); $oHeader->resetType();
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO); $this->assertEquals($oHeader->getType(), Header::AUTO);
} }
public function testFirstPage() public function testFirstPage()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$oHeader->firstPage(); $oHeader->firstPage();
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::FIRST); $this->assertEquals($oHeader->getType(), Header::FIRST);
} }
public function testEvenPage() public function testEvenPage()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new Header(1);
$oHeader->evenPage(); $oHeader->evenPage();
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::EVEN); $this->assertEquals($oHeader->getType(), Header::EVEN);
} }
} }

View File

@ -1,9 +1,11 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Image; use PhpOffice\PhpWord\Section\Image;
use PHPWord_Style_Image;
/**
* @coversDefaultClass PhpOffice\PhpWord\Section\Image
*/
class ImageTest extends \PHPUnit_Framework_TestCase class ImageTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
@ -12,13 +14,13 @@ class ImageTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
); );
$oImage = new PHPWord_Section_Image($src); $oImage = new Image($src);
$this->assertInstanceOf('PHPWord_Section_Image', $oImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src); $this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src)); $this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getIsWatermark(), false); $this->assertEquals($oImage->getIsWatermark(), false);
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
public function testConstructWithStyle() public function testConstructWithStyle()
@ -27,59 +29,59 @@ class ImageTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
); );
$oImage = new PHPWord_Section_Image( $oImage = new Image(
$src, $src,
array('width' => 210, 'height' => 210, 'align' => 'center', array('width' => 210, 'height' => 210, 'align' => 'center',
'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND) 'wrappingStyle' => PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND)
); );
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
/** /**
* @covers PHPWord_Section_Image::__construct * @covers ::__construct
*/ */
public function testValidImageTypes() public function testValidImageTypes()
{ {
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
} }
/** /**
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException * @expectedException PhpOffice\PhpWord\Exceptions\InvalidImageException
* @covers PHPWord_Section_Image::__construct * @covers ::__construct
*/ */
public function testImageNotFound() public function testImageNotFound()
{ {
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/thisisnotarealimage"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/thisisnotarealimage");
} }
/** /**
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException * @expectedException PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
* @covers PHPWord_Section_Image::__construct * @covers ::__construct
*/ */
public function testInvalidImageTypes() public function testInvalidImageTypes()
{ {
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx"); new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx");
} }
public function testStyle() public function testStyle()
{ {
$oImage = new PHPWord_Section_Image(\join( $oImage = new Image(\join(
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width' => 210, 'height' => 210, 'align' => 'center')); ), array('width' => 210, 'height' => 210, 'align' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
public function testRelationID() public function testRelationID()
{ {
$oImage = new PHPWord_Section_Image(\join( $oImage = new Image(\join(
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
)); ));
@ -91,7 +93,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testWatermark() public function testWatermark()
{ {
$oImage = new PHPWord_Section_Image(\join( $oImage = new Image(\join(
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
)); ));
@ -99,4 +101,4 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$oImage->setIsWatermark(true); $oImage->setIsWatermark(true);
$this->assertEquals($oImage->getIsWatermark(), true); $this->assertEquals($oImage->getIsWatermark(), true);
} }
} }

View File

@ -1,16 +1,16 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Link; use PhpOffice\PhpWord\Section\Link;
use PHPWord_Style_Font; use PhpOffice\PhpWord\Style\Font;
class LinkTest extends \PHPUnit_Framework_TestCase class LinkTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructDefault() public function testConstructDefault()
{ {
$oLink = new PHPWord_Section_Link('http://www.google.com'); $oLink = new Link('http://www.google.com');
$this->assertInstanceOf('PHPWord_Section_Link', $oLink); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $oLink);
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com'); $this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
$this->assertEquals($oLink->getLinkName(), null); $this->assertEquals($oLink->getLinkName(), null);
$this->assertEquals($oLink->getFontStyle(), null); $this->assertEquals($oLink->getFontStyle(), null);
@ -19,23 +19,23 @@ class LinkTest extends \PHPUnit_Framework_TestCase
public function testConstructWithParamsArray() public function testConstructWithParamsArray()
{ {
$oLink = new PHPWord_Section_Link( $oLink = new Link(
'http://www.google.com', 'http://www.google.com',
'Search Engine', 'Search Engine',
array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE), array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE),
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
); );
$this->assertInstanceOf('PHPWord_Section_Link', $oLink); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $oLink);
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com'); $this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
$this->assertEquals($oLink->getLinkName(), 'Search Engine'); $this->assertEquals($oLink->getLinkName(), 'Search Engine');
$this->assertInstanceOf('PHPWord_Style_Font', $oLink->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oLink->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
} }
public function testConstructWithParamsString() public function testConstructWithParamsString()
{ {
$oLink = new PHPWord_Section_Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle'); $oLink = new Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle');
$this->assertEquals($oLink->getFontStyle(), 'fontStyle'); $this->assertEquals($oLink->getFontStyle(), 'fontStyle');
$this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle'); $this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle');
@ -43,10 +43,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase
public function testRelationId() public function testRelationId()
{ {
$oLink = new PHPWord_Section_Link('http://www.google.com'); $oLink = new Link('http://www.google.com');
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oLink->setRelationId($iVal); $oLink->setRelationId($iVal);
$this->assertEquals($oLink->getRelationId(), $iVal); $this->assertEquals($oLink->getRelationId(), $iVal);
} }
} }

View File

@ -1,36 +1,38 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_ListItem; use PhpOffice\PhpWord\Section\ListItem;
use PHPWord_Style_ListItem;
class ListItemTest extends \PHPUnit_Framework_TestCase class ListItemTest extends \PHPUnit_Framework_TestCase
{ {
public function testText() public function testText()
{ {
$oListItem = new PHPWord_Section_ListItem('text'); $oListItem = new ListItem('text');
$this->assertInstanceOf('PHPWord_Section_Text', $oListItem->getTextObject()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $oListItem->getTextObject());
} }
public function testStyle() public function testStyle()
{ {
$oListItem = new PHPWord_Section_ListItem( $oListItem = new ListItem(
'text', 'text',
1, 1,
null, null,
array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER) array('listType' => PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER)
); );
$this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle());
$this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER); $this->assertEquals(
$oListItem->getStyle()->getListType(),
PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER
);
} }
public function testDepth() public function testDepth()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oListItem = new PHPWord_Section_ListItem('text', $iVal); $oListItem = new ListItem('text', $iVal);
$this->assertEquals($oListItem->getDepth(), $iVal); $this->assertEquals($oListItem->getDepth(), $iVal);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_MemoryImage; use PhpOffice\PhpWord\Section\MemoryImage;
class MemoryImageTest extends \PHPUnit_Framework_TestCase class MemoryImageTest extends \PHPUnit_Framework_TestCase
{ {
@ -11,9 +11,9 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
); );
$oMemoryImage = new PHPWord_Section_MemoryImage($src); $oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng'); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng');
@ -28,9 +28,9 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif')
); );
$oMemoryImage = new PHPWord_Section_MemoryImage($src); $oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif'); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif');
@ -45,9 +45,9 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oMemoryImage = new PHPWord_Section_MemoryImage($src); $oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg'); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg');
@ -58,12 +58,12 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
public function testBMP() public function testBMP()
{ {
$oMemoryImage = new PHPWord_Section_MemoryImage(\join( $oMemoryImage = new MemoryImage(\join(
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp')
)); ));
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null); $this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
$this->assertEquals($oMemoryImage->getImageFunction(), null); $this->assertEquals($oMemoryImage->getImageFunction(), null);
$this->assertEquals($oMemoryImage->getImageExtension(), null); $this->assertEquals($oMemoryImage->getImageExtension(), null);
@ -72,17 +72,17 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
public function testStyle() public function testStyle()
{ {
$oMemoryImage = new PHPWord_Section_MemoryImage(\join( $oMemoryImage = new MemoryImage(\join(
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width' => 210, 'height' => 210, 'align' => 'center')); ), array('width' => 210, 'height' => 210, 'align' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Image', $oMemoryImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
} }
public function testRelationID() public function testRelationID()
{ {
$oMemoryImage = new PHPWord_Section_MemoryImage(\join( $oMemoryImage = new MemoryImage(\join(
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
)); ));
@ -91,4 +91,4 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
$oMemoryImage->setRelationId($iVal); $oMemoryImage->setRelationId($iVal);
$this->assertEquals($oMemoryImage->getRelationId(), $iVal); $this->assertEquals($oMemoryImage->getRelationId(), $iVal);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Object; use PhpOffice\PhpWord\Section\Object;
class ObjectTest extends \PHPUnit_Framework_TestCase class ObjectTest extends \PHPUnit_Framework_TestCase
{ {
@ -11,10 +11,10 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
); );
$oObject = new PHPWord_Section_Object($src); $oObject = new Object($src);
$this->assertInstanceOf('PHPWord_Section_Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
$this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle());
$this->assertEquals($oObject->getSource(), $src); $this->assertEquals($oObject->getSource(), $src);
} }
@ -24,9 +24,9 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
); );
$oObject = new PHPWord_Section_Object($src); $oObject = new Object($src);
$this->assertInstanceOf('PHPWord_Section_Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
$this->assertEquals($oObject->getSource(), null); $this->assertEquals($oObject->getSource(), null);
$this->assertEquals($oObject->getStyle(), null); $this->assertEquals($oObject->getStyle(), null);
} }
@ -37,10 +37,10 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
); );
$oObject = new PHPWord_Section_Object($src, array('width' => '230px')); $oObject = new Object($src, array('width' => '230px'));
$this->assertInstanceOf('PHPWord_Section_Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
$this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle());
$this->assertEquals($oObject->getSource(), $src); $this->assertEquals($oObject->getSource(), $src);
} }
@ -50,7 +50,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
); );
$oObject = new PHPWord_Section_Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oObject->setRelationId($iVal); $oObject->setRelationId($iVal);
@ -63,7 +63,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
); );
$oObject = new PHPWord_Section_Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oObject->setImageRelationId($iVal); $oObject->setImageRelationId($iVal);
@ -76,10 +76,10 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
); );
$oObject = new PHPWord_Section_Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oObject->setObjectId($iVal); $oObject->setObjectId($iVal);
$this->assertEquals($oObject->getObjectId(), $iVal); $this->assertEquals($oObject->getObjectId(), $iVal);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_PageBreak; use PhpOffice\PhpWord\Section\PageBreak;
class PageBreakTest extends \PHPUnit_Framework_TestCase class PageBreakTest extends \PHPUnit_Framework_TestCase
{ {
@ -11,8 +11,8 @@ class PageBreakTest extends \PHPUnit_Framework_TestCase
public function testConstruct() public function testConstruct()
{ {
// Section Settings // Section Settings
$oPageBreak = new PHPWord_Section_PageBreak(); $oPageBreak = new PageBreak();
$this->assertInstanceOf('PHPWord_Section_PageBreak', $oPageBreak); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\PageBreak', $oPageBreak);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Settings; use PhpOffice\PhpWord\Section\Settings;
class SettingsTest extends \PHPUnit_Framework_TestCase class SettingsTest extends \PHPUnit_Framework_TestCase
{ {
@ -11,7 +11,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testSettingValue() public function testSettingValue()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$oSettings->setSettingValue('_orientation', 'landscape'); $oSettings->setSettingValue('_orientation', 'landscape');
$this->assertEquals('landscape', $oSettings->getOrientation()); $this->assertEquals('landscape', $oSettings->getOrientation());
@ -46,7 +46,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testMargin() public function testMargin()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setMarginTop($iVal); $oSettings->setMarginTop($iVal);
@ -68,7 +68,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testOrientationLandscape() public function testOrientationLandscape()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$oSettings->setLandscape(); $oSettings->setLandscape();
$this->assertEquals('landscape', $oSettings->getOrientation()); $this->assertEquals('landscape', $oSettings->getOrientation());
@ -79,7 +79,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testOrientationPortrait() public function testOrientationPortrait()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$oSettings->setPortrait(); $oSettings->setPortrait();
$this->assertNull($oSettings->getOrientation()); $this->assertNull($oSettings->getOrientation());
@ -90,7 +90,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBorderSize() public function testBorderSize()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setBorderSize($iVal); $oSettings->setBorderSize($iVal);
@ -120,7 +120,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBorderColor() public function testBorderColor()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$oSettings->setBorderColor('FF00AA'); $oSettings->setBorderColor('FF00AA');
$this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor()); $this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor());
@ -145,7 +145,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testNumberingStart() public function testNumberingStart()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$this->assertNull($oSettings->getPageNumberingStart()); $this->assertNull($oSettings->getPageNumberingStart());
@ -160,7 +160,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testHeader() public function testHeader()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$this->assertEquals(720, $oSettings->getHeaderHeight()); $this->assertEquals(720, $oSettings->getHeaderHeight());
@ -175,7 +175,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testFooter() public function testFooter()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$this->assertEquals(720, $oSettings->getFooterHeight()); $this->assertEquals(720, $oSettings->getFooterHeight());
@ -190,7 +190,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testColumnsNum() public function testColumnsNum()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
// Default // Default
$this->assertEquals(1, $oSettings->getColsNum()); $this->assertEquals(1, $oSettings->getColsNum());
@ -206,23 +206,23 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testColumnsSpace() public function testColumnsSpace()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
// Default // Default
$this->assertEquals(720, $oSettings->getColsSpace()); $this->assertEquals(720, $oSettings->getColsSpace());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace($iVal)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Settings', $oSettings->setColsSpace($iVal));
$this->assertEquals($iVal, $oSettings->getColsSpace()); $this->assertEquals($iVal, $oSettings->getColsSpace());
$this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Settings', $oSettings->setColsSpace());
$this->assertEquals(720, $oSettings->getColsSpace()); $this->assertEquals(720, $oSettings->getColsSpace());
} }
public function testBreakType() public function testBreakType()
{ {
// Section Settings // Section Settings
$oSettings = new PHPWord_Section_Settings(); $oSettings = new Settings();
$this->assertNull($oSettings->getBreakType()); $this->assertNull($oSettings->getBreakType());
@ -232,4 +232,4 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$oSettings->setBreakType(); $oSettings->setBreakType();
$this->assertNull($oSettings->getBreakType()); $this->assertNull($oSettings->getBreakType());
} }
} }

View File

@ -1,67 +1,67 @@
<?php <?php
namespace PHPWord\Tests\Section\Table; namespace PHPWord\Tests\Section\Table;
use PHPWord_Section_Table_Cell; use PhpOffice\PhpWord\Section\Table\Cell;
class CellTest extends \PHPUnit_Framework_TestCase class CellTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal); $oCell = new Cell('section', $iVal);
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $oCell); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $oCell);
$this->assertEquals($oCell->getWidth(), null); $this->assertEquals($oCell->getWidth(), null);
} }
public function testConstructWithStyleArray() public function testConstructWithStyleArray()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, array('valign' => 'center')); $oCell = new Cell('section', $iVal, null, array('valign' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Cell', $oCell->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Cell', $oCell->getStyle());
$this->assertEquals($oCell->getWidth(), null); $this->assertEquals($oCell->getWidth(), null);
} }
public function testConstructWithStyleString() public function testConstructWithStyleString()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, 'cellStyle'); $oCell = new Cell('section', $iVal, null, 'cellStyle');
$this->assertEquals($oCell->getStyle(), 'cellStyle'); $this->assertEquals($oCell->getStyle(), 'cellStyle');
} }
public function testAddText() public function testAddText()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addText('text'); $element = $oCell->addText('text');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
} }
public function testAddTextNotUTF8() public function testAddTextNotUTF8()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addText(utf8_decode('ééé')); $element = $oCell->addText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddLink() public function testAddLink()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addLink('http://www.google.fr', 'Nom'); $element = $oCell->addLink('http://www.google.fr', 'Nom');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Link', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
} }
public function testAddTextBreak() public function testAddTextBreak()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$oCell->addTextBreak(); $oCell->addTextBreak();
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
@ -69,21 +69,21 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddListItem() public function testAddListItem()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addListItem('text'); $element = $oCell->addListItem('text');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_ListItem', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'text'); $this->assertEquals($element->getTextObject()->getText(), 'text');
} }
public function testAddListItemNotUTF8() public function testAddListItemNotUTF8()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addListItem(utf8_decode('ééé')); $element = $oCell->addListItem(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_ListItem', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'ééé'); $this->assertEquals($element->getTextObject()->getText(), 'ééé');
} }
@ -93,11 +93,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
} }
public function testAddImageHeader() public function testAddImageHeader()
@ -106,11 +106,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oCell = new PHPWord_Section_Table_Cell('header', 1); $oCell = new Cell('header', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
} }
public function testAddImageFooter() public function testAddImageFooter()
@ -119,44 +119,44 @@ class CellTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oCell = new PHPWord_Section_Table_Cell('footer', 1); $oCell = new Cell('footer', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
} }
public function testAddMemoryImageSection() public function testAddMemoryImageSection()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addMemoryImage( $element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
); );
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
} }
public function testAddMemoryImageHeader() public function testAddMemoryImageHeader()
{ {
$oCell = new PHPWord_Section_Table_Cell('header', 1); $oCell = new Cell('header', 1);
$element = $oCell->addMemoryImage( $element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
); );
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
} }
public function testAddMemoryImageFooter() public function testAddMemoryImageFooter()
{ {
$oCell = new PHPWord_Section_Table_Cell('footer', 1); $oCell = new Cell('footer', 1);
$element = $oCell->addMemoryImage( $element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
); );
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
} }
public function testAddObjectXLS() public function testAddObjectXLS()
@ -165,45 +165,45 @@ class CellTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
); );
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addObject($src); $element = $oCell->addObject($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Object', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $element);
} }
public function testAddPreserveText() public function testAddPreserveText()
{ {
$oCell = new PHPWord_Section_Table_Cell('header', 1); $oCell = new Cell('header', 1);
$element = $oCell->addPreserveText('text'); $element = $oCell->addPreserveText('text');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
} }
public function testAddPreserveTextNotUTF8() public function testAddPreserveTextNotUTF8()
{ {
$oCell = new PHPWord_Section_Table_Cell('header', 1); $oCell = new Cell('header', 1);
$element = $oCell->addPreserveText(utf8_decode('ééé')); $element = $oCell->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testCreateTextRun() public function testCreateTextRun()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->createTextRun(); $element = $oCell->createTextRun();
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_TextRun', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
} }
public function testGetElements() public function testGetElements()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new Cell('section', 1);
$this->assertInternalType('array', $oCell->getElements()); $this->assertInternalType('array', $oCell->getElements());
} }
} }

View File

@ -1,27 +1,27 @@
<?php <?php
namespace PHPWord\Tests\Section\Table; namespace PHPWord\Tests\Section\Table;
use PHPWord_Section_Table_Row; use PhpOffice\PhpWord\Section\Table\Row;
class RowTest extends \PHPUnit_Framework_TestCase class RowTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oRow = new PHPWord_Section_Table_Row('section', $iVal); $oRow = new Row('section', $iVal);
$this->assertInstanceOf('PHPWord_Section_Table_Row', $oRow); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Row', $oRow);
$this->assertEquals($oRow->getHeight(), null); $this->assertEquals($oRow->getHeight(), null);
$this->assertInternalType('array', $oRow->getCells()); $this->assertInternalType('array', $oRow->getCells());
$this->assertCount(0, $oRow->getCells()); $this->assertCount(0, $oRow->getCells());
$this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle());
} }
public function testConstructWithParams() public function testConstructWithParams()
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$iVal2 = rand(1, 1000); $iVal2 = rand(1, 1000);
$oRow = new PHPWord_Section_Table_Row( $oRow = new Row(
'section', 'section',
$iVal, $iVal,
$iVal2, $iVal2,
@ -29,15 +29,15 @@ class RowTest extends \PHPUnit_Framework_TestCase
); );
$this->assertEquals($oRow->getHeight(), $iVal2); $this->assertEquals($oRow->getHeight(), $iVal2);
$this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle());
} }
public function testAddCell() public function testAddCell()
{ {
$oRow = new PHPWord_Section_Table_Row('section', 1); $oRow = new Row('section', 1);
$element = $oRow->addCell(); $element = $oRow->addCell();
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $element);
$this->assertCount(1, $oRow->getCells()); $this->assertCount(1, $oRow->getCells());
} }
} }

View File

@ -1,15 +1,15 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Table; use PhpOffice\PhpWord\Section\Table;
class TableTest extends \PHPUnit_Framework_TestCase class TableTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$oTable = new PHPWord_Section_Table('section', 1); $oTable = new Table('section', 1);
$this->assertInstanceOf('PHPWord_Section_Table', $oTable); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $oTable);
$this->assertEquals($oTable->getStyle(), null); $this->assertEquals($oTable->getStyle(), null);
$this->assertEquals($oTable->getWidth(), null); $this->assertEquals($oTable->getWidth(), null);
$this->assertEquals($oTable->getRows(), array()); $this->assertEquals($oTable->getRows(), array());
@ -18,25 +18,25 @@ class TableTest extends \PHPUnit_Framework_TestCase
public function testStyleText() public function testStyleText()
{ {
$oTable = new PHPWord_Section_Table('section', 1, 'tableStyle'); $oTable = new Table('section', 1, 'tableStyle');
$this->assertEquals($oTable->getStyle(), 'tableStyle'); $this->assertEquals($oTable->getStyle(), 'tableStyle');
} }
public function testStyleArray() public function testStyleArray()
{ {
$oTable = new PHPWord_Section_Table( $oTable = new Table(
'section', 'section',
1, 1,
array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80) array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)
); );
$this->assertInstanceOf('PHPWord_Style_Table', $oTable->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle());
} }
public function testWidth() public function testWidth()
{ {
$oTable = new PHPWord_Section_Table('section', 1); $oTable = new Table('section', 1);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oTable->setWidth($iVal); $oTable->setWidth($iVal);
$this->assertEquals($oTable->getWidth(), $iVal); $this->assertEquals($oTable->getWidth(), $iVal);
@ -44,17 +44,17 @@ class TableTest extends \PHPUnit_Framework_TestCase
public function testRow() public function testRow()
{ {
$oTable = new PHPWord_Section_Table('section', 1); $oTable = new Table('section', 1);
$element = $oTable->addRow(); $element = $oTable->addRow();
$this->assertInstanceOf('PHPWord_Section_Table_Row', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Row', $element);
$this->assertCount(1, $oTable->getRows()); $this->assertCount(1, $oTable->getRows());
} }
public function testCell() public function testCell()
{ {
$oTable = new PHPWord_Section_Table('section', 1); $oTable = new Table('section', 1);
$oTable->addRow(); $oTable->addRow();
$element = $oTable->addCell(); $element = $oTable->addCell();
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $element);
} }
} }

View File

@ -1,13 +1,13 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_TextBreak; use PhpOffice\PhpWord\Section\TextBreak;
use PHPWord_Style_Paragraph; use PhpOffice\PhpWord\Style\Font;
use PHPWord_Style_Font; use PhpOffice\PhpWord\Style\Paragraph;
/** /**
* @package PHPWord\Tests * @package PHPWord\Tests
* @coversDefaultClass PHPWord_Section_TextBreak * @coversDefaultClass PhpOffice\PhpWord\Section\TextBreak
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
*/ */
class TextBreakTest extends \PHPUnit_Framework_TestCase class TextBreakTest extends \PHPUnit_Framework_TestCase
@ -17,7 +17,7 @@ class TextBreakTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstruct() public function testConstruct()
{ {
$object = new PHPWord_Section_TextBreak(); $object = new TextBreak();
$this->assertNull($object->getFontStyle()); $this->assertNull($object->getFontStyle());
$this->assertNull($object->getParagraphStyle()); $this->assertNull($object->getParagraphStyle());
} }
@ -27,9 +27,9 @@ class TextBreakTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructWithStyleObject() public function testConstructWithStyleObject()
{ {
$fStyle = new PHPWord_Style_Font(); $fStyle = new Font();
$pStyle = new PHPWord_Style_Paragraph(); $pStyle = new Paragraph();
$object = new PHPWord_Section_TextBreak($fStyle, $pStyle); $object = new TextBreak($fStyle, $pStyle);
$this->assertEquals($fStyle, $object->getFontStyle()); $this->assertEquals($fStyle, $object->getFontStyle());
$this->assertEquals($pStyle, $object->getParagraphStyle()); $this->assertEquals($pStyle, $object->getParagraphStyle());
} }
@ -41,9 +41,9 @@ class TextBreakTest extends \PHPUnit_Framework_TestCase
{ {
$fStyle = array('size' => 12); $fStyle = array('size' => 12);
$pStyle = array('spacing' => 240); $pStyle = array('spacing' => 240);
$object = new PHPWord_Section_TextBreak($fStyle, $pStyle); $object = new TextBreak($fStyle, $pStyle);
$this->assertInstanceOf('PHPWord_Style_Font', $object->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $object->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $object->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle());
} }
/** /**
@ -53,8 +53,8 @@ class TextBreakTest extends \PHPUnit_Framework_TestCase
{ {
$fStyle = 'fStyle'; $fStyle = 'fStyle';
$pStyle = 'pStyle'; $pStyle = 'pStyle';
$object = new PHPWord_Section_TextBreak($fStyle, $pStyle); $object = new TextBreak($fStyle, $pStyle);
$this->assertEquals($fStyle, $object->getFontStyle()); $this->assertEquals($fStyle, $object->getFontStyle());
$this->assertEquals($pStyle, $object->getParagraphStyle()); $this->assertEquals($pStyle, $object->getParagraphStyle());
} }
} }

View File

@ -1,73 +1,73 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_TextRun; use PhpOffice\PhpWord\Section\TextRun;
class TextRunTest extends \PHPUnit_Framework_TestCase class TextRunTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructNull() public function testConstructNull()
{ {
$oTextRun = new PHPWord_Section_TextRun(); $oTextRun = new TextRun();
$this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements()); $this->assertCount(0, $oTextRun->getElements());
$this->assertEquals($oTextRun->getParagraphStyle(), null); $this->assertEquals($oTextRun->getParagraphStyle(), null);
} }
public function testConstructString() public function testConstructString()
{ {
$oTextRun = new PHPWord_Section_TextRun('pStyle'); $oTextRun = new TextRun('pStyle');
$this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements()); $this->assertCount(0, $oTextRun->getElements());
$this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle'); $this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle');
} }
public function testConstructArray() public function testConstructArray()
{ {
$oTextRun = new PHPWord_Section_TextRun(array('spacing' => 100)); $oTextRun = new TextRun(array('spacing' => 100));
$this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements()); $this->assertCount(0, $oTextRun->getElements());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oTextRun->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oTextRun->getParagraphStyle());
} }
public function testAddText() public function testAddText()
{ {
$oTextRun = new PHPWord_Section_TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addText('text'); $element = $oTextRun->addText('text');
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getText(), 'text'); $this->assertEquals($element->getText(), 'text');
} }
public function testAddTextNotUTF8() public function testAddTextNotUTF8()
{ {
$oTextRun = new PHPWord_Section_TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addText(utf8_decode('ééé')); $element = $oTextRun->addText(utf8_decode('ééé'));
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddLink() public function testAddLink()
{ {
$oTextRun = new PHPWord_Section_TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addLink('http://www.google.fr'); $element = $oTextRun->addLink('http://www.google.fr');
$this->assertInstanceOf('PHPWord_Section_Link', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr'); $this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
} }
public function testAddLinkWithName() public function testAddLinkWithName()
{ {
$oTextRun = new PHPWord_Section_TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé')); $element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé'));
$this->assertInstanceOf('PHPWord_Section_Link', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr'); $this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
$this->assertEquals($element->getLinkName(), 'ééé'); $this->assertEquals($element->getLinkName(), 'ééé');
@ -79,19 +79,19 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
); );
$oTextRun = new PHPWord_Section_TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addImage($src); $element = $oTextRun->addImage($src);
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
} }
public function testCreateFootnote() public function testCreateFootnote()
{ {
$oTextRun = new PHPWord_Section_TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->createFootnote(); $element = $oTextRun->createFootnote();
$this->assertInstanceOf('PHPWord_Section_Footnote', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footnote', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
} }
} }

View File

@ -1,42 +1,42 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Text; use PhpOffice\PhpWord\Section\Text;
class TextTest extends \PHPUnit_Framework_TestCase class TextTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$oText = new PHPWord_Section_Text(); $oText = new Text();
$this->assertInstanceOf('PHPWord_Section_Text', $oText); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $oText);
$this->assertEquals(null, $oText->getText()); $this->assertEquals(null, $oText->getText());
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());
} }
public function testText() public function testText()
{ {
$oText = new PHPWord_Section_Text('text'); $oText = new Text('text');
$this->assertEquals($oText->getText(), 'text'); $this->assertEquals($oText->getText(), 'text');
} }
public function testFont() public function testFont()
{ {
$oText = new PHPWord_Section_Text('text', 'fontStyle'); $oText = new Text('text', 'fontStyle');
$this->assertEquals($oText->getFontStyle(), 'fontStyle'); $this->assertEquals($oText->getFontStyle(), 'fontStyle');
$oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); $oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle());
} }
public function testParagraph() public function testParagraph()
{ {
$oText = new PHPWord_Section_Text('text', 'fontStyle', 'paragraphStyle'); $oText = new Text('text', 'fontStyle', 'paragraphStyle');
$this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle'); $this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle');
$oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); $oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());
} }
} }

View File

@ -1,35 +1,35 @@
<?php <?php
namespace PHPWord\Tests\Section; namespace PHPWord\Tests\Section;
use PHPWord_Section_Title; use PhpOffice\PhpWord\Section\Title;
class TitleTest extends \PHPUnit_Framework_TestCase class TitleTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$oTitle = new PHPWord_Section_Title('text'); $oTitle = new Title('text');
$this->assertInstanceOf('PHPWord_Section_Title', $oTitle); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Title', $oTitle);
$this->assertEquals($oTitle->getText(), 'text'); $this->assertEquals($oTitle->getText(), 'text');
} }
public function testStyleNull() public function testStyleNull()
{ {
$oTitle = new PHPWord_Section_Title('text'); $oTitle = new Title('text');
$this->assertEquals($oTitle->getStyle(), null); $this->assertEquals($oTitle->getStyle(), null);
} }
public function testStyleNotNull() public function testStyleNotNull()
{ {
$oTitle = new PHPWord_Section_Title('text', 1, 'style'); $oTitle = new Title('text', 1, 'style');
$this->assertEquals($oTitle->getStyle(), 'style'); $this->assertEquals($oTitle->getStyle(), 'style');
} }
public function testAnchor() public function testAnchor()
{ {
$oTitle = new PHPWord_Section_Title('text'); $oTitle = new Title('text');
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oTitle->setAnchor($iVal); $oTitle->setAnchor($iVal);
@ -38,10 +38,10 @@ class TitleTest extends \PHPUnit_Framework_TestCase
public function testBookmarkID() public function testBookmarkID()
{ {
$oTitle = new PHPWord_Section_Title('text'); $oTitle = new Title('text');
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oTitle->setBookmarkId($iVal); $oTitle->setBookmarkId($iVal);
$this->assertEquals($oTitle->getBookmarkId(), $iVal); $this->assertEquals($oTitle->getBookmarkId(), $iVal);
} }
} }

View File

@ -1,78 +1,76 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests;
use PHPWord_Section; use PhpOffice\PhpWord\Section;
/** /**
* Class TOCTest * @package PHPWord\Tests
* * @coversDefaultClass PhpOffice\PhpWord\Section
* @package PHPWord\Tests
* @covers PHPWord_Section
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
*/ */
class SectionTest extends \PHPUnit_Framework_TestCase class SectionTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @covers PHPWord_Section::getSettings * @covers ::getSettings
*/ */
public function testGetSettings() public function testGetSettings()
{ {
$oSection = new PHPWord_Section(0); $oSection = new Section(0);
$this->assertAttributeEquals($oSection->getSettings(), '_settings', new PHPWord_Section(0)); $this->assertAttributeEquals($oSection->getSettings(), '_settings', new Section(0));
} }
/** /**
* @covers PHPWord_Section::getElements * @covers ::getElements
*/ */
public function testGetElements() public function testGetElements()
{ {
$oSection = new PHPWord_Section(0); $oSection = new Section(0);
$this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0)); $this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new Section(0));
} }
/** /**
* @covers PHPWord_Section::getFooter * @covers ::getFooter
*/ */
public function testGetFooter() public function testGetFooter()
{ {
$oSection = new PHPWord_Section(0); $oSection = new Section(0);
$this->assertAttributeEquals($oSection->getFooter(), '_footer', new PHPWord_Section(0)); $this->assertAttributeEquals($oSection->getFooter(), '_footer', new Section(0));
} }
/** /**
* @covers PHPWord_Section::getHeaders * @covers ::getHeaders
*/ */
public function testGetHeaders() public function testGetHeaders()
{ {
$oSection = new PHPWord_Section(0); $oSection = new Section(0);
$this->assertAttributeEquals($oSection->getHeaders(), '_headers', new PHPWord_Section(0)); $this->assertAttributeEquals($oSection->getHeaders(), '_headers', new Section(0));
} }
/** /**
* @covers PHPWord_Section::setSettings * @covers ::setSettings
*/ */
public function testSetSettings() public function testSetSettings()
{ {
$expected = 'landscape'; $expected = 'landscape';
$object = new PHPWord_Section(0); $object = new Section(0);
$object->setSettings(array('orientation' => $expected)); $object->setSettings(array('orientation' => $expected));
$this->assertEquals($expected, $object->getSettings()->getOrientation()); $this->assertEquals($expected, $object->getSettings()->getOrientation());
} }
/** /**
* @covers PHPWord_Section::addText * @covers ::addText
* @covers PHPWord_Section::addLink * @covers ::addLink
* @covers PHPWord_Section::addTextBreak * @covers ::addTextBreak
* @covers PHPWord_Section::addPageBreak * @covers ::addPageBreak
* @covers PHPWord_Section::addTable * @covers ::addTable
* @covers PHPWord_Section::addListItem * @covers ::addListItem
* @covers PHPWord_Section::addObject * @covers ::addObject
* @covers PHPWord_Section::addImage * @covers ::addImage
* @covers PHPWord_Section::addMemoryImage * @covers ::addMemoryImage
* @covers PHPWord_Section::addTOC * @covers ::addTOC
* @covers PHPWord_Section::addTitle * @covers ::addTitle
* @covers PHPWord_Section::createTextRun * @covers ::createTextRun
* @covers PHPWord_Section::createFootnote * @covers ::createFootnote
*/ */
public function testAddElements() public function testAddElements()
{ {
@ -86,7 +84,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
); );
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
$section = new PHPWord_Section(0); $section = new Section(0);
$section->addText(utf8_decode('ä')); $section->addText(utf8_decode('ä'));
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä'));
$section->addTextBreak(); $section->addTextBreak();
@ -103,8 +101,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
$elementCollection = $section->getElements(); $elementCollection = $section->getElements();
$elementType = 'Link'; $elementType = 'Link';
$objectType = "PHPWord_Section_{$elementType}"; $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$elementType}", $elementCollection[1]);
$this->assertInstanceOf($objectType, $elementCollection[1]);
// $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', // $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
// 'Table', 'ListItem', 'Object', 'Image', 'MemoryImage', 'TOC', // 'Table', 'ListItem', 'Object', 'Image', 'MemoryImage', 'TOC',
// 'Title', 'TextRun'); // 'Title', 'TextRun');
@ -117,17 +114,16 @@ class SectionTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers PHPWord_Section::createHeader * @covers ::createHeader
* @covers PHPWord_Section::createFooter * @covers ::createFooter
*/ */
public function testCreateHeaderFooter() public function testCreateHeaderFooter()
{ {
$object = new PHPWord_Section(0); $object = new Section(0);
$elements = array('Header', 'Footer'); $elements = array('Header', 'Footer');
foreach ($elements as $element) { foreach ($elements as $element) {
$objectType = "PHPWord_Section_{$element}";
$method = "create{$element}"; $method = "create{$element}";
$this->assertInstanceOf($objectType, $object->$method()); $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$element}", $object->$method());
} }
} }
} }

View File

@ -1,26 +1,24 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests;
use PHPWord_Settings; use PhpOffice\PhpWord\Settings;
/** /**
* Class TOCTest * @package PHPWord\Tests
* * @coversDefaultClass PhpOffice\PhpWord\Settings
* @package PHPWord\Tests
* @covers PHPWord_Settings
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
*/ */
class SettingsTest extends \PHPUnit_Framework_TestCase class SettingsTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @covers PHPWord_Settings::setCompatibility * @covers ::setCompatibility
* @covers PHPWord_Settings::getCompatibility * @covers ::getCompatibility
*/ */
public function testGetSetCompatibility() public function testGetSetCompatibility()
{ {
$this->assertTrue(PHPWord_Settings::getCompatibility()); $this->assertTrue(Settings::getCompatibility());
$this->assertTrue(PHPWord_Settings::setCompatibility(false)); $this->assertTrue(Settings::setCompatibility(false));
$this->assertFalse(PHPWord_Settings::getCompatibility()); $this->assertFalse(Settings::getCompatibility());
$this->assertFalse(PHPWord_Settings::setCompatibility('Non boolean')); $this->assertFalse(Settings::setCompatibility('Non boolean'));
} }
} }