diff --git a/.travis.yml b/.travis.yml
index 713cc268df..65b9de9aa7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,14 +32,14 @@ before_script:
- pyrus install pear/PHP_CodeSniffer
- phpenv rehash
## PHP Copy/Paste Detector
- #- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
+ - curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
## PHP Mess Detector
- #- pear config-set preferred_state beta
- #- printf "\n" | pecl install imagick
- #- pear channel-discover pear.phpmd.org
- #- pear channel-discover pear.pdepend.org
- #- pear install --alldeps phpmd/PHP_PMD
- #- phpenv rehash
+ - pear config-set preferred_state beta
+ - printf "\n" | pecl install imagick
+ - pear channel-discover pear.phpmd.org
+ - pear channel-discover pear.pdepend.org
+ - pear install --alldeps phpmd/PHP_PMD
+ - phpenv rehash
## PHPLOC
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
## PHPDocumentor
@@ -48,18 +48,17 @@ before_script:
script:
## PHP_CodeSniffer
- - phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip
- - phpcs --standard=PSR2 -n tests/
+ - phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
## PHP Copy/Paste Detector
- #- php phpcpd.phar --verbose src/
+ - php phpcpd.phar src/ tests/ --verbose
## PHP Mess Detector
- #- phpmd src/ text unusedcode,naming,design
+ - phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
## PHPLOC
#- php phploc.phar src/
## PHPUnit
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage
## PHPDocumentor
- - vendor/bin/phpdoc.php -d ./src -t ./build/docs
+ - vendor/bin/phpdoc.php -d ./src -t ./build/docs -i ./src/PhpWord/Shared/PCLZip/*
after_script:
## PHPDocumentor
diff --git a/.travis_shell_after_success.sh b/.travis_shell_after_success.sh
index 308388d7f5..35c7a338b9 100644
--- a/.travis_shell_after_success.sh
+++ b/.travis_shell_after_success.sh
@@ -31,7 +31,7 @@ if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPWord" ] && [ "$TRAVIS_PULL_REQUEST" ==
echo "--DEBUG : Git"
git add -f .
- git commit -m "PHPDocumentor (Travis Build : $TRAVIS_BUILD_NUMBER - Branch : $TRAVIS_BRANCH)"
+ git commit -m "PHPDocumentor (Travis Build: $TRAVIS_BUILD_NUMBER - Branch: $TRAVIS_BRANCH)"
git push -fq origin gh-pages > /dev/null
echo -e "Published PHPDoc to gh-pages.\n"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff717ebb0d..64804690ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
## 0.11.0 - Not yet released
-PHPWord license is changed from LGPL 2.1 to LGPL 3 in this release.
+This release changed PHPWord license from LGPL 2.1 to LGPL 3.
### Features
@@ -14,10 +14,17 @@ PHPWord license is changed from LGPL 2.1 to LGPL 3 in this release.
- ...
+### Deprecated
+
+- Static classes `Footnotes`, `Endnotes`, and `TOC`
+
### Miscellaneous
- License: Change the project license from LGPL 2.1 into LGPL 3.0 - GH-211
- Word2007 Writer: New `Style\Image` class - @ivanlanin
+- Refactor: Replace static classes `Footnotes`, `Endnotes`, and `TOC` with `Collections` - @ivanlanin GH-206
+- QA: Reactivate `phpcpd` and `phpmd` on Travis - @ivanlanin
+- Refactor: PHPMD recommendation: Change all `get...` method that returns `boolean` into `is...` or `has...` - @ivanlanin
## 0.10.0 - 4 May 2014
@@ -43,7 +50,7 @@ This release marked heavy refactorings on internal code structure with the creat
- Link: Ability to add link in header/footer - @ivanlanin GH-187
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
-- General: Add `Style::resetStyles()`, `Footnote::resetElements()`, and `TOC::resetTitles()` - @ivanlanin GH-187
+- General: Add `Style::resetStyles()` - @ivanlanin GH-187
- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
- Endnote: Ability to add endnotes - @ivanlanin
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
diff --git a/phpmd.xml b/phpmd.xml
deleted file mode 100644
index c1ebb770d3..0000000000
--- a/phpmd.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index f77b9ce362..ce823a545b 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -21,4 +21,7 @@
+
+
+
\ No newline at end of file
diff --git a/samples/resources/Sample_11_ReadWord2007.docx b/samples/resources/Sample_11_ReadWord2007.docx
index 2143c628c5..aefe9f485e 100644
Binary files a/samples/resources/Sample_11_ReadWord2007.docx and b/samples/resources/Sample_11_ReadWord2007.docx differ
diff --git a/src/PhpWord/Collection/AbstractCollection.php b/src/PhpWord/Collection/AbstractCollection.php
new file mode 100644
index 0000000000..7b5d4579bc
--- /dev/null
+++ b/src/PhpWord/Collection/AbstractCollection.php
@@ -0,0 +1,87 @@
+items;
+ }
+
+ /**
+ * Get item by index
+ *
+ * @param int $index
+ * @return mixed
+ */
+ public function getItem($index)
+ {
+ if (array_key_exists($index, $this->items)) {
+ return $this->items[$index];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Set item
+ *
+ * @param int $index
+ * @param mixed $item
+ */
+ public function setItem($index, $item)
+ {
+ if (array_key_exists($index, $this->items)) {
+ $this->items[$index] = $item;
+ }
+ }
+
+ /**
+ * Add new item
+ *
+ * @param mixed $item
+ * @return int
+ */
+ public function addItem($item)
+ {
+ $index = $this->countItems() + 1;
+ $this->items[$index] = $item;
+
+ return $index;
+ }
+
+ /**
+ * Get item count
+ *
+ * @return int
+ */
+ public function countItems()
+ {
+ return count($this->items);
+ }
+}
diff --git a/src/PhpWord/Collection/Endnotes.php b/src/PhpWord/Collection/Endnotes.php
new file mode 100644
index 0000000000..36c547a320
--- /dev/null
+++ b/src/PhpWord/Collection/Endnotes.php
@@ -0,0 +1,19 @@
+setElementIndex($this->countElements() + 1);
$element->setElementId();
+ $element->setPhpWord($this->phpWord);
$this->elements[] = $element;
}
@@ -62,99 +67,71 @@ public function countElements()
}
/**
- * Add text element
+ * Add text/preservetext element
*
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
- * @return Text
+ * @param string $elementName Text|PreserveText
+ * @return \PhpOffice\PhpWord\Element\Text|\PhpOffice\PhpWord\Element\PreserveText
*/
- public function addText($text, $fontStyle = null, $paragraphStyle = null)
+ public function addText($text, $fontStyle = null, $paragraphStyle = null, $elementName = 'Text')
{
- $this->checkValidity('text');
+ $this->checkValidity($elementName);
+ $elementClass = 'PhpOffice\\PhpWord\\Element\\' . $elementName;
// Reset paragraph style for footnote and textrun. They have their own
if (in_array($this->container, array('textrun', 'footnote', 'endnote'))) {
$paragraphStyle = null;
}
- $text = String::toUTF8($text);
- $textObject = new Text($text, $fontStyle, $paragraphStyle);
- $textObject->setDocPart($this->getDocPart(), $this->getDocPartId());
- $this->addElement($textObject);
+ $element = new $elementClass($text, $fontStyle, $paragraphStyle);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->addElement($element);
- return $textObject;
+ return $element;
}
/**
* Add textrun element
*
* @param mixed $paragraphStyle
- * @return TextRun
+ * @return \PhpOffice\PhpWord\Element\TextRun
*/
public function addTextRun($paragraphStyle = null)
{
- $this->checkValidity('textrun');
+ $this->checkValidity('Textrun');
- $textRun = new TextRun($paragraphStyle);
- $textRun->setDocPart($this->getDocPart(), $this->getDocPartId());
- $this->addElement($textRun);
+ $element = new TextRun($paragraphStyle);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->addElement($element);
- return $textRun;
+ return $element;
}
/**
* Add link element
*
- * @param string $linkSrc
- * @param string $linkName
+ * @param string $target
+ * @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
- * @return Link
+ * @return \PhpOffice\PhpWord\Element\Link
*/
- public function addLink($linkSrc, $linkName = null, $fontStyle = null, $paragraphStyle = null)
+ public function addLink($target, $text = null, $fontStyle = null, $paragraphStyle = null)
{
- $this->checkValidity('link');
+ $this->checkValidity('Link');
$elementDocPart = $this->checkElementDocPart();
- $link = new Link(String::toUTF8($linkSrc), String::toUTF8($linkName), $fontStyle, $paragraphStyle);
- $link->setDocPart($this->getDocPart(), $this->getDocPartId());
- $rId = Media::addElement($elementDocPart, 'link', $linkSrc);
- $link->setRelationId($rId);
- $this->addElement($link);
+ $element = new Link($target, $text, $fontStyle, $paragraphStyle);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
- return $link;
- }
+ $rId = Media::addElement($elementDocPart, 'link', $target);
+ $element->setRelationId($rId);
- /**
- * Add a Title Element
- *
- * @param string $text
- * @param int $depth
- * @return Title
- * @todo Enable title element in other containers
- */
- public function addTitle($text, $depth = 1)
- {
- $this->checkValidity('title');
+ $this->addElement($element);
- $styles = Style::getStyles();
- if (array_key_exists('Heading_' . $depth, $styles)) {
- $style = 'Heading' . $depth;
- } else {
- $style = null;
- }
- $text = String::toUTF8($text);
- $title = new Title($text, $depth, $style);
- $title->setDocPart($this->getDocPart(), $this->getDocPartId());
- $data = Titles::addTitle($text, $depth);
- $anchor = $data[0];
- $bookmarkId = $data[1];
- $title->setAnchor($anchor);
- $title->setBookmarkId($bookmarkId);
- $this->addElement($title);
-
- return $title;
+ return $element;
}
/**
@@ -163,17 +140,11 @@ public function addTitle($text, $depth = 1)
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
- * @return PreserveText
+ * @return \PhpOffice\PhpWord\Element\PreserveText
*/
public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null)
{
- $this->checkValidity('preservetext');
-
- $preserveText = new PreserveText(String::toUTF8($text), $fontStyle, $paragraphStyle);
- $preserveText->setDocPart($this->getDocPart(), $this->getDocPartId());
- $this->addElement($preserveText);
-
- return $preserveText;
+ return $this->addText($text, $fontStyle, $paragraphStyle, 'PreserveText');
}
/**
@@ -185,12 +156,12 @@ public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
- $this->checkValidity('textbreak');
+ $this->checkValidity('TextBreak');
for ($i = 1; $i <= $count; $i++) {
- $textBreak = new TextBreak($fontStyle, $paragraphStyle);
- $textBreak->setDocPart($this->getDocPart(), $this->getDocPartId());
- $this->addElement($textBreak);
+ $element = new TextBreak($fontStyle, $paragraphStyle);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->addElement($element);
}
}
@@ -200,56 +171,43 @@ public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = nu
* @param string $text
* @param int $depth
* @param mixed $fontStyle
- * @param mixed $styleList
+ * @param mixed $listStyle
* @param mixed $paragraphStyle
- * @return ListItem
+ * @return \PhpOffice\PhpWord\Element\ListItem
*/
- public function addListItem($text, $depth = 0, $fontStyle = null, $styleList = null, $paragraphStyle = null)
+ public function addListItem($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
{
- $this->checkValidity('listitem');
+ $this->checkValidity('ListItem');
- $listItem = new ListItem(String::toUTF8($text), $depth, $fontStyle, $styleList, $paragraphStyle);
- $listItem->setDocPart($this->getDocPart(), $this->getDocPartId());
- $this->addElement($listItem);
+ $element = new ListItem($text, $depth, $fontStyle, $listStyle, $paragraphStyle);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->addElement($element);
- return $listItem;
- }
-
- /**
- * Add table element
- *
- * @param mixed $style
- * @return Table
- */
- public function addTable($style = null)
- {
- $this->checkValidity('table');
-
- $table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
- $this->addElement($table);
-
- return $table;
+ return $element;
}
/**
* Add image element
*
- * @param string $src
+ * @param string $source
* @param mixed $style Image style
* @param boolean $isWatermark
- * @return Image
+ * @return \PhpOffice\PhpWord\Element\Image
*/
- public function addImage($src, $style = null, $isWatermark = false)
+ public function addImage($source, $style = null, $isWatermark = false)
{
- $this->checkValidity('image');
+ $this->checkValidity('Image');
$elementDocPart = $this->checkElementDocPart();
- $image = new Image($src, $style, $isWatermark);
- $image->setDocPart($this->getDocPart(), $this->getDocPartId());
- $rId = Media::addElement($elementDocPart, 'image', $src, $image);
- $image->setRelationId($rId);
- $this->addElement($image);
- return $image;
+ $element = new Image($source, $style, $isWatermark);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
+
+ $rId = Media::addElement($elementDocPart, 'image', $source, $element);
+ $element->setRelationId($rId);
+
+ $this->addElement($element);
+
+ return $element;
}
/**
@@ -257,76 +215,63 @@ public function addImage($src, $style = null, $isWatermark = false)
*
* All exceptions should be handled by \PhpOffice\PhpWord\Element\Object
*
- * @param string $src
+ * @param string $source
* @param mixed $style
- * @return Object
+ * @return \PhpOffice\PhpWord\Element\Object
* @throws \PhpOffice\PhpWord\Exception\Exception
- * @todo Enable OLE object element in header and footer
*/
- public function addObject($src, $style = null)
+ public function addObject($source, $style = null)
{
- $this->checkValidity('object');
+ $this->checkValidity('Object');
$elementDocPart = $this->checkElementDocPart();
- $object = new Object($src, $style);
- $object->setDocPart($this->getDocPart(), $this->getDocPartId());
- if (!is_null($object->getSource())) {
- $inf = pathinfo($src);
- $ext = $inf['extension'];
- if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
- $ext = substr($ext, 0, -1);
- }
- $icon = realpath(__DIR__ . "/../resources/{$ext}.png");
- $rId = Media::addElement($elementDocPart, 'object', $src);
- $object->setRelationId($rId);
- $rIdimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));
- $object->setImageRelationId($rIdimg);
- $this->addElement($object);
-
- return $object;
- } else {
- throw new InvalidObjectException();
- }
+ $element = new Object($source, $style);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
+
+ $rId = Media::addElement($elementDocPart, 'object', $source);
+ $element->setRelationId($rId);
+ $rIdIcon = Media::addElement($elementDocPart, 'image', $element->getIcon(), new Image($element->getIcon()));
+ $element->setImageRelationId($rIdIcon);
+
+ $this->addElement($element);
+
+ return $element;
}
/**
* Add footnote element
*
* @param mixed $paragraphStyle
- * @return Footnote
+ * @param string $elementName
+ * @return \PhpOffice\PhpWord\Element\Footnote
*/
- public function addFootnote($paragraphStyle = null)
+ public function addFootnote($paragraphStyle = null, $elementName = 'Footnote')
{
- $this->checkValidity('footnote');
-
- $footnote = new Footnote($paragraphStyle);
- $rId = Footnotes::addElement($footnote);
-
- $footnote->setDocPart('footnote', $this->getDocPartId());
- $footnote->setRelationId($rId);
- $this->addElement($footnote);
+ $this->checkValidity($elementName);
+ $elementClass = 'PhpOffice\\PhpWord\\Element\\' . $elementName;
+ $docPart = strtolower($elementName);
+ $addMethod = "add{$elementName}";
+
+ $element = new $elementClass($paragraphStyle);
+ if ($this->phpWord instanceof PhpWord) {
+ $rId = $this->phpWord->$addMethod($element);
+ }
+ $element->setDocPart($docPart, $this->getDocPartId());
+ $element->setRelationId($rId);
+ $this->addElement($element);
- return $footnote;
+ return $element;
}
/**
* Add endnote element
*
* @param mixed $paragraphStyle
- * @return Endnote
+ * @return \PhpOffice\PhpWord\Element\Endnote
*/
public function addEndnote($paragraphStyle = null)
{
- $this->checkValidity('endnote');
-
- $endnote = new Endnote($paragraphStyle);
- $rId = Endnotes::addElement($endnote);
-
- $endnote->setDocPart('endnote', $this->getDocPartId());
- $endnote->setRelationId($rId);
- $this->addElement($endnote);
-
- return $endnote;
+ return $this->addFootnote($paragraphStyle, 'Endnote');
}
/**
@@ -336,17 +281,17 @@ public function addEndnote($paragraphStyle = null)
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
- * @return CheckBox
+ * @return \PhpOffice\PhpWord\Element\CheckBox
*/
public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = null)
{
- $this->checkValidity('checkbox');
+ $this->checkValidity('CheckBox');
- $checkBox = new CheckBox(String::toUTF8($name), String::toUTF8($text), $fontStyle, $paragraphStyle);
- $checkBox->setDocPart($this->getDocPart(), $this->getDocPartId());
- $this->addElement($checkBox);
+ $element = new CheckBox($name, $text, $fontStyle, $paragraphStyle);
+ $element->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->addElement($element);
- return $checkBox;
+ return $element;
}
/**
@@ -360,26 +305,24 @@ private function checkValidity($method)
// Valid containers for each element
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote');
$validContainers = array(
- 'text' => $allContainers,
- 'link' => $allContainers,
- 'textbreak' => $allContainers,
- 'image' => $allContainers,
- 'object' => $allContainers,
- 'textrun' => array('section', 'header', 'footer', 'cell'),
- 'listitem' => array('section', 'header', 'footer', 'cell'),
- 'checkbox' => array('section', 'header', 'footer', 'cell'),
- 'table' => array('section', 'header', 'footer'),
- 'footnote' => array('section', 'textrun', 'cell'),
- 'endnote' => array('section', 'textrun', 'cell'),
- 'preservetext' => array('header', 'footer', 'cell'),
- 'title' => array('section'),
+ 'Text' => $allContainers,
+ 'Link' => $allContainers,
+ 'TextBreak' => $allContainers,
+ 'Image' => $allContainers,
+ 'Object' => $allContainers,
+ 'TextRun' => array('section', 'header', 'footer', 'cell'),
+ 'ListItem' => array('section', 'header', 'footer', 'cell'),
+ 'CheckBox' => array('section', 'header', 'footer', 'cell'),
+ 'Footnote' => array('section', 'textrun', 'cell'),
+ 'Endnote' => array('section', 'textrun', 'cell'),
+ 'PreserveText' => array('header', 'footer', 'cell'),
);
// Special condition, e.g. preservetext can only exists in cell when
// the cell is located in header or footer
$validSubcontainers = array(
- 'preservetext' => array(array('cell'), array('header', 'footer')),
- 'footnote' => array(array('cell', 'textrun'), array('section')),
- 'endnote' => array(array('cell', 'textrun'), array('section')),
+ 'PreserveText' => array(array('cell'), array('header', 'footer')),
+ 'Footnote' => array(array('cell', 'textrun'), array('section')),
+ 'Endnote' => array(array('cell', 'textrun'), array('section')),
);
// Check if a method is valid for current container
@@ -412,7 +355,7 @@ private function checkElementDocPart()
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
- $docPartId = $inHeaderFooter ? $this->getDocPartId() : $docPartId;
+
return $inHeaderFooter ? $docPart . $docPartId : $docPart;
}
diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php
index 14d1bcc04f..9c0a48c49a 100644
--- a/src/PhpWord/Element/AbstractElement.php
+++ b/src/PhpWord/Element/AbstractElement.php
@@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style;
/**
@@ -18,6 +19,11 @@
*/
abstract class AbstractElement
{
+ /**
+ * PhpWord object
+ */
+ protected $phpWord;
+
/**
* Container type section|header|footer|cell|textrun|footnote|endnote
*
@@ -75,6 +81,26 @@ abstract class AbstractElement
*/
protected $relationId;
+ /**
+ * Get PhpWord
+ *
+ * @return \PhpOffice\PhpWord\PhpWord
+ */
+ public function getPhpWord()
+ {
+ return $this->phpWord;
+ }
+
+ /**
+ * Set PhpWord as reference
+ *
+ * @param \PhpOffice\PhpWord\PhpWord
+ */
+ public function setPhpWord(PhpWord &$phpWord = null)
+ {
+ $this->phpWord = &$phpWord;
+ }
+
/**
* Get section number
*
diff --git a/src/PhpWord/Element/CheckBox.php b/src/PhpWord/Element/CheckBox.php
index d078f52c82..e47a8342c5 100644
--- a/src/PhpWord/Element/CheckBox.php
+++ b/src/PhpWord/Element/CheckBox.php
@@ -9,6 +9,8 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Shared\String;
+
/**
* Check box element
*/
@@ -44,7 +46,7 @@ public function __construct($name = null, $text = null, $fontStyle = null, $para
*/
public function setName($name)
{
- $this->name = $name;
+ $this->name = String::toUTF8($name);
return $this;
}
diff --git a/src/PhpWord/Element/Footer.php b/src/PhpWord/Element/Footer.php
index 3f64a9b23e..77f36f6bfb 100644
--- a/src/PhpWord/Element/Footer.php
+++ b/src/PhpWord/Element/Footer.php
@@ -9,35 +9,49 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Element\Table;
+
/**
* Footer element
*/
class Footer extends AbstractContainer
{
+ /**
+ * Header/footer types constants
+ *
+ * @var string
+ * @link http://www.schemacentral.com/sc/ooxml/a-wtype-4.html Header or Footer Type
+ */
const AUTO = 'default'; // default and odd pages
const FIRST = 'first';
const EVEN = 'even';
+ /**
+ * Container type
+ *
+ * @var string
+ */
+ protected $container = 'footer';
+
/**
* Header type
*
* @var string
*/
- private $type = self::AUTO;
+ protected $type = self::AUTO;
/**
* Create new instance
*
* @param int $sectionId
- * @param int $footerId
+ * @param int $containerId
* @param string $type
*/
- public function __construct($sectionId, $footerId = 1, $type = self::AUTO)
+ public function __construct($sectionId, $containerId = 1, $type = self::AUTO)
{
- $this->container = 'footer';
$this->sectionId = $sectionId;
$this->setType($type);
- $this->setDocPart($this->container, ($sectionId - 1) * 3 + $footerId);
+ $this->setDocPart($this->container, ($sectionId - 1) * 3 + $containerId);
}
/**
@@ -48,6 +62,9 @@ public function __construct($sectionId, $footerId = 1, $type = self::AUTO)
*/
public function setType($value = self::AUTO)
{
+ if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) {
+ $value = self::AUTO;
+ }
$this->type = $value;
}
@@ -61,4 +78,49 @@ public function getType()
{
return $this->type;
}
+
+ /**
+ * Reset type to default
+ *
+ * @return string
+ */
+ public function resetType()
+ {
+ return $this->type = self::AUTO;
+ }
+
+ /**
+ * First page only header
+ *
+ * @return string
+ */
+ public function firstPage()
+ {
+ return $this->type = self::FIRST;
+ }
+
+ /**
+ * Even numbered pages only
+ *
+ * @return string
+ */
+ public function evenPage()
+ {
+ return $this->type = self::EVEN;
+ }
+
+ /**
+ * Add table element
+ *
+ * @param mixed $style
+ * @return \PhpOffice\PhpWord\Element\Table
+ * @todo Merge with the same function on Section
+ */
+ public function addTable($style = null)
+ {
+ $table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
+ $this->addElement($table);
+
+ return $table;
+ }
}
diff --git a/src/PhpWord/Element/Header.php b/src/PhpWord/Element/Header.php
index 609b109213..db0d2d6b64 100644
--- a/src/PhpWord/Element/Header.php
+++ b/src/PhpWord/Element/Header.php
@@ -12,39 +12,15 @@
/**
* Header element
*/
-class Header extends AbstractContainer
+class Header extends Footer
{
- /**
- * Header types constants
- *
- * @var string
- * @link http://www.schemacentral.com/sc/ooxml/a-wtype-4.html Header or Footer Type
- */
- const AUTO = 'default'; // default and odd pages
- const FIRST = 'first';
- const EVEN = 'even';
/**
- * Header type
+ * Container type
*
* @var string
*/
- private $type = self::AUTO;
-
- /**
- * Create new instance
- *
- * @param int $sectionId
- * @param int $headerId
- * @param string $type
- */
- public function __construct($sectionId, $headerId = 1, $type = self::AUTO)
- {
- $this->container = 'header';
- $this->sectionId = $sectionId;
- $this->setType($type);
- $this->setDocPart($this->container, ($sectionId - 1) * 3 + $headerId);
- }
+ protected $container = 'header';
/**
* Add a Watermark Element
@@ -57,58 +33,4 @@ public function addWatermark($src, $style = null)
{
return $this->addImage($src, $style, true);
}
-
- /**
- * Set header type
- *
- * @param string $value
- * @since 0.10.0
- */
- public function setType($value = self::AUTO)
- {
- if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) {
- $value = self::AUTO;
- }
- $this->type = $value;
- }
-
- /**
- * Get header type
- *
- * @return string
- */
- public function getType()
- {
- return $this->type;
- }
-
- /**
- * Reset type to default
- *
- * @return string
- */
- public function resetType()
- {
- return $this->type = self::AUTO;
- }
-
- /**
- * First page only header
- *
- * @return string
- */
- public function firstPage()
- {
- return $this->type = self::FIRST;
- }
-
- /**
- * Even numbered pages only
- *
- * @return string
- */
- public function evenPage()
- {
- return $this->type = self::EVEN;
- }
}
diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php
index 9904710ce2..0d90479ff0 100644
--- a/src/PhpWord/Element/Image.php
+++ b/src/PhpWord/Element/Image.php
@@ -52,7 +52,7 @@ class Image extends AbstractElement
*
* @var boolean
*/
- private $isWatermark;
+ private $watermark;
/**
* Image type
@@ -87,7 +87,7 @@ class Image extends AbstractElement
*
* @var boolean
*/
- private $isMemImage;
+ private $memoryImage;
/**
* Image target file name
@@ -108,14 +108,14 @@ class Image extends AbstractElement
*
* @param string $source
* @param mixed $style
- * @param boolean $isWatermark
+ * @param boolean $watermark
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
- public function __construct($source, $style = null, $isWatermark = false)
+ public function __construct($source, $style = null, $watermark = false)
{
$this->source = $source;
- $this->setIsWatermark($isWatermark);
+ $this->setIsWatermark($watermark);
$this->style = $this->setStyle(new ImageStyle(), $style, true);
$this->checkImage($source);
@@ -166,19 +166,19 @@ public function getMediaId()
*
* @return boolean
*/
- public function getIsWatermark()
+ public function isWatermark()
{
- return $this->isWatermark;
+ return $this->watermark;
}
/**
* Set is watermark
*
- * @param boolean $pValue
+ * @param boolean $value
*/
- public function setIsWatermark($pValue)
+ public function setIsWatermark($value)
{
- $this->isWatermark = $pValue;
+ $this->watermark = $value;
}
/**
@@ -226,9 +226,9 @@ public function getImageExtension()
*
* @return boolean
*/
- public function getIsMemImage()
+ public function isMemImage()
{
- return $this->isMemImage;
+ return $this->memoryImage;
}
/**
@@ -314,14 +314,14 @@ private function checkImage($source)
private function setSourceType($source)
{
if (stripos(strrev($source), strrev('.php')) === 0) {
- $this->isMemImage = true;
+ $this->memoryImage = true;
$this->sourceType = self::SOURCE_GD;
} elseif (strpos($source, 'zip://') !== false) {
- $this->isMemImage = false;
+ $this->memoryImage = false;
$this->sourceType = self::SOURCE_ARCHIVE;
} else {
- $this->isMemImage = (filter_var($source, FILTER_VALIDATE_URL) !== false);
- $this->sourceType = $this->isMemImage ? self::SOURCE_GD : self::SOURCE_LOCAL;
+ $this->memoryImage = (filter_var($source, FILTER_VALIDATE_URL) !== false);
+ $this->sourceType = $this->memoryImage ? self::SOURCE_GD : self::SOURCE_LOCAL;
}
}
@@ -409,4 +409,26 @@ private function setProportionalSize($actualWidth, $actualHeight)
}
}
}
+
+ /**
+ * Get is watermark
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getIsWatermark()
+ {
+ return $this->isWatermark();
+ }
+
+ /**
+ * Get is memory image
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getIsMemImage()
+ {
+ return $this->isMemImage();
+ }
}
diff --git a/src/PhpWord/Element/Link.php b/src/PhpWord/Element/Link.php
index 21d6d7a60c..4b09fab7fe 100644
--- a/src/PhpWord/Element/Link.php
+++ b/src/PhpWord/Element/Link.php
@@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -56,8 +57,8 @@ class Link extends AbstractElement
*/
public function __construct($target, $text = null, $fontStyle = null, $paragraphStyle = null)
{
- $this->target = $target;
- $this->text = is_null($text) ? $target : $text;
+ $this->target = String::toUTF8($target);
+ $this->text = is_null($text) ? $this->target : String::toUTF8($text);
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
diff --git a/src/PhpWord/Element/ListItem.php b/src/PhpWord/Element/ListItem.php
index d63ebc096b..74af97b5af 100644
--- a/src/PhpWord/Element/ListItem.php
+++ b/src/PhpWord/Element/ListItem.php
@@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
@@ -49,7 +50,7 @@ class ListItem extends AbstractElement
*/
public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
{
- $this->textObject = new Text($text, $fontStyle, $paragraphStyle);
+ $this->textObject = new Text(String::toUTF8($text), $fontStyle, $paragraphStyle);
$this->depth = $depth;
// Version >= 0.10.0 will pass numbering style name. Older version will use old method
diff --git a/src/PhpWord/Element/Object.php b/src/PhpWord/Element/Object.php
index ffe33dbf27..3b249cb727 100644
--- a/src/PhpWord/Element/Object.php
+++ b/src/PhpWord/Element/Object.php
@@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
+use PhpOffice\PhpWord\Exception\InvalidObjectException;
/**
* Object element
@@ -30,6 +31,13 @@ class Object extends AbstractElement
*/
private $style;
+ /**
+ * Icon
+ *
+ * @var string
+ */
+ private $icon;
+
/**
* Image Relation ID
*
@@ -40,25 +48,42 @@ class Object extends AbstractElement
/**
* Create a new Ole-Object Element
*
- * @param string $src
+ * @param string $source
* @param mixed $style
*/
- public function __construct($src, $style = null)
+ public function __construct($source, $style = null)
{
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
- $inf = pathinfo($src);
+ $pathInfo = pathinfo($source);
- if (file_exists($src) && in_array($inf['extension'], $supportedTypes)) {
- $this->source = $src;
+ if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
+ $ext = $pathInfo['extension'];
+ if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
+ $ext = substr($ext, 0, -1);
+ }
+
+ $this->source = $source;
$this->style = $this->setStyle(new ImageStyle(), $style, true);
+ $this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
+
return $this;
} else {
- return false;
+ throw new InvalidObjectException();
}
}
/**
- * Get Image style
+ * Get object source
+ *
+ * @return string
+ */
+ public function getSource()
+ {
+ return $this->source;
+ }
+
+ /**
+ * Get object style
*
* @return \PhpOffice\PhpWord\Style\Image
*/
@@ -68,17 +93,17 @@ public function getStyle()
}
/**
- * Get Source
+ * Get object icon
*
* @return string
*/
- public function getSource()
+ public function getIcon()
{
- return $this->source;
+ return $this->icon;
}
/**
- * Get Image Relation ID
+ * Get image relation ID
*
* @return int
*/
diff --git a/src/PhpWord/Element/PreserveText.php b/src/PhpWord/Element/PreserveText.php
index 214f191af4..90bddb6fe0 100644
--- a/src/PhpWord/Element/PreserveText.php
+++ b/src/PhpWord/Element/PreserveText.php
@@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -52,7 +53,8 @@ public function __construct($text = null, $fontStyle = null, $paragraphStyle = n
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
- $matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+ $this->text = String::toUTF8($text);
+ $matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) {
$this->text = $matches;
}
diff --git a/src/PhpWord/Element/Row.php b/src/PhpWord/Element/Row.php
index 45e351a9f6..85ffb6acf0 100644
--- a/src/PhpWord/Element/Row.php
+++ b/src/PhpWord/Element/Row.php
@@ -63,6 +63,7 @@ public function __construct($docPart, $docPartId, $height = null, $style = null)
public function addCell($width = null, $style = null)
{
$cell = new Cell($this->getDocPart(), $this->getDocPartId(), $width, $style);
+ $cell->setPhpWord($this->phpWord);
$this->cells[] = $cell;
return $cell;
}
diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php
index 11ecef4b60..af253f034b 100644
--- a/src/PhpWord/Element/Section.php
+++ b/src/PhpWord/Element/Section.php
@@ -9,7 +9,12 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Element\PageBreak;
+use PhpOffice\PhpWord\Element\TOC;
+use PhpOffice\PhpWord\Element\Table;
+use PhpOffice\PhpWord\Element\Title;
use PhpOffice\PhpWord\Exception\Exception;
+use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Section as SectionSettings;
/**
@@ -80,12 +85,47 @@ public function getSettings()
return $this->settings;
}
+ /**
+ * Add a Title Element
+ *
+ * @param string $text
+ * @param int $depth
+ * @return \PhpOffice\PhpWord\Element\Title
+ */
+ public function addTitle($text, $depth = 1)
+ {
+ $title = new Title($text, $depth);
+ $title->setDocPart($this->getDocPart(), $this->getDocPartId());
+ if ($this->phpWord instanceof PhpWord) {
+ $bookmarkId = $this->phpWord->addTitle($title);
+ $title->setBookmarkId($bookmarkId);
+ }
+ $this->addElement($title);
+
+ return $title;
+ }
+
/**
* Add a PageBreak Element
*/
public function addPageBreak()
{
- $this->elements[] = new PageBreak();
+ $this->addElement(new PageBreak());
+ }
+
+ /**
+ * Add table element
+ *
+ * @param mixed $style
+ * @return \PhpOffice\PhpWord\Element\Table
+ * @todo Merge with the same function on Footer
+ */
+ public function addTable($style = null)
+ {
+ $table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
+ $this->addElement($table);
+
+ return $table;
}
/**
@@ -100,7 +140,8 @@ public function addPageBreak()
public function addTOC($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
{
$toc = new TOC($fontStyle, $tocStyle, $minDepth, $maxDepth);
- $this->elements[] = $toc;
+ $this->addElement($toc);
+
return $toc;
}
@@ -185,6 +226,8 @@ private function addHeaderFooter($type = Header::AUTO, $header = true)
if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
$index = count($collection);
$container = new $containerClass($this->sectionId, ++$index, $type);
+ $container->setPhpWord($this->phpWord);
+
$collection[$index] = $container;
return $container;
} else {
diff --git a/src/PhpWord/Element/TOC.php b/src/PhpWord/Element/TOC.php
index 5efaa5f08f..3c8e6386e8 100644
--- a/src/PhpWord/Element/TOC.php
+++ b/src/PhpWord/Element/TOC.php
@@ -4,14 +4,14 @@
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
- * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
+ * @license http://www.gnu.org/licenses/lgpl.txt LGPL
*/
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
-use PhpOffice\PhpWord\TOC as Titles;
/**
* Table of contents
@@ -87,16 +87,20 @@ public function __construct($fontStyle = null, $tocStyle = null, $minDepth = 1,
*/
public function getTitles()
{
- $titles = Titles::getTitles();
+ if (!$this->phpWord instanceof PhpWord) {
+ return array();
+ }
+
+ $titles = $this->phpWord->getTitles()->getItems();
foreach ($titles as $i => $title) {
- if ($this->minDepth > $title['depth']) {
+ $depth = $title->getDepth();
+ if ($this->minDepth > $depth) {
unset($titles[$i]);
}
- if (($this->maxDepth != 0) && ($this->maxDepth < $title['depth'])) {
+ if (($this->maxDepth != 0) && ($this->maxDepth < $depth)) {
unset($titles[$i]);
}
}
- $titles = array_merge(array(), $titles);
return $titles;
}
diff --git a/src/PhpWord/Element/Table.php b/src/PhpWord/Element/Table.php
index 99fe6b2969..faa2c0f0b6 100644
--- a/src/PhpWord/Element/Table.php
+++ b/src/PhpWord/Element/Table.php
@@ -60,6 +60,7 @@ public function __construct($docPart, $docPartId, $style = null)
public function addRow($height = null, $style = null)
{
$row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style);
+ $row->setPhpWord($this->phpWord);
$this->rows[] = $row;
return $row;
}
diff --git a/src/PhpWord/Element/Text.php b/src/PhpWord/Element/Text.php
index ba908b6fd2..b79a82e34d 100644
--- a/src/PhpWord/Element/Text.php
+++ b/src/PhpWord/Element/Text.php
@@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -127,7 +128,7 @@ public function getParagraphStyle()
*/
public function setText($text)
{
- $this->text = $text;
+ $this->text = String::toUTF8($text);
return $this;
}
diff --git a/src/PhpWord/Element/Title.php b/src/PhpWord/Element/Title.php
index 7c60961efc..c80cc86be2 100644
--- a/src/PhpWord/Element/Title.php
+++ b/src/PhpWord/Element/Title.php
@@ -9,6 +9,9 @@
namespace PhpOffice\PhpWord\Element;
+use PhpOffice\PhpWord\Style;
+use PhpOffice\PhpWord\Shared\String;
+
/**
* Title element
*/
@@ -26,69 +29,48 @@ class Title extends AbstractElement
*
* @var int
*/
- private $depth;
-
- /**
- * Title anchor
- *
- * @var int
- */
- private $anchor;
+ private $depth = 1;
/**
* Title Bookmark ID
*
* @var int
*/
- private $bookmarkId;
+ private $bookmarkId = 1;
/**
- * Title style
+ * Name of the heading style, e.g. 'Heading1'
*
* @var string
*/
private $style;
+ /**
+ * Title anchor
+ *
+ * @var int
+ * @deprecated 0.10.0
+ */
+ private $anchor;
/**
* Create a new Title Element
*
* @param string $text
* @param int $depth
- * @param string $style Name of the heading style, e.g. 'Heading1'
*/
- public function __construct($text, $depth = 1, $style = null)
+ public function __construct($text, $depth = 1)
{
- if (!is_null($style)) {
- $this->style = $style;
- }
- $this->text = $text;
+ $this->text = String::toUTF8($text);
$this->depth = $depth;
+ if (array_key_exists('Heading_' . $this->depth, Style::getStyles())) {
+ $this->style = 'Heading' . $this->depth;
+ }
return $this;
}
- /**
- * Set Anchor
- *
- * @param int $anchor
- */
- public function setAnchor($anchor)
- {
- $this->anchor = $anchor;
- }
-
- /**
- * Get Anchor
- *
- * @return int
- */
- public function getAnchor()
- {
- return $this->anchor;
- }
-
/**
* Set Bookmark ID
*
@@ -138,4 +120,28 @@ public function getStyle()
{
return $this->style;
}
+
+ /**
+ * Set Anchor
+ *
+ * @param int $anchor
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function setAnchor($anchor)
+ {
+ $this->anchor = $anchor;
+ }
+
+ /**
+ * Get Anchor
+ *
+ * @return int
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getAnchor()
+ {
+ return '_Toc' . (252634154 + $this->bookmarkId);
+ }
}
diff --git a/src/PhpWord/Endnotes.php b/src/PhpWord/Endnotes.php
deleted file mode 100644
index be00646f56..0000000000
--- a/src/PhpWord/Endnotes.php
+++ /dev/null
@@ -1,95 +0,0 @@
-getIsMemImage();
+ $isMemImage = $image->isMemImage();
$extension = $image->getImageExtension();
$mediaData['imageExtension'] = $extension;
$mediaData['imageType'] = $image->getImageType();
diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php
index f997dec236..cac3ada376 100644
--- a/src/PhpWord/PhpWord.php
+++ b/src/PhpWord/PhpWord.php
@@ -9,9 +9,14 @@
namespace PhpOffice\PhpWord;
+use PhpOffice\PhpWord\Collection\Endnotes;
+use PhpOffice\PhpWord\Collection\Footnotes;
+use PhpOffice\PhpWord\Collection\Titles;
+use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Style;
+use PhpOffice\PhpWord\Template;
/**
* PHPWord main class
@@ -37,6 +42,34 @@ class PhpWord
*/
private $documentProperties;
+ /**
+ * Collection of sections
+ *
+ * @var \PhpOffice\PhpWord\Element\Section[]
+ */
+ private $sections = array();
+
+ /**
+ * Collection of titles
+ *
+ * @var \PhpOffice\PhpWord\Collection\Titles
+ */
+ private $titles;
+
+ /**
+ * Collection of footnotes
+ *
+ * @var \PhpOffice\PhpWord\Collection\Footnotes
+ */
+ private $footnotes;
+
+ /**
+ * Collection of endnotes
+ *
+ * @var \PhpOffice\PhpWord\Collection\Endnotes
+ */
+ private $endnotes;
+
/**
* Default font name
*
@@ -50,19 +83,15 @@ class PhpWord
*/
private $defaultFontSize;
- /**
- * Collection of sections
- *
- * @var \PhpOffice\PhpWord\Element\Section[]
- */
- private $sections = array();
-
/**
* Create new
*/
public function __construct()
{
$this->documentProperties = new DocumentProperties();
+ $this->titles = new Titles();
+ $this->footnotes = new Footnotes();
+ $this->endnotes = new Endnotes();
$this->defaultFontName = self::DEFAULT_FONT_NAME;
$this->defaultFontSize = self::DEFAULT_FONT_SIZE;
}
@@ -90,6 +119,16 @@ public function setDocumentProperties(DocumentProperties $documentProperties)
return $this;
}
+ /**
+ * Get all sections
+ *
+ * @return \PhpOffice\PhpWord\Element\Section[]
+ */
+ public function getSections()
+ {
+ return $this->sections;
+ }
+
/**
* Create new section
*
@@ -99,11 +138,75 @@ public function setDocumentProperties(DocumentProperties $documentProperties)
public function addSection($settings = null)
{
$section = new Section(count($this->sections) + 1, $settings);
+ $section->setPhpWord($this);
$this->sections[] = $section;
return $section;
}
+ /**
+ * Get titles
+ *
+ * @return \PhpOffice\PhpWord\Collection\Titles
+ */
+ public function getTitles()
+ {
+ return $this->titles;
+ }
+
+ /**
+ * Add new title
+ *
+ * @param \PhpOffice\PhpWord\Element\Title $title
+ * @return int
+ */
+ public function addTitle($title)
+ {
+ return $this->titles->addItem($title);
+ }
+
+ /**
+ * Get footnotes
+ *
+ * @return \PhpOffice\PhpWord\Collection\Footnotes
+ */
+ public function getFootnotes()
+ {
+ return $this->footnotes;
+ }
+
+ /**
+ * Add new footnote
+ *
+ * @param \PhpOffice\PhpWord\Element\Footnote $footnote
+ * @return int
+ */
+ public function addFootnote($footnote)
+ {
+ return $this->footnotes->addItem($footnote);
+ }
+
+ /**
+ * Get endnotes
+ *
+ * @return \PhpOffice\PhpWord\Collection\Endnotes
+ */
+ public function getEndnotes()
+ {
+ return $this->endnotes;
+ }
+
+ /**
+ * Add new endnote
+ *
+ * @param \PhpOffice\PhpWord\Element\Endnote $endnote
+ * @return int
+ */
+ public function addEndnote($endnote)
+ {
+ return $this->endnotes->addItem($endnote);
+ }
+
/**
* Get default font name
*
@@ -223,16 +326,6 @@ public function addNumberingStyle($styleName, $styles)
Style::addNumberingStyle($styleName, $styles);
}
- /**
- * Get all sections
- *
- * @return \PhpOffice\PhpWord\Element\Section[]
- */
- public function getSections()
- {
- return $this->sections;
- }
-
/**
* Load template by filename
*
diff --git a/src/PhpWord/Reader/AbstractReader.php b/src/PhpWord/Reader/AbstractReader.php
index e9e52c63a0..3cd1e1e4f3 100644
--- a/src/PhpWord/Reader/AbstractReader.php
+++ b/src/PhpWord/Reader/AbstractReader.php
@@ -37,7 +37,7 @@ abstract class AbstractReader implements ReaderInterface
*
* @return bool
*/
- public function getReadDataOnly()
+ public function isReadDataOnly()
{
// return $this->readDataOnly;
return true;
@@ -96,4 +96,15 @@ public function canRead($pFilename)
return true;
}
+
+ /**
+ * Read data only?
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getReadDataOnly()
+ {
+ return $this->isReadDataOnly();
+ }
}
diff --git a/src/PhpWord/Reader/Word2007/DocProps.php b/src/PhpWord/Reader/Word2007/DocProps.php
deleted file mode 100644
index abd481db3c..0000000000
--- a/src/PhpWord/Reader/Word2007/DocProps.php
+++ /dev/null
@@ -1,63 +0,0 @@
-getDomFromZip($this->docFile, $this->xmlFile);
-
- $docProps = $phpWord->getDocumentProperties();
-
- $nodes = $xmlReader->getElements('*');
- if ($nodes->length > 0) {
- foreach ($nodes as $node) {
- if (!array_key_exists($node->nodeName, $this->mapping)) {
- continue;
- }
- $method = $this->mapping[$node->nodeName];
- $value = $node->nodeValue == '' ? null : $node->nodeValue;
- if (array_key_exists($node->nodeName, $this->callbacks)) {
- $value = $this->callbacks[$node->nodeName]($value);
- }
- if (method_exists($docProps, $method)) {
- $docProps->$method($value);
- }
- }
- }
- }
-}
diff --git a/src/PhpWord/Reader/Word2007/DocPropsApp.php b/src/PhpWord/Reader/Word2007/DocPropsApp.php
index 233225a687..f3af8a7f00 100644
--- a/src/PhpWord/Reader/Word2007/DocPropsApp.php
+++ b/src/PhpWord/Reader/Word2007/DocPropsApp.php
@@ -12,7 +12,7 @@
/**
* Extended properties reader
*/
-class DocPropsApp extends DocProps
+class DocPropsApp extends DocPropsCore
{
/**
* Property mapping
@@ -20,4 +20,11 @@ class DocPropsApp extends DocProps
* @var array
*/
protected $mapping = array('Company' => 'setCompany', 'Manager' => 'setManager');
+
+ /**
+ * Callback functions
+ *
+ * @var array
+ */
+ protected $callbacks = array();
}
diff --git a/src/PhpWord/Reader/Word2007/DocPropsCore.php b/src/PhpWord/Reader/Word2007/DocPropsCore.php
index 67324cb31d..18b142e29f 100644
--- a/src/PhpWord/Reader/Word2007/DocPropsCore.php
+++ b/src/PhpWord/Reader/Word2007/DocPropsCore.php
@@ -9,10 +9,13 @@
namespace PhpOffice\PhpWord\Reader\Word2007;
+use PhpOffice\PhpWord\PhpWord;
+use PhpOffice\PhpWord\Shared\XMLReader;
+
/**
* Core properties reader
*/
-class DocPropsCore extends DocProps
+class DocPropsCore extends AbstractPart
{
/**
* Property mapping
@@ -37,4 +40,34 @@ class DocPropsCore extends DocProps
* @var array
*/
protected $callbacks = array('dcterms:created' => 'strtotime', 'dcterms:modified' => 'strtotime');
+
+ /**
+ * Read core/extended document properties
+ *
+ * @param \PhpOffice\PhpWord\PhpWord $phpWord
+ */
+ public function read(PhpWord &$phpWord)
+ {
+ $xmlReader = new XMLReader();
+ $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
+
+ $docProps = $phpWord->getDocumentProperties();
+
+ $nodes = $xmlReader->getElements('*');
+ if ($nodes->length > 0) {
+ foreach ($nodes as $node) {
+ if (!array_key_exists($node->nodeName, $this->mapping)) {
+ continue;
+ }
+ $method = $this->mapping[$node->nodeName];
+ $value = $node->nodeValue == '' ? null : $node->nodeValue;
+ if (array_key_exists($node->nodeName, $this->callbacks)) {
+ $value = $this->callbacks[$node->nodeName]($value);
+ }
+ if (method_exists($docProps, $method)) {
+ $docProps->$method($value);
+ }
+ }
+ }
+ }
}
diff --git a/src/PhpWord/Reader/Word2007/Notes.php b/src/PhpWord/Reader/Word2007/Notes.php
index 89e15cfb5e..a213b7f154 100644
--- a/src/PhpWord/Reader/Word2007/Notes.php
+++ b/src/PhpWord/Reader/Word2007/Notes.php
@@ -32,8 +32,8 @@ class Notes extends AbstractPart
public function read(PhpWord &$phpWord)
{
$this->type = ($this->type == 'endnotes') ? 'endnotes' : 'footnotes';
- $collectionClass = 'PhpOffice\\PhpWord\\' . ucfirst($this->type);
- $collection = $collectionClass::getElements();
+ $getMethod = 'get' . $this->type;
+ $collection = $phpWord->$getMethod()->getItems();
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
@@ -49,9 +49,10 @@ public function read(PhpWord &$phpWord)
$element = $collection[$id];
$pNodes = $xmlReader->getElements('w:p/*', $node);
foreach ($pNodes as $pNode) {
- $this->readRun($xmlReader, $pNode, $element, $type);
+ $this->readRun($xmlReader, $pNode, $element, $this->type);
}
- $collectionClass::setElement($id, $element);
+ $addMethod = 'add' . ($this->type == 'endnotes' ? 'endnote' : 'footnote');
+ $phpWord->$addMethod($element);
}
}
}
diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php
index 717b055cfc..5d357d19f0 100644
--- a/src/PhpWord/Settings.php
+++ b/src/PhpWord/Settings.php
@@ -91,6 +91,16 @@ class Settings
*/
private static $measurementUnit = self::UNIT_TWIP;
+ /**
+ * Return the compatibility option used by the XMLWriter
+ *
+ * @return bool Compatibility
+ */
+ public static function hasCompatibility()
+ {
+ return self::$xmlWriterCompatibility;
+ }
+
/**
* Set the compatibility option used by the XMLWriter
*
@@ -110,13 +120,13 @@ public static function setCompatibility($compatibility)
}
/**
- * Return the compatibility option used by the XMLWriter
+ * Get zip handler class
*
- * @return bool Compatibility
+ * @return string
*/
- public static function getCompatibility()
+ public static function getZipClass()
{
- return self::$xmlWriterCompatibility;
+ return self::$zipClass;
}
/**
@@ -136,16 +146,6 @@ public static function setZipClass($zipClass)
return false;
}
- /**
- * Get zip handler class
- *
- * @return string
- */
- public static function getZipClass()
- {
- return self::$zipClass;
- }
-
/**
* Set details of the external library for rendering PDF files
*
@@ -237,4 +237,15 @@ public static function setMeasurementUnit($value)
return true;
}
+
+ /**
+ * Return the compatibility option used by the XMLWriter
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public static function getCompatibility()
+ {
+ return self::hasCompatibility();
+ }
}
diff --git a/src/PhpWord/Shared/Drawing.php b/src/PhpWord/Shared/Drawing.php
index b0ff8d6c73..cac0b8f44c 100644
--- a/src/PhpWord/Shared/Drawing.php
+++ b/src/PhpWord/Shared/Drawing.php
@@ -17,24 +17,24 @@ class Drawing
/**
* Convert pixels to EMU
*
- * @param integer $pValue Value in pixels
+ * @param integer $value Value in pixels
* @return double Value in EMU
*/
- public static function pixelsToEMU($pValue = 0)
+ public static function pixelsToEMU($value = 0)
{
- return round($pValue * 9525);
+ return round($value * 9525);
}
/**
* Convert EMU to pixels
*
- * @param integer $pValue Value in EMU
+ * @param integer $value Value in EMU
* @return integer Value in pixels
*/
- public static function EMUToPixels($pValue = 0)
+ public static function emuToPixels($value = 0)
{
- if ($pValue != 0) {
- return round($pValue / 9525);
+ if ($value != 0) {
+ return round($value / 9525);
} else {
return 0;
}
@@ -43,24 +43,24 @@ public static function EMUToPixels($pValue = 0)
/**
* Convert pixels to points
*
- * @param integer $pValue Value in pixels
+ * @param integer $value Value in pixels
* @return double Value in points
*/
- public static function pixelsToPoints($pValue = 0)
+ public static function pixelsToPoints($value = 0)
{
- return $pValue * 0.67777777;
+ return $value * 0.67777777;
}
/**
* Convert points width to pixels
*
- * @param integer $pValue Value in points
+ * @param integer $value Value in points
* @return integer Value in pixels
*/
- public static function pointsToPixels($pValue = 0)
+ public static function pointsToPixels($value = 0)
{
- if ($pValue != 0) {
- return $pValue * 1.333333333;
+ if ($value != 0) {
+ return $value * 1.333333333;
} else {
return 0;
}
@@ -69,24 +69,24 @@ public static function pointsToPixels($pValue = 0)
/**
* Convert degrees to angle
*
- * @param integer $pValue Degrees
+ * @param integer $value Degrees
* @return integer Angle
*/
- public static function degreesToAngle($pValue = 0)
+ public static function degreesToAngle($value = 0)
{
- return (integer)round($pValue * 60000);
+ return (integer)round($value * 60000);
}
/**
* Convert angle to degrees
*
- * @param integer $pValue Angle
+ * @param integer $value Angle
* @return integer Degrees
*/
- public static function angleToDegrees($pValue = 0)
+ public static function angleToDegrees($value = 0)
{
- if ($pValue != 0) {
- return round($pValue / 60000);
+ if ($value != 0) {
+ return round($value / 60000);
} else {
return 0;
}
@@ -95,24 +95,24 @@ public static function angleToDegrees($pValue = 0)
/**
* Convert pixels to centimeters
*
- * @param integer $pValue Value in pixels
+ * @param integer $value Value in pixels
* @return double Value in centimeters
*/
- public static function pixelsToCentimeters($pValue = 0)
+ public static function pixelsToCentimeters($value = 0)
{
- return $pValue * 0.028;
+ return $value * 0.028;
}
/**
* Convert centimeters width to pixels
*
- * @param integer $pValue Value in centimeters
+ * @param integer $value Value in centimeters
* @return integer Value in pixels
*/
- public static function centimetersToPixels($pValue = 0)
+ public static function centimetersToPixels($value = 0)
{
- if ($pValue != 0) {
- return $pValue / 0.028;
+ if ($value != 0) {
+ return $value / 0.028;
} else {
return 0;
}
@@ -121,27 +121,27 @@ public static function centimetersToPixels($pValue = 0)
/**
* Convert HTML hexadecimal to RGB
*
- * @param string $pValue HTML Color in hexadecimal
+ * @param string $value HTML Color in hexadecimal
* @return array Value in RGB
*/
- public static function htmlToRGB($pValue)
+ public static function htmlToRGB($value)
{
- if ($pValue[0] == '#') {
- $pValue = substr($pValue, 1);
+ if ($value[0] == '#') {
+ $value = substr($value, 1);
}
- if (strlen($pValue) == 6) {
- list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]);
- } elseif (strlen($pValue) == 3) {
- list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]);
+ if (strlen($value) == 6) {
+ list($red, $green, $blue) = array($value[0] . $value[1], $value[2] . $value[3], $value[4] . $value[5]);
+ } elseif (strlen($value) == 3) {
+ list($red, $green, $blue) = array($value[0] . $value[0], $value[1] . $value[1], $value[2] . $value[2]);
} else {
return false;
}
- $color_R = hexdec($color_R);
- $color_G = hexdec($color_G);
- $color_B = hexdec($color_B);
+ $red = hexdec($red);
+ $green = hexdec($green);
+ $blue = hexdec($blue);
- return array($color_R, $color_G, $color_B);
+ return array($red, $green, $blue);
}
}
diff --git a/src/PhpWord/Shared/XMLWriter.php b/src/PhpWord/Shared/XMLWriter.php
index 8f4162e1ec..2a763ed3c6 100644
--- a/src/PhpWord/Shared/XMLWriter.php
+++ b/src/PhpWord/Shared/XMLWriter.php
@@ -73,7 +73,7 @@ public function __construct($tempLocation = self::STORAGE_MEMORY, $tempFolder =
}
// Set xml Compatibility
- $compatibility = Settings::getCompatibility();
+ $compatibility = Settings::hasCompatibility();
if ($compatibility) {
$this->xmlWriter->setIndent(false);
$this->xmlWriter->setIndentString('');
diff --git a/src/PhpWord/Style/Font.php b/src/PhpWord/Style/Font.php
index 7ae31ad770..dde54413e2 100644
--- a/src/PhpWord/Style/Font.php
+++ b/src/PhpWord/Style/Font.php
@@ -287,7 +287,7 @@ public function setSize($value = PhpWord::DEFAULT_FONT_SIZE)
*
* @return bool
*/
- public function getBold()
+ public function isBold()
{
return $this->bold;
}
@@ -310,7 +310,7 @@ public function setBold($value = false)
*
* @return bool
*/
- public function getItalic()
+ public function isItalic()
{
return $this->italic;
}
@@ -333,7 +333,7 @@ public function setItalic($value = false)
*
* @return bool
*/
- public function getSuperScript()
+ public function isSuperScript()
{
return $this->superScript;
}
@@ -359,7 +359,7 @@ public function setSuperScript($value = false)
*
* @return bool
*/
- public function getSubScript()
+ public function isSubScript()
{
return $this->subScript;
}
@@ -408,7 +408,7 @@ public function setUnderline($value = self::UNDERLINE_NONE)
*
* @return bool
*/
- public function getStrikethrough()
+ public function isStrikethrough()
{
return $this->strikethrough;
}
@@ -434,7 +434,7 @@ public function setStrikethrough($value = false)
*
* @return bool
*/
- public function getDoubleStrikethrough()
+ public function isDoubleStrikethrough()
{
return $this->doubleStrikethrough;
}
@@ -604,7 +604,7 @@ public function setHint($value = PhpWord::DEFAULT_FONT_CONTENT_TYPE)
*
* @return bool
*/
- public function getSmallCaps()
+ public function isSmallCaps()
{
return $this->smallCaps;
}
@@ -630,7 +630,7 @@ public function setSmallCaps($value = false)
*
* @return bool
*/
- public function getAllCaps()
+ public function isAllCaps()
{
return $this->allCaps;
}
@@ -680,4 +680,59 @@ public function setShading($value = null)
return $this;
}
+
+ /**
+ * Get bold
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getBold()
+ {
+ return $this->isBold();
+ }
+
+ /**
+ * Get italic
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getItalic()
+ {
+ return $this->isItalic();
+ }
+
+ /**
+ * Get superscript
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getSuperScript()
+ {
+ return $this->isSuperScript();
+ }
+
+ /**
+ * Get subscript
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getSubScript()
+ {
+ return $this->isSubScript();
+ }
+
+ /**
+ * Get strikethrough
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getStrikethrough()
+ {
+ return $this->isStrikethrough();
+ }
}
diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php
index 22371e3716..874ff1df15 100644
--- a/src/PhpWord/Style/Paragraph.php
+++ b/src/PhpWord/Style/Paragraph.php
@@ -338,7 +338,7 @@ public function setTabs($value = null)
/**
* Get parent style ID
*
- * @return string
+ * @return string
*/
public function getBasedOn()
{
@@ -348,8 +348,8 @@ public function getBasedOn()
/**
* Set parent style ID
*
- * @param string $value
- * @return self
+ * @param string $value
+ * @return self
*/
public function setBasedOn($value = 'Normal')
{
@@ -370,8 +370,8 @@ public function getNext()
/**
* Set style for next paragraph
*
- * @param string $value
- * @return self
+ * @param string $value
+ * @return self
*/
public function setNext($value = null)
{
@@ -382,9 +382,9 @@ public function setNext($value = null)
/**
* Get allow first/last line to display on a separate page setting
*
- * @return bool
+ * @return bool
*/
- public function getWidowControl()
+ public function hasWidowControl()
{
return $this->widowControl;
}
@@ -392,8 +392,8 @@ public function getWidowControl()
/**
* Set keep paragraph with next paragraph setting
*
- * @param bool $value
- * @return self
+ * @param bool $value
+ * @return self
*/
public function setWidowControl($value = true)
{
@@ -407,9 +407,9 @@ public function setWidowControl($value = true)
/**
* Get keep paragraph with next paragraph setting
*
- * @return bool
+ * @return bool
*/
- public function getKeepNext()
+ public function isKeepNext()
{
return $this->keepNext;
}
@@ -417,8 +417,8 @@ public function getKeepNext()
/**
* Set keep paragraph with next paragraph setting
*
- * @param bool $value
- * @return self
+ * @param bool $value
+ * @return self
*/
public function setKeepNext($value = false)
{
@@ -432,9 +432,9 @@ public function setKeepNext($value = false)
/**
* Get keep all lines on one page setting
*
- * @return bool
+ * @return bool
*/
- public function getKeepLines()
+ public function isKeepLines()
{
return $this->keepLines;
}
@@ -442,8 +442,8 @@ public function getKeepLines()
/**
* Set keep all lines on one page setting
*
- * @param bool $value
- * @return self
+ * @param bool $value
+ * @return self
*/
public function setKeepLines($value = false)
{
@@ -459,7 +459,7 @@ public function setKeepLines($value = false)
*
* @return bool
*/
- public function getPageBreakBefore()
+ public function hasPageBreakBefore()
{
return $this->pageBreakBefore;
}
@@ -467,8 +467,8 @@ public function getPageBreakBefore()
/**
* Set start paragraph on next page setting
*
- * @param bool $value
- * @return self
+ * @param bool $value
+ * @return self
*/
public function setPageBreakBefore($value = false)
{
@@ -540,4 +540,48 @@ public function setSpace($value = null)
return $this;
}
+
+ /**
+ * Get allow first/last line to display on a separate page setting
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getWidowControl()
+ {
+ return $this->hasWidowControl();
+ }
+
+ /**
+ * Get keep paragraph with next paragraph setting
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getKeepNext()
+ {
+ return $this->isKeepNext();
+ }
+
+ /**
+ * Get keep all lines on one page setting
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getKeepLines()
+ {
+ return $this->isKeepLines();
+ }
+
+ /**
+ * Get start paragraph on next page setting
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getPageBreakBefore()
+ {
+ return $this->hasPageBreakBefore();
+ }
}
diff --git a/src/PhpWord/Style/Row.php b/src/PhpWord/Style/Row.php
index 06284eb728..bd0d35d9f3 100644
--- a/src/PhpWord/Style/Row.php
+++ b/src/PhpWord/Style/Row.php
@@ -45,9 +45,19 @@ public function __construct()
}
/**
- * Set tblHeader
+ * Is tblHeader
*
- * @param boolean $value
+ * @return bool
+ */
+ public function isTblHeader()
+ {
+ return $this->tblHeader;
+ }
+
+ /**
+ * Is tblHeader
+ *
+ * @param bool $value
* @return self
*/
public function setTblHeader($value = false)
@@ -56,19 +66,19 @@ public function setTblHeader($value = false)
}
/**
- * Get tblHeader
+ * Is cantSplit
*
- * @return boolean
+ * @return bool
*/
- public function getTblHeader()
+ public function isCantSplit()
{
- return $this->tblHeader;
+ return $this->cantSplit;
}
/**
- * Set cantSplit
+ * Is cantSplit
*
- * @param boolean $value
+ * @param bool $value
* @return self
*/
public function setCantSplit($value = false)
@@ -77,13 +87,13 @@ public function setCantSplit($value = false)
}
/**
- * Get cantSplit
+ * Is exactHeight
*
- * @return boolean
+ * @return bool
*/
- public function getCantSplit()
+ public function isExactHeight()
{
- return $this->cantSplit;
+ return $this->exactHeight;
}
/**
@@ -98,13 +108,36 @@ public function setExactHeight($value = false)
return $this;
}
+ /**
+ * Get tblHeader
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getTblHeader()
+ {
+ return $this->isTblHeader();
+ }
+
+ /**
+ * Get cantSplit
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getCantSplit()
+ {
+ return $this->isCantSplit();
+ }
+
/**
* Get exactHeight
*
- * @return boolean
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
*/
public function getExactHeight()
{
- return $this->exactHeight;
+ return $this->isExactHeight();
}
}
diff --git a/src/PhpWord/Style/TOC.php b/src/PhpWord/Style/TOC.php
index 2741bbf208..0c16ccc633 100644
--- a/src/PhpWord/Style/TOC.php
+++ b/src/PhpWord/Style/TOC.php
@@ -12,26 +12,12 @@
/**
* TOC style
*/
-class TOC extends AbstractStyle
+class TOC extends Tab
{
- const TABLEADER_DOT = 'dot';
- const TABLEADER_UNDERSCORE = 'underscore';
- const TABLEADER_LINE = 'hyphen';
- const TABLEADER_NONE = '';
-
- /**
- * Tab Leader
- *
- * @var string
- */
- private $tabLeader;
-
- /**
- * Tab Position
- *
- * @var int
- */
- private $tabPos;
+ const TABLEADER_DOT = self::TAB_LEADER_DOT;
+ const TABLEADER_UNDERSCORE = self::TAB_LEADER_UNDERSCORE;
+ const TABLEADER_LINE = self::TAB_LEADER_HYPHEN;
+ const TABLEADER_NONE = self::TAB_LEADER_NONE;
/**
* Indent
@@ -46,8 +32,7 @@ class TOC extends AbstractStyle
*/
public function __construct()
{
- $this->tabPos = 9062;
- $this->tabLeader = self::TABLEADER_DOT;
+ parent::__construct(self::TAB_STOP_RIGHT, 9062, self::TABLEADER_DOT);
$this->indent = 200;
}
@@ -58,17 +43,17 @@ public function __construct()
*/
public function getTabPos()
{
- return $this->tabPos;
+ return $this->getPosition();
}
/**
* Set Tab Position
*
- * @param int $pValue
+ * @param int $value
*/
- public function setTabPos($pValue)
+ public function setTabPos($value)
{
- $this->tabPos = $pValue;
+ $this->setPosition($value);
}
/**
@@ -78,17 +63,17 @@ public function setTabPos($pValue)
*/
public function getTabLeader()
{
- return $this->tabLeader;
+ return $this->getLeader();
}
/**
* Set Tab Leader
*
- * @param string $pValue
+ * @param string $value
*/
- public function setTabLeader($pValue = self::TABLEADER_DOT)
+ public function setTabLeader($value = self::TABLEADER_DOT)
{
- $this->tabLeader = $pValue;
+ $this->setLeader($value);
}
/**
@@ -104,10 +89,10 @@ public function getIndent()
/**
* Set Indent
*
- * @param string $pValue
+ * @param string $value
*/
- public function setIndent($pValue)
+ public function setIndent($value)
{
- $this->indent = $pValue;
+ $this->indent = $value;
}
}
diff --git a/src/PhpWord/Style/Tab.php b/src/PhpWord/Style/Tab.php
index 8ba2e85a81..6e44eeade9 100644
--- a/src/PhpWord/Style/Tab.php
+++ b/src/PhpWord/Style/Tab.php
@@ -44,7 +44,7 @@ class Tab extends AbstractStyle
*
* @var string
*/
- private $val = self::TAB_STOP_CLEAR;
+ private $type = self::TAB_STOP_CLEAR;
/**
* Tab leader character
@@ -54,22 +54,22 @@ class Tab extends AbstractStyle
private $leader = self::TAB_LEADER_NONE;
/**
- * Tab stop position
+ * Tab stop position (twip)
*
- * @var int
+ * @var int|float
*/
private $position = 0;
/**
- * Create a new instance of Tab. Both $val and $leader
+ * Create a new instance of Tab. Both $type and $leader
* must conform to the values put forth in the schema. If they do not
* they will be changed to default values.
*
- * @param string $val Defaults to 'clear' if value is not possible.
+ * @param string $type Defaults to 'clear' if value is not possible.
* @param int $position Must be numeric; otherwise defaults to 0.
* @param string $leader Defaults to null if value is not possible.
*/
- public function __construct($val = null, $position = 0, $leader = null)
+ public function __construct($type = null, $position = 0, $leader = null)
{
$stopTypes = array(
self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT,self::TAB_STOP_CENTER,
@@ -80,7 +80,7 @@ public function __construct($val = null, $position = 0, $leader = null)
self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT
);
- $this->val = $this->setEnumVal($val, $stopTypes, $this->val);
+ $this->type = $this->setEnumVal($type, $stopTypes, $this->type);
$this->position = $this->setNumericVal($position, $this->position);
$this->leader = $this->setEnumVal($leader, $leaderTypes, $this->leader);
}
@@ -90,9 +90,21 @@ public function __construct($val = null, $position = 0, $leader = null)
*
* @return string
*/
- public function getStopType()
+ public function getType()
{
- return $this->val;
+ return $this->type;
+ }
+
+ /**
+ * Set stop type
+ *
+ * @param string $value
+ */
+ public function setType($value)
+ {
+ $enum = array(self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT, self::TAB_STOP_CENTER,
+ self::TAB_STOP_RIGHT, self::TAB_STOP_DECIMAL, self::TAB_STOP_BAR, self::TAB_STOP_NUM);
+ $this->type = $this->setEnumVal($value, $enum, $this->type);
}
/**
@@ -105,13 +117,35 @@ public function getLeader()
return $this->leader;
}
+ /**
+ * Set leader
+ *
+ * @param string $value
+ */
+ public function setLeader($value)
+ {
+ $enum = array(self::TAB_LEADER_NONE, self::TAB_LEADER_DOT, self::TAB_LEADER_HYPHEN,
+ self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT);
+ $this->leader = $this->setEnumVal($value, $enum, $this->leader);
+ }
+
/**
* Get position
*
- * @return integer
+ * @return int|float
*/
public function getPosition()
{
return $this->position;
}
+
+ /**
+ * Set position
+ *
+ * @param int|float $value
+ */
+ public function setPosition($value)
+ {
+ $this->position = $this->setNumericVal($value, $this->position);
+ }
}
diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php
index 6dcee1ae19..8306f78bf3 100644
--- a/src/PhpWord/Style/Table.php
+++ b/src/PhpWord/Style/Table.php
@@ -222,7 +222,7 @@ public function getBorderColor()
/**
* Set border size inside horizontal
*
- * @param $value
+ * @param int $value
*/
public function setBorderInsideHSize($value = null)
{
@@ -232,7 +232,7 @@ public function setBorderInsideHSize($value = null)
/**
* Get border size inside horizontal
*
- * @return
+ * @return int
*/
public function getBorderInsideHSize()
{
@@ -242,7 +242,7 @@ public function getBorderInsideHSize()
/**
* Set border size inside vertical
*
- * @param $value
+ * @param int $value
*/
public function setBorderInsideVSize($value = null)
{
@@ -252,7 +252,7 @@ public function setBorderInsideVSize($value = null)
/**
* Get border size inside vertical
*
- * @return
+ * @return int
*/
public function getBorderInsideVSize()
{
@@ -262,7 +262,7 @@ public function getBorderInsideVSize()
/**
* Set border color inside horizontal
*
- * @param $value
+ * @param string $value
*/
public function setBorderInsideHColor($value = null)
{
@@ -272,7 +272,7 @@ public function setBorderInsideHColor($value = null)
/**
* Get border color inside horizontal
*
- * @return
+ * @return string
*/
public function getBorderInsideHColor()
{
@@ -282,7 +282,7 @@ public function getBorderInsideHColor()
/**
* Set border color inside vertical
*
- * @param $value
+ * @param string $value
*/
public function setBorderInsideVColor($value = null)
{
@@ -292,7 +292,7 @@ public function setBorderInsideVColor($value = null)
/**
* Get border color inside vertical
*
- * @return
+ * @return string
*/
public function getBorderInsideVColor()
{
diff --git a/src/PhpWord/TOC.php b/src/PhpWord/TOC.php
deleted file mode 100644
index 064a836de0..0000000000
--- a/src/PhpWord/TOC.php
+++ /dev/null
@@ -1,78 +0,0 @@
-useDiskCaching;
}
@@ -131,7 +131,7 @@ public function getUseDiskCaching()
/**
* Set use disk caching status
*
- * @param boolean $pValue
+ * @param bool $pValue
* @param string $pDirectory
* @return self
*/
@@ -356,4 +356,15 @@ private function deleteDir($dir)
rmdir($dir);
}
+
+ /**
+ * Get use disk caching status
+ *
+ * @deprecated 0.10.0
+ * @codeCoverageIgnore
+ */
+ public function getUseDiskCaching()
+ {
+ return $this->isUseDiskCaching();
+ }
}
diff --git a/src/PhpWord/Writer/HTML.php b/src/PhpWord/Writer/HTML.php
index 8ce1264cc5..b8d9e87bd1 100644
--- a/src/PhpWord/Writer/HTML.php
+++ b/src/PhpWord/Writer/HTML.php
@@ -167,14 +167,16 @@ private function writeHTMLBody()
*/
private function writeNotes()
{
+ $phpWord = $this->getPhpWord();
$html = '';
+
if (!empty($this->notes)) {
$html .= "
";
foreach ($this->notes as $noteId => $noteMark) {
$noteAnchor = "note-{$noteId}";
list($noteType, $noteTypeId) = explode('-', $noteMark);
- $collectionObject = 'PhpOffice\\PhpWord\\' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes');
- $collection = $collectionObject::getElements();
+ $method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes');
+ $collection = $phpWord->$method()->getItems();
if (array_key_exists($noteTypeId, $collection)) {
$element = $collection[$noteTypeId];
$elmWriter = new TextRunWriter($this, $element, true);
diff --git a/src/PhpWord/Writer/HTML/Element/Endnote.php b/src/PhpWord/Writer/HTML/Element/Endnote.php
index 7b13ecdb3d..60f078e312 100644
--- a/src/PhpWord/Writer/HTML/Element/Endnote.php
+++ b/src/PhpWord/Writer/HTML/Element/Endnote.php
@@ -14,6 +14,12 @@
*
* @since 0.10.0
*/
-class Endnote extends Note
+class Endnote extends Footnote
{
+ /**
+ * Note type
+ *
+ * @var string
+ */
+ protected $noteType = 'endnote';
}
diff --git a/src/PhpWord/Writer/HTML/Element/Footnote.php b/src/PhpWord/Writer/HTML/Element/Footnote.php
index 3283895d1e..713878cac2 100644
--- a/src/PhpWord/Writer/HTML/Element/Footnote.php
+++ b/src/PhpWord/Writer/HTML/Element/Footnote.php
@@ -14,6 +14,27 @@
*
* @since 0.10.0
*/
-class Footnote extends Note
+class Footnote extends Element
{
+ /**
+ * Note type footnote|endnote
+ *
+ * @var string
+ */
+ protected $noteType = 'footnote';
+
+ /**
+ * Write footnote/endnote marks
+ *
+ * @return string
+ */
+ public function write()
+ {
+ $noteId = count($this->parentWriter->getNotes()) + 1;
+ $noteMark = $this->noteType . '-' . $this->element->getRelationId();
+ $this->parentWriter->addNote($noteId, $noteMark);
+ $html = "{$noteId}";
+
+ return $html;
+ }
}
diff --git a/src/PhpWord/Writer/HTML/Element/Note.php b/src/PhpWord/Writer/HTML/Element/Note.php
deleted file mode 100644
index 4610495c0c..0000000000
--- a/src/PhpWord/Writer/HTML/Element/Note.php
+++ /dev/null
@@ -1,34 +0,0 @@
-parentWriter->getNotes()) + 1;
- $prefix = ($this->element instanceof \PhpOffice\PhpWord\Element\Endnote) ? 'endnote' : 'footnote';
- $noteMark = $prefix . '-' . $this->element->getRelationId();
- $this->parentWriter->addNote($noteId, $noteMark);
- $html = "{$noteId}";
-
- return $html;
- }
-}
diff --git a/src/PhpWord/Writer/HTML/Style/Font.php b/src/PhpWord/Writer/HTML/Style/Font.php
index 309d47181a..c858694e36 100644
--- a/src/PhpWord/Writer/HTML/Style/Font.php
+++ b/src/PhpWord/Writer/HTML/Style/Font.php
@@ -41,22 +41,22 @@ public function write()
$css['color'] = '#' . $this->style->getColor();
}
$css['background'] = $this->style->getFgColor();
- if ($this->style->getBold()) {
+ if ($this->style->isBold()) {
$css['font-weight'] = 'bold';
}
- if ($this->style->getItalic()) {
+ if ($this->style->isItalic()) {
$css['font-style'] = 'italic';
}
- if ($this->style->getSuperScript()) {
+ if ($this->style->isSuperScript()) {
$css['vertical-align'] = 'super';
- } elseif ($this->style->getSubScript()) {
+ } elseif ($this->style->isSubScript()) {
$css['vertical-align'] = 'sub';
}
$css['text-decoration'] = '';
if ($this->style->getUnderline() != FontStyle::UNDERLINE_NONE) {
$css['text-decoration'] .= 'underline ';
}
- if ($this->style->getStrikethrough()) {
+ if ($this->style->isStrikethrough()) {
$css['text-decoration'] .= 'line-through ';
}
diff --git a/src/PhpWord/Writer/ODText/Element/Text.php b/src/PhpWord/Writer/ODText/Element/Text.php
index b5e55752c7..bedc212ff9 100644
--- a/src/PhpWord/Writer/ODText/Element/Text.php
+++ b/src/PhpWord/Writer/ODText/Element/Text.php
@@ -25,12 +25,12 @@ public function write()
$paragraphStyle = $this->element->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value
- // $SfIsObject = ($fontStyle instanceof Font) ? true : false;
- $SfIsObject = false;
+ // $fStyleIsObject = ($fontStyle instanceof Font) ? true : false;
+ $fStyleIsObject = false;
- if ($SfIsObject) {
+ if ($fStyleIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared
- throw new Exception('PhpWord : $SfIsObject wouldn\'t be an object');
+ throw new Exception('PhpWord : $fStyleIsObject wouldn\'t be an object');
} else {
if (!$this->withoutP) {
$this->xmlWriter->startElement('text:p'); // text:p
diff --git a/src/PhpWord/Writer/ODText/Style/Font.php b/src/PhpWord/Writer/ODText/Style/Font.php
index aebf3872d7..7e72dcb668 100644
--- a/src/PhpWord/Writer/ODText/Style/Font.php
+++ b/src/PhpWord/Writer/ODText/Style/Font.php
@@ -46,12 +46,12 @@ public function write()
if ($this->style->getColor()) {
$this->xmlWriter->writeAttribute('fo:color', '#' . $this->style->getColor());
}
- if ($this->style->getItalic()) {
+ if ($this->style->isItalic()) {
$this->xmlWriter->writeAttribute('fo:font-style', 'italic');
$this->xmlWriter->writeAttribute('style:font-style-asian', 'italic');
$this->xmlWriter->writeAttribute('style:font-style-complex', 'italic');
}
- if ($this->style->getBold()) {
+ if ($this->style->isBold()) {
$this->xmlWriter->writeAttribute('fo:font-weight', 'bold');
$this->xmlWriter->writeAttribute('style:font-weight-asian', 'bold');
}
diff --git a/src/PhpWord/Writer/RTF/Element/Text.php b/src/PhpWord/Writer/RTF/Element/Text.php
index 8a718909b4..d4e29eec3c 100644
--- a/src/PhpWord/Writer/RTF/Element/Text.php
+++ b/src/PhpWord/Writer/RTF/Element/Text.php
@@ -73,10 +73,10 @@ public function write()
} else {
$rtfText .= '\f0';
}
- if ($fontStyle->getBold()) {
+ if ($fontStyle->isBold()) {
$rtfText .= '\b';
}
- if ($fontStyle->getItalic()) {
+ if ($fontStyle->isItalic()) {
$rtfText .= '\i';
}
if ($fontStyle->getSize()) {
@@ -92,10 +92,10 @@ public function write()
$rtfText .= '\cf0';
$rtfText .= '\f0';
- if ($fontStyle->getBold()) {
+ if ($fontStyle->isBold()) {
$rtfText .= '\b0';
}
- if ($fontStyle->getItalic()) {
+ if ($fontStyle->isItalic()) {
$rtfText .= '\i0';
}
if ($fontStyle->getSize()) {
diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php
index 105093a7a8..be91dd8544 100644
--- a/src/PhpWord/Writer/Word2007.php
+++ b/src/PhpWord/Writer/Word2007.php
@@ -179,29 +179,27 @@ private function addHeaderFooterContent(Section &$section, $objZip, $elmType, &$
*
* @param mixed $objZip
* @param integer $rId
- * @param string $notesType
+ * @param string $noteType
*/
- private function addNotes($objZip, &$rId, $notesType = 'footnote')
+ private function addNotes($objZip, &$rId, $noteType = 'footnote')
{
- $notesType = ($notesType == 'endnote') ? 'endnote' : 'footnote';
- $notesTypes = "{$notesType}s";
- $collection = 'PhpOffice\\PhpWord\\' . ucfirst($notesTypes);
- $xmlFile = "{$notesTypes}.xml";
- $relsFile = "word/_rels/{$xmlFile}.rels";
- $xmlPath = "word/{$xmlFile}";
+ $noteType = ($noteType == 'endnote') ? 'endnote' : 'footnote';
+ $noteTypePlural = "{$noteType}s";
+ $method = 'get' . $noteTypePlural;
+ $collection = $this->phpWord->$method();
// Add footnotes media files, relations, and contents
- if ($collection::countElements() > 0) {
- $media = Media::getElements($notesType);
+ if ($collection->countItems() > 0) {
+ $media = Media::getElements($noteType);
$this->addFilesToPackage($objZip, $media);
$this->registerContentTypes($media);
if (!empty($media)) {
- $objZip->addFromString($relsFile, $this->getWriterPart('rels')->writeMediaRels($media));
+ $objZip->addFromString("word/_rels/{$noteTypePlural}.xml.rels", $this->getWriterPart('rels')->writeMediaRels($media));
}
- $elements = $collection::getElements();
- $objZip->addFromString($xmlPath, $this->getWriterPart($notesTypes)->write($elements));
- $this->cTypes['override']["/{$xmlPath}"] = $notesTypes;
- $this->docRels[] = array('target' => $xmlFile, 'type' => $notesTypes, 'rID' => ++$rId);
+ $elements = $collection->getItems();
+ $objZip->addFromString("word/{$noteTypePlural}.xml", $this->getWriterPart($noteTypePlural)->write($elements));
+ $this->cTypes['override']["/word/{$noteTypePlural}.xml"] = $noteTypePlural;
+ $this->docRels[] = array('target' => "{$noteTypePlural}.xml", 'type' => $noteTypePlural, 'rID' => ++$rId);
}
}
diff --git a/src/PhpWord/Writer/Word2007/Element/Endnote.php b/src/PhpWord/Writer/Word2007/Element/Endnote.php
index d270186698..bd5bf80222 100644
--- a/src/PhpWord/Writer/Word2007/Element/Endnote.php
+++ b/src/PhpWord/Writer/Word2007/Element/Endnote.php
@@ -14,14 +14,12 @@
*
* @since 0.10.0
*/
-class Endnote extends Note
+class Endnote extends Footnote
{
/**
- * Write element
+ * Reference type
+ *
+ * @var string
*/
- public function write()
- {
- $this->referenceType = 'endnoteReference';
- parent::write();
- }
+ protected $referenceType = 'endnoteReference';
}
diff --git a/src/PhpWord/Writer/Word2007/Element/Footnote.php b/src/PhpWord/Writer/Word2007/Element/Footnote.php
index b53bd55381..5f149b124b 100644
--- a/src/PhpWord/Writer/Word2007/Element/Footnote.php
+++ b/src/PhpWord/Writer/Word2007/Element/Footnote.php
@@ -14,14 +14,35 @@
*
* @since 0.10.0
*/
-class Footnote extends Note
+class Footnote extends Element
{
+ /**
+ * Reference type footnoteReference|endnoteReference
+ *
+ * @var string
+ */
+ protected $referenceType = 'footnoteReference';
+
/**
* Write element
*/
public function write()
{
- $this->referenceType = 'footnoteReference';
- parent::write();
+ if (!$this->withoutP) {
+ $this->xmlWriter->startElement('w:p');
+ }
+ $this->xmlWriter->startElement('w:r');
+ $this->xmlWriter->startElement('w:rPr');
+ $this->xmlWriter->startElement('w:rStyle');
+ $this->xmlWriter->writeAttribute('w:val', ucfirst($this->referenceType));
+ $this->xmlWriter->endElement(); // w:rStyle
+ $this->xmlWriter->endElement(); // w:rPr
+ $this->xmlWriter->startElement("w:{$this->referenceType}");
+ $this->xmlWriter->writeAttribute('w:id', $this->element->getRelationId());
+ $this->xmlWriter->endElement(); // w:$referenceType
+ $this->xmlWriter->endElement(); // w:r
+ if (!$this->withoutP) {
+ $this->xmlWriter->endElement(); // w:p
+ }
}
}
diff --git a/src/PhpWord/Writer/Word2007/Element/Image.php b/src/PhpWord/Writer/Word2007/Element/Image.php
index 1f5f6e8516..dcee63a58f 100644
--- a/src/PhpWord/Writer/Word2007/Element/Image.php
+++ b/src/PhpWord/Writer/Word2007/Element/Image.php
@@ -23,7 +23,7 @@ class Image extends Element
*/
public function write()
{
- if ($this->element->getIsWatermark()) {
+ if ($this->element->isWatermark()) {
$this->writeWatermark();
} else {
$this->writeImage();
diff --git a/src/PhpWord/Writer/Word2007/Element/Note.php b/src/PhpWord/Writer/Word2007/Element/Note.php
deleted file mode 100644
index 5e0b36e92f..0000000000
--- a/src/PhpWord/Writer/Word2007/Element/Note.php
+++ /dev/null
@@ -1,48 +0,0 @@
-withoutP) {
- $this->xmlWriter->startElement('w:p');
- }
- $this->xmlWriter->startElement('w:r');
- $this->xmlWriter->startElement('w:rPr');
- $this->xmlWriter->startElement('w:rStyle');
- $this->xmlWriter->writeAttribute('w:val', ucfirst($this->referenceType));
- $this->xmlWriter->endElement(); // w:rStyle
- $this->xmlWriter->endElement(); // w:rPr
- $this->xmlWriter->startElement("w:{$this->referenceType}");
- $this->xmlWriter->writeAttribute('w:id', $this->element->getRelationId());
- $this->xmlWriter->endElement(); // w:$referenceType
- $this->xmlWriter->endElement(); // w:r
- if (!$this->withoutP) {
- $this->xmlWriter->endElement(); // w:p
- }
- }
-}
diff --git a/src/PhpWord/Writer/Word2007/Element/TOC.php b/src/PhpWord/Writer/Word2007/Element/TOC.php
index d56a8d1dd0..ff23fa00e7 100644
--- a/src/PhpWord/Writer/Word2007/Element/TOC.php
+++ b/src/PhpWord/Writer/Word2007/Element/TOC.php
@@ -12,6 +12,7 @@
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
+use PhpOffice\PhpWord\Writer\Word2007\Style\Tab as TabStyleWriter;
/**
* TOC element writer
@@ -26,59 +27,53 @@ class TOC extends Element
public function write()
{
$titles = $this->element->getTitles();
- $fontStyle = $this->element->getStyleFont();
-
$tocStyle = $this->element->getStyleTOC();
- $fIndent = $tocStyle->getIndent();
- $tabLeader = $tocStyle->getTabLeader();
- $tabPos = $tocStyle->getTabPos();
-
- $maxDepth = $this->element->getMaxDepth();
- $minDepth = $this->element->getMinDepth();
-
+ $fontStyle = $this->element->getStyleFont();
$isObject = ($fontStyle instanceof Font) ? true : false;
- for ($i = 0; $i < count($titles); $i++) {
- $title = $titles[$i];
- $indent = ($title['depth'] - 1) * $fIndent;
+ $tocFieldWritten = false;
+ foreach ($titles as $title) {
+ $indent = ($title->getDepth() - 1) * $tocStyle->getIndent();
+ $anchor = '_Toc' . ($title->getBookmarkId() + 252634154);
$this->xmlWriter->startElement('w:p');
+ // Style
$this->xmlWriter->startElement('w:pPr');
+ // Paragraph
if ($isObject && !is_null($fontStyle->getParagraphStyle())) {
$styleWriter = new ParagraphStyleWriter($this->xmlWriter, $fontStyle->getParagraphStyle());
$styleWriter->write();
}
- if ($indent > 0) {
- $this->xmlWriter->startElement('w:ind');
- $this->xmlWriter->writeAttribute('w:left', $indent);
- $this->xmlWriter->endElement();
- }
-
+ // Font
if (!empty($fontStyle) && !$isObject) {
- $this->xmlWriter->startElement('w:pPr');
- $this->xmlWriter->startElement('w:pStyle');
+ $this->xmlWriter->startElement('w:rPr');
+ $this->xmlWriter->startElement('w:rStyle');
$this->xmlWriter->writeAttribute('w:val', $fontStyle);
$this->xmlWriter->endElement();
- $this->xmlWriter->endElement();
+ $this->xmlWriter->endElement(); // w:rPr
}
+ // Tab
$this->xmlWriter->startElement('w:tabs');
- $this->xmlWriter->startElement('w:tab');
- $this->xmlWriter->writeAttribute('w:val', 'right');
- if (!empty($tabLeader)) {
- $this->xmlWriter->writeAttribute('w:leader', $tabLeader);
- }
- $this->xmlWriter->writeAttribute('w:pos', $tabPos);
- $this->xmlWriter->endElement();
+ $styleWriter = new TabStyleWriter($this->xmlWriter, $tocStyle);
+ $styleWriter->write();
$this->xmlWriter->endElement();
+ // Indent
+ if ($indent > 0) {
+ $this->xmlWriter->startElement('w:ind');
+ $this->xmlWriter->writeAttribute('w:left', $indent);
+ $this->xmlWriter->endElement();
+ }
+
$this->xmlWriter->endElement(); // w:pPr
+ if ($tocFieldWritten !== true) {
+ $tocFieldWritten = true;
- if ($i == 0) {
$this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:fldChar');
$this->xmlWriter->writeAttribute('w:fldCharType', 'begin');
@@ -88,7 +83,7 @@ public function write()
$this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:instrText');
$this->xmlWriter->writeAttribute('xml:space', 'preserve');
- $this->xmlWriter->writeRaw('TOC \o "' . $minDepth . '-' . $maxDepth . '" \h \z \u');
+ $this->xmlWriter->writeRaw('TOC \o "' . $this->element->getMinDepth() . '-' . $this->element->getMaxDepth() . '" \h \z \u');
$this->xmlWriter->endElement();
$this->xmlWriter->endElement();
@@ -100,7 +95,7 @@ public function write()
}
$this->xmlWriter->startElement('w:hyperlink');
- $this->xmlWriter->writeAttribute('w:anchor', $title['anchor']);
+ $this->xmlWriter->writeAttribute('w:anchor', $anchor);
$this->xmlWriter->writeAttribute('w:history', '1');
$this->xmlWriter->startElement('w:r');
@@ -111,7 +106,7 @@ public function write()
}
$this->xmlWriter->startElement('w:t');
- $this->xmlWriter->writeRaw($title['text']);
+ $this->xmlWriter->writeRaw($title->getText());
$this->xmlWriter->endElement();
$this->xmlWriter->endElement();
@@ -128,7 +123,7 @@ public function write()
$this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:instrText');
$this->xmlWriter->writeAttribute('xml:space', 'preserve');
- $this->xmlWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h');
+ $this->xmlWriter->writeRaw('PAGEREF ' . $anchor . ' \h');
$this->xmlWriter->endElement();
$this->xmlWriter->endElement();
diff --git a/src/PhpWord/Writer/Word2007/Element/Table.php b/src/PhpWord/Writer/Word2007/Element/Table.php
index 954dd6a980..3c659e34a2 100644
--- a/src/PhpWord/Writer/Word2007/Element/Table.php
+++ b/src/PhpWord/Writer/Word2007/Element/Table.php
@@ -84,25 +84,22 @@ public function write()
$row = $rows[$i];
$height = $row->getHeight();
$rowStyle = $row->getStyle();
- $tblHeader = $rowStyle->getTblHeader();
- $cantSplit = $rowStyle->getCantSplit();
- $exactHeight = $rowStyle->getExactHeight();
$this->xmlWriter->startElement('w:tr');
- if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) {
+ if (!is_null($height) || $rowStyle->isTblHeader() || $rowStyle->isCantSplit()) {
$this->xmlWriter->startElement('w:trPr');
if (!is_null($height)) {
$this->xmlWriter->startElement('w:trHeight');
$this->xmlWriter->writeAttribute('w:val', $height);
- $this->xmlWriter->writeAttribute('w:hRule', ($exactHeight ? 'exact' : 'atLeast'));
+ $this->xmlWriter->writeAttribute('w:hRule', ($rowStyle->isExactHeight() ? 'exact' : 'atLeast'));
$this->xmlWriter->endElement();
}
- if ($tblHeader) {
+ if ($rowStyle->isTblHeader()) {
$this->xmlWriter->startElement('w:tblHeader');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
- if ($cantSplit) {
+ if ($rowStyle->isCantSplit()) {
$this->xmlWriter->startElement('w:cantSplit');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
diff --git a/src/PhpWord/Writer/Word2007/Element/Title.php b/src/PhpWord/Writer/Word2007/Element/Title.php
index 5d3ab37151..025b95d3c0 100644
--- a/src/PhpWord/Writer/Word2007/Element/Title.php
+++ b/src/PhpWord/Writer/Word2007/Element/Title.php
@@ -23,8 +23,8 @@ class Title extends Element
*/
public function write()
{
- $anchor = $this->element->getAnchor();
$bookmarkId = $this->element->getBookmarkId();
+ $anchor = '_Toc' . ($bookmarkId + 252634154);
$style = $this->element->getStyle();
$text = htmlspecialchars($this->element->getText());
$text = String::controlCharacterPHP2OOXML($text);
diff --git a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php
index eec380c90c..29c004c62e 100644
--- a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php
+++ b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php
@@ -62,7 +62,7 @@ protected function getXmlWriter()
{
$useDiskCaching = false;
if (!is_null($this->parentWriter)) {
- if ($this->parentWriter->getUseDiskCaching()) {
+ if ($this->parentWriter->isUseDiskCaching()) {
$useDiskCaching = true;
}
}
diff --git a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php
index 08c39ce7f0..24df901146 100644
--- a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php
+++ b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php
@@ -24,24 +24,24 @@ class ContentTypes extends AbstractPart
*/
public function writeContentTypes($contentTypes)
{
- $OpenXMLPrefix = 'application/vnd.openxmlformats-';
- $WordMLPrefix = $OpenXMLPrefix . 'officedocument.wordprocessingml.';
+ $openXMLPrefix = 'application/vnd.openxmlformats-';
+ $wordMLPrefix = $openXMLPrefix . 'officedocument.wordprocessingml.';
$overrides = array(
- '/docProps/core.xml' => $OpenXMLPrefix . 'package.core-properties+xml',
- '/docProps/app.xml' => $OpenXMLPrefix . 'officedocument.extended-properties+xml',
- '/word/document.xml' => $WordMLPrefix . 'document.main+xml',
- '/word/styles.xml' => $WordMLPrefix . 'styles+xml',
- '/word/numbering.xml' => $WordMLPrefix . 'numbering+xml',
- '/word/settings.xml' => $WordMLPrefix . 'settings+xml',
- '/word/theme/theme1.xml' => $OpenXMLPrefix . 'officedocument.theme+xml',
- '/word/webSettings.xml' => $WordMLPrefix . 'webSettings+xml',
- '/word/fontTable.xml' => $WordMLPrefix . 'fontTable+xml',
+ '/docProps/core.xml' => $openXMLPrefix . 'package.core-properties+xml',
+ '/docProps/app.xml' => $openXMLPrefix . 'officedocument.extended-properties+xml',
+ '/word/document.xml' => $wordMLPrefix . 'document.main+xml',
+ '/word/styles.xml' => $wordMLPrefix . 'styles+xml',
+ '/word/numbering.xml' => $wordMLPrefix . 'numbering+xml',
+ '/word/settings.xml' => $wordMLPrefix . 'settings+xml',
+ '/word/theme/theme1.xml' => $openXMLPrefix . 'officedocument.theme+xml',
+ '/word/webSettings.xml' => $wordMLPrefix . 'webSettings+xml',
+ '/word/fontTable.xml' => $wordMLPrefix . 'fontTable+xml',
);
$defaults = $contentTypes['default'];
if (!empty($contentTypes['override'])) {
foreach ($contentTypes['override'] as $key => $val) {
- $overrides[$key] = $WordMLPrefix . $val . '+xml';
+ $overrides[$key] = $wordMLPrefix . $val . '+xml';
}
}
diff --git a/src/PhpWord/Writer/Word2007/Style/Font.php b/src/PhpWord/Writer/Word2007/Style/Font.php
index f508ccbdbb..c62510d0bd 100644
--- a/src/PhpWord/Writer/Word2007/Style/Font.php
+++ b/src/PhpWord/Writer/Word2007/Style/Font.php
@@ -89,12 +89,12 @@ private function writeStyle()
}
// Bold
- if ($this->style->getBold()) {
+ if ($this->style->isBold()) {
$this->xmlWriter->writeElement('w:b', null);
}
// Italic
- if ($this->style->getItalic()) {
+ if ($this->style->isItalic()) {
$this->xmlWriter->writeElement('w:i', null);
$this->xmlWriter->writeElement('w:iCs', null);
}
@@ -107,12 +107,12 @@ private function writeStyle()
}
// Strikethrough
- if ($this->style->getStrikethrough()) {
+ if ($this->style->isStrikethrough()) {
$this->xmlWriter->writeElement('w:strike', null);
}
// Double strikethrough
- if ($this->style->getDoubleStrikethrough()) {
+ if ($this->style->isDoubleStrikethrough()) {
$this->xmlWriter->writeElement('w:dstrike', null);
}
@@ -130,19 +130,19 @@ private function writeStyle()
}
// Superscript/subscript
- if ($this->style->getSuperScript() || $this->style->getSubScript()) {
+ if ($this->style->isSuperScript() || $this->style->isSubScript()) {
$this->xmlWriter->startElement('w:vertAlign');
- $this->xmlWriter->writeAttribute('w:val', $this->style->getSuperScript() ? 'superscript' : 'subscript');
+ $this->xmlWriter->writeAttribute('w:val', $this->style->isSuperScript() ? 'superscript' : 'subscript');
$this->xmlWriter->endElement();
}
// Small caps
- if ($this->style->getSmallCaps()) {
+ if ($this->style->isSmallCaps()) {
$this->xmlWriter->writeElement('w:smallCaps', null);
}
// All caps
- if ($this->style->getAllCaps()) {
+ if ($this->style->isAllCaps()) {
$this->xmlWriter->writeElement('w:caps', null);
}
diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php
index 432a45ff78..993ec6a0d7 100644
--- a/src/PhpWord/Writer/Word2007/Style/Paragraph.php
+++ b/src/PhpWord/Writer/Word2007/Style/Paragraph.php
@@ -60,11 +60,6 @@ private function writeStyle()
return;
}
- $widowControl = $this->style->getWidowControl();
- $keepNext = $this->style->getKeepNext();
- $keepLines = $this->style->getKeepLines();
- $pageBreakBefore = $this->style->getPageBreakBefore();
-
if (!$this->withoutPPR) {
$this->xmlWriter->startElement('w:pPr');
}
@@ -89,22 +84,22 @@ private function writeStyle()
}
// Pagination
- if (!$widowControl) {
+ if (!$this->style->hasWidowControl()) {
$this->xmlWriter->startElement('w:widowControl');
$this->xmlWriter->writeAttribute('w:val', '0');
$this->xmlWriter->endElement();
}
- if ($keepNext) {
+ if ($this->style->isKeepNext()) {
$this->xmlWriter->startElement('w:keepNext');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
- if ($keepLines) {
+ if ($this->style->isKeepLines()) {
$this->xmlWriter->startElement('w:keepLines');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
- if ($pageBreakBefore) {
+ if ($this->style->hasPageBreakBefore()) {
$this->xmlWriter->startElement('w:pageBreakBefore');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
diff --git a/src/PhpWord/Writer/Word2007/Style/Tab.php b/src/PhpWord/Writer/Word2007/Style/Tab.php
index 60e2db0ee8..2536025369 100644
--- a/src/PhpWord/Writer/Word2007/Style/Tab.php
+++ b/src/PhpWord/Writer/Word2007/Style/Tab.php
@@ -26,7 +26,7 @@ public function write()
}
$this->xmlWriter->startElement("w:tab");
- $this->xmlWriter->writeAttribute("w:val", $this->style->getStopType());
+ $this->xmlWriter->writeAttribute("w:val", $this->style->getType());
$this->xmlWriter->writeAttribute("w:leader", $this->style->getLeader());
$this->xmlWriter->writeAttribute('w:pos', $this->convertTwip($this->style->getPosition()));
$this->xmlWriter->endElement();
diff --git a/tests/PhpWord/Tests/Element/CellTest.php b/tests/PhpWord/Tests/Element/CellTest.php
index 2d7cfd56a9..a1ef6e3682 100644
--- a/tests/PhpWord/Tests/Element/CellTest.php
+++ b/tests/PhpWord/Tests/Element/CellTest.php
@@ -219,7 +219,7 @@ public function testAddObjectException()
{
$src = __DIR__ . "/../_files/xsl/passthrough.xsl";
$oCell = new Cell('section', 1);
- $element = $oCell->addObject($src);
+ $oCell->addObject($src);
}
/**
@@ -255,7 +255,7 @@ public function testAddPreserveTextNotUTF8()
public function testAddPreserveTextException()
{
$oCell = new Cell('section', 1);
- $element = $oCell->addPreserveText('text');
+ $oCell->addPreserveText('text');
}
/**
diff --git a/tests/PhpWord/Tests/Element/ImageTest.php b/tests/PhpWord/Tests/Element/ImageTest.php
index ab4d7a5931..28b3946e85 100644
--- a/tests/PhpWord/Tests/Element/ImageTest.php
+++ b/tests/PhpWord/Tests/Element/ImageTest.php
@@ -29,7 +29,7 @@ public function testConstruct()
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
- $this->assertEquals($oImage->getIsWatermark(), false);
+ $this->assertEquals($oImage->isWatermark(), false);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
}
@@ -72,7 +72,7 @@ public function testImages()
$this->assertEquals($image->getImageExtension(), $extension);
$this->assertEquals($image->getImageCreateFunction(), $createFunction);
$this->assertEquals($image->getImageFunction(), $imageFunction);
- $this->assertFalse($image->getIsMemImage());
+ $this->assertFalse($image->isMemImage());
}
}
@@ -107,6 +107,7 @@ public function testInvalidImageLocal()
public function testInvalidImagePhp()
{
$object = new Image('test.php');
+ $object->getSource();
}
/**
@@ -117,6 +118,7 @@ public function testInvalidImagePhp()
public function testUnsupportedImage()
{
$object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP');
+ $object->getSource();
}
/**
diff --git a/tests/PhpWord/Tests/Element/ObjectTest.php b/tests/PhpWord/Tests/Element/ObjectTest.php
index 45fa627180..8d92f4afb1 100644
--- a/tests/PhpWord/Tests/Element/ObjectTest.php
+++ b/tests/PhpWord/Tests/Element/ObjectTest.php
@@ -34,15 +34,14 @@ public function testConstructWithSupportedFiles()
/**
* Create new instance with non-supported files
+ *
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
*/
public function testConstructWithNotSupportedFiles()
{
$src = __DIR__ . "/../_files/xsl/passthrough.xsl";
$oObject = new Object($src);
-
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
- $this->assertEquals($oObject->getSource(), null);
- $this->assertEquals($oObject->getStyle(), null);
+ $oObject->getSource();
}
/**
diff --git a/tests/PhpWord/Tests/Element/SectionTest.php b/tests/PhpWord/Tests/Element/SectionTest.php
index 9624299c25..49e6a9fe7f 100644
--- a/tests/PhpWord/Tests/Element/SectionTest.php
+++ b/tests/PhpWord/Tests/Element/SectionTest.php
@@ -12,6 +12,7 @@
use PhpOffice\PhpWord\Element\Header;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception;
+use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style;
/**
@@ -75,9 +76,10 @@ public function testAddElements()
{
$objectSource = __DIR__ . "/../_files/documents/reader.docx";
$imageSource = __DIR__ . "/../_files/images/PhpWord.png";
- $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
+ // $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
$section = new Section(0);
+ $section->setPhpWord(new PhpWord());
$section->addText(utf8_decode('ä'));
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä'));
$section->addTextBreak();
@@ -96,10 +98,10 @@ public function testAddElements()
$elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
'Table', 'ListItem', 'Object', 'Image',
'Title', 'TextRun', 'Footnote', 'CheckBox', 'TOC');
- $i = 0;
+ $elmCount = 0;
foreach ($elementTypes as $elementType) {
- $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$i]);
- $i++;
+ $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$elmCount]);
+ $elmCount++;
}
}
@@ -122,6 +124,7 @@ public function testAddTitleWithStyle()
{
Style::addTitleStyle(1, array('size' => 14));
$section = new Section(0);
+ $section->setPhpWord(new PhpWord());
$section->addTitle('Test', 1);
$elementCollection = $section->getElements();
@@ -163,6 +166,6 @@ public function testHasDifferentFirstPage()
public function testAddHeaderException()
{
$object = new Section(1);
- $header = $object->addHeader('ODD');
+ $object->addHeader('ODD');
}
}
diff --git a/tests/PhpWord/Tests/Element/TOCTest.php b/tests/PhpWord/Tests/Element/TOCTest.php
index f3d4238163..854670cb27 100644
--- a/tests/PhpWord/Tests/Element/TOCTest.php
+++ b/tests/PhpWord/Tests/Element/TOCTest.php
@@ -9,6 +9,8 @@
namespace PhpOffice\PhpWord\Tests\Element;
+use PhpOffice\PhpWord\PhpWord;
+use PhpOffice\PhpWord\Element\Title;
use PhpOffice\PhpWord\Element\TOC;
/**
@@ -24,11 +26,11 @@ class TOCTest extends \PHPUnit_Framework_TestCase
public function testConstructWithStyleArray()
{
$expected = array(
- 'tabPos' => 9062,
- 'tabLeader' => \PhpOffice\PhpWord\Style\TOC::TABLEADER_DOT,
+ 'position' => 9062,
+ 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT,
'indent' => 200,
);
- $object = new TOC(array('_size' => 11), array('_tabPos' => $expected['tabPos']));
+ $object = new TOC(array('size' => 11), array('position' => $expected['position']));
$tocStyle = $object->getStyleTOC();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TOC', $tocStyle);
@@ -46,7 +48,7 @@ public function testConstructWithStyleArray()
public function testConstructWithStyleName()
{
$object = new TOC('Font Style');
- $tocStyle = $object->getStyleTOC();
+ // $tocStyle = $object->getStyleTOC();
$this->assertEquals('Font Style', $object->getStyleFont());
}
@@ -56,17 +58,19 @@ public function testConstructWithStyleName()
*/
public function testSetGetMinMaxDepth()
{
- $toc = new TOC();
$titles = array(
'Heading 1' => 1,
'Heading 2' => 2,
'Heading 3' => 3,
'Heading 4' => 4,
);
+
+ $phpWord = new PhpWord();
foreach ($titles as $text => $depth) {
- \PhpOffice\PhpWord\TOC::addTitle($text, $depth);
+ $phpWord->addTitle(new Title($text, $depth));
}
-
+ $toc = new TOC();
+ $toc->setPhpWord($phpWord);
$this->assertEquals(1, $toc->getMinDepth());
$this->assertEquals(9, $toc->getMaxDepth());
diff --git a/tests/PhpWord/Tests/Element/TextRunTest.php b/tests/PhpWord/Tests/Element/TextRunTest.php
index 7dfe4e636a..9ce44543fd 100644
--- a/tests/PhpWord/Tests/Element/TextRunTest.php
+++ b/tests/PhpWord/Tests/Element/TextRunTest.php
@@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Tests\Element;
+use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Element\TextRun;
/**
@@ -113,7 +114,7 @@ public function testAddLinkWithName()
public function testAddTextBreak()
{
$oTextRun = new TextRun();
- $element = $oTextRun->addTextBreak(2);
+ $oTextRun->addTextBreak(2);
$this->assertCount(2, $oTextRun->getElements());
}
@@ -138,6 +139,7 @@ public function testAddImage()
public function testCreateFootnote()
{
$oTextRun = new TextRun();
+ $oTextRun->setPhpWord(new PhpWord());
$element = $oTextRun->addFootnote();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $element);
diff --git a/tests/PhpWord/Tests/Element/TitleTest.php b/tests/PhpWord/Tests/Element/TitleTest.php
index d4635f6f57..5236398064 100644
--- a/tests/PhpWord/Tests/Element/TitleTest.php
+++ b/tests/PhpWord/Tests/Element/TitleTest.php
@@ -40,28 +40,6 @@ public function testStyleNull()
$this->assertEquals($oTitle->getStyle(), null);
}
- /**
- * Get style not null
- */
- public function testStyleNotNull()
- {
- $oTitle = new Title('text', 1, 'style');
-
- $this->assertEquals($oTitle->getStyle(), 'style');
- }
-
- /**
- * Get anchor
- */
- public function testAnchor()
- {
- $oTitle = new Title('text');
-
- $iVal = rand(1, 1000);
- $oTitle->setAnchor($iVal);
- $this->assertEquals($oTitle->getAnchor(), $iVal);
- }
-
/**
* Get bookmark Id
*/
diff --git a/tests/PhpWord/Tests/EndnotesTest.php b/tests/PhpWord/Tests/EndnotesTest.php
deleted file mode 100644
index 7217a1acc3..0000000000
--- a/tests/PhpWord/Tests/EndnotesTest.php
+++ /dev/null
@@ -1,39 +0,0 @@
-assertEquals(1, $rId);
- $this->assertEquals(1, count(Endnotes::getElements()));
- $this->assertEquals($endnote2, Endnotes::getElement(1));
- $this->assertNull(Endnotes::getElement(2));
-
- Endnotes::resetElements();
- $this->assertEquals(0, Endnotes::countElements());
- }
-}
diff --git a/tests/PhpWord/Tests/FootnotesTest.php b/tests/PhpWord/Tests/FootnotesTest.php
deleted file mode 100644
index 5371273d39..0000000000
--- a/tests/PhpWord/Tests/FootnotesTest.php
+++ /dev/null
@@ -1,39 +0,0 @@
-assertEquals(1, $rId);
- $this->assertEquals(1, count(Footnotes::getElements()));
- $this->assertEquals($footnote2, Footnotes::getElement(1));
- $this->assertNull(Footnotes::getElement(2));
-
- Footnotes::resetElements();
- $this->assertEquals(0, Footnotes::countElements());
- }
-}
diff --git a/tests/PhpWord/Tests/PhpWordTest.php b/tests/PhpWord/Tests/PhpWordTest.php
index eddb6b23de..ae82b1fee4 100644
--- a/tests/PhpWord/Tests/PhpWordTest.php
+++ b/tests/PhpWord/Tests/PhpWordTest.php
@@ -51,9 +51,8 @@ public function testSetGetDocumentProperties()
public function testCreateGetSections()
{
$phpWord = new PhpWord();
- $this->assertEquals(new Section(1), $phpWord->addSection());
$phpWord->addSection();
- $this->assertEquals(2, count($phpWord->getSections()));
+ $this->assertEquals(1, count($phpWord->getSections()));
}
/**
diff --git a/tests/PhpWord/Tests/SettingsTest.php b/tests/PhpWord/Tests/SettingsTest.php
index 94fe74494c..2bb16fce01 100644
--- a/tests/PhpWord/Tests/SettingsTest.php
+++ b/tests/PhpWord/Tests/SettingsTest.php
@@ -23,9 +23,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
*/
public function testSetGetCompatibility()
{
- $this->assertTrue(Settings::getCompatibility());
+ $this->assertTrue(Settings::hasCompatibility());
$this->assertTrue(Settings::setCompatibility(false));
- $this->assertFalse(Settings::getCompatibility());
+ $this->assertFalse(Settings::hasCompatibility());
$this->assertFalse(Settings::setCompatibility('Non boolean'));
}
diff --git a/tests/PhpWord/Tests/Shared/DrawingTest.php b/tests/PhpWord/Tests/Shared/DrawingTest.php
index 2ae0217057..2d95810f25 100644
--- a/tests/PhpWord/Tests/Shared/DrawingTest.php
+++ b/tests/PhpWord/Tests/Shared/DrawingTest.php
@@ -32,7 +32,7 @@ public function testUnitConversions()
$result = Drawing::pixelsToEMU($value);
$this->assertEquals(round($value * 9525), $result);
- $result = Drawing::EMUToPixels($value);
+ $result = Drawing::emuToPixels($value);
$this->assertEquals(round($value / 9525), $result);
$result = Drawing::pixelsToPoints($value);
diff --git a/tests/PhpWord/Tests/Shared/FontTest.php b/tests/PhpWord/Tests/Shared/FontTest.php
index c68aac12bc..f41de0bfd9 100644
--- a/tests/PhpWord/Tests/Shared/FontTest.php
+++ b/tests/PhpWord/Tests/Shared/FontTest.php
@@ -25,8 +25,6 @@ class FontTest extends \PHPUnit_Framework_TestCase
*/
public function testConversions()
{
- $phpWord = new PhpWord();
-
$original = 1;
$result = Font::fontSizeToPixels($original);
diff --git a/tests/PhpWord/Tests/Style/CellTest.php b/tests/PhpWord/Tests/Style/CellTest.php
index 7f12ce1c40..a3a7e03084 100644
--- a/tests/PhpWord/Tests/Style/CellTest.php
+++ b/tests/PhpWord/Tests/Style/CellTest.php
@@ -56,7 +56,6 @@ public function testBorderColor()
{
$object = new Cell();
- $default = '000000';
$value = 'FF0000';
$object->setStyleValue('borderColor', $value);
diff --git a/tests/PhpWord/Tests/Style/TOCTest.php b/tests/PhpWord/Tests/Style/TOCTest.php
index 43537dbb10..fd2a809e0d 100644
--- a/tests/PhpWord/Tests/Style/TOCTest.php
+++ b/tests/PhpWord/Tests/Style/TOCTest.php
@@ -27,8 +27,8 @@ public function testProperties()
$object = new TOC();
$properties = array(
- 'tabPos' => 9062,
- 'tabLeader' => TOC::TABLEADER_DOT,
+ 'position' => 9062,
+ 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT,
'indent' => 200,
);
foreach ($properties as $key => $value) {
@@ -37,10 +37,6 @@ public function testProperties()
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
-
- // setStyleValue
- $object->setStyleValue("{$key}", null);
- $this->assertEquals(null, $object->$get());
}
}
}
diff --git a/tests/PhpWord/Tests/TOCTest.php b/tests/PhpWord/Tests/TOCTest.php
deleted file mode 100644
index 1db3e6f008..0000000000
--- a/tests/PhpWord/Tests/TOCTest.php
+++ /dev/null
@@ -1,53 +0,0 @@
- 1,
- 'Heading 2' => 2,
- 'Heading 3' => 3,
- );
- $toc = new TOC();
-
- foreach ($titles as $text => $depth) {
- $response = $toc->addTitle($text, $depth);
- }
- $this->assertEquals($anchor, $response[0]);
- $this->assertEquals($bookmark, $response[1]);
-
- $i = 0;
- $savedTitles = $toc->getTitles();
- foreach ($titles as $text => $depth) {
- $this->assertEquals($text, $savedTitles[$i]['text']);
- $this->assertEquals($depth, $savedTitles[$i]['depth']);
- $i++;
- }
-
- TOC::resetTitles();
- $this->assertEquals(0, count($toc->getTitles()));
- }
-}
diff --git a/tests/PhpWord/Tests/Writer/ODTextTest.php b/tests/PhpWord/Tests/Writer/ODTextTest.php
index dc545fdc78..2e68374c9e 100644
--- a/tests/PhpWord/Tests/Writer/ODTextTest.php
+++ b/tests/PhpWord/Tests/Writer/ODTextTest.php
@@ -129,7 +129,7 @@ public function testSetGetUseDiskCaching()
{
$object = new ODText();
$object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR);
- $this->assertTrue($object->getUseDiskCaching());
+ $this->assertTrue($object->isUseDiskCaching());
$this->assertEquals(PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory());
}
diff --git a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php b/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php
index f597d463c5..ff01edb34e 100644
--- a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php
+++ b/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php
@@ -48,7 +48,6 @@ public function testConstruct()
public function testSetGetAbstractRendererProperties()
{
define('DOMPDF_ENABLE_AUTOLOAD', false);
- $file = __DIR__ . "/../../_files/temp.pdf";
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
diff --git a/tests/PhpWord/Tests/Writer/PDFTest.php b/tests/PhpWord/Tests/Writer/PDFTest.php
index 3e583d0f96..b164392f3f 100644
--- a/tests/PhpWord/Tests/Writer/PDFTest.php
+++ b/tests/PhpWord/Tests/Writer/PDFTest.php
@@ -47,5 +47,6 @@ public function testConstruct()
public function testConstructException()
{
$writer = new PDF(new PhpWord());
+ $writer->save();
}
}
diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php
index dd4665e244..8286473bd5 100644
--- a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php
+++ b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php
@@ -361,11 +361,11 @@ public function testWriteParagraphStyle()
$doc = TestHelperDOCX::getDocument($phpWord);
// Test the attributes
- $i = 0;
+ $attributeCount = 0;
foreach ($attributes as $key => $value) {
- $i++;
+ $attributeCount++;
$nodeName = ($key == 'align') ? 'jc' : $key;
- $path = "/w:document/w:body/w:p[{$i}]/w:pPr/w:{$nodeName}";
+ $path = "/w:document/w:body/w:p[{$attributeCount}]/w:pPr/w:{$nodeName}";
if ($key != 'align') {
$value = $value ? 1 : 0;
}
@@ -416,7 +416,6 @@ public function testWriteFontStyle()
public function testWriteTableStyle()
{
$phpWord = new PhpWord();
- $tWidth = 120;
$rHeight = 120;
$cWidth = 120;
$imageSrc = __DIR__ . "/../../../_files/images/earth.jpg";
@@ -511,7 +510,7 @@ public function testWriteGutterAndLineNumbering()
$lineNumberingPath = '/w:document/w:body/w:sectPr/w:lnNumType';
$phpWord = new PhpWord();
- $section = $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array()));
+ $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array()));
$doc = TestHelperDOCX::getDocument($phpWord);
$this->assertEquals(240, $doc->getElement($pageMarginPath)->getAttribute('w:gutter'));
diff --git a/tests/PhpWord/Tests/Writer/Word2007Test.php b/tests/PhpWord/Tests/Writer/Word2007Test.php
index a297b16252..1d4687f1af 100644
--- a/tests/PhpWord/Tests/Writer/Word2007Test.php
+++ b/tests/PhpWord/Tests/Writer/Word2007Test.php
@@ -171,13 +171,13 @@ public function testGetWriterPartNull()
public function testSetGetUseDiskCaching()
{
$phpWord = new PhpWord();
- $section = $phpWord->addSection();
+ $phpWord->addSection();
$object = new Word2007($phpWord);
$object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR);
$writer = new Word2007($phpWord);
$writer->save('php://output');
- $this->assertTrue($object->getUseDiskCaching());
+ $this->assertTrue($object->isUseDiskCaching());
}
/**