Merge pull request #220 from ivanlanin/nonstatic

Remove static classes #206; Reactivate PHPCPD and PHPMD
This commit is contained in:
Ivan Lanin 2014-05-05 00:46:53 +07:00
commit acd25a4db4
88 changed files with 1267 additions and 1347 deletions

View File

@ -32,14 +32,14 @@ before_script:
- pyrus install pear/PHP_CodeSniffer - pyrus install pear/PHP_CodeSniffer
- phpenv rehash - phpenv rehash
## PHP Copy/Paste Detector ## 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 ## PHP Mess Detector
#- pear config-set preferred_state beta - pear config-set preferred_state beta
#- printf "\n" | pecl install imagick - printf "\n" | pecl install imagick
#- pear channel-discover pear.phpmd.org - pear channel-discover pear.phpmd.org
#- pear channel-discover pear.pdepend.org - pear channel-discover pear.pdepend.org
#- pear install --alldeps phpmd/PHP_PMD - pear install --alldeps phpmd/PHP_PMD
#- phpenv rehash - phpenv rehash
## PHPLOC ## PHPLOC
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar #- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
## PHPDocumentor ## PHPDocumentor
@ -48,18 +48,17 @@ before_script:
script: script:
## PHP_CodeSniffer ## PHP_CodeSniffer
- phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip - phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
- phpcs --standard=PSR2 -n tests/
## PHP Copy/Paste Detector ## PHP Copy/Paste Detector
#- php phpcpd.phar --verbose src/ - php phpcpd.phar src/ tests/ --verbose
## PHP Mess Detector ## PHP Mess Detector
#- phpmd src/ text unusedcode,naming,design - phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
## PHPLOC ## PHPLOC
#- php phploc.phar src/ #- php phploc.phar src/
## PHPUnit ## PHPUnit
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage - phpunit -c ./ --coverage-text --coverage-html ./build/coverage
## PHPDocumentor ## 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: after_script:
## PHPDocumentor ## PHPDocumentor

View File

@ -31,7 +31,7 @@ if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPWord" ] && [ "$TRAVIS_PULL_REQUEST" ==
echo "--DEBUG : Git" echo "--DEBUG : Git"
git add -f . 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 git push -fq origin gh-pages > /dev/null
echo -e "Published PHPDoc to gh-pages.\n" echo -e "Published PHPDoc to gh-pages.\n"

View File

@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
## 0.11.0 - Not yet released ## 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 ### 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 ### Miscellaneous
- License: Change the project license from LGPL 2.1 into LGPL 3.0 - GH-211 - License: Change the project license from LGPL 2.1 into LGPL 3.0 - GH-211
- Word2007 Writer: New `Style\Image` class - @ivanlanin - 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 ## 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 - 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 - 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 - 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 - DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
- Endnote: Ability to add endnotes - @ivanlanin - Endnote: Ability to add endnotes - @ivanlanin
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198 - ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198

View File

@ -1,14 +0,0 @@
<?xml version="1.0"?>
<ruleset name="PHPWord mess detector ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation=" http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml/LongVariable" />
<rule ref="rulesets/naming.xml/ShortVariable" />
<rule ref="rulesets/naming.xml/ShortMethodName" />
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
<rule ref="rulesets/naming.xml/ConstantNamingConventions" />
</ruleset>

View File

@ -21,4 +21,7 @@
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>
<logging>
<log type="coverage-html" target="./build/coverage" charset="UTF-8" highlight="true" />
</logging>
</phpunit> </phpunit>

View File

@ -0,0 +1,87 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Collection abstract class
*
* @since 0.10.0
*/
abstract class AbstractCollection
{
/**
* Items
*
* @var array
*/
private $items = array();
/**
* Get items
*
* @return array
*/
public function getItems()
{
return $this->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);
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Endnotes collection
*
* @since 0.10.0
*/
class Endnotes extends AbstractCollection
{
}

View File

@ -0,0 +1,19 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Footnotes collection
*
* @since 0.10.0
*/
class Footnotes extends AbstractCollection
{
}

View File

@ -0,0 +1,19 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Titles collection
*
* @since 0.10.0
*/
class Titles extends AbstractCollection
{
}

View File

@ -9,13 +9,15 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Endnotes; use PhpOffice\PhpWord\Element\CheckBox;
use PhpOffice\PhpWord\Exception\InvalidObjectException; use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Footnotes; use PhpOffice\PhpWord\Element\Link;
use PhpOffice\PhpWord\Element\ListItem;
use PhpOffice\PhpWord\Element\Object;
use PhpOffice\PhpWord\Element\TextBreak;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\TOC as Titles;
/** /**
* Container abstract class * Container abstract class
@ -36,8 +38,11 @@ abstract class AbstractContainer extends AbstractElement
*/ */
protected function addElement(AbstractElement $element) protected function addElement(AbstractElement $element)
{ {
$type = get_class($element);
$type = str_replace('PhpOffice\\PhpWord\\Element\\', '', $type);
$element->setElementIndex($this->countElements() + 1); $element->setElementIndex($this->countElements() + 1);
$element->setElementId(); $element->setElementId();
$element->setPhpWord($this->phpWord);
$this->elements[] = $element; $this->elements[] = $element;
} }
@ -62,99 +67,71 @@ abstract class AbstractContainer extends AbstractElement
} }
/** /**
* Add text element * Add text/preservetext element
* *
* @param string $text * @param string $text
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $paragraphStyle * @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 // Reset paragraph style for footnote and textrun. They have their own
if (in_array($this->container, array('textrun', 'footnote', 'endnote'))) { if (in_array($this->container, array('textrun', 'footnote', 'endnote'))) {
$paragraphStyle = null; $paragraphStyle = null;
} }
$text = String::toUTF8($text); $element = new $elementClass($text, $fontStyle, $paragraphStyle);
$textObject = new Text($text, $fontStyle, $paragraphStyle); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$textObject->setDocPart($this->getDocPart(), $this->getDocPartId()); $this->addElement($element);
$this->addElement($textObject);
return $textObject; return $element;
} }
/** /**
* Add textrun element * Add textrun element
* *
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return TextRun * @return \PhpOffice\PhpWord\Element\TextRun
*/ */
public function addTextRun($paragraphStyle = null) public function addTextRun($paragraphStyle = null)
{ {
$this->checkValidity('textrun'); $this->checkValidity('Textrun');
$textRun = new TextRun($paragraphStyle); $element = new TextRun($paragraphStyle);
$textRun->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($textRun); $this->addElement($element);
return $textRun; return $element;
} }
/** /**
* Add link element * Add link element
* *
* @param string $linkSrc * @param string $target
* @param string $linkName * @param string $text
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $paragraphStyle * @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(); $elementDocPart = $this->checkElementDocPart();
$link = new Link(String::toUTF8($linkSrc), String::toUTF8($linkName), $fontStyle, $paragraphStyle); $element = new Link($target, $text, $fontStyle, $paragraphStyle);
$link->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$rId = Media::addElement($elementDocPart, 'link', $linkSrc);
$link->setRelationId($rId);
$this->addElement($link);
return $link; $rId = Media::addElement($elementDocPart, 'link', $target);
} $element->setRelationId($rId);
/** $this->addElement($element);
* 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');
$styles = Style::getStyles(); return $element;
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;
} }
/** /**
@ -163,17 +140,11 @@ abstract class AbstractContainer extends AbstractElement
* @param string $text * @param string $text
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return PreserveText * @return \PhpOffice\PhpWord\Element\PreserveText
*/ */
public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null) public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null)
{ {
$this->checkValidity('preservetext'); return $this->addText($text, $fontStyle, $paragraphStyle, 'PreserveText');
$preserveText = new PreserveText(String::toUTF8($text), $fontStyle, $paragraphStyle);
$preserveText->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($preserveText);
return $preserveText;
} }
/** /**
@ -185,12 +156,12 @@ abstract class AbstractContainer extends AbstractElement
*/ */
public function addTextBreak($count = 1, $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++) { for ($i = 1; $i <= $count; $i++) {
$textBreak = new TextBreak($fontStyle, $paragraphStyle); $element = new TextBreak($fontStyle, $paragraphStyle);
$textBreak->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($textBreak); $this->addElement($element);
} }
} }
@ -200,56 +171,43 @@ abstract class AbstractContainer extends AbstractElement
* @param string $text * @param string $text
* @param int $depth * @param int $depth
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $styleList * @param mixed $listStyle
* @param mixed $paragraphStyle * @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); $element = new ListItem($text, $depth, $fontStyle, $listStyle, $paragraphStyle);
$listItem->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($listItem); $this->addElement($element);
return $listItem; return $element;
}
/**
* 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;
} }
/** /**
* Add image element * Add image element
* *
* @param string $src * @param string $source
* @param mixed $style Image style * @param mixed $style Image style
* @param boolean $isWatermark * @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(); $elementDocPart = $this->checkElementDocPart();
$image = new Image($src, $style, $isWatermark); $element = new Image($source, $style, $isWatermark);
$image->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$rId = Media::addElement($elementDocPart, 'image', $src, $image);
$image->setRelationId($rId); $rId = Media::addElement($elementDocPart, 'image', $source, $element);
$this->addElement($image); $element->setRelationId($rId);
return $image;
$this->addElement($element);
return $element;
} }
/** /**
@ -257,76 +215,63 @@ abstract class AbstractContainer extends AbstractElement
* *
* All exceptions should be handled by \PhpOffice\PhpWord\Element\Object * All exceptions should be handled by \PhpOffice\PhpWord\Element\Object
* *
* @param string $src * @param string $source
* @param mixed $style * @param mixed $style
* @return Object * @return \PhpOffice\PhpWord\Element\Object
* @throws \PhpOffice\PhpWord\Exception\Exception * @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(); $elementDocPart = $this->checkElementDocPart();
$object = new Object($src, $style); $element = new Object($source, $style);
$object->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->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; $rId = Media::addElement($elementDocPart, 'object', $source);
} else { $element->setRelationId($rId);
throw new InvalidObjectException(); $rIdIcon = Media::addElement($elementDocPart, 'image', $element->getIcon(), new Image($element->getIcon()));
} $element->setImageRelationId($rIdIcon);
$this->addElement($element);
return $element;
} }
/** /**
* Add footnote element * Add footnote element
* *
* @param mixed $paragraphStyle * @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'); $this->checkValidity($elementName);
$elementClass = 'PhpOffice\\PhpWord\\Element\\' . $elementName;
$docPart = strtolower($elementName);
$addMethod = "add{$elementName}";
$footnote = new Footnote($paragraphStyle); $element = new $elementClass($paragraphStyle);
$rId = Footnotes::addElement($footnote); if ($this->phpWord instanceof PhpWord) {
$rId = $this->phpWord->$addMethod($element);
}
$element->setDocPart($docPart, $this->getDocPartId());
$element->setRelationId($rId);
$this->addElement($element);
$footnote->setDocPart('footnote', $this->getDocPartId()); return $element;
$footnote->setRelationId($rId);
$this->addElement($footnote);
return $footnote;
} }
/** /**
* Add endnote element * Add endnote element
* *
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return Endnote * @return \PhpOffice\PhpWord\Element\Endnote
*/ */
public function addEndnote($paragraphStyle = null) public function addEndnote($paragraphStyle = null)
{ {
$this->checkValidity('endnote'); return $this->addFootnote($paragraphStyle, 'Endnote');
$endnote = new Endnote($paragraphStyle);
$rId = Endnotes::addElement($endnote);
$endnote->setDocPart('endnote', $this->getDocPartId());
$endnote->setRelationId($rId);
$this->addElement($endnote);
return $endnote;
} }
/** /**
@ -336,17 +281,17 @@ abstract class AbstractContainer extends AbstractElement
* @param string $text * @param string $text
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return CheckBox * @return \PhpOffice\PhpWord\Element\CheckBox
*/ */
public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = null) 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); $element = new CheckBox($name, $text, $fontStyle, $paragraphStyle);
$checkBox->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($checkBox); $this->addElement($element);
return $checkBox; return $element;
} }
/** /**
@ -360,26 +305,24 @@ abstract class AbstractContainer extends AbstractElement
// Valid containers for each element // Valid containers for each element
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote'); $allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote');
$validContainers = array( $validContainers = array(
'text' => $allContainers, 'Text' => $allContainers,
'link' => $allContainers, 'Link' => $allContainers,
'textbreak' => $allContainers, 'TextBreak' => $allContainers,
'image' => $allContainers, 'Image' => $allContainers,
'object' => $allContainers, 'Object' => $allContainers,
'textrun' => array('section', 'header', 'footer', 'cell'), 'TextRun' => array('section', 'header', 'footer', 'cell'),
'listitem' => array('section', 'header', 'footer', 'cell'), 'ListItem' => array('section', 'header', 'footer', 'cell'),
'checkbox' => array('section', 'header', 'footer', 'cell'), 'CheckBox' => array('section', 'header', 'footer', 'cell'),
'table' => array('section', 'header', 'footer'), 'Footnote' => array('section', 'textrun', 'cell'),
'footnote' => array('section', 'textrun', 'cell'), 'Endnote' => array('section', 'textrun', 'cell'),
'endnote' => array('section', 'textrun', 'cell'), 'PreserveText' => array('header', 'footer', 'cell'),
'preservetext' => array('header', 'footer', 'cell'),
'title' => array('section'),
); );
// Special condition, e.g. preservetext can only exists in cell when // Special condition, e.g. preservetext can only exists in cell when
// the cell is located in header or footer // the cell is located in header or footer
$validSubcontainers = array( $validSubcontainers = array(
'preservetext' => array(array('cell'), array('header', 'footer')), 'PreserveText' => array(array('cell'), array('header', 'footer')),
'footnote' => array(array('cell', 'textrun'), array('section')), 'Footnote' => array(array('cell', 'textrun'), array('section')),
'endnote' => array(array('cell', 'textrun'), array('section')), 'Endnote' => array(array('cell', 'textrun'), array('section')),
); );
// Check if a method is valid for current container // Check if a method is valid for current container
@ -412,7 +355,7 @@ abstract class AbstractContainer extends AbstractElement
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container; $docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId; $docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer'); $inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
$docPartId = $inHeaderFooter ? $this->getDocPartId() : $docPartId;
return $inHeaderFooter ? $docPart . $docPartId : $docPart; return $inHeaderFooter ? $docPart . $docPartId : $docPart;
} }

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
/** /**
@ -18,6 +19,11 @@ use PhpOffice\PhpWord\Style;
*/ */
abstract class AbstractElement abstract class AbstractElement
{ {
/**
* PhpWord object
*/
protected $phpWord;
/** /**
* Container type section|header|footer|cell|textrun|footnote|endnote * Container type section|header|footer|cell|textrun|footnote|endnote
* *
@ -75,6 +81,26 @@ abstract class AbstractElement
*/ */
protected $relationId; 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 * Get section number
* *

View File

@ -9,6 +9,8 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\String;
/** /**
* Check box element * Check box element
*/ */
@ -44,7 +46,7 @@ class CheckBox extends Text
*/ */
public function setName($name) public function setName($name)
{ {
$this->name = $name; $this->name = String::toUTF8($name);
return $this; return $this;
} }

View File

@ -9,35 +9,49 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Element\Table;
/** /**
* Footer element * Footer element
*/ */
class Footer extends AbstractContainer 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 AUTO = 'default'; // default and odd pages
const FIRST = 'first'; const FIRST = 'first';
const EVEN = 'even'; const EVEN = 'even';
/**
* Container type
*
* @var string
*/
protected $container = 'footer';
/** /**
* Header type * Header type
* *
* @var string * @var string
*/ */
private $type = self::AUTO; protected $type = self::AUTO;
/** /**
* Create new instance * Create new instance
* *
* @param int $sectionId * @param int $sectionId
* @param int $footerId * @param int $containerId
* @param string $type * @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->sectionId = $sectionId;
$this->setType($type); $this->setType($type);
$this->setDocPart($this->container, ($sectionId - 1) * 3 + $footerId); $this->setDocPart($this->container, ($sectionId - 1) * 3 + $containerId);
} }
/** /**
@ -48,6 +62,9 @@ class Footer extends AbstractContainer
*/ */
public function setType($value = 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; $this->type = $value;
} }
@ -61,4 +78,49 @@ class Footer extends AbstractContainer
{ {
return $this->type; 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;
}
} }

View File

@ -12,39 +12,15 @@ namespace PhpOffice\PhpWord\Element;
/** /**
* Header element * 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 * @var string
*/ */
private $type = self::AUTO; protected $container = 'header';
/**
* 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);
}
/** /**
* Add a Watermark Element * Add a Watermark Element
@ -57,58 +33,4 @@ class Header extends AbstractContainer
{ {
return $this->addImage($src, $style, true); 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;
}
} }

View File

@ -52,7 +52,7 @@ class Image extends AbstractElement
* *
* @var boolean * @var boolean
*/ */
private $isWatermark; private $watermark;
/** /**
* Image type * Image type
@ -87,7 +87,7 @@ class Image extends AbstractElement
* *
* @var boolean * @var boolean
*/ */
private $isMemImage; private $memoryImage;
/** /**
* Image target file name * Image target file name
@ -108,14 +108,14 @@ class Image extends AbstractElement
* *
* @param string $source * @param string $source
* @param mixed $style * @param mixed $style
* @param boolean $isWatermark * @param boolean $watermark
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException * @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException * @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->source = $source;
$this->setIsWatermark($isWatermark); $this->setIsWatermark($watermark);
$this->style = $this->setStyle(new ImageStyle(), $style, true); $this->style = $this->setStyle(new ImageStyle(), $style, true);
$this->checkImage($source); $this->checkImage($source);
@ -166,19 +166,19 @@ class Image extends AbstractElement
* *
* @return boolean * @return boolean
*/ */
public function getIsWatermark() public function isWatermark()
{ {
return $this->isWatermark; return $this->watermark;
} }
/** /**
* Set is 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 @@ class Image extends AbstractElement
* *
* @return boolean * @return boolean
*/ */
public function getIsMemImage() public function isMemImage()
{ {
return $this->isMemImage; return $this->memoryImage;
} }
/** /**
@ -314,14 +314,14 @@ class Image extends AbstractElement
private function setSourceType($source) private function setSourceType($source)
{ {
if (stripos(strrev($source), strrev('.php')) === 0) { if (stripos(strrev($source), strrev('.php')) === 0) {
$this->isMemImage = true; $this->memoryImage = true;
$this->sourceType = self::SOURCE_GD; $this->sourceType = self::SOURCE_GD;
} elseif (strpos($source, 'zip://') !== false) { } elseif (strpos($source, 'zip://') !== false) {
$this->isMemImage = false; $this->memoryImage = false;
$this->sourceType = self::SOURCE_ARCHIVE; $this->sourceType = self::SOURCE_ARCHIVE;
} else { } else {
$this->isMemImage = (filter_var($source, FILTER_VALIDATE_URL) !== false); $this->memoryImage = (filter_var($source, FILTER_VALIDATE_URL) !== false);
$this->sourceType = $this->isMemImage ? self::SOURCE_GD : self::SOURCE_LOCAL; $this->sourceType = $this->memoryImage ? self::SOURCE_GD : self::SOURCE_LOCAL;
} }
} }
@ -409,4 +409,26 @@ class Image extends AbstractElement
} }
} }
} }
/**
* 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();
}
} }

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
@ -56,8 +57,8 @@ class Link extends AbstractElement
*/ */
public function __construct($target, $text = null, $fontStyle = null, $paragraphStyle = null) public function __construct($target, $text = null, $fontStyle = null, $paragraphStyle = null)
{ {
$this->target = $target; $this->target = String::toUTF8($target);
$this->text = is_null($text) ? $target : $text; $this->text = is_null($text) ? $this->target : String::toUTF8($text);
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle); $this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle); $this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; 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) 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; $this->depth = $depth;
// Version >= 0.10.0 will pass numbering style name. Older version will use old method // Version >= 0.10.0 will pass numbering style name. Older version will use old method

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Image as ImageStyle; use PhpOffice\PhpWord\Style\Image as ImageStyle;
use PhpOffice\PhpWord\Exception\InvalidObjectException;
/** /**
* Object element * Object element
@ -30,6 +31,13 @@ class Object extends AbstractElement
*/ */
private $style; private $style;
/**
* Icon
*
* @var string
*/
private $icon;
/** /**
* Image Relation ID * Image Relation ID
* *
@ -40,35 +48,32 @@ class Object extends AbstractElement
/** /**
* Create a new Ole-Object Element * Create a new Ole-Object Element
* *
* @param string $src * @param string $source
* @param mixed $style * @param mixed $style
*/ */
public function __construct($src, $style = null) public function __construct($source, $style = null)
{ {
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx'); $supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
$inf = pathinfo($src); $pathInfo = pathinfo($source);
if (file_exists($src) && in_array($inf['extension'], $supportedTypes)) { if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
$this->source = $src; $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->style = $this->setStyle(new ImageStyle(), $style, true);
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
return $this; return $this;
} else { } else {
return false; throw new InvalidObjectException();
} }
} }
/** /**
* Get Image style * Get object source
*
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->style;
}
/**
* Get Source
* *
* @return string * @return string
*/ */
@ -78,7 +83,27 @@ class Object extends AbstractElement
} }
/** /**
* Get Image Relation ID * Get object style
*
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->style;
}
/**
* Get object icon
*
* @return string
*/
public function getIcon()
{
return $this->icon;
}
/**
* Get image relation ID
* *
* @return int * @return int
*/ */

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
@ -52,7 +53,8 @@ class PreserveText extends AbstractElement
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle); $this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle); $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])) { if (isset($matches[0])) {
$this->text = $matches; $this->text = $matches;
} }

View File

@ -63,6 +63,7 @@ class Row extends AbstractElement
public function addCell($width = null, $style = null) public function addCell($width = null, $style = null)
{ {
$cell = new Cell($this->getDocPart(), $this->getDocPartId(), $width, $style); $cell = new Cell($this->getDocPart(), $this->getDocPartId(), $width, $style);
$cell->setPhpWord($this->phpWord);
$this->cells[] = $cell; $this->cells[] = $cell;
return $cell; return $cell;
} }

View File

@ -9,7 +9,12 @@
namespace PhpOffice\PhpWord\Element; 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\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Section as SectionSettings; use PhpOffice\PhpWord\Style\Section as SectionSettings;
/** /**
@ -80,12 +85,47 @@ class Section extends AbstractContainer
return $this->settings; 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 * Add a PageBreak Element
*/ */
public function addPageBreak() 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 @@ class Section extends AbstractContainer
public function addTOC($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9) public function addTOC($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
{ {
$toc = new TOC($fontStyle, $tocStyle, $minDepth, $maxDepth); $toc = new TOC($fontStyle, $tocStyle, $minDepth, $maxDepth);
$this->elements[] = $toc; $this->addElement($toc);
return $toc; return $toc;
} }
@ -185,6 +226,8 @@ class Section extends AbstractContainer
if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) { if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
$index = count($collection); $index = count($collection);
$container = new $containerClass($this->sectionId, ++$index, $type); $container = new $containerClass($this->sectionId, ++$index, $type);
$container->setPhpWord($this->phpWord);
$collection[$index] = $container; $collection[$index] = $container;
return $container; return $container;
} else { } else {

View File

@ -4,14 +4,14 @@
* *
* @link https://github.com/PHPOffice/PHPWord * @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 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; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\TOC as TOCStyle; use PhpOffice\PhpWord\Style\TOC as TOCStyle;
use PhpOffice\PhpWord\TOC as Titles;
/** /**
* Table of contents * Table of contents
@ -87,16 +87,20 @@ class TOC extends AbstractElement
*/ */
public function getTitles() public function getTitles()
{ {
$titles = Titles::getTitles(); if (!$this->phpWord instanceof PhpWord) {
return array();
}
$titles = $this->phpWord->getTitles()->getItems();
foreach ($titles as $i => $title) { foreach ($titles as $i => $title) {
if ($this->minDepth > $title['depth']) { $depth = $title->getDepth();
if ($this->minDepth > $depth) {
unset($titles[$i]); unset($titles[$i]);
} }
if (($this->maxDepth != 0) && ($this->maxDepth < $title['depth'])) { if (($this->maxDepth != 0) && ($this->maxDepth < $depth)) {
unset($titles[$i]); unset($titles[$i]);
} }
} }
$titles = array_merge(array(), $titles);
return $titles; return $titles;
} }

View File

@ -60,6 +60,7 @@ class Table extends AbstractElement
public function addRow($height = null, $style = null) public function addRow($height = null, $style = null)
{ {
$row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style); $row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style);
$row->setPhpWord($this->phpWord);
$this->rows[] = $row; $this->rows[] = $row;
return $row; return $row;
} }

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
@ -127,7 +128,7 @@ class Text extends AbstractElement
*/ */
public function setText($text) public function setText($text)
{ {
$this->text = $text; $this->text = String::toUTF8($text);
return $this; return $this;
} }

View File

@ -9,6 +9,9 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Shared\String;
/** /**
* Title element * Title element
*/ */
@ -26,69 +29,48 @@ class Title extends AbstractElement
* *
* @var int * @var int
*/ */
private $depth; private $depth = 1;
/**
* Title anchor
*
* @var int
*/
private $anchor;
/** /**
* Title Bookmark ID * Title Bookmark ID
* *
* @var int * @var int
*/ */
private $bookmarkId; private $bookmarkId = 1;
/** /**
* Title style * Name of the heading style, e.g. 'Heading1'
* *
* @var string * @var string
*/ */
private $style; private $style;
/**
* Title anchor
*
* @var int
* @deprecated 0.10.0
*/
private $anchor;
/** /**
* Create a new Title Element * Create a new Title Element
* *
* @param string $text * @param string $text
* @param int $depth * @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 = String::toUTF8($text);
$this->depth = $depth;
if (array_key_exists('Heading_' . $this->depth, Style::getStyles())) {
$this->style = 'Heading' . $this->depth;
} }
$this->text = $text;
$this->depth = $depth;
return $this; 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 * Set Bookmark ID
* *
@ -138,4 +120,28 @@ class Title extends AbstractElement
{ {
return $this->style; 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);
}
} }

View File

@ -1,95 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord;
/**
* Endnote collection
*
* @since 0.10.0
*/
class Endnotes
{
/**
* Elements
*
* @var array
*/
private static $elements = array();
/**
* Add new element
*
* @param \PhpOffice\PhpWord\Element\Endnote $element
* @return integer Reference ID
*/
public static function addElement($element)
{
$rId = self::countElements() + 1;
self::$elements[$rId] = $element;
return $rId;
}
/**
* Set element
*
* @param integer $index
* @param \PhpOffice\PhpWord\Element\Endnote $element
*/
public static function setElement($index, $element)
{
if (array_key_exists($index, self::$elements)) {
self::$elements[$index] = $element;
}
}
/**
* Get element by index
*
* @param integer $index
* @return \PhpOffice\PhpWord\Element\Endnote
*/
public static function getElement($index)
{
if (array_key_exists($index, self::$elements)) {
return self::$elements[$index];
} else {
return null;
}
}
/**
* Get elements
*
* @return array
*/
public static function getElements()
{
return self::$elements;
}
/**
* Get element count
*
* @return integer
*/
public static function countElements()
{
return count(self::$elements);
}
/**
* Reset elements
*/
public static function resetElements()
{
self::$elements = array();
}
}

View File

@ -1,162 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord;
/**
* Footnote collection
*/
class Footnotes
{
/**
* Elements
*
* @var array
*/
private static $elements = array();
/**
* Add new element
*
* @param \PhpOffice\PhpWord\Element\Footnote $element
* @return integer Reference ID
* @since 0.10.0
*/
public static function addElement($element)
{
$rId = self::countElements() + 1;
self::$elements[$rId] = $element;
return $rId;
}
/**
* Set element
*
* @param integer $index
* @param \PhpOffice\PhpWord\Element\Footnote $element
* @since 0.10.0
*/
public static function setElement($index, $element)
{
if (array_key_exists($index, self::$elements)) {
self::$elements[$index] = $element;
}
}
/**
* Get element by index
*
* @param integer $index
* @return \PhpOffice\PhpWord\Element\Footnote
* @since 0.10.0
*/
public static function getElement($index)
{
if (array_key_exists($index, self::$elements)) {
return self::$elements[$index];
} else {
return null;
}
}
/**
* Get elements
*
* @return array
* @since 0.10.0
*/
public static function getElements()
{
return self::$elements;
}
/**
* Get element count
*
* @return integer
* @since 0.10.0
*/
public static function countElements()
{
return count(self::$elements);
}
/**
* Reset elements
*
* @since 0.10.0
*/
public static function resetElements()
{
self::$elements = array();
}
/**
* Add new footnote
*
* @param \PhpOffice\PhpWord\Element\Footnote $element
* @return integer Reference ID
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public static function addFootnoteElement($element)
{
return self::addElement($element);
}
/**
* Get Footnote Elements
*
* @return array
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public static function getFootnoteElements()
{
return self::getElements();
}
/**
* Get Footnote Elements Count
*
* @return integer
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public static function countFootnoteElements()
{
return self::countElements();
}
/**
* Add new Footnote Link Element
*
* @param string $linkSrc
* @return integer Reference ID
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public static function addFootnoteLinkElement($linkSrc)
{
return Media::addElement('footnotes', 'link', $linkSrc);
}
/**
* Get Footnote Link Elements
*
* @return array
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public static function getFootnoteLinkElements()
{
return Media::getElements('footnotes', 'link');
}
}

View File

@ -59,7 +59,7 @@ class Media
if (is_null($image)) { if (is_null($image)) {
throw new Exception('Image object not assigned.'); throw new Exception('Image object not assigned.');
} }
$isMemImage = $image->getIsMemImage(); $isMemImage = $image->isMemImage();
$extension = $image->getImageExtension(); $extension = $image->getImageExtension();
$mediaData['imageExtension'] = $extension; $mediaData['imageExtension'] = $extension;
$mediaData['imageType'] = $image->getImageType(); $mediaData['imageType'] = $image->getImageType();

View File

@ -9,9 +9,14 @@
namespace PhpOffice\PhpWord; 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\Element\Section;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Template;
/** /**
* PHPWord main class * PHPWord main class
@ -37,6 +42,34 @@ class PhpWord
*/ */
private $documentProperties; 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 * Default font name
* *
@ -50,19 +83,15 @@ class PhpWord
*/ */
private $defaultFontSize; private $defaultFontSize;
/**
* Collection of sections
*
* @var \PhpOffice\PhpWord\Element\Section[]
*/
private $sections = array();
/** /**
* Create new * Create new
*/ */
public function __construct() public function __construct()
{ {
$this->documentProperties = new DocumentProperties(); $this->documentProperties = new DocumentProperties();
$this->titles = new Titles();
$this->footnotes = new Footnotes();
$this->endnotes = new Endnotes();
$this->defaultFontName = self::DEFAULT_FONT_NAME; $this->defaultFontName = self::DEFAULT_FONT_NAME;
$this->defaultFontSize = self::DEFAULT_FONT_SIZE; $this->defaultFontSize = self::DEFAULT_FONT_SIZE;
} }
@ -90,6 +119,16 @@ class PhpWord
return $this; return $this;
} }
/**
* Get all sections
*
* @return \PhpOffice\PhpWord\Element\Section[]
*/
public function getSections()
{
return $this->sections;
}
/** /**
* Create new section * Create new section
* *
@ -99,11 +138,75 @@ class PhpWord
public function addSection($settings = null) public function addSection($settings = null)
{ {
$section = new Section(count($this->sections) + 1, $settings); $section = new Section(count($this->sections) + 1, $settings);
$section->setPhpWord($this);
$this->sections[] = $section; $this->sections[] = $section;
return $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 * Get default font name
* *
@ -223,16 +326,6 @@ class PhpWord
Style::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 * Load template by filename
* *

View File

@ -37,7 +37,7 @@ abstract class AbstractReader implements ReaderInterface
* *
* @return bool * @return bool
*/ */
public function getReadDataOnly() public function isReadDataOnly()
{ {
// return $this->readDataOnly; // return $this->readDataOnly;
return true; return true;
@ -96,4 +96,15 @@ abstract class AbstractReader implements ReaderInterface
return true; return true;
} }
/**
* Read data only?
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getReadDataOnly()
{
return $this->isReadDataOnly();
}
} }

View File

@ -1,63 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Core/extended document properties reader
*/
class DocProps extends AbstractPart
{
/**
* Property mapping
*
* @var array
*/
protected $mapping = array();
/**
* Callback functions
*
* @var array
*/
protected $callbacks = array();
/**
* 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);
}
}
}
}
}

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Reader\Word2007;
/** /**
* Extended properties reader * Extended properties reader
*/ */
class DocPropsApp extends DocProps class DocPropsApp extends DocPropsCore
{ {
/** /**
* Property mapping * Property mapping
@ -20,4 +20,11 @@ class DocPropsApp extends DocProps
* @var array * @var array
*/ */
protected $mapping = array('Company' => 'setCompany', 'Manager' => 'setManager'); protected $mapping = array('Company' => 'setCompany', 'Manager' => 'setManager');
/**
* Callback functions
*
* @var array
*/
protected $callbacks = array();
} }

View File

@ -9,10 +9,13 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Core properties reader * Core properties reader
*/ */
class DocPropsCore extends DocProps class DocPropsCore extends AbstractPart
{ {
/** /**
* Property mapping * Property mapping
@ -37,4 +40,34 @@ class DocPropsCore extends DocProps
* @var array * @var array
*/ */
protected $callbacks = array('dcterms:created' => 'strtotime', 'dcterms:modified' => 'strtotime'); 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);
}
}
}
}
} }

View File

@ -32,8 +32,8 @@ class Notes extends AbstractPart
public function read(PhpWord &$phpWord) public function read(PhpWord &$phpWord)
{ {
$this->type = ($this->type == 'endnotes') ? 'endnotes' : 'footnotes'; $this->type = ($this->type == 'endnotes') ? 'endnotes' : 'footnotes';
$collectionClass = 'PhpOffice\\PhpWord\\' . ucfirst($this->type); $getMethod = 'get' . $this->type;
$collection = $collectionClass::getElements(); $collection = $phpWord->$getMethod()->getItems();
$xmlReader = new XMLReader(); $xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
@ -49,9 +49,10 @@ class Notes extends AbstractPart
$element = $collection[$id]; $element = $collection[$id];
$pNodes = $xmlReader->getElements('w:p/*', $node); $pNodes = $xmlReader->getElements('w:p/*', $node);
foreach ($pNodes as $pNode) { 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);
} }
} }
} }

View File

@ -91,6 +91,16 @@ class Settings
*/ */
private static $measurementUnit = self::UNIT_TWIP; 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 * Set the compatibility option used by the XMLWriter
* *
@ -110,13 +120,13 @@ class Settings
} }
/** /**
* 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 @@ class Settings
return false; 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 * Set details of the external library for rendering PDF files
* *
@ -237,4 +237,15 @@ class Settings
return true; return true;
} }
/**
* Return the compatibility option used by the XMLWriter
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public static function getCompatibility()
{
return self::hasCompatibility();
}
} }

View File

@ -17,24 +17,24 @@ class Drawing
/** /**
* Convert pixels to EMU * Convert pixels to EMU
* *
* @param integer $pValue Value in pixels * @param integer $value Value in pixels
* @return double Value in EMU * @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 * Convert EMU to pixels
* *
* @param integer $pValue Value in EMU * @param integer $value Value in EMU
* @return integer Value in pixels * @return integer Value in pixels
*/ */
public static function EMUToPixels($pValue = 0) public static function emuToPixels($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return round($pValue / 9525); return round($value / 9525);
} else { } else {
return 0; return 0;
} }
@ -43,24 +43,24 @@ class Drawing
/** /**
* Convert pixels to points * Convert pixels to points
* *
* @param integer $pValue Value in pixels * @param integer $value Value in pixels
* @return double Value in points * @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 * Convert points width to pixels
* *
* @param integer $pValue Value in points * @param integer $value Value in points
* @return integer Value in pixels * @return integer Value in pixels
*/ */
public static function pointsToPixels($pValue = 0) public static function pointsToPixels($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return $pValue * 1.333333333; return $value * 1.333333333;
} else { } else {
return 0; return 0;
} }
@ -69,24 +69,24 @@ class Drawing
/** /**
* Convert degrees to angle * Convert degrees to angle
* *
* @param integer $pValue Degrees * @param integer $value Degrees
* @return integer Angle * @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 * Convert angle to degrees
* *
* @param integer $pValue Angle * @param integer $value Angle
* @return integer Degrees * @return integer Degrees
*/ */
public static function angleToDegrees($pValue = 0) public static function angleToDegrees($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return round($pValue / 60000); return round($value / 60000);
} else { } else {
return 0; return 0;
} }
@ -95,24 +95,24 @@ class Drawing
/** /**
* Convert pixels to centimeters * Convert pixels to centimeters
* *
* @param integer $pValue Value in pixels * @param integer $value Value in pixels
* @return double Value in centimeters * @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 * Convert centimeters width to pixels
* *
* @param integer $pValue Value in centimeters * @param integer $value Value in centimeters
* @return integer Value in pixels * @return integer Value in pixels
*/ */
public static function centimetersToPixels($pValue = 0) public static function centimetersToPixels($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return $pValue / 0.028; return $value / 0.028;
} else { } else {
return 0; return 0;
} }
@ -121,27 +121,27 @@ class Drawing
/** /**
* Convert HTML hexadecimal to RGB * Convert HTML hexadecimal to RGB
* *
* @param string $pValue HTML Color in hexadecimal * @param string $value HTML Color in hexadecimal
* @return array Value in RGB * @return array Value in RGB
*/ */
public static function htmlToRGB($pValue) public static function htmlToRGB($value)
{ {
if ($pValue[0] == '#') { if ($value[0] == '#') {
$pValue = substr($pValue, 1); $value = substr($value, 1);
} }
if (strlen($pValue) == 6) { if (strlen($value) == 6) {
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]); list($red, $green, $blue) = array($value[0] . $value[1], $value[2] . $value[3], $value[4] . $value[5]);
} elseif (strlen($pValue) == 3) { } elseif (strlen($value) == 3) {
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]); list($red, $green, $blue) = array($value[0] . $value[0], $value[1] . $value[1], $value[2] . $value[2]);
} else { } else {
return false; return false;
} }
$color_R = hexdec($color_R); $red = hexdec($red);
$color_G = hexdec($color_G); $green = hexdec($green);
$color_B = hexdec($color_B); $blue = hexdec($blue);
return array($color_R, $color_G, $color_B); return array($red, $green, $blue);
} }
} }

View File

@ -73,7 +73,7 @@ class XMLWriter
} }
// Set xml Compatibility // Set xml Compatibility
$compatibility = Settings::getCompatibility(); $compatibility = Settings::hasCompatibility();
if ($compatibility) { if ($compatibility) {
$this->xmlWriter->setIndent(false); $this->xmlWriter->setIndent(false);
$this->xmlWriter->setIndentString(''); $this->xmlWriter->setIndentString('');

View File

@ -287,7 +287,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getBold() public function isBold()
{ {
return $this->bold; return $this->bold;
} }
@ -310,7 +310,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getItalic() public function isItalic()
{ {
return $this->italic; return $this->italic;
} }
@ -333,7 +333,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getSuperScript() public function isSuperScript()
{ {
return $this->superScript; return $this->superScript;
} }
@ -359,7 +359,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getSubScript() public function isSubScript()
{ {
return $this->subScript; return $this->subScript;
} }
@ -408,7 +408,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getStrikethrough() public function isStrikethrough()
{ {
return $this->strikethrough; return $this->strikethrough;
} }
@ -434,7 +434,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getDoubleStrikethrough() public function isDoubleStrikethrough()
{ {
return $this->doubleStrikethrough; return $this->doubleStrikethrough;
} }
@ -604,7 +604,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getSmallCaps() public function isSmallCaps()
{ {
return $this->smallCaps; return $this->smallCaps;
} }
@ -630,7 +630,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getAllCaps() public function isAllCaps()
{ {
return $this->allCaps; return $this->allCaps;
} }
@ -680,4 +680,59 @@ class Font extends AbstractStyle
return $this; 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();
}
} }

View File

@ -338,7 +338,7 @@ class Paragraph extends AbstractStyle
/** /**
* Get parent style ID * Get parent style ID
* *
* @return string * @return string
*/ */
public function getBasedOn() public function getBasedOn()
{ {
@ -348,8 +348,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set parent style ID * Set parent style ID
* *
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setBasedOn($value = 'Normal') public function setBasedOn($value = 'Normal')
{ {
@ -370,8 +370,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set style for next paragraph * Set style for next paragraph
* *
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setNext($value = null) public function setNext($value = null)
{ {
@ -382,9 +382,9 @@ class Paragraph extends AbstractStyle
/** /**
* Get allow first/last line to display on a separate page setting * 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; return $this->widowControl;
} }
@ -392,8 +392,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set keep paragraph with next paragraph setting * Set keep paragraph with next paragraph setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setWidowControl($value = true) public function setWidowControl($value = true)
{ {
@ -407,9 +407,9 @@ class Paragraph extends AbstractStyle
/** /**
* Get keep paragraph with next paragraph setting * Get keep paragraph with next paragraph setting
* *
* @return bool * @return bool
*/ */
public function getKeepNext() public function isKeepNext()
{ {
return $this->keepNext; return $this->keepNext;
} }
@ -417,8 +417,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set keep paragraph with next paragraph setting * Set keep paragraph with next paragraph setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setKeepNext($value = false) public function setKeepNext($value = false)
{ {
@ -432,9 +432,9 @@ class Paragraph extends AbstractStyle
/** /**
* Get keep all lines on one page setting * Get keep all lines on one page setting
* *
* @return bool * @return bool
*/ */
public function getKeepLines() public function isKeepLines()
{ {
return $this->keepLines; return $this->keepLines;
} }
@ -442,8 +442,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set keep all lines on one page setting * Set keep all lines on one page setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setKeepLines($value = false) public function setKeepLines($value = false)
{ {
@ -459,7 +459,7 @@ class Paragraph extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getPageBreakBefore() public function hasPageBreakBefore()
{ {
return $this->pageBreakBefore; return $this->pageBreakBefore;
} }
@ -467,8 +467,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set start paragraph on next page setting * Set start paragraph on next page setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setPageBreakBefore($value = false) public function setPageBreakBefore($value = false)
{ {
@ -540,4 +540,48 @@ class Paragraph extends AbstractStyle
return $this; 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();
}
} }

View File

@ -45,9 +45,19 @@ class Row extends AbstractStyle
} }
/** /**
* Set tblHeader * Is tblHeader
* *
* @param boolean $value * @return bool
*/
public function isTblHeader()
{
return $this->tblHeader;
}
/**
* Is tblHeader
*
* @param bool $value
* @return self * @return self
*/ */
public function setTblHeader($value = false) public function setTblHeader($value = false)
@ -56,19 +66,19 @@ class Row extends AbstractStyle
} }
/** /**
* 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 * @return self
*/ */
public function setCantSplit($value = false) public function setCantSplit($value = false)
@ -77,13 +87,13 @@ class Row extends AbstractStyle
} }
/** /**
* Get cantSplit * Is exactHeight
* *
* @return boolean * @return bool
*/ */
public function getCantSplit() public function isExactHeight()
{ {
return $this->cantSplit; return $this->exactHeight;
} }
/** /**
@ -98,13 +108,36 @@ class Row extends AbstractStyle
return $this; 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 * Get exactHeight
* *
* @return boolean * @deprecated 0.10.0
* @codeCoverageIgnore
*/ */
public function getExactHeight() public function getExactHeight()
{ {
return $this->exactHeight; return $this->isExactHeight();
} }
} }

View File

@ -12,26 +12,12 @@ namespace PhpOffice\PhpWord\Style;
/** /**
* TOC style * TOC style
*/ */
class TOC extends AbstractStyle class TOC extends Tab
{ {
const TABLEADER_DOT = 'dot'; const TABLEADER_DOT = self::TAB_LEADER_DOT;
const TABLEADER_UNDERSCORE = 'underscore'; const TABLEADER_UNDERSCORE = self::TAB_LEADER_UNDERSCORE;
const TABLEADER_LINE = 'hyphen'; const TABLEADER_LINE = self::TAB_LEADER_HYPHEN;
const TABLEADER_NONE = ''; const TABLEADER_NONE = self::TAB_LEADER_NONE;
/**
* Tab Leader
*
* @var string
*/
private $tabLeader;
/**
* Tab Position
*
* @var int
*/
private $tabPos;
/** /**
* Indent * Indent
@ -46,8 +32,7 @@ class TOC extends AbstractStyle
*/ */
public function __construct() public function __construct()
{ {
$this->tabPos = 9062; parent::__construct(self::TAB_STOP_RIGHT, 9062, self::TABLEADER_DOT);
$this->tabLeader = self::TABLEADER_DOT;
$this->indent = 200; $this->indent = 200;
} }
@ -58,17 +43,17 @@ class TOC extends AbstractStyle
*/ */
public function getTabPos() public function getTabPos()
{ {
return $this->tabPos; return $this->getPosition();
} }
/** /**
* Set Tab Position * 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 @@ class TOC extends AbstractStyle
*/ */
public function getTabLeader() public function getTabLeader()
{ {
return $this->tabLeader; return $this->getLeader();
} }
/** /**
* Set Tab Leader * 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 @@ class TOC extends AbstractStyle
/** /**
* Set Indent * Set Indent
* *
* @param string $pValue * @param string $value
*/ */
public function setIndent($pValue) public function setIndent($value)
{ {
$this->indent = $pValue; $this->indent = $value;
} }
} }

View File

@ -44,7 +44,7 @@ class Tab extends AbstractStyle
* *
* @var string * @var string
*/ */
private $val = self::TAB_STOP_CLEAR; private $type = self::TAB_STOP_CLEAR;
/** /**
* Tab leader character * Tab leader character
@ -54,22 +54,22 @@ class Tab extends AbstractStyle
private $leader = self::TAB_LEADER_NONE; private $leader = self::TAB_LEADER_NONE;
/** /**
* Tab stop position * Tab stop position (twip)
* *
* @var int * @var int|float
*/ */
private $position = 0; 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 * must conform to the values put forth in the schema. If they do not
* they will be changed to default values. * 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 int $position Must be numeric; otherwise defaults to 0.
* @param string $leader Defaults to null if value is not possible. * @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( $stopTypes = array(
self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT,self::TAB_STOP_CENTER, self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT,self::TAB_STOP_CENTER,
@ -80,7 +80,7 @@ class Tab extends AbstractStyle
self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT 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->position = $this->setNumericVal($position, $this->position);
$this->leader = $this->setEnumVal($leader, $leaderTypes, $this->leader); $this->leader = $this->setEnumVal($leader, $leaderTypes, $this->leader);
} }
@ -90,9 +90,21 @@ class Tab extends AbstractStyle
* *
* @return string * @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 @@ class Tab extends AbstractStyle
return $this->leader; 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 * Get position
* *
* @return integer * @return int|float
*/ */
public function getPosition() public function getPosition()
{ {
return $this->position; return $this->position;
} }
/**
* Set position
*
* @param int|float $value
*/
public function setPosition($value)
{
$this->position = $this->setNumericVal($value, $this->position);
}
} }

View File

@ -222,7 +222,7 @@ class Table extends Border
/** /**
* Set border size inside horizontal * Set border size inside horizontal
* *
* @param $value * @param int $value
*/ */
public function setBorderInsideHSize($value = null) public function setBorderInsideHSize($value = null)
{ {
@ -232,7 +232,7 @@ class Table extends Border
/** /**
* Get border size inside horizontal * Get border size inside horizontal
* *
* @return * @return int
*/ */
public function getBorderInsideHSize() public function getBorderInsideHSize()
{ {
@ -242,7 +242,7 @@ class Table extends Border
/** /**
* Set border size inside vertical * Set border size inside vertical
* *
* @param $value * @param int $value
*/ */
public function setBorderInsideVSize($value = null) public function setBorderInsideVSize($value = null)
{ {
@ -252,7 +252,7 @@ class Table extends Border
/** /**
* Get border size inside vertical * Get border size inside vertical
* *
* @return * @return int
*/ */
public function getBorderInsideVSize() public function getBorderInsideVSize()
{ {
@ -262,7 +262,7 @@ class Table extends Border
/** /**
* Set border color inside horizontal * Set border color inside horizontal
* *
* @param $value * @param string $value
*/ */
public function setBorderInsideHColor($value = null) public function setBorderInsideHColor($value = null)
{ {
@ -272,7 +272,7 @@ class Table extends Border
/** /**
* Get border color inside horizontal * Get border color inside horizontal
* *
* @return * @return string
*/ */
public function getBorderInsideHColor() public function getBorderInsideHColor()
{ {
@ -282,7 +282,7 @@ class Table extends Border
/** /**
* Set border color inside vertical * Set border color inside vertical
* *
* @param $value * @param string $value
*/ */
public function setBorderInsideVColor($value = null) public function setBorderInsideVColor($value = null)
{ {
@ -292,7 +292,7 @@ class Table extends Border
/** /**
* Get border color inside vertical * Get border color inside vertical
* *
* @return * @return string
*/ */
public function getBorderInsideVColor() public function getBorderInsideVColor()
{ {

View File

@ -1,78 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord;
/**
* Table of contents
*/
class TOC
{
/**
* Title elements
*
* @var array
*/
private static $titles = array();
/**
* Title anchor
*
* @var int
*/
private static $anchor = 252634154;
/**
* Title bookmark
*
* @var int
*/
private static $bookmarkId = 0;
/**
* Add a Title
*
* @param string $text
* @param int $depth
* @return array
*/
public static function addTitle($text, $depth = 0)
{
$anchor = '_Toc' . ++self::$anchor;
$bookmarkId = self::$bookmarkId++;
$title = array();
$title['text'] = $text;
$title['depth'] = $depth;
$title['anchor'] = $anchor;
$title['bookmarkId'] = $bookmarkId;
self::$titles[] = $title;
return array($anchor, $bookmarkId);
}
/**
* Get all titles
*
* @return array
*/
public static function getTitles()
{
return self::$titles;
}
/**
* Reset titles
*/
public static function resetTitles()
{
self::$titles = array();
}
}

View File

@ -44,7 +44,7 @@ abstract class AbstractWriter implements WriterInterface
/** /**
* Use disk caching * Use disk caching
* *
* @var boolean * @var bool
*/ */
private $useDiskCaching = false; private $useDiskCaching = false;
@ -121,9 +121,9 @@ abstract class AbstractWriter implements WriterInterface
/** /**
* Get use disk caching status * Get use disk caching status
* *
* @return boolean * @return bool
*/ */
public function getUseDiskCaching() public function isUseDiskCaching()
{ {
return $this->useDiskCaching; return $this->useDiskCaching;
} }
@ -131,7 +131,7 @@ abstract class AbstractWriter implements WriterInterface
/** /**
* Set use disk caching status * Set use disk caching status
* *
* @param boolean $pValue * @param bool $pValue
* @param string $pDirectory * @param string $pDirectory
* @return self * @return self
*/ */
@ -356,4 +356,15 @@ abstract class AbstractWriter implements WriterInterface
rmdir($dir); rmdir($dir);
} }
/**
* Get use disk caching status
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getUseDiskCaching()
{
return $this->isUseDiskCaching();
}
} }

View File

@ -167,14 +167,16 @@ class HTML extends AbstractWriter implements WriterInterface
*/ */
private function writeNotes() private function writeNotes()
{ {
$phpWord = $this->getPhpWord();
$html = ''; $html = '';
if (!empty($this->notes)) { if (!empty($this->notes)) {
$html .= "<hr />"; $html .= "<hr />";
foreach ($this->notes as $noteId => $noteMark) { foreach ($this->notes as $noteId => $noteMark) {
$noteAnchor = "note-{$noteId}"; $noteAnchor = "note-{$noteId}";
list($noteType, $noteTypeId) = explode('-', $noteMark); list($noteType, $noteTypeId) = explode('-', $noteMark);
$collectionObject = 'PhpOffice\\PhpWord\\' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes'); $method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes');
$collection = $collectionObject::getElements(); $collection = $phpWord->$method()->getItems();
if (array_key_exists($noteTypeId, $collection)) { if (array_key_exists($noteTypeId, $collection)) {
$element = $collection[$noteTypeId]; $element = $collection[$noteTypeId];
$elmWriter = new TextRunWriter($this, $element, true); $elmWriter = new TextRunWriter($this, $element, true);

View File

@ -14,6 +14,12 @@ namespace PhpOffice\PhpWord\Writer\HTML\Element;
* *
* @since 0.10.0 * @since 0.10.0
*/ */
class Endnote extends Note class Endnote extends Footnote
{ {
/**
* Note type
*
* @var string
*/
protected $noteType = 'endnote';
} }

View File

@ -14,6 +14,27 @@ namespace PhpOffice\PhpWord\Writer\HTML\Element;
* *
* @since 0.10.0 * @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 = "<a name=\"{$noteMark}\"><a href=\"#note-{$noteId}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>";
return $html;
}
} }

View File

@ -1,34 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\HTML\Element;
/**
* Note element HTML writer
*
* @since 0.10.0
*/
class Note extends Element
{
/**
* Write footnote/endnote marks
*
* @return string
*/
public function write()
{
$noteId = count($this->parentWriter->getNotes()) + 1;
$prefix = ($this->element instanceof \PhpOffice\PhpWord\Element\Endnote) ? 'endnote' : 'footnote';
$noteMark = $prefix . '-' . $this->element->getRelationId();
$this->parentWriter->addNote($noteId, $noteMark);
$html = "<a name=\"{$noteMark}\"><a href=\"#note-{$noteId}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>";
return $html;
}
}

View File

@ -41,22 +41,22 @@ class Font extends AbstractStyle
$css['color'] = '#' . $this->style->getColor(); $css['color'] = '#' . $this->style->getColor();
} }
$css['background'] = $this->style->getFgColor(); $css['background'] = $this->style->getFgColor();
if ($this->style->getBold()) { if ($this->style->isBold()) {
$css['font-weight'] = 'bold'; $css['font-weight'] = 'bold';
} }
if ($this->style->getItalic()) { if ($this->style->isItalic()) {
$css['font-style'] = 'italic'; $css['font-style'] = 'italic';
} }
if ($this->style->getSuperScript()) { if ($this->style->isSuperScript()) {
$css['vertical-align'] = 'super'; $css['vertical-align'] = 'super';
} elseif ($this->style->getSubScript()) { } elseif ($this->style->isSubScript()) {
$css['vertical-align'] = 'sub'; $css['vertical-align'] = 'sub';
} }
$css['text-decoration'] = ''; $css['text-decoration'] = '';
if ($this->style->getUnderline() != FontStyle::UNDERLINE_NONE) { if ($this->style->getUnderline() != FontStyle::UNDERLINE_NONE) {
$css['text-decoration'] .= 'underline '; $css['text-decoration'] .= 'underline ';
} }
if ($this->style->getStrikethrough()) { if ($this->style->isStrikethrough()) {
$css['text-decoration'] .= 'line-through '; $css['text-decoration'] .= 'line-through ';
} }

View File

@ -25,12 +25,12 @@ class Text extends Element
$paragraphStyle = $this->element->getParagraphStyle(); $paragraphStyle = $this->element->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value // @todo Commented for TextRun. Should really checkout this value
// $SfIsObject = ($fontStyle instanceof Font) ? true : false; // $fStyleIsObject = ($fontStyle instanceof Font) ? true : false;
$SfIsObject = false; $fStyleIsObject = false;
if ($SfIsObject) { if ($fStyleIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared // 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 { } else {
if (!$this->withoutP) { if (!$this->withoutP) {
$this->xmlWriter->startElement('text:p'); // text:p $this->xmlWriter->startElement('text:p'); // text:p

View File

@ -46,12 +46,12 @@ class Font extends AbstractStyle
if ($this->style->getColor()) { if ($this->style->getColor()) {
$this->xmlWriter->writeAttribute('fo:color', '#' . $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('fo:font-style', 'italic');
$this->xmlWriter->writeAttribute('style:font-style-asian', 'italic'); $this->xmlWriter->writeAttribute('style:font-style-asian', 'italic');
$this->xmlWriter->writeAttribute('style:font-style-complex', '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('fo:font-weight', 'bold');
$this->xmlWriter->writeAttribute('style:font-weight-asian', 'bold'); $this->xmlWriter->writeAttribute('style:font-weight-asian', 'bold');
} }

View File

@ -73,10 +73,10 @@ class Text extends Element
} else { } else {
$rtfText .= '\f0'; $rtfText .= '\f0';
} }
if ($fontStyle->getBold()) { if ($fontStyle->isBold()) {
$rtfText .= '\b'; $rtfText .= '\b';
} }
if ($fontStyle->getItalic()) { if ($fontStyle->isItalic()) {
$rtfText .= '\i'; $rtfText .= '\i';
} }
if ($fontStyle->getSize()) { if ($fontStyle->getSize()) {
@ -92,10 +92,10 @@ class Text extends Element
$rtfText .= '\cf0'; $rtfText .= '\cf0';
$rtfText .= '\f0'; $rtfText .= '\f0';
if ($fontStyle->getBold()) { if ($fontStyle->isBold()) {
$rtfText .= '\b0'; $rtfText .= '\b0';
} }
if ($fontStyle->getItalic()) { if ($fontStyle->isItalic()) {
$rtfText .= '\i0'; $rtfText .= '\i0';
} }
if ($fontStyle->getSize()) { if ($fontStyle->getSize()) {

View File

@ -179,29 +179,27 @@ class Word2007 extends AbstractWriter implements WriterInterface
* *
* @param mixed $objZip * @param mixed $objZip
* @param integer $rId * @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'; $noteType = ($noteType == 'endnote') ? 'endnote' : 'footnote';
$notesTypes = "{$notesType}s"; $noteTypePlural = "{$noteType}s";
$collection = 'PhpOffice\\PhpWord\\' . ucfirst($notesTypes); $method = 'get' . $noteTypePlural;
$xmlFile = "{$notesTypes}.xml"; $collection = $this->phpWord->$method();
$relsFile = "word/_rels/{$xmlFile}.rels";
$xmlPath = "word/{$xmlFile}";
// Add footnotes media files, relations, and contents // Add footnotes media files, relations, and contents
if ($collection::countElements() > 0) { if ($collection->countItems() > 0) {
$media = Media::getElements($notesType); $media = Media::getElements($noteType);
$this->addFilesToPackage($objZip, $media); $this->addFilesToPackage($objZip, $media);
$this->registerContentTypes($media); $this->registerContentTypes($media);
if (!empty($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(); $elements = $collection->getItems();
$objZip->addFromString($xmlPath, $this->getWriterPart($notesTypes)->write($elements)); $objZip->addFromString("word/{$noteTypePlural}.xml", $this->getWriterPart($noteTypePlural)->write($elements));
$this->cTypes['override']["/{$xmlPath}"] = $notesTypes; $this->cTypes['override']["/word/{$noteTypePlural}.xml"] = $noteTypePlural;
$this->docRels[] = array('target' => $xmlFile, 'type' => $notesTypes, 'rID' => ++$rId); $this->docRels[] = array('target' => "{$noteTypePlural}.xml", 'type' => $noteTypePlural, 'rID' => ++$rId);
} }
} }

View File

@ -14,14 +14,12 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
* *
* @since 0.10.0 * @since 0.10.0
*/ */
class Endnote extends Note class Endnote extends Footnote
{ {
/** /**
* Write element * Reference type
*
* @var string
*/ */
public function write() protected $referenceType = 'endnoteReference';
{
$this->referenceType = 'endnoteReference';
parent::write();
}
} }

View File

@ -14,14 +14,35 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
* *
* @since 0.10.0 * @since 0.10.0
*/ */
class Footnote extends Note class Footnote extends Element
{ {
/**
* Reference type footnoteReference|endnoteReference
*
* @var string
*/
protected $referenceType = 'footnoteReference';
/** /**
* Write element * Write element
*/ */
public function write() public function write()
{ {
$this->referenceType = 'footnoteReference'; if (!$this->withoutP) {
parent::write(); $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
}
} }
} }

View File

@ -23,7 +23,7 @@ class Image extends Element
*/ */
public function write() public function write()
{ {
if ($this->element->getIsWatermark()) { if ($this->element->isWatermark()) {
$this->writeWatermark(); $this->writeWatermark();
} else { } else {
$this->writeImage(); $this->writeImage();

View File

@ -1,48 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
/**
* Note element writer
*
* @since 0.10.0
*/
class Note extends Element
{
/**
* Reference type footnoteReference|endnoteReference
*
* @var string
*/
protected $referenceType = 'footnoteReference';
/**
* Write element
*/
public function 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
}
}
}

View File

@ -12,6 +12,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Tab as TabStyleWriter;
/** /**
* TOC element writer * TOC element writer
@ -26,59 +27,53 @@ class TOC extends Element
public function write() public function write()
{ {
$titles = $this->element->getTitles(); $titles = $this->element->getTitles();
$fontStyle = $this->element->getStyleFont();
$tocStyle = $this->element->getStyleTOC(); $tocStyle = $this->element->getStyleTOC();
$fIndent = $tocStyle->getIndent(); $fontStyle = $this->element->getStyleFont();
$tabLeader = $tocStyle->getTabLeader();
$tabPos = $tocStyle->getTabPos();
$maxDepth = $this->element->getMaxDepth();
$minDepth = $this->element->getMinDepth();
$isObject = ($fontStyle instanceof Font) ? true : false; $isObject = ($fontStyle instanceof Font) ? true : false;
for ($i = 0; $i < count($titles); $i++) { $tocFieldWritten = false;
$title = $titles[$i]; foreach ($titles as $title) {
$indent = ($title['depth'] - 1) * $fIndent; $indent = ($title->getDepth() - 1) * $tocStyle->getIndent();
$anchor = '_Toc' . ($title->getBookmarkId() + 252634154);
$this->xmlWriter->startElement('w:p'); $this->xmlWriter->startElement('w:p');
// Style
$this->xmlWriter->startElement('w:pPr'); $this->xmlWriter->startElement('w:pPr');
// Paragraph
if ($isObject && !is_null($fontStyle->getParagraphStyle())) { if ($isObject && !is_null($fontStyle->getParagraphStyle())) {
$styleWriter = new ParagraphStyleWriter($this->xmlWriter, $fontStyle->getParagraphStyle()); $styleWriter = new ParagraphStyleWriter($this->xmlWriter, $fontStyle->getParagraphStyle());
$styleWriter->write(); $styleWriter->write();
} }
// Font
if (!empty($fontStyle) && !$isObject) {
$this->xmlWriter->startElement('w:rPr');
$this->xmlWriter->startElement('w:rStyle');
$this->xmlWriter->writeAttribute('w:val', $fontStyle);
$this->xmlWriter->endElement();
$this->xmlWriter->endElement(); // w:rPr
}
// Tab
$this->xmlWriter->startElement('w:tabs');
$styleWriter = new TabStyleWriter($this->xmlWriter, $tocStyle);
$styleWriter->write();
$this->xmlWriter->endElement();
// Indent
if ($indent > 0) { if ($indent > 0) {
$this->xmlWriter->startElement('w:ind'); $this->xmlWriter->startElement('w:ind');
$this->xmlWriter->writeAttribute('w:left', $indent); $this->xmlWriter->writeAttribute('w:left', $indent);
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if (!empty($fontStyle) && !$isObject) {
$this->xmlWriter->startElement('w:pPr');
$this->xmlWriter->startElement('w:pStyle');
$this->xmlWriter->writeAttribute('w:val', $fontStyle);
$this->xmlWriter->endElement();
$this->xmlWriter->endElement();
}
$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();
$this->xmlWriter->endElement();
$this->xmlWriter->endElement(); // w:pPr $this->xmlWriter->endElement(); // w:pPr
if ($tocFieldWritten !== true) {
$tocFieldWritten = true;
if ($i == 0) {
$this->xmlWriter->startElement('w:r'); $this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:fldChar'); $this->xmlWriter->startElement('w:fldChar');
$this->xmlWriter->writeAttribute('w:fldCharType', 'begin'); $this->xmlWriter->writeAttribute('w:fldCharType', 'begin');
@ -88,7 +83,7 @@ class TOC extends Element
$this->xmlWriter->startElement('w:r'); $this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:instrText'); $this->xmlWriter->startElement('w:instrText');
$this->xmlWriter->writeAttribute('xml:space', 'preserve'); $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();
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
@ -100,7 +95,7 @@ class TOC extends Element
} }
$this->xmlWriter->startElement('w:hyperlink'); $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->writeAttribute('w:history', '1');
$this->xmlWriter->startElement('w:r'); $this->xmlWriter->startElement('w:r');
@ -111,7 +106,7 @@ class TOC extends Element
} }
$this->xmlWriter->startElement('w:t'); $this->xmlWriter->startElement('w:t');
$this->xmlWriter->writeRaw($title['text']); $this->xmlWriter->writeRaw($title->getText());
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
@ -128,7 +123,7 @@ class TOC extends Element
$this->xmlWriter->startElement('w:r'); $this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:instrText'); $this->xmlWriter->startElement('w:instrText');
$this->xmlWriter->writeAttribute('xml:space', 'preserve'); $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();
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();

View File

@ -84,25 +84,22 @@ class Table extends Element
$row = $rows[$i]; $row = $rows[$i];
$height = $row->getHeight(); $height = $row->getHeight();
$rowStyle = $row->getStyle(); $rowStyle = $row->getStyle();
$tblHeader = $rowStyle->getTblHeader();
$cantSplit = $rowStyle->getCantSplit();
$exactHeight = $rowStyle->getExactHeight();
$this->xmlWriter->startElement('w:tr'); $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'); $this->xmlWriter->startElement('w:trPr');
if (!is_null($height)) { if (!is_null($height)) {
$this->xmlWriter->startElement('w:trHeight'); $this->xmlWriter->startElement('w:trHeight');
$this->xmlWriter->writeAttribute('w:val', $height); $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(); $this->xmlWriter->endElement();
} }
if ($tblHeader) { if ($rowStyle->isTblHeader()) {
$this->xmlWriter->startElement('w:tblHeader'); $this->xmlWriter->startElement('w:tblHeader');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($cantSplit) { if ($rowStyle->isCantSplit()) {
$this->xmlWriter->startElement('w:cantSplit'); $this->xmlWriter->startElement('w:cantSplit');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();

View File

@ -23,8 +23,8 @@ class Title extends Element
*/ */
public function write() public function write()
{ {
$anchor = $this->element->getAnchor();
$bookmarkId = $this->element->getBookmarkId(); $bookmarkId = $this->element->getBookmarkId();
$anchor = '_Toc' . ($bookmarkId + 252634154);
$style = $this->element->getStyle(); $style = $this->element->getStyle();
$text = htmlspecialchars($this->element->getText()); $text = htmlspecialchars($this->element->getText());
$text = String::controlCharacterPHP2OOXML($text); $text = String::controlCharacterPHP2OOXML($text);

View File

@ -62,7 +62,7 @@ abstract class AbstractPart
{ {
$useDiskCaching = false; $useDiskCaching = false;
if (!is_null($this->parentWriter)) { if (!is_null($this->parentWriter)) {
if ($this->parentWriter->getUseDiskCaching()) { if ($this->parentWriter->isUseDiskCaching()) {
$useDiskCaching = true; $useDiskCaching = true;
} }
} }

View File

@ -24,24 +24,24 @@ class ContentTypes extends AbstractPart
*/ */
public function writeContentTypes($contentTypes) public function writeContentTypes($contentTypes)
{ {
$OpenXMLPrefix = 'application/vnd.openxmlformats-'; $openXMLPrefix = 'application/vnd.openxmlformats-';
$WordMLPrefix = $OpenXMLPrefix . 'officedocument.wordprocessingml.'; $wordMLPrefix = $openXMLPrefix . 'officedocument.wordprocessingml.';
$overrides = array( $overrides = array(
'/docProps/core.xml' => $OpenXMLPrefix . 'package.core-properties+xml', '/docProps/core.xml' => $openXMLPrefix . 'package.core-properties+xml',
'/docProps/app.xml' => $OpenXMLPrefix . 'officedocument.extended-properties+xml', '/docProps/app.xml' => $openXMLPrefix . 'officedocument.extended-properties+xml',
'/word/document.xml' => $WordMLPrefix . 'document.main+xml', '/word/document.xml' => $wordMLPrefix . 'document.main+xml',
'/word/styles.xml' => $WordMLPrefix . 'styles+xml', '/word/styles.xml' => $wordMLPrefix . 'styles+xml',
'/word/numbering.xml' => $WordMLPrefix . 'numbering+xml', '/word/numbering.xml' => $wordMLPrefix . 'numbering+xml',
'/word/settings.xml' => $WordMLPrefix . 'settings+xml', '/word/settings.xml' => $wordMLPrefix . 'settings+xml',
'/word/theme/theme1.xml' => $OpenXMLPrefix . 'officedocument.theme+xml', '/word/theme/theme1.xml' => $openXMLPrefix . 'officedocument.theme+xml',
'/word/webSettings.xml' => $WordMLPrefix . 'webSettings+xml', '/word/webSettings.xml' => $wordMLPrefix . 'webSettings+xml',
'/word/fontTable.xml' => $WordMLPrefix . 'fontTable+xml', '/word/fontTable.xml' => $wordMLPrefix . 'fontTable+xml',
); );
$defaults = $contentTypes['default']; $defaults = $contentTypes['default'];
if (!empty($contentTypes['override'])) { if (!empty($contentTypes['override'])) {
foreach ($contentTypes['override'] as $key => $val) { foreach ($contentTypes['override'] as $key => $val) {
$overrides[$key] = $WordMLPrefix . $val . '+xml'; $overrides[$key] = $wordMLPrefix . $val . '+xml';
} }
} }

View File

@ -89,12 +89,12 @@ class Font extends AbstractStyle
} }
// Bold // Bold
if ($this->style->getBold()) { if ($this->style->isBold()) {
$this->xmlWriter->writeElement('w:b', null); $this->xmlWriter->writeElement('w:b', null);
} }
// Italic // Italic
if ($this->style->getItalic()) { if ($this->style->isItalic()) {
$this->xmlWriter->writeElement('w:i', null); $this->xmlWriter->writeElement('w:i', null);
$this->xmlWriter->writeElement('w:iCs', null); $this->xmlWriter->writeElement('w:iCs', null);
} }
@ -107,12 +107,12 @@ class Font extends AbstractStyle
} }
// Strikethrough // Strikethrough
if ($this->style->getStrikethrough()) { if ($this->style->isStrikethrough()) {
$this->xmlWriter->writeElement('w:strike', null); $this->xmlWriter->writeElement('w:strike', null);
} }
// Double strikethrough // Double strikethrough
if ($this->style->getDoubleStrikethrough()) { if ($this->style->isDoubleStrikethrough()) {
$this->xmlWriter->writeElement('w:dstrike', null); $this->xmlWriter->writeElement('w:dstrike', null);
} }
@ -130,19 +130,19 @@ class Font extends AbstractStyle
} }
// Superscript/subscript // Superscript/subscript
if ($this->style->getSuperScript() || $this->style->getSubScript()) { if ($this->style->isSuperScript() || $this->style->isSubScript()) {
$this->xmlWriter->startElement('w:vertAlign'); $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(); $this->xmlWriter->endElement();
} }
// Small caps // Small caps
if ($this->style->getSmallCaps()) { if ($this->style->isSmallCaps()) {
$this->xmlWriter->writeElement('w:smallCaps', null); $this->xmlWriter->writeElement('w:smallCaps', null);
} }
// All caps // All caps
if ($this->style->getAllCaps()) { if ($this->style->isAllCaps()) {
$this->xmlWriter->writeElement('w:caps', null); $this->xmlWriter->writeElement('w:caps', null);
} }

View File

@ -60,11 +60,6 @@ class Paragraph extends AbstractStyle
return; return;
} }
$widowControl = $this->style->getWidowControl();
$keepNext = $this->style->getKeepNext();
$keepLines = $this->style->getKeepLines();
$pageBreakBefore = $this->style->getPageBreakBefore();
if (!$this->withoutPPR) { if (!$this->withoutPPR) {
$this->xmlWriter->startElement('w:pPr'); $this->xmlWriter->startElement('w:pPr');
} }
@ -89,22 +84,22 @@ class Paragraph extends AbstractStyle
} }
// Pagination // Pagination
if (!$widowControl) { if (!$this->style->hasWidowControl()) {
$this->xmlWriter->startElement('w:widowControl'); $this->xmlWriter->startElement('w:widowControl');
$this->xmlWriter->writeAttribute('w:val', '0'); $this->xmlWriter->writeAttribute('w:val', '0');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($keepNext) { if ($this->style->isKeepNext()) {
$this->xmlWriter->startElement('w:keepNext'); $this->xmlWriter->startElement('w:keepNext');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($keepLines) { if ($this->style->isKeepLines()) {
$this->xmlWriter->startElement('w:keepLines'); $this->xmlWriter->startElement('w:keepLines');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($pageBreakBefore) { if ($this->style->hasPageBreakBefore()) {
$this->xmlWriter->startElement('w:pageBreakBefore'); $this->xmlWriter->startElement('w:pageBreakBefore');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();

View File

@ -26,7 +26,7 @@ class Tab extends AbstractStyle
} }
$this->xmlWriter->startElement("w:tab"); $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:leader", $this->style->getLeader());
$this->xmlWriter->writeAttribute('w:pos', $this->convertTwip($this->style->getPosition())); $this->xmlWriter->writeAttribute('w:pos', $this->convertTwip($this->style->getPosition()));
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();

View File

@ -219,7 +219,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{ {
$src = __DIR__ . "/../_files/xsl/passthrough.xsl"; $src = __DIR__ . "/../_files/xsl/passthrough.xsl";
$oCell = new Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addObject($src); $oCell->addObject($src);
} }
/** /**
@ -255,7 +255,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddPreserveTextException() public function testAddPreserveTextException()
{ {
$oCell = new Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addPreserveText('text'); $oCell->addPreserveText('text');
} }
/** /**

View File

@ -29,7 +29,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src); $this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src)); $this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getIsWatermark(), false); $this->assertEquals($oImage->isWatermark(), false);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
@ -72,7 +72,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($image->getImageExtension(), $extension); $this->assertEquals($image->getImageExtension(), $extension);
$this->assertEquals($image->getImageCreateFunction(), $createFunction); $this->assertEquals($image->getImageCreateFunction(), $createFunction);
$this->assertEquals($image->getImageFunction(), $imageFunction); $this->assertEquals($image->getImageFunction(), $imageFunction);
$this->assertFalse($image->getIsMemImage()); $this->assertFalse($image->isMemImage());
} }
} }
@ -107,6 +107,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testInvalidImagePhp() public function testInvalidImagePhp()
{ {
$object = new Image('test.php'); $object = new Image('test.php');
$object->getSource();
} }
/** /**
@ -117,6 +118,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testUnsupportedImage() public function testUnsupportedImage()
{ {
$object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP'); $object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP');
$object->getSource();
} }
/** /**

View File

@ -34,15 +34,14 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
/** /**
* Create new instance with non-supported files * Create new instance with non-supported files
*
* @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
*/ */
public function testConstructWithNotSupportedFiles() public function testConstructWithNotSupportedFiles()
{ {
$src = __DIR__ . "/../_files/xsl/passthrough.xsl"; $src = __DIR__ . "/../_files/xsl/passthrough.xsl";
$oObject = new Object($src); $oObject = new Object($src);
$oObject->getSource();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
$this->assertEquals($oObject->getSource(), null);
$this->assertEquals($oObject->getStyle(), null);
} }
/** /**

View File

@ -12,6 +12,7 @@ namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Element\Header; use PhpOffice\PhpWord\Element\Header;
use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
/** /**
@ -75,9 +76,10 @@ class SectionTest extends \PHPUnit_Framework_TestCase
{ {
$objectSource = __DIR__ . "/../_files/documents/reader.docx"; $objectSource = __DIR__ . "/../_files/documents/reader.docx";
$imageSource = __DIR__ . "/../_files/images/PhpWord.png"; $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 = new Section(0);
$section->setPhpWord(new PhpWord());
$section->addText(utf8_decode('ä')); $section->addText(utf8_decode('ä'));
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä'));
$section->addTextBreak(); $section->addTextBreak();
@ -96,10 +98,10 @@ class SectionTest extends \PHPUnit_Framework_TestCase
$elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
'Table', 'ListItem', 'Object', 'Image', 'Table', 'ListItem', 'Object', 'Image',
'Title', 'TextRun', 'Footnote', 'CheckBox', 'TOC'); 'Title', 'TextRun', 'Footnote', 'CheckBox', 'TOC');
$i = 0; $elmCount = 0;
foreach ($elementTypes as $elementType) { foreach ($elementTypes as $elementType) {
$this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$i]); $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$elmCount]);
$i++; $elmCount++;
} }
} }
@ -122,6 +124,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
{ {
Style::addTitleStyle(1, array('size' => 14)); Style::addTitleStyle(1, array('size' => 14));
$section = new Section(0); $section = new Section(0);
$section->setPhpWord(new PhpWord());
$section->addTitle('Test', 1); $section->addTitle('Test', 1);
$elementCollection = $section->getElements(); $elementCollection = $section->getElements();
@ -163,6 +166,6 @@ class SectionTest extends \PHPUnit_Framework_TestCase
public function testAddHeaderException() public function testAddHeaderException()
{ {
$object = new Section(1); $object = new Section(1);
$header = $object->addHeader('ODD'); $object->addHeader('ODD');
} }
} }

View File

@ -9,6 +9,8 @@
namespace PhpOffice\PhpWord\Tests\Element; namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Element\Title;
use PhpOffice\PhpWord\Element\TOC; use PhpOffice\PhpWord\Element\TOC;
/** /**
@ -24,11 +26,11 @@ class TOCTest extends \PHPUnit_Framework_TestCase
public function testConstructWithStyleArray() public function testConstructWithStyleArray()
{ {
$expected = array( $expected = array(
'tabPos' => 9062, 'position' => 9062,
'tabLeader' => \PhpOffice\PhpWord\Style\TOC::TABLEADER_DOT, 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT,
'indent' => 200, '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(); $tocStyle = $object->getStyleTOC();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TOC', $tocStyle); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TOC', $tocStyle);
@ -46,7 +48,7 @@ class TOCTest extends \PHPUnit_Framework_TestCase
public function testConstructWithStyleName() public function testConstructWithStyleName()
{ {
$object = new TOC('Font Style'); $object = new TOC('Font Style');
$tocStyle = $object->getStyleTOC(); // $tocStyle = $object->getStyleTOC();
$this->assertEquals('Font Style', $object->getStyleFont()); $this->assertEquals('Font Style', $object->getStyleFont());
} }
@ -56,17 +58,19 @@ class TOCTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetMinMaxDepth() public function testSetGetMinMaxDepth()
{ {
$toc = new TOC();
$titles = array( $titles = array(
'Heading 1' => 1, 'Heading 1' => 1,
'Heading 2' => 2, 'Heading 2' => 2,
'Heading 3' => 3, 'Heading 3' => 3,
'Heading 4' => 4, 'Heading 4' => 4,
); );
foreach ($titles as $text => $depth) {
\PhpOffice\PhpWord\TOC::addTitle($text, $depth);
}
$phpWord = new PhpWord();
foreach ($titles as $text => $depth) {
$phpWord->addTitle(new Title($text, $depth));
}
$toc = new TOC();
$toc->setPhpWord($phpWord);
$this->assertEquals(1, $toc->getMinDepth()); $this->assertEquals(1, $toc->getMinDepth());
$this->assertEquals(9, $toc->getMaxDepth()); $this->assertEquals(9, $toc->getMaxDepth());

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Tests\Element; namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\Element\TextRun;
/** /**
@ -113,7 +114,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
public function testAddTextBreak() public function testAddTextBreak()
{ {
$oTextRun = new TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addTextBreak(2); $oTextRun->addTextBreak(2);
$this->assertCount(2, $oTextRun->getElements()); $this->assertCount(2, $oTextRun->getElements());
} }
@ -138,6 +139,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
public function testCreateFootnote() public function testCreateFootnote()
{ {
$oTextRun = new TextRun(); $oTextRun = new TextRun();
$oTextRun->setPhpWord(new PhpWord());
$element = $oTextRun->addFootnote(); $element = $oTextRun->addFootnote();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $element);

View File

@ -40,28 +40,6 @@ class TitleTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($oTitle->getStyle(), null); $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 * Get bookmark Id
*/ */

View File

@ -1,39 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\Endnotes;
/**
* Test class for PhpOffice\PhpWord\Endnotes
*
* @runTestsInSeparateProcesses
*/
class EndnotesTest extends \PHPUnit_Framework_TestCase
{
/**
* Test endnote collection
*/
public function testEndnotes()
{
$endnote1 = new \PhpOffice\PhpWord\Element\Endnote();
$endnote2 = new \PhpOffice\PhpWord\Element\Endnote();
$rId = Endnotes::addElement($endnote1);
Endnotes::setElement(1, $endnote2);
$this->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());
}
}

View File

@ -1,39 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\Footnotes;
/**
* Test class for PhpOffice\PhpWord\Footnotes
*
* @runTestsInSeparateProcesses
*/
class FootnotesTest extends \PHPUnit_Framework_TestCase
{
/**
* Test footnote collection
*/
public function testFootnotes()
{
$footnote1 = new \PhpOffice\PhpWord\Element\Footnote();
$footnote2 = new \PhpOffice\PhpWord\Element\Footnote();
$rId = Footnotes::addElement($footnote1);
Footnotes::setElement(1, $footnote2);
$this->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());
}
}

View File

@ -51,9 +51,8 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
public function testCreateGetSections() public function testCreateGetSections()
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$this->assertEquals(new Section(1), $phpWord->addSection());
$phpWord->addSection(); $phpWord->addSection();
$this->assertEquals(2, count($phpWord->getSections())); $this->assertEquals(1, count($phpWord->getSections()));
} }
/** /**

View File

@ -23,9 +23,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetCompatibility() public function testSetGetCompatibility()
{ {
$this->assertTrue(Settings::getCompatibility()); $this->assertTrue(Settings::hasCompatibility());
$this->assertTrue(Settings::setCompatibility(false)); $this->assertTrue(Settings::setCompatibility(false));
$this->assertFalse(Settings::getCompatibility()); $this->assertFalse(Settings::hasCompatibility());
$this->assertFalse(Settings::setCompatibility('Non boolean')); $this->assertFalse(Settings::setCompatibility('Non boolean'));
} }

View File

@ -32,7 +32,7 @@ class DrawingTest extends \PHPUnit_Framework_TestCase
$result = Drawing::pixelsToEMU($value); $result = Drawing::pixelsToEMU($value);
$this->assertEquals(round($value * 9525), $result); $this->assertEquals(round($value * 9525), $result);
$result = Drawing::EMUToPixels($value); $result = Drawing::emuToPixels($value);
$this->assertEquals(round($value / 9525), $result); $this->assertEquals(round($value / 9525), $result);
$result = Drawing::pixelsToPoints($value); $result = Drawing::pixelsToPoints($value);

View File

@ -25,8 +25,6 @@ class FontTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConversions() public function testConversions()
{ {
$phpWord = new PhpWord();
$original = 1; $original = 1;
$result = Font::fontSizeToPixels($original); $result = Font::fontSizeToPixels($original);

View File

@ -56,7 +56,6 @@ class CellTest extends \PHPUnit_Framework_TestCase
{ {
$object = new Cell(); $object = new Cell();
$default = '000000';
$value = 'FF0000'; $value = 'FF0000';
$object->setStyleValue('borderColor', $value); $object->setStyleValue('borderColor', $value);

View File

@ -27,8 +27,8 @@ class TOCTest extends \PHPUnit_Framework_TestCase
$object = new TOC(); $object = new TOC();
$properties = array( $properties = array(
'tabPos' => 9062, 'position' => 9062,
'tabLeader' => TOC::TABLEADER_DOT, 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT,
'indent' => 200, 'indent' => 200,
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
@ -37,10 +37,6 @@ class TOCTest extends \PHPUnit_Framework_TestCase
$get = "get{$key}"; $get = "get{$key}";
$object->$set($value); $object->$set($value);
$this->assertEquals($value, $object->$get()); $this->assertEquals($value, $object->$get());
// setStyleValue
$object->setStyleValue("{$key}", null);
$this->assertEquals(null, $object->$get());
} }
} }
} }

View File

@ -1,53 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\TOC;
/**
* Test class for PhpOffice\PhpWord\TOC
*
* @runTestsInSeparateProcesses
*/
class TOCTest extends \PHPUnit_Framework_TestCase
{
/**
* Add and get title
*/
public function testAddAndGetTitle()
{
$titleCount = 3;
$anchor = '_Toc' . (252634154 + $titleCount);
$bookmark = $titleCount - 1;
$titles = array(
'Heading 1' => 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()));
}
}

View File

@ -129,7 +129,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
{ {
$object = new ODText(); $object = new ODText();
$object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR); $object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR);
$this->assertTrue($object->getUseDiskCaching()); $this->assertTrue($object->isUseDiskCaching());
$this->assertEquals(PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory()); $this->assertEquals(PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory());
} }

View File

@ -48,7 +48,6 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase
public function testSetGetAbstractRendererProperties() public function testSetGetAbstractRendererProperties()
{ {
define('DOMPDF_ENABLE_AUTOLOAD', false); define('DOMPDF_ENABLE_AUTOLOAD', false);
$file = __DIR__ . "/../../_files/temp.pdf";
$rendererName = Settings::PDF_RENDERER_DOMPDF; $rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf'); $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');

View File

@ -47,5 +47,6 @@ class PDFTest extends \PHPUnit_Framework_TestCase
public function testConstructException() public function testConstructException()
{ {
$writer = new PDF(new PhpWord()); $writer = new PDF(new PhpWord());
$writer->save();
} }
} }

View File

@ -361,11 +361,11 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
// Test the attributes // Test the attributes
$i = 0; $attributeCount = 0;
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
$i++; $attributeCount++;
$nodeName = ($key == 'align') ? 'jc' : $key; $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') { if ($key != 'align') {
$value = $value ? 1 : 0; $value = $value ? 1 : 0;
} }
@ -416,7 +416,6 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
public function testWriteTableStyle() public function testWriteTableStyle()
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$tWidth = 120;
$rHeight = 120; $rHeight = 120;
$cWidth = 120; $cWidth = 120;
$imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg";
@ -511,7 +510,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$lineNumberingPath = '/w:document/w:body/w:sectPr/w:lnNumType'; $lineNumberingPath = '/w:document/w:body/w:sectPr/w:lnNumType';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array())); $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array()));
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$this->assertEquals(240, $doc->getElement($pageMarginPath)->getAttribute('w:gutter')); $this->assertEquals(240, $doc->getElement($pageMarginPath)->getAttribute('w:gutter'));

View File

@ -171,13 +171,13 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
public function testSetGetUseDiskCaching() public function testSetGetUseDiskCaching()
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $phpWord->addSection();
$object = new Word2007($phpWord); $object = new Word2007($phpWord);
$object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR); $object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR);
$writer = new Word2007($phpWord); $writer = new Word2007($phpWord);
$writer->save('php://output'); $writer->save('php://output');
$this->assertTrue($object->getUseDiskCaching()); $this->assertTrue($object->isUseDiskCaching());
} }
/** /**