Refactor: Composite Word2007 & ODText writer parts

This commit is contained in:
Ivan Lanin 2014-05-06 08:50:55 +07:00
parent 5c6925334b
commit 13c178d140
47 changed files with 350 additions and 508 deletions

View File

@ -237,7 +237,8 @@ class Settings
*/
public static function setMeasurementUnit($value)
{
$units = array(self::UNIT_TWIP, self::UNIT_CM, self::UNIT_MM, self::UNIT_INCH, self::UNIT_POINT, self::UNIT_PICA);
$units = array(self::UNIT_TWIP, self::UNIT_CM, self::UNIT_MM, self::UNIT_INCH,
self::UNIT_POINT, self::UNIT_PICA);
if (!in_array($value, $units)) {
return false;
}

View File

@ -205,7 +205,8 @@ class Template
// If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row.
$tmpXmlRow = $this->getSlice($extraRowStart, $extraRowEnd);
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) && !preg_match('#<w:vMerge w:val="continue" />#', $tmpXmlRow)) {
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
!preg_match('#<w:vMerge w:val="continue" />#', $tmpXmlRow)) {
break;
}
// This row was a spanned row, update $rowEnd and search for the next row.
@ -234,7 +235,12 @@ class Template
public function cloneBlock($blockname, $clones = 1, $replace = true)
{
$xmlBlock = null;
preg_match('/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is', $this->documentXML, $matches);
$pattern =
preg_match(
'/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is',
$this->documentXML,
$matches
);
if (isset($matches[3])) {
$xmlBlock = $matches[3];
@ -244,7 +250,11 @@ class Template
}
if ($replace) {
$this->documentXML = str_replace($matches[2] . $matches[3] . $matches[4], implode('', $cloned), $this->documentXML);
$this->documentXML = str_replace(
$matches[2] . $matches[3] . $matches[4],
implode('', $cloned),
$this->documentXML
);
}
}
@ -259,10 +269,18 @@ class Template
*/
public function replaceBlock($blockname, $replacement)
{
preg_match('/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is', $this->documentXML, $matches);
preg_match(
'/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is',
$this->documentXML,
$matches
);
if (isset($matches[3])) {
$this->documentXML = str_replace($matches[2] . $matches[3] . $matches[4], $replacement, $this->documentXML);
$this->documentXML = str_replace(
$matches[2] . $matches[3] . $matches[4],
$replacement,
$this->documentXML
);
}
}

View File

@ -35,6 +35,13 @@ abstract class AbstractWriter implements WriterInterface
*/
protected $phpWord = null;
/**
* Part name and file name pairs
*
* @var array
*/
protected $parts = array();
/**
* Individual writers
*
@ -114,13 +121,13 @@ abstract class AbstractWriter implements WriterInterface
/**
* Get writer part
*
* @param string $pPartName Writer part name
* @param string $partName Writer part name
* @return mixed
*/
public function getWriterPart($pPartName = '')
public function getWriterPart($partName = '')
{
if ($pPartName != '' && isset($this->writerParts[strtolower($pPartName)])) {
return $this->writerParts[strtolower($pPartName)];
if ($partName != '' && isset($this->writerParts[strtolower($partName)])) {
return $this->writerParts[strtolower($partName)];
} else {
return null;
}
@ -139,19 +146,19 @@ abstract class AbstractWriter implements WriterInterface
/**
* Set use disk caching status
*
* @param bool $pValue
* @param string $pDirectory
* @param bool $value
* @param string $directory
* @return self
*/
public function setUseDiskCaching($pValue = false, $pDirectory = null)
public function setUseDiskCaching($value = false, $directory = null)
{
$this->useDiskCaching = $pValue;
$this->useDiskCaching = $value;
if (!is_null($pDirectory)) {
if (is_dir($pDirectory)) {
$this->diskCachingDirectory = $pDirectory;
if (!is_null($directory)) {
if (is_dir($directory)) {
$this->diskCachingDirectory = $directory;
} else {
throw new Exception("Directory does not exist: $pDirectory");
throw new Exception("Directory does not exist: $directory");
}
}
@ -227,7 +234,7 @@ abstract class AbstractWriter implements WriterInterface
{
if ($this->originalFilename != $this->tempFilename) {
if (copy($this->tempFilename, $this->originalFilename) === false) {
throw new Exception("Could not copy temporary zip file {$this->tempFilename} to {$this->originalFilename}.");
throw new Exception("Could not copy temporary zip file.");
}
@unlink($this->tempFilename);
}
@ -258,7 +265,6 @@ abstract class AbstractWriter implements WriterInterface
$objZip = new $zipClass();
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
$reflection = new \ReflectionObject($objZip);
$zipOverWrite = $reflection->getConstant('OVERWRITE');
$zipCreate = $reflection->getConstant('CREATE');

View File

@ -188,7 +188,8 @@ class HTML extends AbstractWriter implements WriterInterface
if (array_key_exists($noteTypeId, $collection)) {
$element = $collection[$noteTypeId];
$elmWriter = new TextRunWriter($this, $element, true);
$content = "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>" . $elmWriter->write();
$content = "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>";
$content .= $elmWriter->write();
$html .= "<p><a name=\"{$noteAnchor}\" />{$content}</p>" . PHP_EOL;
}
}

View File

@ -23,7 +23,8 @@ use PhpOffice\PhpWord\Writer\HTML;
/**
* Generic element HTML writer
*
* Section: Text, TextRun, Link, Title, PreserveText, TextBreak, PageBreak, Table, ListItem, Image, Object, Endnote, Footnote
* Section: Text, TextRun, Link, Title, PreserveText, TextBreak, PageBreak, Table, ListItem, Image,
* Object, Endnote, Footnote
* Cell: Text, TextRun, Link, PreserveText, TextBreak, ListItem, Image, Object, Endnote, Footnote
* TextRun: Text, Link, TextBreak, Image, Endnote, Footnote
*

View File

@ -39,14 +39,19 @@ class ODText extends AbstractWriter implements WriterInterface
$this->setPhpWord($phpWord);
// Create parts
$parts = array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles');
foreach ($parts as $part) {
$partName = strtolower($part);
$partClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\' . $part;
$this->parts = array(
'Mimetype' => 'mimetype',
'Content' => 'content.xml',
'Meta' => 'meta.xml',
'Styles' => 'styles.xml',
'Manifest' => 'META-INF/manifest.xml',
);
foreach (array_keys($this->parts) as $partName) {
$partClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\' . $partName;
if (class_exists($partClass)) {
$partObject = new $partClass();
$partObject->setParentWriter($this);
$this->writerParts[$partName] = $partObject;
$this->writerParts[strtolower($partName)] = $partObject;
}
}
@ -72,12 +77,12 @@ class ODText extends AbstractWriter implements WriterInterface
$this->addFilesToPackage($objZip, $sectionMedia);
}
// Add parts
$objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype());
$objZip->addFromString('content.xml', $this->getWriterPart('content')->writeContent($this->phpWord));
$objZip->addFromString('meta.xml', $this->getWriterPart('meta')->writeMeta($this->phpWord));
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->writeStyles($this->phpWord));
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest());
// Write parts
foreach ($this->parts as $partName => $fileName) {
if ($fileName != '') {
$objZip->addFromString($fileName, $this->getWriterPart($partName)->write());
}
}
// Close file
if ($objZip->close() === false) {

View File

@ -59,9 +59,10 @@ class Element
/**
* Create new instance
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $element
* @param bool $withoutP
*/
public function __construct(XMLWriter $xmlWriter, AbstractPart $parentWriter, AbstractElement $element, $withoutP = false)
public function __construct(XMLWriter $xmlWriter, AbstractPart $parentWriter, $element, $withoutP = false)
{
$this->xmlWriter = $xmlWriter;
$this->parentWriter = $parentWriter;

View File

@ -56,7 +56,8 @@ class Table extends Element
$elementWriter->write();
}
} else {
$elementWriter = new ElementWriter($this->xmlWriter, $this->parentWriter, new TextBreakElement());
$element = new TextBreakElement();
$elementWriter = new ElementWriter($this->xmlWriter, $this->parentWriter, $element);
$elementWriter->write();
}
$this->xmlWriter->endElement(); // table:table-cell

View File

@ -29,21 +29,18 @@ use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Writer\ODText\Element\Element as ElementWriter;
/**
* ODText content part writer
* ODText content part writer: content.xml
*/
class Content extends AbstractPart
{
/**
* Write content file to XML format
* Write part
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @return string XML Output
* @return string
*/
public function writeContent(PhpWord $phpWord = null)
public function write()
{
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
$phpWord = $this->getParentWriter()->getPhpWord();
$xmlWriter = $this->getXmlWriter();
$xmlWriter->startDocument('1.0', 'UTF-8');

View File

@ -20,49 +20,38 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\PhpWord\Media;
/**
* ODText manifest part writer
* ODText manifest part writer: META-INF/manifest.xml
*/
class Manifest extends AbstractPart
{
/**
* Write Manifest file to XML format
* Write part
*
* @return string XML Output
* @return string
*/
public function writeManifest()
public function write()
{
// Create XML writer
$parts = array('content.xml', 'meta.xml', 'styles.xml');
$xmlWriter = $this->getXmlWriter();
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8');
// manifest:manifest
$xmlWriter->startElement('manifest:manifest');
$xmlWriter->writeAttribute('manifest:version', '1.2');
$xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
$xmlWriter->writeAttribute('manifest:version', '1.2');
$xmlWriter->writeAttribute('manifest:full-path', '/');
$xmlWriter->writeAttribute('manifest:version', '1.2');
$xmlWriter->endElement();
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'content.xml');
$xmlWriter->endElement();
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'meta.xml');
$xmlWriter->endElement();
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'styles.xml');
$xmlWriter->endElement();
// Parts
foreach ($parts as $part) {
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', $part);
$xmlWriter->endElement();
}
// Media files
$media = Media::getElements('section');

View File

@ -21,29 +21,22 @@ use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
/**
* ODText meta part writer
* ODText meta part writer: meta.xml
*/
class Meta extends AbstractPart
{
/**
* Write Meta file to XML format
* Write part
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @return string XML Output
* @return string
*/
public function writeMeta(PhpWord $phpWord = null)
public function write()
{
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
// Create XML writer
$phpWord = $this->getParentWriter()->getPhpWord();
$docProps = $phpWord->getDocumentProperties();
$xmlWriter = $this->getXmlWriter();
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8');
// office:document-meta
$xmlWriter->startElement('office:document-meta');
$xmlWriter->writeAttribute('office:version', '1.2');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
@ -55,27 +48,18 @@ class Meta extends AbstractPart
// office:meta
$xmlWriter->startElement('office:meta');
// dc:creator
$xmlWriter->writeElement('dc:creator', $phpWord->getDocumentProperties()->getLastModifiedBy());
// dc:date
$xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $phpWord->getDocumentProperties()->getModified()));
// dc:description
$xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription());
// dc:subject
$xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject());
// dc:title
$xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle());
// meta:creation-date
$xmlWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $phpWord->getDocumentProperties()->getCreated()));
// meta:initial-creator
$xmlWriter->writeElement('meta:initial-creator', $phpWord->getDocumentProperties()->getCreator());
// meta:keyword
$xmlWriter->writeElement('meta:keyword', $phpWord->getDocumentProperties()->getKeywords());
$xmlWriter->writeElement('dc:creator', $docProps->getLastModifiedBy());
$xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $docProps->getModified()));
$xmlWriter->writeElement('dc:description', $docProps->getDescription());
$xmlWriter->writeElement('dc:subject', $docProps->getSubject());
$xmlWriter->writeElement('dc:title', $docProps->getTitle());
$xmlWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $docProps->getCreated()));
$xmlWriter->writeElement('meta:initial-creator', $docProps->getCreator());
$xmlWriter->writeElement('meta:keyword', $docProps->getKeywords());
// @todo : Where these properties are written ?
// $phpWord->getDocumentProperties()->getCategory()
// $phpWord->getDocumentProperties()->getCompany()
// $docProps->getCategory()
// $docProps->getCompany()
$xmlWriter->endElement();

View File

@ -18,16 +18,16 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part;
/**
* ODText mimetype part writer
* ODText mimetype part writer: mimetype
*/
class Mimetype extends AbstractPart
{
/**
* Write Mimetype to Text format
* Write part
*
* @return string Text Output
* @return string
*/
public function writeMimetype()
public function write()
{
return 'application/vnd.oasis.opendocument.text';
}

View File

@ -22,23 +22,17 @@ use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style;
/**
* ODText styloes part writer
* ODText styloes part writer: styles.xml
*/
class Styles extends AbstractPart
{
/**
* Write Styles file to XML format
* Write part
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @return string XML Output
* @return string
*/
public function writeStyles(PhpWord $phpWord = null)
public function write()
{
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
// Create XML writer
$xmlWriter = $this->getXmlWriter();
// XML header

View File

@ -260,6 +260,7 @@ class RTF extends AbstractWriter implements WriterInterface
private function populateColorTable()
{
$phpWord = $this->phpWord;
$defaultFontColor = PhpWord::DEFAULT_FONT_COLOR;
$arrColors = array();
// PhpWord object : $this->phpWord
@ -272,10 +273,10 @@ class RTF extends AbstractWriter implements WriterInterface
if ($style instanceof Font) {
$color = $style->getColor();
$fgcolor = $style->getFgColor();
if (in_array($color, $arrColors) == false && $color != PhpWord::DEFAULT_FONT_COLOR && !empty($color)) {
if (!in_array($color, $arrColors) && $color != $defaultFontColor && !empty($color)) {
$arrColors[] = $color;
}
if (in_array($fgcolor, $arrColors) == false && $fgcolor != PhpWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) {
if (!in_array($fgcolor, $arrColors) && $fgcolor != $defaultFontColor && !empty($fgcolor)) {
$arrColors[] = $fgcolor;
}
}

View File

@ -52,16 +52,31 @@ class Word2007 extends AbstractWriter implements WriterInterface
$this->setPhpWord($phpWord);
// Create parts
$parts = array('ContentTypes', 'RelsMain', 'RelsDocument', 'DocPropsApp', 'DocPropsCore', 'Document', 'Styles',
'Numbering', 'Settings', 'WebSettings', 'Header', 'Footer', 'Footnotes',
'Endnotes', 'FontTable', 'Theme');
foreach ($parts as $part) {
$partName = strtolower($part);
$partClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\' . $part;
$this->parts = array(
'ContentTypes' => '[Content_Types].xml',
'Rels' => '_rels/.rels',
'DocPropsApp' => 'docProps/app.xml',
'DocPropsCore' => 'docProps/core.xml',
'RelsDocument' => 'word/_rels/document.xml.rels',
'Document' => 'word/document.xml',
'Styles' => 'word/styles.xml',
'Numbering' => 'word/numbering.xml',
'Settings' => 'word/settings.xml',
'WebSettings' => 'word/webSettings.xml',
'FontTable' => 'word/fontTable.xml',
'Theme' => 'word/theme/theme1.xml',
'RelsPart' => '',
'Header' => '',
'Footer' => '',
'Footnotes' => '',
'Endnotes' => '',
);
foreach (array_keys($this->parts) as $partName) {
$partClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\' . $partName;
if (class_exists($partClass)) {
$partObject = new $partClass();
$partObject->setParentWriter($this);
$this->writerParts[$partName] = $partObject;
$this->writerParts[strtolower($partName)] = $partObject;
}
}
@ -112,18 +127,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
$this->addNotes($objZip, $rId, 'endnote');
// Write parts
$objZip->addFromString('[Content_Types].xml', $this->getWriterPart('contenttypes')->write());
$objZip->addFromString('_rels/.rels', $this->getWriterPart('relsmain')->write());
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docpropsapp')->write());
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('docpropscore')->write());
$objZip->addFromString('word/_rels/document.xml.rels', $this->getWriterPart('relsdocument')->write());
$objZip->addFromString('word/document.xml', $this->getWriterPart('document')->write());
$objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->write());
$objZip->addFromString('word/numbering.xml', $this->getWriterPart('numbering')->write());
$objZip->addFromString('word/settings.xml', $this->getWriterPart('settings')->write());
$objZip->addFromString('word/webSettings.xml', $this->getWriterPart('websettings')->write());
$objZip->addFromString('word/fontTable.xml', $this->getWriterPart('fonttable')->write());
$objZip->addFromString('word/theme/theme1.xml', $this->getWriterPart('theme')->write());
foreach ($this->parts as $partName => $fileName) {
if ($fileName != '') {
$objZip->addFromString($fileName, $this->getWriterPart($partName)->write());
}
}
// Close file
if ($objZip->close() === false) {
@ -157,7 +165,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
}
/**
* Add header/footer media files
* Add header/footer media files, e.g. footer1.xml.rels
*
* @param mixed $objZip
* @param string $docPart
@ -172,8 +180,9 @@ class Word2007 extends AbstractWriter implements WriterInterface
$this->addFilesToPackage($objZip, $media);
$this->registerContentTypes($media);
}
$relsFile = "word/_rels/{$file}.xml.rels";
$objZip->addFromString($relsFile, $this->getWriterPart('rels')->writeMediaRels($media));
$writerPart = $this->getWriterPart('relspart')->setMedia($media);
$objZip->addFromString("word/_rels/{$file}.xml.rels", $writerPart->write());
}
}
}
@ -183,22 +192,23 @@ class Word2007 extends AbstractWriter implements WriterInterface
* Add header/footer content
*
* @param mixed $objZip
* @param string $elmType
* @param string $elmType header|footer
* @param integer $rId
*/
private function addHeaderFooterContent(Section &$section, $objZip, $elmType, &$rId)
{
$getFunction = $elmType == 'header' ? 'getHeaders' : 'getFooters';
$writeFunction = $elmType == 'header' ? 'writeHeader' : 'writeFooter';
$elmCount = ($section->getSectionId() - 1) * 3;
$elmObjects = $section->$getFunction();
foreach ($elmObjects as &$elmObject) {
$elements = $section->$getFunction();
foreach ($elements as &$element) {
$elmCount++;
$elmObject->setRelationId(++$rId);
$elmFile = "{$elmType}{$elmCount}.xml";
$objZip->addFromString("word/$elmFile", $this->getWriterPart($elmType)->$writeFunction($elmObject));
$element->setRelationId(++$rId);
$elmFile = "{$elmType}{$elmCount}.xml"; // e.g. footer1.xml
$this->contentTypes['override']["/word/$elmFile"] = $elmType;
$this->relationships[] = array('target' => $elmFile, 'type' => $elmType, 'rID' => $rId);
$writerPart = $this->getWriterPart($elmType)->setElement($element);
$objZip->addFromString("word/$elmFile", $writerPart->write());
}
}
@ -221,13 +231,18 @@ class Word2007 extends AbstractWriter implements WriterInterface
$media = Media::getElements($noteType);
$this->addFilesToPackage($objZip, $media);
$this->registerContentTypes($media);
if (!empty($media)) {
$objZip->addFromString("word/_rels/{$partName}.xml.rels", $this->getWriterPart('rels')->writeMediaRels($media));
}
$elements = $collection->getItems();
$objZip->addFromString("word/{$partName}.xml", $this->getWriterPart($partName)->write($elements));
$this->contentTypes['override']["/word/{$partName}.xml"] = $partName;
$this->relationships[] = array('target' => "{$partName}.xml", 'type' => $partName, 'rID' => ++$rId);
// Write relationships file, e.g. word/_rels/footnotes.xml
if (!empty($media)) {
$writerPart = $this->getWriterPart('relspart')->setMedia($media);
$objZip->addFromString("word/_rels/{$partName}.xml.rels", $writerPart->write());
}
// Write content file, e.g. word/footnotes.xml
$writerPart = $this->getWriterPart($partName)->setElements($collection->getItems());
$objZip->addFromString("word/{$partName}.xml", $writerPart->write());
}
}

View File

@ -59,9 +59,10 @@ class Element
/**
* Create new instance
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $element
* @param bool $withoutP
*/
public function __construct(XMLWriter $xmlWriter, AbstractPart $parentWriter, AbstractElement $element, $withoutP = false)
public function __construct(XMLWriter $xmlWriter, AbstractPart $parentWriter, $element, $withoutP = false)
{
$this->xmlWriter = $xmlWriter;
$this->parentWriter = $parentWriter;

View File

@ -81,6 +81,8 @@ class TOC extends Element
if ($tocFieldWritten !== true) {
$tocFieldWritten = true;
$minDepth = $this->element->getMinDepth();
$maxDepth = $this->element->getMaxDepth();
$this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:fldChar');
@ -91,7 +93,7 @@ class TOC extends Element
$this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:instrText');
$this->xmlWriter->writeAttribute('xml:space', 'preserve');
$this->xmlWriter->writeRaw('TOC \o "' . $this->element->getMinDepth() . '-' . $this->element->getMaxDepth() . '" \h \z \u');
$this->xmlWriter->writeRaw("TOC \o {$minDepth}-{$maxDepth} \h \z \u");
$this->xmlWriter->endElement();
$this->xmlWriter->endElement();

View File

@ -21,16 +21,18 @@ use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 contenttypes part writer
* Word2007 contenttypes part writer: [Content_Types].xml
*/
class ContentTypes extends AbstractPart
{
/**
* Write [Content_Types].xml
* Write part
*
* @return string
*/
public function write()
{
$contentTypes = $this->parentWriter->getContentTypes();
$contentTypes = $this->getParentWriter()->getContentTypes();
$openXMLPrefix = 'application/vnd.openxmlformats-';
$wordMLPrefix = $openXMLPrefix . 'officedocument.wordprocessingml.';
@ -90,17 +92,4 @@ class ContentTypes extends AbstractPart
}
}
}
/**
* Write [Content_Types].xml
*
* @param array $contentTypes
* @deprecated 0.11.0
* @codeCoverageIgnore
*/
public function writeContentTypes($contentTypes)
{
$contentTypes = null; // dummy assignment
return $this->write();
}
}

View File

@ -21,26 +21,26 @@ use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
/**
* Word2007 extended document properties part writer
* Word2007 extended document properties part writer: docProps/app.xml
*
* @since 0.11.0
*/
class DocPropsApp extends AbstractPart
{
/**
* Write docProps/app.xml
* Write part
*
* @return string
*/
public function write()
{
$phpWord = $this->parentWriter->getPhpWord();
if (is_null($phpWord)) {
throw new Exception('No PhpWord assigned.');
}
$phpWord = $this->getParentWriter()->getPhpWord();
$xmlWriter = $this->getXmlWriter();
$schema = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties';
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('Properties');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
$xmlWriter->writeAttribute('xmlns', $schema);
$xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
$xmlWriter->writeElement('Application', 'PHPWord');

View File

@ -21,26 +21,26 @@ use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
/**
* Word2007 core document properties part writer
* Word2007 core document properties part writer: docProps/core.xml
*
* @since 0.11.0
*/
class DocPropsCore extends AbstractPart
{
/**
* Write docProps/core.xml
* Write part
*
* @return string
*/
public function write()
{
$phpWord = $this->parentWriter->getPhpWord();
if (is_null($phpWord)) {
throw new Exception('No PhpWord assigned.');
}
$phpWord = $this->getParentWriter()->getPhpWord();
$xmlWriter = $this->getXmlWriter();
$schema = 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties';
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('cp:coreProperties');
$xmlWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
$xmlWriter->writeAttribute('xmlns:cp', $schema);
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
$xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');

View File

@ -24,26 +24,24 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter;
/**
* Word2007 document part writer
* Word2007 document part writer: word/document.xml
*/
class Document extends AbstractPart
{
/**
* Write word/document.xml
* Write part
*
* @return string
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
public function write()
{
$phpWord = $this->parentWriter->getPhpWord();
if (is_null($phpWord)) {
throw new Exception('No PhpWord assigned.');
}
$phpWord = $this->getParentWriter()->getPhpWord();
$xmlWriter = $this->getXmlWriter();
$sections = $phpWord->getSections();
$sectionCount = count($sections);
$currentSection = 0;
$drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing';
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:document');
@ -52,7 +50,7 @@ class Document extends AbstractPart
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlWriter->writeAttribute('xmlns:wp', $drawingSchema);
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
@ -133,17 +131,4 @@ class Document extends AbstractPart
$xmlWriter->endElement(); // w:sectPr
}
/**
* Write word/document.xml
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @deprecated 0.11.0
* @codeCoverageIgnore
*/
public function writeDocument(PhpWord $phpWord = null)
{
$this->parentWriter->setPhpWord($phpWord);
return $this->write();
}
}

View File

@ -18,7 +18,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
/**
* Word2007 endnotes part writer
* Word2007 endnotes part writer: word/endnotes.xml
*/
class Endnotes extends Footnotes
{

View File

@ -18,7 +18,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
/**
* Word2007 font table writer
* Word2007 font table writer: word/fontTable.xml
*
* @since 0.10.0
*/

View File

@ -17,10 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Element\AbstractContainer as Container;
/**
* Word2007 footer part writer
* Word2007 footer part writer: word/footerx.xml
*/
class Footer extends AbstractPart
{
@ -32,13 +30,21 @@ class Footer extends AbstractPart
protected $rootElement = 'w:ftr';
/**
* Write word/footerx.xml
* Footer/header element to be written
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @var \PhpOffice\PhpWord\Element\Footer
*/
public function writeFooter(Container $element)
protected $element;
/**
* Write part
*
* @return string
*/
public function write()
{
$xmlWriter = $this->getXmlWriter();
$drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing';
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement($this->rootElement);
@ -47,15 +53,28 @@ class Footer extends AbstractPart
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlWriter->writeAttribute('xmlns:wp', $drawingSchema);
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$this->writeContainerElements($xmlWriter, $element);
$this->writeContainerElements($xmlWriter, $this->element);
$xmlWriter->endElement(); // $this->rootElement
return $xmlWriter->getData();
}
/**
* Set element
*
* @param \PhpOffice\PhpWord\Element\Footer|\PhpOffice\PhpWord\Element\Header $element
* @return self
*/
public function setElement($element)
{
$this->element = $element;
return $this;
}
}

View File

@ -22,7 +22,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
/**
* Word2007 footnotes part writer
* Word2007 footnotes part writer: word/(footnotes|endnotes).xml
*/
class Footnotes extends AbstractPart
{
@ -55,13 +55,21 @@ class Footnotes extends AbstractPart
protected $refStyle = 'FootnoteReference';
/**
* Write word/(footnotes|endnotes).xml
* Footnotes/endnotes collection to be written
*
* @param array $elements
* @var \PhpOffice\PhpWord\Collection\Footnotes|\PhpOffice\PhpWord\Collection\Endnotes
*/
public function write($elements)
protected $elements;
/**
* Write part
*
* @return string
*/
public function write()
{
$xmlWriter = $this->getXmlWriter();
$drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing';
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement($this->rootNode);
@ -70,7 +78,7 @@ class Footnotes extends AbstractPart
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlWriter->writeAttribute('xmlns:wp', $drawingSchema);
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
@ -98,7 +106,7 @@ class Footnotes extends AbstractPart
$xmlWriter->endElement(); // $this->elementNode
// Content
foreach ($elements as $element) {
foreach ($this->elements as $element) {
if ($element instanceof Footnote) {
$this->writeNote($xmlWriter, $element);
}
@ -109,6 +117,19 @@ class Footnotes extends AbstractPart
return $xmlWriter->getData();
}
/**
* Set element
*
* @param \PhpOffice\PhpWord\Collection\Footnotes|\PhpOffice\PhpWord\Collection\Endnotes $elements
* @return self
*/
public function setElements($elements)
{
$this->elements = $elements;
return $this;
}
/**
* Write note item
*

View File

@ -17,10 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Element\AbstractContainer as Container;
/**
* Word2007 header part writer
* Word2007 header part writer: word/headerx.xml
*/
class Header extends Footer
{
@ -30,14 +28,4 @@ class Header extends Footer
* @var string
*/
protected $rootElement = 'w:hdr';
/**
* Write word/headerx.xml
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
*/
public function writeHeader(Container $element)
{
return $this->writeFooter($element);
}
}

View File

@ -22,18 +22,20 @@ use PhpOffice\PhpWord\Style\NumberingLevel;
use PhpOffice\PhpWord\Style;
/**
* Word2007 numbering part writer
* Word2007 numbering part writer: word/numbering.xml
*/
class Numbering extends AbstractPart
{
/**
* Write word/numbering.xml
* Write part
*
* @return string
*/
public function write()
{
$styles = Style::getStyles();
$xmlWriter = $this->getXmlWriter();
$styles = Style::getStyles();
$drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing';
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:numbering');
@ -42,7 +44,7 @@ class Numbering extends AbstractPart
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlWriter->writeAttribute('xmlns:wp', $drawingSchema);
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
@ -167,15 +169,4 @@ class Numbering extends AbstractPart
{
return strtoupper(substr(md5(rand()), 0, $length));
}
/**
* Write numbering
*
* @deprecated 0.11.0
* @codeCoverageIgnore
*/
public function writeNumbering()
{
return $this->write();
}
}

View File

@ -21,7 +21,7 @@ use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 relationship writer
* Word2007 main relationship writer: _rels/.rels
*
* @since 0.10.0
*/
@ -33,14 +33,19 @@ class Rels extends AbstractPart
const RELS_BASE = 'http://schemas.openxmlformats.org/';
/**
* Write word/_rels/(header|footer|footnotes)*.xml.rels
* Write part
*
* @param array $mediaRels
* @return string
*/
public function writeMediaRels($mediaRels)
public function write()
{
$xmlRels = array(
'docProps/core.xml' => 'package/2006/relationships/metadata/core-properties',
'docProps/app.xml' => 'officeDocument/2006/relationships/extended-properties',
'word/document.xml' => 'officeDocument/2006/relationships/officeDocument',
);
$xmlWriter = $this->getXmlWriter();
$this->writeRels($xmlWriter, null, $mediaRels);
$this->writeRels($xmlWriter, $xmlRels);
return $xmlWriter->getData();
}
@ -73,10 +78,12 @@ class Rels extends AbstractPart
foreach ($mediaRels as $mediaRel) {
$mediaType = $mediaRel['type'];
$type = array_key_exists($mediaType, $mapping) ? $mapping[$mediaType] : $mediaType;
$type = "officeDocument/2006/relationships/{$type}";
$target = array_key_exists($mediaType, $targetPaths) ? $targetPaths[$mediaType] : '';
$target .= $mediaRel['target'];
$targetMode = ($type == 'hyperlink') ? 'External' : '';
$this->writeRel($xmlWriter, $relId++, "officeDocument/2006/relationships/{$type}", $target, $targetMode);
$this->writeRel($xmlWriter, $relId++, $type, $target, $targetMode);
}
}

View File

@ -17,17 +17,17 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 document relationship writer
* Word2007 document relationship writer: word/_rels/document.xml.rels
*
* @since 0.11.0
*/
class RelsDocument extends Rels
{
/**
* Write _rels/.rels
* Write part
*
* @return string
*/
public function write()
{
@ -40,7 +40,7 @@ class RelsDocument extends Rels
'fontTable.xml' => 'officeDocument/2006/relationships/fontTable',
);
$xmlWriter = $this->getXmlWriter();
$this->writeRels($xmlWriter, $xmlRels, $this->parentWriter->getRelationships());
$this->writeRels($xmlWriter, $xmlRels, $this->getParentWriter()->getRelationships());
return $xmlWriter->getData();
}

View File

@ -17,28 +17,43 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 main relationship writer
* Word2007 part relationship writer: word/_rels/(header|footer|footnotes|endnotes)*.xml.rels
*
* @since 0.11.0
*/
class RelsMain extends Rels
class RelsPart extends Rels
{
/**
* Write _rels/.rels
* Media relationships
*
* @var array
*/
private $media = array();
/**
* Write part
*
* @return string
*/
public function write()
{
$xmlRels = array(
'docProps/core.xml' => 'package/2006/relationships/metadata/core-properties',
'docProps/app.xml' => 'officeDocument/2006/relationships/extended-properties',
'word/document.xml' => 'officeDocument/2006/relationships/officeDocument',
);
$xmlWriter = $this->getXmlWriter();
$this->writeRels($xmlWriter, $xmlRels);
$this->writeRels($xmlWriter, null, $this->media);
return $xmlWriter->getData();
}
/**
* Set media
*
* @param array $media
* @return self
*/
public function setMedia($media)
{
$this->media = $media;
return $this;
}
}

View File

@ -18,12 +18,14 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
/**
* Word2007 settings part writer
* Word2007 settings part writer: word/settings.xml
*/
class Settings extends AbstractPart
{
/**
* Write word/settings.xml
* Write part
*
* @return string
*/
public function write()
{
@ -136,15 +138,4 @@ class Settings extends AbstractPart
$xmlWriter->endElement();
}
}
/**
* Write word/settings.xml
*
* @deprecated 0.11.0
* @codeCoverageIgnore
*/
public function writeSettings()
{
return $this->write();
}
}

View File

@ -20,32 +20,29 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\Table;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Table as TableStyleWriter;
/**
* Word2007 styles part writer
* Word2007 styles part writer: word/styles.xml
*
* @todo Do something with the numbering style introduced in 0.10.0
*/
class Styles extends AbstractPart
{
/**
* Write word/styles.xml
* Write part
*
* @return string
*/
public function write()
{
$phpWord = $this->parentWriter->getPhpWord();
if (is_null($phpWord)) {
throw new Exception('No PhpWord assigned.');
}
$phpWord = $this->getParentWriter()->getPhpWord();
$xmlWriter = $this->getXmlWriter();
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
@ -220,17 +217,4 @@ class Styles extends AbstractPart
$xmlWriter->endElement(); // w:style
}
}
/**
* Write word/styles.xml
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @deprecated 0.11.0
* @codeCoverageIgnore
*/
public function writeStyles(PhpWord $phpWord = null)
{
$this->parentWriter->setPhpWord($phpWord);
return $this->write();
}
}

View File

@ -18,14 +18,16 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
/**
* Word2007 theme writer
* Word2007 theme writer: word/theme/theme1.xml
*
* @since 0.10.0
*/
class Theme extends AbstractPart
{
/**
* Write theme/theme1.xml
* Write part
*
* @return string
*/
public function write()
{

View File

@ -18,12 +18,14 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
/**
* Word2007 web settings part writer
* Word2007 web settings part writer: word/webSettings.xml
*/
class WebSettings extends Settings
{
/**
* Write word/webSettings.xml
* Write part
*
* @return string
*/
public function write()
{
@ -46,15 +48,4 @@ class WebSettings extends Settings
return $xmlWriter->getData();
}
/**
* Write word/webSettings.xml
*
* @deprecated 0.11.0
* @codeCoverageIgnore
*/
public function writeWebSettings()
{
return $this->write();
}
}

View File

@ -50,14 +50,20 @@ class Section extends AbstractStyle
$this->xmlWriter->endElement(); // w:pgSz
// Margins
$margins = array(
'w:top' => array('getMarginTop', SectionStyle::DEFAULT_MARGIN),
'w:right' => array('getMarginRight', SectionStyle::DEFAULT_MARGIN),
'w:bottom' => array('getMarginBottom', SectionStyle::DEFAULT_MARGIN),
'w:left' => array('getMarginLeft', SectionStyle::DEFAULT_MARGIN),
'w:header' => array('getHeaderHeight', SectionStyle::DEFAULT_HEADER_HEIGHT),
'w:footer' => array('getFooterHeight', SectionStyle::DEFAULT_FOOTER_HEIGHT),
'w:gutter' => array('getGutter', SectionStyle::DEFAULT_GUTTER),
);
$this->xmlWriter->startElement('w:pgMar');
$this->xmlWriter->writeAttribute('w:top', $this->convertTwip($this->style->getMarginTop(), SectionStyle::DEFAULT_MARGIN));
$this->xmlWriter->writeAttribute('w:right', $this->convertTwip($this->style->getMarginRight(), SectionStyle::DEFAULT_MARGIN));
$this->xmlWriter->writeAttribute('w:bottom', $this->convertTwip($this->style->getMarginBottom(), SectionStyle::DEFAULT_MARGIN));
$this->xmlWriter->writeAttribute('w:left', $this->convertTwip($this->style->getMarginLeft(), SectionStyle::DEFAULT_MARGIN));
$this->xmlWriter->writeAttribute('w:header', $this->convertTwip($this->style->getHeaderHeight(), SectionStyle::DEFAULT_HEADER_HEIGHT));
$this->xmlWriter->writeAttribute('w:footer', $this->convertTwip($this->style->getFooterHeight(), SectionStyle::DEFAULT_FOOTER_HEIGHT));
$this->xmlWriter->writeAttribute('w:gutter', $this->convertTwip($this->style->getGutter(), SectionStyle::DEFAULT_GUTTER));
foreach ($margins as $attribute => $value) {
list($method, $default) = $value;
$this->xmlWriter->writeAttribute($attribute, $this->convertTwip($this->style->$method(), $default));
}
$this->xmlWriter->endElement();
// Borders
@ -91,7 +97,10 @@ class Section extends AbstractStyle
// Columns
$this->xmlWriter->startElement('w:cols');
$this->xmlWriter->writeAttribute('w:num', $this->style->getColsNum());
$this->xmlWriter->writeAttribute('w:space', $this->convertTwip($this->style->getColsSpace(), SectionStyle::DEFAULT_COLUMN_SPACING));
$this->xmlWriter->writeAttribute('w:space', $this->convertTwip(
$this->style->getColsSpace(),
SectionStyle::DEFAULT_COLUMN_SPACING
));
$this->xmlWriter->endElement();
// Line numbering

View File

@ -63,7 +63,8 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($iVal, $oSettings->getHeaderHeight());
$oSettings->setSettingValue('lineNumbering', array());
$oSettings->setSettingValue('lineNumbering', array('start' => 1, 'increment' => 1, 'distance' => 240, 'restart' => 'newPage'));
$oSettings->setSettingValue('lineNumbering', array('start' => 1, 'increment' => 1,
'distance' => 240, 'restart' => 'newPage'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\LineNumbering', $oSettings->getLineNumbering());
$oSettings->setSettingValue('lineNumbering', null);

View File

@ -64,7 +64,8 @@ class HTMLTest extends \PHPUnit_Framework_TestCase
$docProps = $phpWord->getDocumentProperties();
$docProps->setTitle('HTML Test');
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11,
'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph');

View File

@ -36,18 +36,6 @@ class ContentTest extends \PHPUnit_Framework_TestCase
TestHelperDOCX::clear();
}
/**
* Test construct with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testConstructNoPhpWord()
{
$object = new Content();
$object->writeContent();
}
/**
* Test write content
*/

View File

@ -1,40 +0,0 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Writer\ODText\Part;
use PhpOffice\PhpWord\Writer\ODText\Part\Meta;
/**
* Test class for PhpOffice\PhpWord\Writer\ODText\Part\Meta
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\Meta
* @runTestsInSeparateProcesses
*/
class MetaTest extends \PHPUnit_Framework_TestCase
{
/**
* Test construct with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testConstructNoPhpWord()
{
$object = new Meta();
$object->writeMeta();
}
}

View File

@ -1,40 +0,0 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Writer\Part\ODText;
use PhpOffice\PhpWord\Writer\ODText\Part\Styles;
/**
* Test class for PhpOffice\PhpWord\Writer\ODText\Part\Styles
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\Styles
* @runTestsInSeparateProcesses
*/
class StylesTest extends \PHPUnit_Framework_TestCase
{
/**
* Test construct with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testConstructNoPhpWord()
{
$object = new Styles();
$object->writeStyles();
}
}

View File

@ -58,7 +58,8 @@ class RTFTest extends \PHPUnit_Framework_TestCase
$file = __DIR__ . "/../_files/temp.rtf";
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11,
'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph');

View File

@ -1,52 +0,0 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part;
use PhpOffice\PhpWord\Writer\Word2007\Part\DocProps;
/**
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\DocProps
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Part\DocProps
* @runTestsInSeparateProcesses
*/
class DocPropsTest extends \PHPUnit_Framework_TestCase
{
/**
* Test write docProps/app.xml with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testWriteDocPropsAppNoPhpWord()
{
$object = new DocProps();
$object->writeDocPropsApp();
}
/**
* Test write docProps/core.xml with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testWriteDocPropsCoreNoPhpWord()
{
$object = new DocProps();
$object->writeDocPropsCore();
}
}

View File

@ -36,18 +36,6 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
TestHelperDOCX::clear();
}
/**
* Test write word/document.xm with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testWriteDocumentNoPhpWord()
{
$object = new Document();
$object->writeDocument();
}
/**
* Write end section page numbering
*/
@ -121,8 +109,8 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'center')); // Style #1
$phpWord->addFontStyle('fStyle', array('size' => '20', 'doubleStrikethrough' => true, 'allCaps' => true)); // Style #2
$phpWord->addTitleStyle(1, array('color' => '333333', 'bold' => true)); // Style #3
$phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true)); // Style #2
$phpWord->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3
$fontStyle = new Font('text', array('align' => 'center'));
$section = $phpWord->addSection();
$section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #4

View File

@ -29,8 +29,6 @@ class FooterTest extends \PHPUnit_Framework_TestCase
{
/**
* Write footer
*
* @covers ::writeFooter
*/
public function testWriteFooter()
{
@ -44,11 +42,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$container->addImage($imageSrc);
$writer = new Word2007();
$writer->setUseDiskCaching(true);
$object = new Footer();
$object->setParentWriter($writer);
$object->writeFooter($container);
$writer->setUseDiskCaching(true);
$xml = simplexml_load_string($object->writeFooter($container));
$object->setElement($container);
$xml = simplexml_load_string($object->write());
$this->assertInstanceOf('SimpleXMLElement', $xml);
}

View File

@ -43,11 +43,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$container->addWatermark($imageSrc);
$writer = new Word2007();
$writer->setUseDiskCaching(true);
$object = new Header();
$object->setParentWriter($writer);
$object->writeHeader($container);
$writer->setUseDiskCaching(true);
$xml = simplexml_load_string($object->writeHeader($container));
$object->setElement($container);
$xml = simplexml_load_string($object->write());
$this->assertInstanceOf('SimpleXMLElement', $xml);
}

View File

@ -36,18 +36,6 @@ class StylesTest extends \PHPUnit_Framework_TestCase
TestHelperDOCX::clear();
}
/**
* Test construct with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testConstructNoPhpWord()
{
$object = new Styles();
$object->writeStyles();
}
/**
* Test write styles
*/

View File

@ -45,7 +45,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
$writerParts = array(
'ContentTypes' => 'ContentTypes',
'Rels' => 'Rels',
'DocProps' => 'DocProps',
'DocPropsApp' => 'DocPropsApp',
'Document' => 'Document',
'Styles' => 'Styles',
'Numbering' => 'Numbering',