From 4119c6af07d0f3e42293873bc54b080c4ba421d5 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Wed, 12 Mar 2014 21:55:20 +0700 Subject: [PATCH 1/7] Reorganize samples and write unsupported element to ODText and RTF --- Classes/PHPWord/Reader/Word2007.php | 4 +- Classes/PHPWord/Writer/ODText/Content.php | 34 ++++++++++----- Classes/PHPWord/Writer/RTF.php | 40 +++++++++++------ Tests/PHPWord/SectionTest.php | 17 +++++++- samples/Sample_01_SimpleText.php | 40 ++++++----------- samples/Sample_02_TabStops.php | 41 ++++++------------ samples/Sample_03_Sections.php | 40 ++++++----------- samples/Sample_04_Textrun.php | 40 ++++++----------- samples/Sample_05_Multicolumn.php | 41 ++++++------------ samples/Sample_06_Footnote.php | 31 ++++++------- samples/Sample_07_TemplateCloneRow.php | 16 ++++++- samples/Sample_08_ParagraphPagination.php | 41 ++++++------------ samples/Sample_09_Tables.php | 39 ++++++----------- samples/Sample_10_ReadWord2007.php | 41 +++++++----------- .../Sample_07_TemplateCloneRow.docx | Bin 15 files changed, 208 insertions(+), 257 deletions(-) rename samples/{ => resources}/Sample_07_TemplateCloneRow.docx (100%) diff --git a/Classes/PHPWord/Reader/Word2007.php b/Classes/PHPWord/Reader/Word2007.php index 48a13e5912..4d372f2717 100644 --- a/Classes/PHPWord/Reader/Word2007.php +++ b/Classes/PHPWord/Reader/Word2007.php @@ -254,8 +254,8 @@ public function load($pFilename) if ($elm->getName() != 'style') { continue; } - unset($pStyle); - unset($fStyle); + $pStyle = null; + $fStyle = null; $hasParagraphStyle = isset($elm->pPr); $hasFontStyle = isset($elm->rPr); $styleName = (string)$elm->name['val']; diff --git a/Classes/PHPWord/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php index 7ee571a377..b788478e25 100755 --- a/Classes/PHPWord/Writer/ODText/Content.php +++ b/Classes/PHPWord/Writer/ODText/Content.php @@ -253,28 +253,25 @@ public function writeContent(PHPWord $pPHPWord = null) $this->_writeTextRun($objWriter, $element); } elseif ($element instanceof PHPWord_Section_TextBreak) { $this->_writeTextBreak($objWriter); - /* } elseif ($element instanceof PHPWord_Section_Link) { - $this->_writeLink($objWriter, $element); + $this->writeUnsupportedElement($objWriter, 'link'); } elseif ($element instanceof PHPWord_Section_Title) { - $this->_writeTitle($objWriter, $element); + $this->writeUnsupportedElement($objWriter, 'title'); } elseif ($element instanceof PHPWord_Section_PageBreak) { - $this->_writePageBreak($objWriter); + $this->writeUnsupportedElement($objWriter, 'page break'); } elseif ($element instanceof PHPWord_Section_Table) { - $this->_writeTable($objWriter, $element); + $this->writeUnsupportedElement($objWriter, 'table'); } elseif ($element instanceof PHPWord_Section_ListItem) { - $this->_writeListItem($objWriter, $element); + $this->writeUnsupportedElement($objWriter, 'list item'); } elseif ($element instanceof PHPWord_Section_Image || $element instanceof PHPWord_Section_MemoryImage) { - $this->_writeImage($objWriter, $element); + $this->writeUnsupportedElement($objWriter, 'image'); } elseif ($element instanceof PHPWord_Section_Object) { - $this->_writeObject($objWriter, $element); + $this->writeUnsupportedElement($objWriter, 'object'); } elseif ($element instanceof PHPWord_TOC) { - $this->_writeTOC($objWriter); - */ + $this->writeUnsupportedElement($objWriter, 'TOC'); } else { - print_r($element); - echo '
'; + $this->writeUnsupportedElement($objWriter, 'other'); } } @@ -387,4 +384,17 @@ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PH private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null) { } + + /** + * Write unsupported element + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param string $element + */ + private function writeUnsupportedElement($objWriter, $element) + { + $objWriter->startElement('text:p'); + $objWriter->writeRaw("Cannot write content. This version of PHPWord has not supported {$element} element in ODText."); + $objWriter->endElement(); + } } diff --git a/Classes/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php index 66ec7383e8..7730e2bd3c 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/Classes/PHPWord/Writer/RTF.php @@ -314,28 +314,25 @@ private function getDataContent() $sRTFBody .= $this->getDataContentTextBreak(); } elseif ($element instanceof PHPWord_Section_TextRun) { $sRTFBody .= $this->getDataContentTextRun($element); - /* } elseif($element instanceof PHPWord_Section_Link) { - $this->_writeLink($objWriter, $element); + $sRTFBody .= $this->getDataContentUnsupportedElement('link'); } elseif($element instanceof PHPWord_Section_Title) { - $this->_writeTitle($objWriter, $element); + $sRTFBody .= $this->getDataContentUnsupportedElement('title'); } elseif($element instanceof PHPWord_Section_PageBreak) { - $this->_writePageBreak($objWriter); + $sRTFBody .= $this->getDataContentUnsupportedElement('page break'); } elseif($element instanceof PHPWord_Section_Table) { - $this->_writeTable($objWriter, $element); + $sRTFBody .= $this->getDataContentUnsupportedElement('table'); } elseif($element instanceof PHPWord_Section_ListItem) { - $this->_writeListItem($objWriter, $element); + $sRTFBody .= $this->getDataContentUnsupportedElement('list item'); } elseif($element instanceof PHPWord_Section_Image || $element instanceof PHPWord_Section_MemoryImage) { - $this->_writeImage($objWriter, $element); + $sRTFBody .= $this->getDataContentUnsupportedElement('image'); } elseif($element instanceof PHPWord_Section_Object) { - $this->_writeObject($objWriter, $element); + $sRTFBody .= $this->getDataContentUnsupportedElement('object'); } elseif($element instanceof PHPWord_TOC) { - $this->_writeTOC($objWriter); - */ + $sRTFBody .= $this->getDataContentUnsupportedElement('TOC'); } else { - print_r($element); - echo '
'; + $sRTFBody .= $this->getDataContentUnsupportedElement('other'); } } } @@ -381,7 +378,7 @@ private function getDataContentText(PHPWord_Section_Text $text, $withoutP = fals $this->_lastParagraphStyle = ''; } - if ($styleFont) { + if ($styleFont instanceof PHPWord_Style_Font) { if ($styleFont->getColor() != null) { $idxColor = array_search($styleFont->getColor(), $this->_colorTable); if ($idxColor !== false) { @@ -413,7 +410,7 @@ private function getDataContentText(PHPWord_Section_Text $text, $withoutP = fals } $sRTFText .= $text->getText(); - if ($styleFont) { + if ($styleFont instanceof PHPWord_Style_Font) { $sRTFText .= '\cf0'; $sRTFText .= '\f0'; @@ -461,4 +458,19 @@ private function getDataContentTextBreak() return '\par' . PHP_EOL; } + + /** + * Write unsupported element + * + * @param string $element + */ + private function getDataContentUnsupportedElement($element) + { + $sRTFText = ''; + $sRTFText .= '\pard\nowidctlpar' . PHP_EOL; + $sRTFText .= "Cannot write content. This version of PHPWord has not supported {$element} element in RTF."; + $sRTFText .= '\par' . PHP_EOL; + + return $sRTFText; + } } diff --git a/Tests/PHPWord/SectionTest.php b/Tests/PHPWord/SectionTest.php index 3af02eca5e..5380f84d1c 100644 --- a/Tests/PHPWord/SectionTest.php +++ b/Tests/PHPWord/SectionTest.php @@ -4,26 +4,41 @@ use PHPUnit_Framework_TestCase; use PHPWord_Section; +/** + * @covers PHPWord_Section + */ class SectionTest extends \PHPUnit_Framework_TestCase { + /** + * @covers PHPWord_Section::getSettings + */ public function testGetSettings() { $oSection = new PHPWord_Section(0); $this->assertAttributeEquals($oSection->getSettings(), '_settings', new PHPWord_Section(0)); } - public function testGetElementss() + /** + * @covers PHPWord_Section::getElements + */ + public function testGetElements() { $oSection = new PHPWord_Section(0); $this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0)); } + /** + * @covers PHPWord_Section::getFooter + */ public function testGetFooter() { $oSection = new PHPWord_Section(0); $this->assertAttributeEquals($oSection->getFooter(), '_footer', new PHPWord_Section(0)); } + /** + * @covers PHPWord_Section::getHeaders + */ public function testGetHeaders() { $oSection = new PHPWord_Section(0); diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index 4b055cca8a..2a251c9671 100755 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -1,13 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -29,22 +23,16 @@ $section->addText('I am styled by two style definitions.', 'rStyle', 'pStyle'); $section->addText('I have only a paragraph style definition.', null, 'pStyle'); -// Save File -echo date('H:i:s') , " Write to Word2007 format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -echo date('H:i:s') , " Write to OpenDocumentText format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -$objWriter->save(str_replace('.php', '.odt', __FILE__)); - -echo date('H:i:s') , " Write to RTF format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -$objWriter->save(str_replace('.php', '.rtf', __FILE__)); - - -// Echo memory peak usage -echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , " Done writing file" , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php index 177e8598f1..e9e2d84bcb 100755 --- a/samples/Sample_02_TabStops.php +++ b/samples/Sample_02_TabStops.php @@ -1,14 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -42,22 +35,16 @@ $section->addText("Left Aligned\tRight Aligned", NULL, 'rightTab'); $section->addText("\tCenter Aligned", NULL, 'centerTab'); -// Save File -echo date('H:i:s') , ' Write to Word2007 format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -$objWriter->save(str_replace('.php', '.odt', __FILE__)); - -echo date('H:i:s') , ' Write to RTF format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -$objWriter->save(str_replace('.php', '.rtf', __FILE__)); - - -// Echo memory peak usage -echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , ' Done writing file' , EOL; \ No newline at end of file +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php index afca97dae6..1e49629e9c 100755 --- a/samples/Sample_03_Sections.php +++ b/samples/Sample_03_Sections.php @@ -1,13 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -34,22 +28,16 @@ $section->createHeader()->addText('Header'); $section->createFooter()->addText('Footer'); -// Save File -echo date('H:i:s') , ' Write to Word2007 format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -$objWriter->save(str_replace('.php', '.odt', __FILE__)); - -echo date('H:i:s') , ' Write to RTF format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -$objWriter->save(str_replace('.php', '.rtf', __FILE__)); - - -// Echo memory peak usage -echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , ' Done writing file' , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index ac0906c9c2..ce70417e20 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -1,14 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -42,21 +35,16 @@ $textrun->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18)); $textrun->addText(' Here is some more text. '); -// Save File -echo date('H:i:s') , ' Write to Word2007 format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -$objWriter->save(str_replace('.php', '.odt', __FILE__)); - -echo date('H:i:s') , ' Write to RTF format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -$objWriter->save(str_replace('.php', '.rtf', __FILE__)); - -// Echo memory peak usage -echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , ' Done writing file' , EOL; \ No newline at end of file +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php index 7f0a75d0b2..3877defeff 100644 --- a/samples/Sample_05_Multicolumn.php +++ b/samples/Sample_05_Multicolumn.php @@ -1,14 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -45,22 +38,16 @@ $section = $PHPWord->createSection(array('breakType' => 'continuous')); $section->addText('Normal paragraph again.'); -// Save File -echo date('H:i:s') , " Write to Word2007 format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -echo date('H:i:s') , " Write to OpenDocumentText format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -$objWriter->save(str_replace('.php', '.odt', __FILE__)); - -echo date('H:i:s') , " Write to RTF format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -$objWriter->save(str_replace('.php', '.rtf', __FILE__)); - - -// Echo memory peak usage -echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , " Done writing file" , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php index 123dedccdf..daaa6b4636 100755 --- a/samples/Sample_06_Footnote.php +++ b/samples/Sample_06_Footnote.php @@ -1,12 +1,7 @@ '); -} +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -41,14 +36,16 @@ $footnote = $section->createFootnote(); $footnote->addText('The reference for this is wrapped in its own line'); -// Save File -echo date('H:i:s') , " Write to Word2007 format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - - -// Echo memory peak usage -echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , " Done writing file" , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php index ccdee2c32d..f797b986e5 100755 --- a/samples/Sample_07_TemplateCloneRow.php +++ b/samples/Sample_07_TemplateCloneRow.php @@ -1,9 +1,14 @@ '); require_once '../Classes/PHPWord.php'; +// New Word document +echo date('H:i:s') , " Create new PHPWord object" , EOL; $PHPWord = new PHPWord(); -$document = $PHPWord->loadTemplate('Sample_07_TemplateCloneRow.docx'); +$document = $PHPWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx'); // Simple table $document->cloneRow('rowValue', 10); @@ -51,4 +56,11 @@ $document->setValue('userName#3', 'Ray'); $document->setValue('userPhone#3', '+1 428 889 775'); -$document->saveAs('Sample_07_TemplateCloneRow_result.docx'); +$name = 'Sample_07_TemplateCloneRow_result.docx'; +echo date('H:i:s'), " Write to Word2007 format", EOL; +$document->saveAs($name); +rename($name, "results/{$name}"); + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php index 7bbead7a92..edd1992c43 100644 --- a/samples/Sample_08_ParagraphPagination.php +++ b/samples/Sample_08_ParagraphPagination.php @@ -1,14 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word document @@ -55,22 +48,16 @@ 'heading styles.', null, array('pageBreakBefore' => true)); -// Save File -echo date('H:i:s') , " Write to Word2007 format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -echo date('H:i:s') , " Write to OpenDocumentText format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -$objWriter->save(str_replace('.php', '.odt', __FILE__)); - -echo date('H:i:s') , " Write to RTF format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -$objWriter->save(str_replace('.php', '.rtf', __FILE__)); - - -// Echo memory peak usage -echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , " Done writing file" , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php index f90ac3c91b..96e411a020 100644 --- a/samples/Sample_09_Tables.php +++ b/samples/Sample_09_Tables.php @@ -1,13 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -82,21 +76,16 @@ $table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered); $table->addCell(null, $cellRowContinue); -// Save File -echo date('H:i:s') , ' Write to Word2007 format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -// echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; -// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -// $objWriter->save(str_replace('.php', '.odt', __FILE__)); -// -// echo date('H:i:s') , ' Write to RTF format' , EOL; -// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -// $objWriter->save(str_replace('.php', '.rtf', __FILE__)); - -// Echo memory peak usage -echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , ' Done writing file' , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_10_ReadWord2007.php b/samples/Sample_10_ReadWord2007.php index a837a5745a..d96e92644c 100644 --- a/samples/Sample_10_ReadWord2007.php +++ b/samples/Sample_10_ReadWord2007.php @@ -1,33 +1,24 @@ '); - require_once '../Classes/PHPWord.php'; // Read contents -$sample = 'Sample_10_ReadWord2007'; -$source = "resources/{$sample}.docx"; -$target = "results/{$sample}"; -echo '

', date('H:i:s'), " Reading contents from `{$source}`

"; +$name = basename(__FILE__, '.php'); +$source = "resources/{$name}.docx"; +echo date('H:i:s'), " Reading contents from `{$source}`", EOL; $PHPWord = PHPWord_IOFactory::load($source); -// Rewrite contents -echo date('H:i:s') , " Write to Word2007 format" , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save("{$sample}.docx"); -rename("{$sample}.docx", "{$target}.docx"); - -echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); -$objWriter->save("{$sample}.odt"); -rename("{$sample}.odt", "{$target}.odt"); - -echo date('H:i:s') , ' Write to RTF format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); -$objWriter->save("{$sample}.rtf"); -rename("{$sample}.rtf", "{$target}.rtf"); +// (Re)write contents +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo memory peak usage -echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; -echo date('H:i:s') , " Done writing file" , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_07_TemplateCloneRow.docx b/samples/resources/Sample_07_TemplateCloneRow.docx similarity index 100% rename from samples/Sample_07_TemplateCloneRow.docx rename to samples/resources/Sample_07_TemplateCloneRow.docx From a78ba1c925bdfd390dffdb93d0e4b2f015b60cb8 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Wed, 12 Mar 2014 21:57:59 +0700 Subject: [PATCH 2/7] Remove duplicate on SectionTest --- Tests/PHPWord/SectionTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Tests/PHPWord/SectionTest.php b/Tests/PHPWord/SectionTest.php index 5380f84d1c..7dede3746f 100644 --- a/Tests/PHPWord/SectionTest.php +++ b/Tests/PHPWord/SectionTest.php @@ -44,10 +44,4 @@ public function testGetHeaders() $oSection = new PHPWord_Section(0); $this->assertAttributeEquals($oSection->getHeaders(), '_headers', new PHPWord_Section(0)); } - - public function testGetElements() - { - $oSection = new PHPWord_Section(0); - $this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0)); - } } From d4d42752d4a25cd74acd0a1c2616fff0bb82dd5d Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 13 Mar 2014 01:58:00 +0700 Subject: [PATCH 3/7] Unit test for PHPWord\Style --- Classes/PHPWord/Section.php | 12 +++- Tests/PHPWord/MediaTest.php | 2 +- Tests/PHPWord/SectionTest.php | 87 ++++++++++++++++++++++++++ Tests/PHPWord/Style/TOCTest.php | 1 + Tests/PHPWord/StyleTest.php | 45 +++++++++++++ Tests/PHPWord/TOCTest.php | 8 ++- Tests/PHPWord/Writer/Word2007Test.php | 31 +++++---- Tests/PHPWordTest.php | 6 +- Tests/_files/images/PHPWord.png | Bin 0 -> 16712 bytes Tests/_inc/TestHelperDOCX.php | 2 +- 10 files changed, 173 insertions(+), 21 deletions(-) create mode 100644 Tests/PHPWord/StyleTest.php create mode 100644 Tests/_files/images/PHPWord.png diff --git a/Classes/PHPWord/Section.php b/Classes/PHPWord/Section.php index 70dceba276..bdf37f81da 100755 --- a/Classes/PHPWord/Section.php +++ b/Classes/PHPWord/Section.php @@ -243,7 +243,9 @@ public function addObject($src, $style = null) $this->_elementCollection[] = $object; return $object; } else { - trigger_error('Source does not exist or unsupported object type.'); + throw new PHPWord_Exception( + 'Source does not exist or unsupported object type.' + ); } } @@ -265,7 +267,9 @@ public function addImage($src, $style = null) $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Source does not exist or unsupported image type.'); + throw new PHPWord_Exception( + 'Source does not exist or unsupported image type.' + ); } } @@ -286,7 +290,9 @@ public function addMemoryImage($link, $style = null) $this->_elementCollection[] = $memoryImage; return $memoryImage; } else { - trigger_error('Unsupported image type.'); + throw new PHPWord_Exception( + 'Unsupported image type.' + ); } } diff --git a/Tests/PHPWord/MediaTest.php b/Tests/PHPWord/MediaTest.php index e572272435..1d302444ed 100644 --- a/Tests/PHPWord/MediaTest.php +++ b/Tests/PHPWord/MediaTest.php @@ -48,4 +48,4 @@ public function testAddSectionMediaElement() $this->assertInstanceOf('PHPWord_Section_Image', $element); } } -} \ No newline at end of file +} diff --git a/Tests/PHPWord/SectionTest.php b/Tests/PHPWord/SectionTest.php index 7dede3746f..bbb3014acd 100644 --- a/Tests/PHPWord/SectionTest.php +++ b/Tests/PHPWord/SectionTest.php @@ -5,7 +5,11 @@ use PHPWord_Section; /** + * Class TOCTest + * + * @package PHPWord\Tests * @covers PHPWord_Section + * @runTestsInSeparateProcesses */ class SectionTest extends \PHPUnit_Framework_TestCase { @@ -44,4 +48,87 @@ public function testGetHeaders() $oSection = new PHPWord_Section(0); $this->assertAttributeEquals($oSection->getHeaders(), '_headers', new PHPWord_Section(0)); } + + /** + * @covers PHPWord_Section::setSettings + */ + public function testSetSettings() + { + $expected = 'landscape'; + $object = new PHPWord_Section(0); + $object->setSettings(array('orientation' => $expected)); + $this->assertEquals($expected, $object->getSettings()->getOrientation()); + } + + /** + * @covers PHPWord_Section::addText + * @covers PHPWord_Section::addLink + * @covers PHPWord_Section::addTextBreak + * @covers PHPWord_Section::addPageBreak + * @covers PHPWord_Section::addTable + * @covers PHPWord_Section::addListItem + * @covers PHPWord_Section::addObject + * @covers PHPWord_Section::addImage + * @covers PHPWord_Section::addMemoryImage + * @covers PHPWord_Section::addTOC + * @covers PHPWord_Section::addTitle + * @covers PHPWord_Section::createTextRun + * @covers PHPWord_Section::createFootnote + */ + public function testAddElements() + { + $objectSource = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + ); + $imageSource = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png') + ); + $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; + + $section = new PHPWord_Section(0); + $section->addText(utf8_decode('ä')); + $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); + $section->addTextBreak(); + $section->addPageBreak(); + $section->addTable(); + $section->addListItem(utf8_decode('ä')); + $section->addObject($objectSource); + $section->addImage($imageSource); + $section->addMemoryImage($imageUrl); + $section->addTOC(); + $section->addTitle(utf8_decode('ä'), 1); + $section->createTextRun(); + $section->createFootnote(); + + $elementCollection = $section->getElements(); + $elementType = 'Link'; + $objectType = "PHPWord_Section_{$elementType}"; + $this->assertInstanceOf($objectType, $elementCollection[1]); + // $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', + // 'Table', 'ListItem', 'Object', 'Image', 'MemoryImage', 'TOC', + // 'Title', 'TextRun'); + // $i = 0; + // foreach ($elementTypes as $elementType) { + // $objectType = "PHPWord_Section_{$elementType}"; + // $this->assertInstanceOf($objectType, $elementCollection[$i]); + // $i++; + // } + } + + /** + * @covers PHPWord_Section::createHeader + * @covers PHPWord_Section::createFooter + */ + public function testCreateHeaderFooter() + { + $object = new PHPWord_Section(0); + $elements = array('Header', 'Footer'); + foreach ($elements as $element) { + $objectType = "PHPWord_Section_{$element}"; + $method = "create{$element}"; + $this->assertInstanceOf($objectType, $object->$method()); + } + } } diff --git a/Tests/PHPWord/Style/TOCTest.php b/Tests/PHPWord/Style/TOCTest.php index 80e34d7472..b72d85fcac 100644 --- a/Tests/PHPWord/Style/TOCTest.php +++ b/Tests/PHPWord/Style/TOCTest.php @@ -8,6 +8,7 @@ * Class TOCTest * * @package PHPWord\Tests + * @covers PHPWord_Style_TOC * @runTestsInSeparateProcesses */ class TOCTest extends \PHPUnit_Framework_TestCase diff --git a/Tests/PHPWord/StyleTest.php b/Tests/PHPWord/StyleTest.php new file mode 100644 index 0000000000..36e961acf5 --- /dev/null +++ b/Tests/PHPWord/StyleTest.php @@ -0,0 +1,45 @@ + 'center'); + $font = array('italic' => true); + $table = array('bgColor' => 'CCCCCC'); + $styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font', + 'Link' => 'Font', 'Table' => 'TableFull', + 'Heading_1' => 'Font', 'Normal' => 'Paragraph'); + $elementCount = 6; + PHPWord_Style::addParagraphStyle('Paragraph', $paragraph); + PHPWord_Style::addFontStyle('Font', $font); + PHPWord_Style::addLinkStyle('Link', $font); + PHPWord_Style::addTableStyle('Table', $table); + PHPWord_Style::addTitleStyle(1, $font); + PHPWord_Style::setDefaultParagraphStyle($paragraph); + + $this->assertEquals($elementCount, count(PHPWord_Style::getStyles())); + foreach ($styles as $name => $style) { + $expected = "PHPWord_Style_{$style}"; + $this->assertInstanceOf($expected, PHPWord_Style::getStyle($name)); + } + $this->assertNull(PHPWord_Style::getStyle('Unknown')); + } +} diff --git a/Tests/PHPWord/TOCTest.php b/Tests/PHPWord/TOCTest.php index 74038ee3d4..b093f49c56 100644 --- a/Tests/PHPWord/TOCTest.php +++ b/Tests/PHPWord/TOCTest.php @@ -6,7 +6,11 @@ use PHPWord_Style_TOC; /** - * @covers PHPWord_TOC + * Class TOCTest + * + * @package PHPWord\Tests + * @covers PHPWord_TOC + * @runTestsInSeparateProcesses */ class TOCTest extends PHPUnit_Framework_TestCase { @@ -46,7 +50,7 @@ public function testAddAndGetTitle() // Prepare variables $titleCount = 3; $anchor = '_Toc' . (252634154 + $titleCount); - $bookmark = $titleCount - 1; // zero based + $bookmark = $titleCount - 1; $titles = array( 'Heading 1' => 1, 'Heading 2' => 2, diff --git a/Tests/PHPWord/Writer/Word2007Test.php b/Tests/PHPWord/Writer/Word2007Test.php index 59bc63871c..ae828ec33e 100644 --- a/Tests/PHPWord/Writer/Word2007Test.php +++ b/Tests/PHPWord/Writer/Word2007Test.php @@ -66,23 +66,28 @@ public function testSave() */ public function testCheckContentTypes() { + $images = array( + 'mars_noext_jpg' => '1.jpg', + 'mars.jpg' => '2.jpg', + 'mario.gif' => '3.gif', + 'firefox.png' => '4.png', + 'duke_nukem.bmp' => '5.bmp', + 'angela_merkel.tif' => '6.tif', + ); $phpWord = new PHPWord(); $section = $phpWord->createSection(); - $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/mario.gif"); - $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png"); - $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp"); - $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif"); + foreach ($images as $source => $target) { + $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}"); + } $doc = TestHelperDOCX::getDocument($phpWord); $mediaPath = $doc->getPath() . "/word/media"; - $this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg", $mediaPath . "/section_image1.jpg"); - $this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg", $mediaPath . "/section_image2.jpg"); - $this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif", $mediaPath . "/section_image3.gif"); - $this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png", $mediaPath . "/section_image4.png"); - $this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp", $mediaPath . "/section_image5.bmp"); - $this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif", $mediaPath . "/section_image6.tif"); + foreach ($images as $source => $target) { + $this->assertFileEquals( + PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}", + $mediaPath . "/section_image{$target}" + ); + } } -} \ No newline at end of file +} diff --git a/Tests/PHPWordTest.php b/Tests/PHPWordTest.php index 54ab4ae088..0aa4f348be 100644 --- a/Tests/PHPWordTest.php +++ b/Tests/PHPWordTest.php @@ -8,7 +8,11 @@ use PHPWord_Style; /** - * @covers PHPWord + * Class PHPWordTest + * + * @package PHPWord\Tests + * @covers PHPWord + * @runTestsInSeparateProcesses */ class PHPWordTest extends PHPUnit_Framework_TestCase { diff --git a/Tests/_files/images/PHPWord.png b/Tests/_files/images/PHPWord.png new file mode 100644 index 0000000000000000000000000000000000000000..9b7f4930f4df5a26ac45e3e53cc248dc135edb36 GIT binary patch literal 16712 zcmV)UK(N1wP)004&%004{+008|`004nN004b?008NW002DY000@xb3BE2000U( zX+uL$P-t&-Z*ypGa3D!TLm+T+Z)Rz1WdHz3$DNjUR8-d%htIutdZEoQ(iwV_E---f zE+8EQ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~d)GtO@vkuJM{=|C0F)00000NkvXXu0mjfgLw1L literal 0 HcmV?d00001 diff --git a/Tests/_inc/TestHelperDOCX.php b/Tests/_inc/TestHelperDOCX.php index 2d59dcb636..5f8e51a3f7 100644 --- a/Tests/_inc/TestHelperDOCX.php +++ b/Tests/_inc/TestHelperDOCX.php @@ -67,4 +67,4 @@ public static function getFile() { return self::$file; } -} \ No newline at end of file +} From 2f0438ff15605c118e3c7edd537d3d041d386dc7 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 13 Mar 2014 02:08:31 +0700 Subject: [PATCH 4/7] Change all remaining `trigger_error()` into `throw new Exception()` --- Classes/PHPWord/Section/Footer.php | 4 ++-- Classes/PHPWord/Section/Header.php | 6 +++--- Classes/PHPWord/Section/Table/Cell.php | 10 +++++----- Classes/PHPWord/Section/TextRun.php | 2 +- Classes/PHPWord/Template.php | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Classes/PHPWord/Section/Footer.php b/Classes/PHPWord/Section/Footer.php index 04d40f331e..3455adc9c9 100755 --- a/Classes/PHPWord/Section/Footer.php +++ b/Classes/PHPWord/Section/Footer.php @@ -133,7 +133,7 @@ public function addImage($src, $style = null) $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Src does not exist or invalid image type.', E_USER_ERROR); + throw new Exception('Src does not exist or invalid image type.'); } } @@ -154,7 +154,7 @@ public function addMemoryImage($link, $style = null) $this->_elementCollection[] = $memoryImage; return $memoryImage; } else { - trigger_error('Unsupported image type.'); + throw new Exception('Unsupported image type.'); } } diff --git a/Classes/PHPWord/Section/Header.php b/Classes/PHPWord/Section/Header.php index 6c62440657..83c82c4973 100755 --- a/Classes/PHPWord/Section/Header.php +++ b/Classes/PHPWord/Section/Header.php @@ -162,7 +162,7 @@ public function addImage($src, $style = null) $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Src does not exist or invalid image type.', E_USER_ERROR); + throw new Exception('Src does not exist or invalid image type.'); } } @@ -183,7 +183,7 @@ public function addMemoryImage($link, $style = null) $this->_elementCollection[] = $memoryImage; return $memoryImage; } else { - trigger_error('Unsupported image type.'); + throw new Exception('Unsupported image type.'); } } @@ -223,7 +223,7 @@ public function addWatermark($src, $style = null) $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Src does not exist or invalid image type.', E_USER_ERROR); + throw new Exception('Src does not exist or invalid image type.'); } } diff --git a/Classes/PHPWord/Section/Table/Cell.php b/Classes/PHPWord/Section/Table/Cell.php index 4f8f78fee9..898c6bf2b2 100755 --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/Classes/PHPWord/Section/Table/Cell.php @@ -140,7 +140,7 @@ public function addLink($linkSrc, $linkName = null, $style = null) $this->_elementCollection[] = $link; return $link; } else { - trigger_error('Unsupported Link header / footer reference'); + throw new Exception('Unsupported Link header / footer reference'); return false; } } @@ -198,7 +198,7 @@ public function addImage($src, $style = null) $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Source does not exist or unsupported image type.'); + throw new Exception('Source does not exist or unsupported image type.'); } } @@ -225,7 +225,7 @@ public function addMemoryImage($link, $style = null) $this->_elementCollection[] = $memoryImage; return $memoryImage; } else { - trigger_error('Unsupported image type.'); + throw new Exception('Unsupported image type.'); } } @@ -266,7 +266,7 @@ public function addObject($src, $style = null) $this->_elementCollection[] = $object; return $object; } else { - trigger_error('Source does not exist or unsupported object type.'); + throw new Exception('Source does not exist or unsupported object type.'); } } @@ -288,7 +288,7 @@ public function addPreserveText($text, $styleFont = null, $styleParagraph = null $this->_elementCollection[] = $ptext; return $ptext; } else { - trigger_error('addPreserveText only supported in footer/header.'); + throw new Exception('addPreserveText only supported in footer/header.'); } } diff --git a/Classes/PHPWord/Section/TextRun.php b/Classes/PHPWord/Section/TextRun.php index c26b2ef652..eeb936a0db 100755 --- a/Classes/PHPWord/Section/TextRun.php +++ b/Classes/PHPWord/Section/TextRun.php @@ -127,7 +127,7 @@ public function addImage($imageSrc, $style = null) $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Source does not exist or unsupported image type.'); + throw new Exception('Source does not exist or unsupported image type.'); } } diff --git a/Classes/PHPWord/Template.php b/Classes/PHPWord/Template.php index 4d356dd35c..840d22950a 100755 --- a/Classes/PHPWord/Template.php +++ b/Classes/PHPWord/Template.php @@ -164,7 +164,7 @@ private function _findRowStart($offset) $rowStart = strrpos($this->_documentXML, "", ((strlen($this->_documentXML) - $offset) * -1)); } if (!$rowStart) { - trigger_error("Can not find the start position of the row to clone."); + throw new Exception("Can not find the start position of the row to clone."); return false; } return $rowStart; @@ -208,7 +208,7 @@ public function cloneRow($search, $numberOfClones) $tagPos = strpos($this->_documentXML, $search); if (!$tagPos) { - trigger_error("Can not clone row, template variable not found or variable contains markup."); + throw new Exception("Can not clone row, template variable not found or variable contains markup."); return false; } From acfe64bb5323fbb014c40c2e6a61fe6a893e0015 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 13 Mar 2014 19:09:35 +0700 Subject: [PATCH 5/7] More unit tests for Writer\Word2007\Base --- Classes/PHPWord/Style/Font.php | 2 - Classes/PHPWord/Style/Row.php | 22 ++- Classes/PHPWord/Writer/Word2007/Base.php | 47 +++++- README.md | 3 +- Tests/PHPWord/Writer/Word2007/BaseTest.php | 170 ++++++++++++++++++++- Tests/_inc/XmlDocument.php | 43 +++++- samples/Sample_01_SimpleText.php | 36 ++++- 7 files changed, 294 insertions(+), 29 deletions(-) diff --git a/Classes/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php index bb22a61bfd..cbd7fc9472 100755 --- a/Classes/PHPWord/Style/Font.php +++ b/Classes/PHPWord/Style/Font.php @@ -173,8 +173,6 @@ public function __construct($type = 'text', $paragraphStyle = null) } elseif (is_array($paragraphStyle)) { $this->_paragraphStyle = new PHPWord_Style_Paragraph; $this->_paragraphStyle->setArrayStyle($paragraphStyle); - } elseif (null === $paragraphStyle) { - $this->_paragraphStyle = new PHPWord_Style_Paragraph; } else { $this->_paragraphStyle = $paragraphStyle; } diff --git a/Classes/PHPWord/Style/Row.php b/Classes/PHPWord/Style/Row.php index 66d5505fb8..c7140d5897 100644 --- a/Classes/PHPWord/Style/Row.php +++ b/Classes/PHPWord/Style/Row.php @@ -36,22 +36,20 @@ class PHPWord_Style_Row * * @var bool */ - private $_tblHeader; + private $_tblHeader = false; /** * Table row cannot break across pages * * @var bool */ - private $_cantSplit; + private $_cantSplit = false; /** * Create a new row style */ public function __construct() { - $this->_tblHeader = null; - $this->_cantSplit = null; } /** @@ -62,23 +60,31 @@ public function setStyleValue($key, $value) $this->$key = $value; } - public function setTblHeader($pValue = null) + public function setTblHeader($pValue = false) { + if (!is_bool($pValue)) { + $pValue = false; + } $this->_tblHeader = $pValue; + return $this; } public function getTblHeader() { - return $this->_tblHeader ? 1 : 0; + return $this->_tblHeader; } - public function setCantSplit($pValue = null) + public function setCantSplit($pValue = false) { + if (!is_bool($pValue)) { + $pValue = false; + } $this->_cantSplit = $pValue; + return $this; } public function getCantSplit() { - return $this->_cantSplit ? 1 : 0; + return $this->_cantSplit; } } diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 4e18fdd811..e6af27220a 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -31,6 +31,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart { + /** + * Write text + */ protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { $styleFont = $text->getFontStyle(); @@ -81,6 +84,9 @@ protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWor } } + /** + * Write text run + */ protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) { $elements = $textrun->getElements(); @@ -222,6 +228,9 @@ protected function _writeParagraphStyle( } } + /** + * Write table + */ protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) { $rID = $link->getRelationId(); @@ -278,6 +287,9 @@ protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWor } } + /** + * Write preserve text + */ protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun) { $styleFont = $textrun->getFontStyle(); @@ -370,6 +382,9 @@ protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null $objWriter->endElement(); // p } + /** + * Write text style + */ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style) { $font = $style->getName(); @@ -451,11 +466,17 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P $objWriter->endElement(); } + /** + * Write text break + */ protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) { $objWriter->writeElement('w:p', null); } + /** + * Write table + */ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table) { $_rows = $table->getRows(); @@ -499,14 +520,14 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->writeAttribute('w:val', $height); $objWriter->endElement(); } - if (!is_null($tblHeader)) { + if ($tblHeader) { $objWriter->startElement('w:tblHeader'); - $objWriter->writeAttribute('w:val', $tblHeader); + $objWriter->writeAttribute('w:val', '1'); $objWriter->endElement(); } - if (!is_null($cantSplit)) { + if ($cantSplit) { $objWriter->startElement('w:cantSplit'); - $objWriter->writeAttribute('w:val', $cantSplit); + $objWriter->writeAttribute('w:val', '1'); $objWriter->endElement(); } $objWriter->endElement(); @@ -565,6 +586,9 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo } } + /** + * Write table style + */ protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null) { $margins = $style->getCellMargin(); @@ -610,6 +634,9 @@ protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, } } + /** + * Write cell style + */ protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null) { $bgColor = $style->getBgColor(); @@ -794,6 +821,9 @@ protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo } } + /** + * Write watermark + */ protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) { $rId = $image->getRelationId(); @@ -838,6 +868,9 @@ protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $ $objWriter->endElement(); } + /** + * Write title + */ protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title) { $text = htmlspecialchars($title->getText()); @@ -880,6 +913,9 @@ protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->endElement(); } + /** + * Write footnote + */ protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote) { $objWriter->startElement('w:footnote'); @@ -915,6 +951,9 @@ protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PH $objWriter->endElement(); // w:footnote } + /** + * Write footnote reference + */ protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false) { if (!$withoutP) { diff --git a/README.md b/README.md index 1003a29a38..9140529218 100755 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ __Want to contribute?__ Fork us! ## Requirements * PHP version 5.3.0 or higher -* PHP extension [php_zip](http://php.net/manual/en/book.zip.php) enabled +* PHP extension [ZipArchive](http://php.net/manual/en/book.zip.php) +* PHP extension [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) ## Installation diff --git a/Tests/PHPWord/Writer/Word2007/BaseTest.php b/Tests/PHPWord/Writer/Word2007/BaseTest.php index cd1f6dbd52..866cd5d3dd 100644 --- a/Tests/PHPWord/Writer/Word2007/BaseTest.php +++ b/Tests/PHPWord/Writer/Word2007/BaseTest.php @@ -7,7 +7,9 @@ /** * Class BaseTest - * @package PHPWord\Tests + * + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_Writer_Word2007_Base * @runTestsInSeparateProcesses */ class BaseTest extends \PHPUnit_Framework_TestCase @@ -20,6 +22,54 @@ public function tearDown() TestHelperDOCX::clear(); } + public function testWriteText() + { + $rStyle = 'rStyle'; + $pStyle = 'pStyle'; + + $PHPWord = new PHPWord(); + $PHPWord->addFontStyle($rStyle, array('bold' => true)); + $PHPWord->addParagraphStyle($pStyle, array('align' => 'justify')); + $section = $PHPWord->createSection(); + $section->addText('Test', $rStyle, $pStyle); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $element = "/w:document/w:body/w:p/w:r/w:rPr/w:rStyle"; + $this->assertEquals($rStyle, $doc->getElementAttribute($element, 'w:val')); + $element = "/w:document/w:body/w:p/w:pPr/w:pStyle"; + $this->assertEquals($pStyle, $doc->getElementAttribute($element, 'w:val')); + } + + /** + * Write text run + */ + public function testWriteTextRun() + { + $pStyle = 'pStyle'; + $aStyle = array('align' => 'justify'); + $imageSrc = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + ); + + $PHPWord = new PHPWord(); + $PHPWord->addParagraphStyle($pStyle, $aStyle); + $section = $PHPWord->createSection('Test'); + $textrun = $section->createTextRun($pStyle); + $textrun->addText('Test'); + $textrun->addTextBreak(); + $textrun = $section->createTextRun($aStyle); + $textrun->addLink('http://test.com'); + $textrun->addImage($imageSrc); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $parent = "/w:document/w:body/w:p"; + $this->assertTrue($doc->elementExists("{$parent}/w:pPr/w:pStyle[@w:val='{$pStyle}']")); + } + + /** + * Write paragraph style: Alignment + */ public function testWriteParagraphStyleAlign() { $PHPWord = new PHPWord(); @@ -34,7 +84,7 @@ public function testWriteParagraphStyleAlign() } /** - * Test write paragraph pagination + * Write paragraph style: Pagination */ public function testWriteParagraphStylePagination() { @@ -63,6 +113,116 @@ public function testWriteParagraphStylePagination() } } + /** + * covers ::_writeTextStyle + */ + public function testWriteFontStyle() + { + $PHPWord = new PHPWord(); + $styles['name'] = 'Verdana'; + $styles['size'] = 14; + $styles['bold'] = true; + $styles['italic'] = true; + $styles['underline'] = 'dash'; + $styles['strikethrough'] = true; + $styles['superScript'] = true; + $styles['color'] = 'FF0000'; + $styles['fgColor'] = 'yellow'; + + $section = $PHPWord->createSection(); + $section->addText('Test', $styles); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $parent = '/w:document/w:body/w:p/w:r/w:rPr'; + $this->assertEquals($styles['name'], $doc->getElementAttribute("{$parent}/w:rFonts", 'w:ascii')); + $this->assertEquals($styles['size'] * 2, $doc->getElementAttribute("{$parent}/w:sz", 'w:val')); + $this->assertTrue($doc->elementExists("{$parent}/w:b")); + $this->assertTrue($doc->elementExists("{$parent}/w:i")); + $this->assertEquals($styles['underline'], $doc->getElementAttribute("{$parent}/w:u", 'w:val')); + $this->assertTrue($doc->elementExists("{$parent}/w:strike")); + $this->assertEquals('superscript', $doc->getElementAttribute("{$parent}/w:vertAlign", 'w:val')); + $this->assertEquals($styles['color'], $doc->getElementAttribute("{$parent}/w:color", 'w:val')); + $this->assertEquals($styles['fgColor'], $doc->getElementAttribute("{$parent}/w:highlight", 'w:val')); + } + + /** + * Write link + */ + public function testWriteLink() + { + $PHPWord = new PHPWord(); + $section = $PHPWord->createSection(); + + $expected = 'PHPWord'; + $section->addLink('http://github.com/phpoffice/phpword', $expected); + + $doc = TestHelperDOCX::getDocument($PHPWord); + $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); + + $this->assertEquals($expected, $element->nodeValue); + } + + /** + * Write table + */ + public function testWriteTableStyle() + { + $PHPWord = new PHPWord(); + $tWidth = 120; + $rHeight = 120; + $cWidth = 120; + $tStyles["cellMarginTop"] = 120; + $tStyles["cellMarginRight"] = 120; + $tStyles["cellMarginBottom"] = 120; + $tStyles["cellMarginLeft"] = 120; + $rStyles["tblHeader"] = true; + $rStyles["cantSplit"] = true; + $cStyles["valign"] = 'top'; + $cStyles["textDirection"] = 'btLr'; + $cStyles["bgColor"] = 'FF0000'; + $cStyles["borderTopSize"] = 120; + $cStyles["borderBottomSize"] = 120; + $cStyles["borderLeftSize"] = 120; + $cStyles["borderRightSize"] = 120; + $cStyles["borderTopColor"] = 'FF0000'; + $cStyles["borderBottomColor"] = 'FF0000'; + $cStyles["borderLeftColor"] = 'FF0000'; + $cStyles["borderRightColor"] = 'FF0000'; + + $section = $PHPWord->createSection(); + $table = $section->addTable($tStyles); + $table->setWidth = 100; + $table->addRow($rHeight, $rStyles); + $cell = $table->addCell($cWidth, $cStyles); + $cell->addText('Test'); + $cell->addTextBreak(); + $cell->addLink('http://google.com'); + $cell->addListItem('Test'); + $textrun = $cell->createTextRun(); + $textrun->addText('Test'); + + $doc = TestHelperDOCX::getDocument($PHPWord); + + $parent = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellMar'; + $this->assertEquals($tStyles['cellMarginTop'], $doc->getElementAttribute("{$parent}/w:top", 'w:w')); + $this->assertEquals($tStyles['cellMarginRight'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); + $this->assertEquals($tStyles['cellMarginBottom'], $doc->getElementAttribute("{$parent}/w:bottom", 'w:w')); + $this->assertEquals($tStyles['cellMarginLeft'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); + + $parent = '/w:document/w:body/w:tbl/w:tr/w:trPr'; + $this->assertEquals($rHeight, $doc->getElementAttribute("{$parent}/w:trHeight", 'w:val')); + $this->assertEquals($rStyles['tblHeader'], $doc->getElementAttribute("{$parent}/w:tblHeader", 'w:val')); + $this->assertEquals($rStyles['cantSplit'], $doc->getElementAttribute("{$parent}/w:cantSplit", 'w:val')); + + $parent = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr'; + $this->assertEquals($cWidth, $doc->getElementAttribute("{$parent}/w:tcW", 'w:w')); + $this->assertEquals($cStyles['valign'], $doc->getElementAttribute("{$parent}/w:vAlign", 'w:val')); + $this->assertEquals($cStyles['textDirection'], $doc->getElementAttribute("{$parent}/w:textDirection", 'w:val')); + } + + /** + * Write cell style + */ public function testWriteCellStyleCellGridSpan() { $PHPWord = new PHPWord(); @@ -87,6 +247,9 @@ public function testWriteCellStyleCellGridSpan() $this->assertEquals(5, $element->getAttribute('w:val')); } + /** + * Write image + */ public function testWriteImagePosition() { $PHPWord = new PHPWord(); @@ -109,6 +272,9 @@ public function testWriteImagePosition() $this->assertRegExp('/position:absolute;/', $style); } + /** + * Write preserve text + */ public function testWritePreserveText() { $PHPWord = new PHPWord(); diff --git a/Tests/_inc/XmlDocument.php b/Tests/_inc/XmlDocument.php index f16bd6d8de..4d3d00347d 100644 --- a/Tests/_inc/XmlDocument.php +++ b/Tests/_inc/XmlDocument.php @@ -45,11 +45,11 @@ public function getFileDom($file = 'word/document.xml') } /** - * @param string $path - * @param string $file - * @return \DOMElement + * @param string $path + * @param string $file + * @return \DOMNodeList */ - public function getElement($path, $file = 'word/document.xml') + public function getNodeList($path, $file = 'word/document.xml') { if ($this->dom === null || $file !== $this->file) { $this->getFileDom($file); @@ -60,7 +60,18 @@ public function getElement($path, $file = 'word/document.xml') } - $elements = $this->xpath->query($path); + return $this->xpath->query($path); + } + + /** + * @param string $path + * @param string $file + * @return \DOMElement + */ + public function getElement($path, $file = 'word/document.xml') + { + $elements = $this->getNodeList($path, $file); + return $elements->item(0); } @@ -79,4 +90,26 @@ public function getPath() { return $this->path; } + + /** + * @param string $path + * @param string $attribute + * @param string $file + * @return string + */ + public function getElementAttribute($path, $attribute, $file = 'word/document.xml') + { + return $this->getElement($path, $file)->getAttribute($attribute); + } + + /** + * @param string $path + * @param string $file + * @return string + */ + public function elementExists($path, $file = 'word/document.xml') + { + $nodeList = $this->getNodeList($path, $file); + return !($nodeList->length == 0); + } } diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index 2a251c9671..add71ea99b 100755 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -7,21 +7,43 @@ // New Word Document echo date('H:i:s') , " Create new PHPWord object" , EOL; $PHPWord = new PHPWord(); +$PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16)); +$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100)); // New portrait section $section = $PHPWord->createSection(); -// Add text elements +// Simple text $section->addText('Hello World!'); -$section->addTextBreak(2); -$section->addText('I am inline styled.', array('name'=>'Verdana', 'color'=>'006699')); +// Two text break $section->addTextBreak(2); -$PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16)); -$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100)); -$section->addText('I am styled by two style definitions.', 'rStyle', 'pStyle'); -$section->addText('I have only a paragraph style definition.', null, 'pStyle'); +// Defined style +$section->addText('I am styled by a font style definition.', 'rStyle'); +$section->addText('I am styled by a paragraph style definition.', null, 'pStyle'); +$section->addText('I am styled by both font and paragraph style.', 'rStyle', 'pStyle'); +$section->addTextBreak(); + +// Inline font style +$fontStyle['name'] = 'Times New Roman'; +$fontStyle['size'] = 20; +$fontStyle['bold'] = true; +$fontStyle['italic'] = true; +$fontStyle['underline'] = 'dash'; +$fontStyle['strikethrough'] = true; +$fontStyle['superScript'] = true; +$fontStyle['color'] = 'FF0000'; +$fontStyle['fgColor'] = 'yellow'; +$section->addText('I am inline styled.', $fontStyle); +$section->addTextBreak(); + +// Link +$section->addLink('http://www.google.com', null, 'NLink'); +$section->addTextBreak(); + +// Image +$section->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18)); // Save file $name = basename(__FILE__, '.php'); From 8d942b589a5e965833fb6d62a720bf93f7d88f12 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 13 Mar 2014 19:34:16 +0700 Subject: [PATCH 6/7] Rename Reader sample and sync Base.php --- Classes/PHPWord/Writer/Word2007/Base.php | 8 ++++---- ..._ReadWord2007.php => Sample_11_ReadWord2007.php} | 0 ...eadWord2007.docx => Sample_11_ReadWord2007.docx} | Bin 3 files changed, 4 insertions(+), 4 deletions(-) rename samples/{Sample_10_ReadWord2007.php => Sample_11_ReadWord2007.php} (100%) rename samples/resources/{Sample_10_ReadWord2007.docx => Sample_11_ReadWord2007.docx} (100%) diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 04800dfb17..0fb54b2728 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -500,14 +500,14 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->writeAttribute('w:val', $height); $objWriter->endElement(); } - if (!is_null($tblHeader)) { + if ($tblHeader) { $objWriter->startElement('w:tblHeader'); - $objWriter->writeAttribute('w:val', $tblHeader); + $objWriter->writeAttribute('w:val', '1'); $objWriter->endElement(); } - if (!is_null($cantSplit)) { + if ($cantSplit) { $objWriter->startElement('w:cantSplit'); - $objWriter->writeAttribute('w:val', $cantSplit); + $objWriter->writeAttribute('w:val', '1'); $objWriter->endElement(); } $objWriter->endElement(); diff --git a/samples/Sample_10_ReadWord2007.php b/samples/Sample_11_ReadWord2007.php similarity index 100% rename from samples/Sample_10_ReadWord2007.php rename to samples/Sample_11_ReadWord2007.php diff --git a/samples/resources/Sample_10_ReadWord2007.docx b/samples/resources/Sample_11_ReadWord2007.docx similarity index 100% rename from samples/resources/Sample_10_ReadWord2007.docx rename to samples/resources/Sample_11_ReadWord2007.docx From 1aa83b943820aa66a49ea9112f250e0187cb4cf7 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 13 Mar 2014 20:58:24 +0700 Subject: [PATCH 7/7] Some more tests for Writer/Word2007/Base.php. We're on 71.84% coverage now :) --- Classes/PHPWord/Section/MemoryImage.php | 2 +- Classes/PHPWord/Settings.php | 15 +++-- Classes/PHPWord/Writer/RTF.php | 16 ++--- Classes/PHPWord/Writer/Word2007/Base.php | 78 ++++++++++++++++++---- Tests/PHPWord/Writer/Word2007/BaseTest.php | 74 ++++++++++++-------- samples/Sample_01_SimpleText.php | 6 +- samples/Sample_10_EastAsianFontStyle.php | 31 ++++----- 7 files changed, 146 insertions(+), 76 deletions(-) diff --git a/Classes/PHPWord/Section/MemoryImage.php b/Classes/PHPWord/Section/MemoryImage.php index 8486a2a313..f1488c4543 100755 --- a/Classes/PHPWord/Section/MemoryImage.php +++ b/Classes/PHPWord/Section/MemoryImage.php @@ -229,4 +229,4 @@ public function getImageExtension() { return $this->_imageExtension; } -} \ No newline at end of file +} diff --git a/Classes/PHPWord/Settings.php b/Classes/PHPWord/Settings.php index 67ef697ea3..af400551c3 100644 --- a/Classes/PHPWord/Settings.php +++ b/Classes/PHPWord/Settings.php @@ -28,7 +28,8 @@ /** * PHPWord_Settings */ -class PHPWord_Settings { +class PHPWord_Settings +{ /** * Compatibility option for XMLWriter * @@ -42,12 +43,13 @@ class PHPWord_Settings { * @param boolean $compatibility This sets the setIndent and setIndentString for better compatibility * @return boolean Success or failure */ - public static function setCompatibility($compatibility) { + public static function setCompatibility($compatibility) + { if (is_bool($compatibility)) { self::$_xmlWriterCompatibility = $compatibility; - return TRUE; + return true; } - return FALSE; + return false; } // function setCompatibility() @@ -56,7 +58,8 @@ public static function setCompatibility($compatibility) { * * @return boolean Compatibility */ - public static function getCompatibility() { + public static function getCompatibility() + { return self::$_xmlWriterCompatibility; } // function getCompatibility() -} \ No newline at end of file +} diff --git a/Classes/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php index 7730e2bd3c..9104c6fefb 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/Classes/PHPWord/Writer/RTF.php @@ -314,22 +314,22 @@ private function getDataContent() $sRTFBody .= $this->getDataContentTextBreak(); } elseif ($element instanceof PHPWord_Section_TextRun) { $sRTFBody .= $this->getDataContentTextRun($element); - } elseif($element instanceof PHPWord_Section_Link) { + } elseif ($element instanceof PHPWord_Section_Link) { $sRTFBody .= $this->getDataContentUnsupportedElement('link'); - } elseif($element instanceof PHPWord_Section_Title) { + } elseif ($element instanceof PHPWord_Section_Title) { $sRTFBody .= $this->getDataContentUnsupportedElement('title'); - } elseif($element instanceof PHPWord_Section_PageBreak) { + } elseif ($element instanceof PHPWord_Section_PageBreak) { $sRTFBody .= $this->getDataContentUnsupportedElement('page break'); - } elseif($element instanceof PHPWord_Section_Table) { + } elseif ($element instanceof PHPWord_Section_Table) { $sRTFBody .= $this->getDataContentUnsupportedElement('table'); - } elseif($element instanceof PHPWord_Section_ListItem) { + } elseif ($element instanceof PHPWord_Section_ListItem) { $sRTFBody .= $this->getDataContentUnsupportedElement('list item'); - } elseif($element instanceof PHPWord_Section_Image || + } elseif ($element instanceof PHPWord_Section_Image || $element instanceof PHPWord_Section_MemoryImage) { $sRTFBody .= $this->getDataContentUnsupportedElement('image'); - } elseif($element instanceof PHPWord_Section_Object) { + } elseif ($element instanceof PHPWord_Section_Object) { $sRTFBody .= $this->getDataContentUnsupportedElement('object'); - } elseif($element instanceof PHPWord_TOC) { + } elseif ($element instanceof PHPWord_TOC) { $sRTFBody .= $this->getDataContentUnsupportedElement('TOC'); } else { $sRTFBody .= $this->getDataContentUnsupportedElement('other'); diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 0fb54b2728..f132425332 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -29,9 +29,14 @@ /** * Class PHPWord_Writer_Word2007_Base */ -class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart { +class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart +{ - protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { + /** + * Write text + */ + protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) + { $styleFont = $text->getFontStyle(); $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; @@ -80,7 +85,11 @@ protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWor } } - protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) { + /** + * Write text run + */ + protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) + { $elements = $textrun->getElements(); $styleParagraph = $textrun->getParagraphStyle(); @@ -221,7 +230,11 @@ protected function _writeParagraphStyle( } } - protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) { + /** + * Write link + */ + protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) + { $rID = $link->getRelationId(); $linkName = $link->getLinkName(); if (is_null($linkName)) { @@ -276,7 +289,11 @@ protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWor } } - protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun) { + /** + * Write preserve text + */ + protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun) + { $styleFont = $textrun->getFontStyle(); $styleParagraph = $textrun->getParagraphStyle(); @@ -367,7 +384,11 @@ protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null $objWriter->endElement(); // p } - protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style) { + /** + * Write text style + */ + protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style) + { $font = $style->getName(); $bold = $style->getBold(); $italic = $style->getItalic(); @@ -454,11 +475,19 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P $objWriter->endElement(); } - protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) { + /** + * Write text break + */ + protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) + { $objWriter->writeElement('w:p', null); } - protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table) { + /** + * Write table + */ + protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table) + { $_rows = $table->getRows(); $_cRows = count($_rows); @@ -566,7 +595,11 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo } } - protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null) { + /** + * Write table style + */ + protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null) + { $margins = $style->getCellMargin(); $mTop = (!is_null($margins[0])) ? true : false; $mLeft = (!is_null($margins[1])) ? true : false; @@ -610,7 +643,11 @@ protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, } } - protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null) { + /** + * Write cell style + */ + protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null) + { $bgColor = $style->getBgColor(); $valign = $style->getVAlign(); $textDir = $style->getTextDirection(); @@ -716,7 +753,8 @@ protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, P * @param \PHPWord_Shared_XMLWriter $objWriter * @param \PHPWord_Section_Image $image */ - protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image, $withoutP = false) { + protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image, $withoutP = false) + { $rId = $image->getRelationId(); $style = $image->getStyle(); @@ -792,7 +830,11 @@ protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo } } - protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) { + /** + * Write watermark + */ + protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) + { $rId = $image->getRelationId(); $style = $image->getStyle(); @@ -835,7 +877,11 @@ protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $ $objWriter->endElement(); } - protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title) { + /** + * Write title + */ + protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title) + { $text = htmlspecialchars($title->getText()); $text = PHPWord_Shared_String::ControlCharacterPHP2OOXML($text); $anchor = $title->getAnchor(); @@ -876,6 +922,9 @@ protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->endElement(); } + /** + * Write footnote + */ protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote) { $objWriter->startElement('w:footnote'); @@ -911,6 +960,9 @@ protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PH $objWriter->endElement(); // w:footnote } + /** + * Write footnote reference + */ protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false) { if (!$withoutP) { diff --git a/Tests/PHPWord/Writer/Word2007/BaseTest.php b/Tests/PHPWord/Writer/Word2007/BaseTest.php index 130a20993e..56f859d9de 100644 --- a/Tests/PHPWord/Writer/Word2007/BaseTest.php +++ b/Tests/PHPWord/Writer/Word2007/BaseTest.php @@ -28,7 +28,7 @@ public function testWriteText() $PHPWord = new PHPWord(); $PHPWord->addFontStyle($rStyle, array('bold' => true)); - $PHPWord->addParagraphStyle($pStyle, array('align' => 'justify')); + $PHPWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); $section = $PHPWord->createSection(); $section->addText('Test', $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($PHPWord); @@ -45,7 +45,7 @@ public function testWriteText() public function testWriteTextRun() { $pStyle = 'pStyle'; - $aStyle = array('align' => 'justify'); + $aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120); $imageSrc = join( DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') @@ -66,6 +66,41 @@ public function testWriteTextRun() $this->assertTrue($doc->elementExists("{$parent}/w:pPr/w:pStyle[@w:val='{$pStyle}']")); } + /** + * Write link + */ + public function testWriteLink() + { + $PHPWord = new PHPWord(); + $section = $PHPWord->createSection(); + + $expected = 'PHPWord'; + $section->addLink('http://github.com/phpoffice/phpword', $expected); + + $doc = TestHelperDOCX::getDocument($PHPWord); + $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); + + $this->assertEquals($expected, $element->nodeValue); + } + + /** + * Write preserve text + */ + public function testWritePreserveText() + { + $PHPWord = new PHPWord(); + $section = $PHPWord->createSection(); + $footer = $section->createFooter(); + + $footer->addPreserveText('{PAGE}'); + + $doc = TestHelperDOCX::getDocument($PHPWord); + $preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml'); + + $this->assertEquals('PAGE', $preserve->nodeValue); + $this->assertEquals('preserve', $preserve->getAttribute('xml:space')); + } + /** * Write paragraph style: Alignment */ @@ -144,23 +179,6 @@ public function testWriteFontStyle() $this->assertEquals($styles['fgColor'], $doc->getElementAttribute("{$parent}/w:highlight", 'w:val')); } - /** - * Write link - */ - public function testWriteLink() - { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); - - $expected = 'PHPWord'; - $section->addLink('http://github.com/phpoffice/phpword', $expected); - - $doc = TestHelperDOCX::getDocument($PHPWord); - $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); - - $this->assertEquals($expected, $element->nodeValue); - } - /** * Write table */ @@ -272,20 +290,18 @@ public function testWriteImagePosition() } /** - * Write preserve text + * Write title */ - public function testWritePreserveText() + public function testWriteTitle() { $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); - $footer = $section->createFooter(); - - $footer->addPreserveText('{PAGE}'); - + $PHPWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); + $PHPWord->createSection()->addTitle('Test', 1); $doc = TestHelperDOCX::getDocument($PHPWord); - $preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml'); - $this->assertEquals('PAGE', $preserve->nodeValue); - $this->assertEquals('preserve', $preserve->getAttribute('xml:space')); + $element = "/w:document/w:body/w:p/w:pPr/w:pStyle"; + $this->assertEquals('Heading1', $doc->getElementAttribute($element, 'w:val')); + $element = "/w:document/w:body/w:p/w:r/w:fldChar"; + $this->assertEquals('end', $doc->getElementAttribute($element, 'w:fldCharType')); } } diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index add71ea99b..55ffaf2589 100755 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -7,13 +7,15 @@ // New Word Document echo date('H:i:s') , " Create new PHPWord object" , EOL; $PHPWord = new PHPWord(); -$PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16)); -$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100)); +$PHPWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16)); +$PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); +$PHPWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); // New portrait section $section = $PHPWord->createSection(); // Simple text +$section->addTitle('Welcome to PHPWord', 1); $section->addText('Hello World!'); // Two text break diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php index cc0a7ef670..8be721091c 100644 --- a/samples/Sample_10_EastAsianFontStyle.php +++ b/samples/Sample_10_EastAsianFontStyle.php @@ -1,13 +1,7 @@ '); -} - +define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once '../Classes/PHPWord.php'; // New Word Document @@ -18,13 +12,16 @@ //1.Use EastAisa FontStyle $section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); -// Save File -echo date('H:i:s') , ' Write to Word2007 format' , EOL; -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save(str_replace('.php', '.docx', __FILE__)); - -// Echo memory peak usage -echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} -// Echo done -echo date('H:i:s') , ' Done writing file' , EOL; +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;