From 8a1d07f71a7e8feba54f893a266e2a3b6dcf2f59 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 8 May 2014 22:42:56 +0700 Subject: [PATCH] Fix Travis test errors --- CHANGELOG.md | 2 +- composer.json | 4 ++-- src/PhpWord/Element/TextBox.php | 2 -- src/PhpWord/Style/AbstractStyle.php | 4 ++-- src/PhpWord/Style/Font.php | 3 +-- src/PhpWord/Style/NumberingLevel.php | 3 ++- src/PhpWord/Style/TextBox.php | 18 ++++++++++++++++++ src/PhpWord/Writer/ODText/Element/Table.php | 3 --- .../Writer/Word2007/Element/TextBox.php | 14 ++------------ .../Writer/Word2007/Element/TextRun.php | 2 -- src/PhpWord/Writer/Word2007/Part/Styles.php | 2 +- src/PhpWord/Writer/Word2007/Style/Table.php | 2 -- src/PhpWord/Writer/Word2007/Style/TextBox.php | 16 ++++++++++++++++ tests/PhpWord/Tests/Style/CellTest.php | 4 ++-- 14 files changed, 47 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b309236f..f23ca147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ This release changed PHPWord license from LGPL 2.1 to LGPL 3. - Refactor: PHPMD recommendation: Change all `get...` method that returns `boolean` into `is...` or `has...` - @ivanlanin - Docs: Create gh-pages branch for API documentation - @Progi1984 GH-154 - QA: Add `.scrutinizer.yml` and include `composer.lock` for preparation to Scrutinizer - @ivanlanin GH-186 -- Word2007 Writer: Refactor writer parts using composite pattern - @ivanlanin +- Writer: Refactor writer parts using composite pattern - @ivanlanin - Docs: Show code quality and test code coverage badge on README ## 0.10.0 - 4 May 2014 diff --git a/composer.json b/composer.json index 8396f073..a7b16860 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { "name": "phpoffice/phpword", - "description": "PHPWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP", + "description": "PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)", "keywords": [ "PHP", "PhpOffice", "office", "PhpWord", "word", "template", "reader", "writer", "docx", "OOXML", "OpenXML", "Office Open XML", "ISO IEC 29500", "WordprocessingML", - "RTF", "Rich Text Format", "doc", "odt", "OpenDocument" + "RTF", "Rich Text Format", "doc", "odt", "OpenDocument", "PDF", "HTML" ], "homepage": "http://phpoffice.github.io", "type": "library", diff --git a/src/PhpWord/Element/TextBox.php b/src/PhpWord/Element/TextBox.php index 041c2657..c3c83d81 100644 --- a/src/PhpWord/Element/TextBox.php +++ b/src/PhpWord/Element/TextBox.php @@ -36,8 +36,6 @@ class TextBox extends AbstractContainer /** * Create a new textbox * - * @param string $docPart - * @param integer $docPartId * @param mixed $style */ public function __construct($style = null) diff --git a/src/PhpWord/Style/AbstractStyle.php b/src/PhpWord/Style/AbstractStyle.php index e4fbb9a5..d909a20a 100644 --- a/src/PhpWord/Style/AbstractStyle.php +++ b/src/PhpWord/Style/AbstractStyle.php @@ -230,9 +230,9 @@ abstract class AbstractStyle */ protected function setEnumVal($value = null, $enum = array(), $default = null) { - if (!is_null($value) && !empty($enum) && !in_array($value, $enum)) { + if ($value != null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) { throw new \InvalidArgumentException('Invalid style value.'); - } elseif (is_null($value)) { + } elseif (is_null($value) || trim($value) == '') { $value = $default; } diff --git a/src/PhpWord/Style/Font.php b/src/PhpWord/Style/Font.php index 57d0770a..32874b2f 100644 --- a/src/PhpWord/Style/Font.php +++ b/src/PhpWord/Style/Font.php @@ -17,7 +17,6 @@ namespace PhpOffice\PhpWord\Style; -use PhpOffice\PhpWord\Exception\InvalidStyleException; use PhpOffice\PhpWord\PhpWord; /** @@ -652,7 +651,7 @@ class Font extends AbstractStyle /** * Toggle $target property to false when $source true * - * @param mixed $target Target property + * @param bool $target Target property * @param bool $sourceValue */ private function toggleFalse(&$target, $sourceValue) diff --git a/src/PhpWord/Style/NumberingLevel.php b/src/PhpWord/Style/NumberingLevel.php index be9b9b25..465231a7 100644 --- a/src/PhpWord/Style/NumberingLevel.php +++ b/src/PhpWord/Style/NumberingLevel.php @@ -377,10 +377,11 @@ class NumberingLevel extends AbstractStyle * @param string $value * @return self */ - public function setHint($value) + public function setHint($value = null) { $enum = array('default', 'eastAsia', 'cs'); $this->hint = $this->setEnumVal($value, $enum, $this->hint); + return $this; } } diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php index 401e2cc0..2beeaed1 100644 --- a/src/PhpWord/Style/TextBox.php +++ b/src/PhpWord/Style/TextBox.php @@ -169,6 +169,24 @@ class TextBox extends Image return array($this->innerMarginLeft, $this->innerMarginTop, $this->innerMarginRight, $this->innerMarginBottom); } + /** + * Has inner margin? + * + * @return bool + */ + public function hasInnerMargins() + { + $hasInnerMargins = false; + $margins = $this->getInnerMargins(); + for ($i = 0; $i < count($margins); $i++) { + if (!is_null($margins[$i])) { + $hasInnerMargins = true; + } + } + + return $hasInnerMargins; + } + /** * Set border size * diff --git a/src/PhpWord/Writer/ODText/Element/Table.php b/src/PhpWord/Writer/ODText/Element/Table.php index d8664fac..411f1f38 100644 --- a/src/PhpWord/Writer/ODText/Element/Table.php +++ b/src/PhpWord/Writer/ODText/Element/Table.php @@ -17,9 +17,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element; -use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement; -use PhpOffice\PhpWord\Writer\ODText\Element\Element as ElementWriter; - /** * Table element writer * diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php index 1ee8a4cb..d464b967 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php @@ -17,7 +17,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element; -use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\TextBox as TextBoxStyleWriter; /** @@ -35,11 +34,7 @@ class TextBox extends AbstractElement $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); $style = $element->getStyle(); - - if ($style instanceof TextBoxStyle) { - $styleWriter = new TextBoxStyleWriter($xmlWriter, $style); - $styleWriter->write(); - } + $styleWriter = new TextBoxStyleWriter($xmlWriter, $style); if (!$this->withoutP) { $xmlWriter->startElement('w:p'); @@ -57,20 +52,15 @@ class TextBox extends AbstractElement $xmlWriter->startElement('v:shape'); $xmlWriter->writeAttribute('type', '#_x0000_t0202'); $styleWriter->write(); - $xmlWriter->startElement('v:textbox'); - $margins = implode(', ', $style->getInnerMargin()); - $xmlWriter->writeAttribute('inset', $margins); - + $styleWriter->writeInnerMargin(); $xmlWriter->startElement('w:txbxContent'); $xmlWriter->startElement('w:p'); $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $xmlWriter->endElement(); // w:p $xmlWriter->endElement(); // w:txbxContent - $xmlWriter->endElement(); // v: textbox - $styleWriter->writeW10Wrap(); $xmlWriter->endElement(); // v:shape $xmlWriter->endElement(); // w:pict diff --git a/src/PhpWord/Writer/Word2007/Element/TextRun.php b/src/PhpWord/Writer/Word2007/Element/TextRun.php index 0343b16c..cb72ab18 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextRun.php +++ b/src/PhpWord/Writer/Word2007/Element/TextRun.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element; -use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; - /** * TextRun element writer * diff --git a/src/PhpWord/Writer/Word2007/Part/Styles.php b/src/PhpWord/Writer/Word2007/Part/Styles.php index 108e7a0e..13e07e71 100644 --- a/src/PhpWord/Writer/Word2007/Part/Styles.php +++ b/src/PhpWord/Writer/Word2007/Part/Styles.php @@ -62,7 +62,7 @@ class Styles extends AbstractPart // Font style if ($style instanceof Font) { - $paragraphStyle = $style->getParagraphStyle(); + $paragraphStyle = $style->getParagraph(); $styleType = $style->getStyleType(); $type = ($styleType == 'title') ? 'paragraph' : 'character'; if (!is_null($paragraphStyle)) { diff --git a/src/PhpWord/Writer/Word2007/Style/Table.php b/src/PhpWord/Writer/Word2007/Style/Table.php index 7be6e6ae..7c59fd03 100644 --- a/src/PhpWord/Writer/Word2007/Style/Table.php +++ b/src/PhpWord/Writer/Word2007/Style/Table.php @@ -94,8 +94,6 @@ class Table extends AbstractStyle /** * Write row style - * - * @param string $type */ private function writeFirstRow(\PhpOffice\PhpWord\Style\Table $style) { diff --git a/src/PhpWord/Writer/Word2007/Style/TextBox.php b/src/PhpWord/Writer/Word2007/Style/TextBox.php index ee9c74cc..6020a2b0 100644 --- a/src/PhpWord/Writer/Word2007/Style/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Style/TextBox.php @@ -48,6 +48,7 @@ class TextBox extends Image if (is_null($this->w10wrap)) { return; } + $style = $this->getStyle(); $relativePositions = array( TextBoxStyle::POSITION_RELATIVE_TO_MARGIN => 'margin', @@ -80,6 +81,21 @@ class TextBox extends Image $xmlWriter->endElement(); // w10:wrap } + /** + * Writer inner margin + */ + public function writeInnerMargin() + { + $style = $this->getStyle(); + if (!$style->hasInnerMargins()) { + return; + } + + $xmlWriter = $this->getXmlWriter(); + $margins = implode(', ', $style->getInnerMargin()); + $xmlWriter->writeAttribute('inset', $margins); + } + /** * Writer border */ diff --git a/tests/PhpWord/Tests/Style/CellTest.php b/tests/PhpWord/Tests/Style/CellTest.php index cb08cd2b..1a026710 100644 --- a/tests/PhpWord/Tests/Style/CellTest.php +++ b/tests/PhpWord/Tests/Style/CellTest.php @@ -35,7 +35,7 @@ class CellTest extends \PHPUnit_Framework_TestCase $object = new Cell(); $attributes = array( - 'valign' => 'left', + 'valign' => Cell::VALIGN_TOP, 'textDirection' => Cell::TEXT_DIR_BTLR, 'bgColor' => 'FFFF00', 'borderTopSize' => 120, @@ -47,7 +47,7 @@ class CellTest extends \PHPUnit_Framework_TestCase 'borderBottomSize' => 120, 'borderBottomColor' => 'FFFF00', 'gridSpan' => 2, - 'vMerge' => 2, + 'vMerge' => Cell::VMERGE_RESTART, ); foreach ($attributes as $key => $value) { $set = "set{$key}";